-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.lua
More file actions
113 lines (91 loc) · 3.12 KB
/
Copy pathmain.lua
File metadata and controls
113 lines (91 loc) · 3.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
require "constants"
require "Animation"
require "app.Context"
local SceneId = require "enums.SceneId"
local Sound = require "util.Sound"
local push = require "libraries.push"
require "players.BasePlayer"
require "players.BasePlayerController"
require "players.HumanPlayerController"
require "players.AIPlayerController"
require "SceneManager"
require "CardManager"
require "CharacterManager"
require "ResourceManager"
require "RunState"
require "scenes.BaseScene"
require "scenes.MenuScene"
require "scenes.CardBrowseScene"
require "scenes.CharacterSelectScene"
require "scenes.BattleScene"
require "scenes.PauseScene"
require "scenes.GameOverScene"
require "scenes.BattleEndScene"
function love.load()
lg = love.graphics
lg.setDefaultFilter("nearest", "nearest")
push:setupScreen(GAME_WIDTH, GAME_HEIGHT, GAME_WIDTH, GAME_HEIGHT, {
fullscreen = true,
resizable = false,
pixelperfect = false,
highdpi = true,
canvas = true,
})
push:setBorderColor(COLORS.BLACK)
math.randomseed(os.time())
love.keyboard.setKeyRepeat(true)
-- Initialize context
ctx = Context:new()
-- Initialize resources
ctx.resourceManager:loadAllAssets(ctx.cardManager:getAllCardNames())
ctx.resourceManager:loadCharacterAssets(ctx.characterManager)
-- Cache fonts/images in context (removes need for global `font*` and `background`)
ctx.fonts.fontXL = ctx.resourceManager:getFont("fontXL")
ctx.fonts.fontL = ctx.resourceManager:getFont("fontL")
ctx.fonts.fontM = ctx.resourceManager:getFont("fontM")
ctx.fonts.fontS = ctx.resourceManager:getFont("fontS")
ctx.assets.background = ctx.resourceManager:getImage("background")
-- Initialize scenes
ctx.sceneManager:addScene(MenuScene:new(ctx))
ctx.sceneManager:addScene(CardBrowseScene:new(ctx))
ctx.sceneManager:addScene(CharacterSelectScene:new(ctx))
ctx.sceneManager:addScene(BattleScene:new(ctx))
ctx.sceneManager:addScene(PauseScene:new(ctx))
ctx.sceneManager:addScene(GameOverScene:new(ctx))
ctx.sceneManager:addScene(BattleEndScene:new(ctx))
ctx.sceneManager:changeScene(SceneId.Menu)
local backgroundMusic = ctx.resourceManager:getSound("music")
backgroundMusic:setLooping(true)
backgroundMusic:setVolume(0.5)
backgroundMusic:play()
end
function love.keypressed(key)
ctx.sceneManager:keypressed(key)
end
function love.update(dt)
ctx.sceneManager:update(dt)
end
function love.draw()
push:apply("start")
lg.clear(COLORS.BLACK)
-- Background
local saturationShader = ctx.resourceManager:getShader("saturation")
lg.setShader(saturationShader)
saturationShader:send("saturation", 0.75)
lg.draw(ctx.assets.background, 0, 0, 0, PIXEL_TO_GAME_SCALE, PIXEL_TO_GAME_SCALE)
lg.setShader()
lg.setColor({ 0, 0, 0, 0.25 })
lg.rectangle("fill", 0, 0, GAME_WIDTH, GAME_HEIGHT)
-- Draw current scene
ctx.sceneManager:draw()
push:apply("end")
end
function love.resize(w, h)
push:resize(w, h)
end
function love.textinput(t)
ctx.sceneManager:textinput(t)
end
function love.wheelmoved(dx, dy)
ctx.sceneManager:wheelmoved(dx, dy)
end