-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.lua
executable file
·80 lines (66 loc) · 1.96 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
math.randomseed(os.time())
require 'src/dependencies'
require 'src/constants'
function love.load()
love.window.setTitle('Space Wars')
push:setupScreen(VIRTUAL_WIDTH, VIRTUAL_HEIGHT, WINDOW_WIDTH, WINDOW_HEIGHT, {
fullscreen = false,
resizable = true
})
offsetY = 0
offsetX = 0
gAudio['explosion']:setVolume(0.25)
gAudio['powerup-1']:setVolume(0.25)
gAudio['bullets']:setVolume(0.25)
backgroundWidth, backgroundHeight = background:getDimensions()
-- statemachine implementation
gStateMachine = StateMachine{
['start'] = function () return StartState() end,
['select-craft'] = function () return CraftSelectState() end,
['play'] = function () return PlayState() end,
['shop'] = function () return ShopState() end,
['boss'] = function () return BossState() end,
['end'] = function () return EndState() end
}
gStateMachine:change('start')
love.keyboard.keypressed = {}
end
function love.update(dt)
if love.keyboard.wasPressed('escape') then
love.event.quit()
end
Timer.update(dt)
gStateMachine:update(dt)
-- background parallax scrolling
offsetY = offsetY + SCROLL_SPEED * dt
offsetY = offsetY % (0.5 * backgroundHeight)
love.keyboard.keypressed = {}
end
function love.resize(w, h)
return push:resize(w, h)
end
function love.keypressed(key)
love.keyboard.keypressed[key] = true
end
function love.keyboard.wasPressed(key)
return love.keyboard.keypressed[key]
end
function love.draw()
push:start()
--draw here
--love.graphics.translate(offsetX, offsetY)
love.graphics.draw(background, offsetX, - (0.5 * backgroundHeight) + offsetY)
gStateMachine:render()
push:finish()
end
function tableIsEmpty(table)
local counter = 0
for i, v in pairs (table) do
counter = counter + 1
end
if counter == 0 then
return true
else
return false
end
end