forked from bloonguyen1207/radon_run
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.lua
139 lines (110 loc) · 3.94 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
require './src/Dependencies'
-- size of our actual window
WINDOW_WIDTH = 1280
WINDOW_HEIGHT = 720
-- size we're trying to emulate with push
VIRTUAL_WIDTH = 432
VIRTUAL_HEIGHT = 243
-- Game title and shit
GAME_TITLE = 'Radon Run'
BACKGROUND_SCROLL_SPEED = 60
GRAVITY = 7
TOTAL_GHOST_COUNT = 3
function love.load()
-- set love's default filter to "nearest-neighbor", which essentially
-- means there will be no filtering of pixels (blurriness), which is
-- important for a nice crisp, 2D look
love.graphics.setDefaultFilter('nearest', 'nearest')
-- set the title of our application window
love.window.setTitle(GAME_TITLE)
-- seed the RNG so that calls to random are always random
math.randomseed(os.time())
Player = Player()
Obstacles = {
Obstacle(gGraphics['obstacles']['longTable'], 14),
Obstacle(gGraphics['obstacles']['lamp'], 17, 15),
Obstacle(gGraphics['obstacles']['mirror'], 108, 16),
Obstacle(gGraphics['obstacles']['bookcase'], 180),
Obstacle(gGraphics['obstacles']['diningTable'], 324),
}
Tiles = {
Tile(50, 120),
Tile(125, 75),
Tile(255, 75),
Tile(335, 120),
}
Ghosts = {
Ghost(gGraphics['ghosts']['adam'], 50, 150),
Ghost(gGraphics['ghosts']['bob'], 224, 95, -1),
Ghost(gGraphics['ghosts']['carl'], 330, 30),
}
Monitor = Monitor(VIRTUAL_WIDTH - 50, 30)
gStateMachine = StateMachine {
['menu'] = function() return MenuState() end,
['info'] = function() return InfoState() end,
['play'] = function() return PlayState() end,
['ghostInfo'] = function() return GhostInfoState() end,
}
gStateMachine:change('menu', {})
-- initialize our virtual resolution, which will be rendered within our
-- actual window no matter its dimensions
push:setupScreen(VIRTUAL_WIDTH, VIRTUAL_HEIGHT, WINDOW_WIDTH, WINDOW_HEIGHT, {
fullscreen = false,
resizable = true,
vsync = true
})
-- a table we'll use to keep track of which keys have been pressed this
-- frame, to get around the fact that LÖVE's default callback won't let us
-- test for input from within other functions
love.keyboard.keysPressed = {}
end
--[[
Called whenever we change the dimensions of our window, as by dragging
out its bottom corner, for example. In this case, we only need to worry
about calling out to `push` to handle the resizing. Takes in a `w` and
`h` variable representing width and height, respectively.
]]
function love.resize(w, h)
push:resize(w, h)
end
function love.update(dt)
gStateMachine:update(dt)
-- reset keys pressed
love.keyboard.keysPressed = {}
end
--[[
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.keyboard.wasPressed(key)
if love.keyboard.keysPressed[key] then
return true
else
return false
end
end
--[[
Called each frame after update; is responsible simply for
drawing all of our game objects and more to the screen.
]]
function love.draw()
love.graphics.setFont( gFonts['small'] )
-- begin drawing with push, in our virtual resolution
push:start()
love.graphics.draw(gGraphics['background'], 0, 0)
love.graphics.draw(gGraphics['ground'], 0, VIRTUAL_HEIGHT - 48)
-- use the state machine to defer rendering to the current state we're in
gStateMachine:render()
push:finish()
end