-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.lua
123 lines (104 loc) · 3.63 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
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
114
115
116
117
118
119
120
121
122
123
require "src/Dependencies"
gameWidth, gameHeight = 640, 480 -- fixed game resolution
function love.load()
love.graphics.setDefaultFilter('nearest', 'nearest')
love.window.setTitle("It’s Raining Burgers!")
-- seed the RNG so that calls to random are always random
math.randomseed(os.time())
-- the state machine we'll be using to transition between various states
-- in our game instead of clumping them together in our update and draw
-- methods
--
-- our current game state can be any of the following:
-- 1. 'start' (the beginning of the game, where we're told to press Enter)
gStateMachine = StateMachine {
['start'] = function()
return StartState()
end,
['play'] = function()
return PlayState()
end,
['ready'] = function()
return ReadyState()
end,
['award'] = function()
return AwardState()
end,
['gameOver'] = function()
return GameOverState()
end
}
gStateMachine:change('start')
push:setupScreen(gStateMachine.width, gStateMachine.height, gameWidth, gameHeight, {
resizable = true
})
gTextures = {
['background'] = love.graphics.newImage('asset/sprites/background.png'),
['lettuce'] = love.graphics.newImage('asset/sprites/lettuce.png'),
['lowerBun'] = love.graphics.newImage('asset/sprites/lowerBun.png'),
['meat'] = love.graphics.newImage('asset/sprites/meat.png'),
['tomato'] = love.graphics.newImage('asset/sprites/tomato.png'),
['upperBun'] = love.graphics.newImage('asset/sprites/upperBun.png')
}
gAudioManager = AudioManager()
-- a table we'll use to keep track of which keys have been pressed this
-- frame, to get around the fact that Love's default callback won't let us
-- test for input from within other functions
love.keyboard.keysPressed = {}
love.mouse.keysPressed = {}
love.mouse.keysReleased = {}
end
function love.update(dt)
-- we pass in dt to the state object we're currently using
gStateMachine:update(dt)
-- reset keys pressed
love.keyboard.keysPressed = {}
love.mouse.keysPressed = {}
love.mouse.keysReleased = {}
end
function love.draw()
push:apply('start')
gStateMachine:render()
DisplayFPS()
push:apply('end')
end
function love.resize(w, h)
push:resize(w, h)
end
-- HANDLING KEY PRESSING
--[[
A callback that processes key strokes as they happen, just the once.
Does not account for keys that are held down, which is handled by a
separate function (`love.keyboard.isDown`). Useful for when we want
things to happen right away, just once, like when we want to quit.
]]
function love.keypressed(key)
-- add to our table of keys pressed this frame
love.keyboard.keysPressed[key] = true
end
--[[
A custom function that will let us test for individual keystrokes outside
of the default `love.keypressed` callback, since we can't call that logic
elsewhere by default.
]]
function love.mousepressed(x, y, key)
love.mouse.keysPressed[key] = true
end
function love.mousereleased(x, y, key)
love.mouse.keysReleased[key] = true
end
function love.keyboard.wasPressed(key)
return love.keyboard.keysPressed[key]
end
function love.mouse.wasPressed(key)
return love.mouse.keysPressed[key]
end
function love.mouse.wasReleased(key)
return love.mouse.keysReleased[key]
end
function DisplayFPS()
-- simple FPS display across all states
love.graphics.setColor(0, 1, 0, 1)
--love.graphics.print('FPS: ' .. tostring(love.timer.getFPS()), 5, 5)
love.graphics.setColor(1, 1, 1, 1)
end