This repository has been archived by the owner on Oct 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.lua
207 lines (168 loc) · 4.5 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
198
199
200
201
202
203
204
205
206
207
love2dAudioPlay = love.audio.play -- slam can not deal with love2d 11.0 play method which can take table of sources
require 'src/slam' -- https://github.com/vrld/slam
gameBackground = require 'src/background'
game = require 'src/game'
mainmenu = require 'src/mainmenu'
-- /!\ too much indistinguishable letters for gameplay on futur_font, menu only.
defaultFont, futurFontTiny, futurFont, futurFontHuge = nil
-- Stats
stats =
{
score = 0,
bestScore = 0,
combo = 0,
bestCombo = 0,
waveLevel = 0,
bestWave = 0,
scoreTheme = 0,
bestScoreTheme = 0,
comboTheme = 0,
bestComboTheme = 0,
waveLevelTheme = 0,
bestWaveTheme = 0,
scoreCustom = 0,
bestScoreCustom = 0,
comboCustom = 0,
bestComboCustom = 0,
waveLevelCustom = 0,
}
gameState =
{
mainmenu = true,
game = false,
pause = false
}
mode =
{
classic = true,
theme = false,
custom = false
}
local currentState = mainmenu
local pausedAudioSources = nil
windowWidth = 512
windowHeight = 836
function switchState(newState)
gameState[currentState.state] = false
currentState.stop()
currentState = newState
currentState.play()
gameState[currentState.state] = true
end
function love.load()
love.window.setTitle("ZZType")
--love.window.setMode(windowWidth, windowHeight)
love.filesystem.setIdentity("ZZType")
num = 0
textdbg = ""
defaultFont = love.graphics.getFont()
futurFontTiny = love.graphics.newFont("resources/Kenney_Rocket_Square.ttf", 7)
futurFont = love.graphics.newFont("resources/Kenney_Rocket_Square.ttf", 15)
futurFontHuge = love.graphics.newFont("resources/Kenney_Rocket_Square.ttf", 70)
loadStats()
gameBackground.initialize()
mainmenu.initialize()
game.initialize()
currentState.play()
end
function love.update(dt)
if gameIsPaused then
return
end
currentState.update(dt)
end
function love.draw()
gameBackground.draw()
currentState.draw()
-- debug
--love.graphics.print(textdbg, 350, 750)
end
function love.focus(f)
gameIsPaused = not f
if (gameIsPaused == true) then
pausedAudioSources = love.audio.pause()
else
if (pausedAudioSources ~= nil) then
love2dAudioPlay(pausedAudioSources)
end
end
end
function love.quit()
saveStats()
end
function love.textinput(t)
currentState.textinput(t)
end
function love.keypressed(key)
currentState.keypressed(key)
end
function love.mousepressed(x, y, button, istouch, presses)
currentState.mousepressed(x, y, button, istouch, presses)
if (button == 2) then
background.reroll()
end
end
function love.mousemoved(x, y, dx, dy, istouch)
currentState.mousemoved(x, y, dx, dy, istouch)
end
function loadStats()
local fileName = "stats.lua"
if love.filesystem.getInfo(fileName) == nil then
love.filesystem.newFile(fileName)
saveStats()
end
loadedStats = love.filesystem.load(fileName)
loadedStats()
end
function saveStats()
local fileName = "stats.lua"
if love.filesystem.getInfo(fileName) == nil then
love.filesystem.newFile(fileName)
end
save = "stats.score = " .. stats.score
save = save.. ";stats.bestScore = " .. stats.bestScore
save = save.. ";stats.bestCombo = " .. stats.bestCombo
save = save.. ";stats.waveLevel = " .. stats.waveLevel
save = save.. ";stats.bestWave = " .. stats.bestWave
save = save.. ";stats.scoreTheme = " .. stats.scoreTheme
save = save.. ";stats.bestScoreTheme = " .. stats.bestScoreTheme
save = save.. ";stats.bestComboTheme = " .. stats.bestComboTheme
save = save.. ";stats.waveLevelTheme = " .. stats.waveLevelTheme
save = save.. ";stats.bestWaveTheme = " .. stats.bestWaveTheme
save = save.. ";stats.scoreCustom = " .. stats.scoreCustom
save = save.. ";stats.bestScoreCustom = " .. stats.bestScoreCustom
save = save.. ";stats.bestComboCustom = " .. stats.bestComboCustom
save = save.. ";stats.waveLevelCustom = " .. stats.waveLevelCustom
love.filesystem.write(fileName, save)
end
function stats.setStat(name, value)
if (mode.classic == true) then
if (stats[name] ~= nil) then
stats[name] = value
end
elseif (mode.theme == true) then
if (stats[name.."Theme"] ~= nil) then
stats[name.."Theme"] = value
end
else
if (stats[name.."Custom"] ~= nil) then
stats[name.."Custom"] = value
end
end
end
function stats.getStat(name)
if (mode.classic == true) then
if (stats[name] ~= nil) then
return stats[name]
end
elseif (mode.theme == true) then
if (stats[name.."Theme"] ~= nil) then
return stats[name.."Theme"]
end
else
if (stats[name.."Custom"] ~= nil) then
return stats[name.."Custom"]
end
end
return 0
end