/
main.lua
66 lines (49 loc) · 1.41 KB
/
main.lua
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
--[[
Asteriod Fighter
By lwz7512 @2020/12/01
Idea from:
https://arcade.academy/examples/asteroid_smasher.html
]]
require 'src/Dependencies'
love.graphics.setDefaultFilter('nearest', 'nearest')
function love.load()
love.graphics.setFont(gFonts['medium'])
love.window.setTitle('Asteriod Fighter')
math.randomseed(os.time())
push:setupScreen(VIRTUAL_WIDTH, VIRTUAL_HEIGHT, WINDOW_WIDTH, WINDOW_HEIGHT, {
fullscreen = false,
vsync = true,
resizable = true,
canvas = false
})
gStateMachine = StateMachine {
['start'] = function() return StartState() end,
['play'] = function() return PlayState() end,
['over'] = function() return EndState() end,
['levelup'] = function() return LevelUpState() end,
['won'] = function() return WonState() end,
}
gStateMachine:change('start', {level = START_LEVEL, score = 0})
love.keyboard.keysPressed = {}
end
function love.resize(w, h)
push:resize(w, h)
end
function love.keypressed(key)
if key == 'escape' then
love.event.quit()
end
love.keyboard.keysPressed[key] = true
end
function love.keyboard.wasPressed(key)
return love.keyboard.keysPressed[key]
end
function love.update(dt)
gStateMachine:update(dt)
love.keyboard.keysPressed = {}
end
function love.draw()
push:start()
gStateMachine:render()
push:finish()
end