-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.lua
197 lines (162 loc) · 5.3 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
-- require("lib/lovedebug")
flux = require("lib/flux")
require("modules/resources")
require("modules/utils")
require("modules/transitions")
require("modules/window")
require("modules/buttons")
require("scenes/menu")
require("scenes/game")
require("scenes/credits")
-- =============================================================
-- Variables
global = {
debug = true,
borderless = false,
width = 640,
height = 360,
screenWidth = 0,
screenHeight = 0,
hFullscreenScale = 1,
vFullscreenScale = 1,
scaledFullscreen = false,
hScaleBefore = 1,
vScaleBefore = 1,
volume = 1,
inGame = false,
inCredits = false,
easing = "backout"
}
settings = {
hScale = 1,
vScale = 1,
fullscreen = false,
sound = true
}
-- =============================================================
-- Love2D main functions
function love.load()
-- load settings
if not love.filesystem.exists("data.bin") then love.filesystem.write("data.bin", table.show(settings, "settings")) end
settingsChunk = love.filesystem.load("data.bin")
settingsChunk()
setupWindow()
math.randomseed(os.time())
-- load resources
loadImg("menu", "menu.png")
loadImg("credits", "credits.png")
loadImg("game", "game.png")
loadImg("btnPlayUp", "btn-play-up.png")
loadImg("btnPlayDown", "btn-play-down.png")
loadSfx("select_0", "select_0.ogg")
loadSfx("select_1", "select_1.ogg")
loadSfx("select_2", "select_2.ogg")
loadSfx("select_3", "select_3.ogg")
loadBgm("music", "music.mp3")
loadSfx("yaay", "yaay.ogg")
loadFont("font", "smart.ttf", 32)
loadRes()
-- setup objects
-- button.play.up = res.img.playUp
-- button.play.down = res.img.playDown
-- button.play.width = button.play.up:getWidth()
-- button.play.height = button.play.up:getHeight()
-- button.play.x = global.width / 2 - (button.play.up:getWidth() / 2)
-- button.play.y = global.height * 3 / 4 - (button.play.down:getHeight() / 2) - 10
-- button.exit.up = res.img.exitUp
-- button.exit.down = res.img.exitDown
-- button.exit.width = button.exit.up:getWidth()
-- button.exit.height = button.exit.up:getHeight()
button.play.up = res.img.btnPlayUp
button.play.down = res.img.btnPlayDown
button.play.width = button.play.up:getWidth()
button.play.height = button.play.up:getHeight()
button.play.x = 32
button.play.y = 280
love.graphics.setFont(res.fnt.font)
if settings.sound then res.bgm.music:play() end
end
-- -------------------------------------------------------------
function love.update(dt)
flux.update(dt)
if not timers.inTransition then
if global.inGame then
updateGame(dt)
elseif global.inCredits then
updateCredits(dt)
else
updateMenu(dt)
end
end
updateTimers(dt)
end
-- -------------------------------------------------------------
function love.draw(dt)
if global.inGame then
drawGame(dt)
elseif global.inCredits then
drawCredits(dt)
else
drawMenu(dt)
end
if timers.inTransition then
drawTransition()
end
if global.debug then
local yy = 5
love.graphics.setColor(255, 255, 255, 255)
love.graphics.print("::Debug::", 5, yy)
yy = yy + 25
love.graphics.print("FPS: " .. love.timer.getFPS(), 5, yy)
yy = yy + 25
love.graphics.print("play.isDown: " .. tostring(button.play.isDown), 5, yy)
yy = yy + 25
love.graphics.print("mouse on button: " .. tostring(boxHit(love.mouse.getX(), love.mouse.getY(), button.play.x * settings.hScale, button.play.y * settings.vScale, button.play.width * settings.hScale, button.play.height * settings.vScale)), 5, yy)
end
end
-- -------------------------------------------------------------
function love.keypressed(k)
if not timers.inTransition then
if k == "+" then scaleUpWindow() return end
if k == "-" then scaleDownWindow() return end
if k == "return" and love.keyboard.isDown("lalt", "ralt", "alt") then
toggleFullscreen()
return
end
end
end
-- -------------------------------------------------------------
function love.keyreleased(k)
if not timers.toGame and not timers.toMenu then
-- quit the game
if k == "escape" then
if global.inGame or global.inCredits then
timers.inTransition = true
timers.toMenu = true
startTransition()
res.sfx.select_1:play()
else
res.sfx.select_0:play()
timers.inTransition = true
timers.exit = true
exitTransition()
end
return
end
end
end
-- -------------------------------------------------------------
function love.mousepressed(x, y, b)
buttonPressed(x, y, b)
end
-- -------------------------------------------------------------
function love.mousereleased(x, y, b)
buttonReleased(x, y, b)
end
-- -------------------------------------------------------------
function love.mousemoved(x, y, dx, dy) end
-- -------------------------------------------------------------
function love.quit()
storeWindowScale()
love.filesystem.write("data.bin", table.show(settings, "settings"))
end