-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.lua
71 lines (55 loc) · 1.64 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
require 'src/Dependencies'
function love.load()
math.randomseed(os.time())
love.graphics.setDefaultFilter('nearest', 'nearest')
push:setupScreen(VIRTUAL_WIDTH, VIRTUAL_HEIGHT, WINDOW_WIDTH, WINDOW_HEIGHT, {
vsync = true,
fullscreen = false,
resizable = true
})
smallFont = love.graphics.newFont('fonts/font.ttf', 8)
mediumFont = love.graphics.newFont('fonts/font.ttf', 28)
hugeFont = love.graphics.newFont('fonts/font.ttf', 56)
love.keyboard.keysPressed = {}
gStateMachine = StateMachine {
['title'] = function() return StartState() end,
['play'] = function() return PlayState() end,
['gameOver'] = function() return GameOverState() end
}
gStateMachine:change('title')
gSounds = {
['jump'] = love.audio.newSource('sounds/jump.wav', 'static'),
['hurt'] = love.audio.newSource('sounds/hurt.wav', 'static'),
['score'] = love.audio.newSource('sounds/score.wav', 'static'),
['music'] = love.audio.newSource('sounds/backgroundSound.mp3', 'static')
}
for k, s in pairs(gSounds) do
s:setVolume(0.5)
end
gSounds['music']:setLooping(true)
gSounds['music']:play()
end
function love.resize(w, h)
push:resize(w, h)
end
function love.keypressed(key)
if love.keyboard.isDown('escape') then
love.event.quit()
end
love.keyboard.keysPressed[key] = true
end
function love.keyboard.wasPressed(key)
if love.keyboard.keysPressed[key] then
return true
end
return false
end
function love.update(dt)
gStateMachine:update(dt)
love.keyboard.keysPressed = {}
end
function love.draw()
push:apply('start')
gStateMachine:render()
push:apply('end')
end