This repository has been archived by the owner on Oct 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.lua
304 lines (288 loc) · 8.11 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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
-- Main requires Lane, Note, Song
-- Song requires Lane, Note, Tween
function percentWidth(percent)
-- DOESN'T TAKE A DECIMAL! TAKES AN INTEGER (0 - 100)
return love.graphics.getWidth() * (percent / 100)
end
function percentHeight(percent)
-- DOESN'T TAKE A DECIMAL! TAKES AN INTEGER (0 - 100)
return love.graphics.getHeight() * (percent / 100)
end
function convertBeatTime(BPM, beatTime, measure, offset)
-- Due to the way this is made, only supports 4/4 for the time being
local BPS = BPM / 60
local secondsToNextMeasure = 4 / BPS
local Time = secondsToNextMeasure * measure
Time = Time + (beatTime * secondsToNextMeasure)
return Time - offset
end
function love.load()
timeElapsedSinceStart = 0
math.randomseed(os.time())
print("// - // Break the rules // - //")
--love.window.setMode(711, 400, { fullscreen = true, vsync = 0 })
Lane = require("lane")
Note = require("note")
Song = require("song")
keys = {
"d", "f", "j", "k"
}
lanes = Song.Lanes
notes = Song.Notes
currentLong = {}
if Song.Info.UseBPM then
print("Using BPM")
Song.Info.OriginalOffset = Song.Info.Offset
for _, i in next, notes do
i.OriginalMeasure = i.Measure
end
for n, i in next, notes do
if i.Time == 0 then
-- Another really terrible solution that might need to be changed in the future
-- It works for now tho.
if i.ChangeBPM then
Song.Info.Offset = -convertBeatTime(Song.Info.BPM, 0, i.OriginalMeasure, Song.Info.OriginalOffset)
for m, j in next, notes do
if m > n then
j.Measure = j.Measure - i.Measure
if j.Long then
j.LongMeasure = j.LongMeasure - i.Measure
end
end
end
i.Measure = 0
--print(n, i.ChangeBPM, Song.Info.Offset)
Song.Info.BPM = i.ChangeBPM
end
i.Time = convertBeatTime(Song.Info.BPM, i.BeatTime, i.Measure, Song.Info.Offset)
--[[ now this is what the cool kids call "debugging"
i call it torture but its the same thing
if n == 29 or n == 30 then
print("--- "..n.." ---")
print(i.BeatTime)
print(i.Measure, i.OriginalMeasure)
print(Song.Info.Offset)
print(Song.Info.BPM)
print(i.Time)
print("--- PROCESS ---")
local BPS = Song.Info.BPM / 60
print("BPS = BPM / 60 = "..BPS)
local STOMEAS = 4 / BPS
print("STOMEAS = 4 / BPS = "..STOMEAS)
local TIME = STOMEAS * i.OriginalMeasure
print("TIME = STOMEAS * MEASURE = "..TIME)
TIME = TIME + 0 * STOMEAS
print("TIME = TIME + BEATTIME * STOMEAS = "..TIME)
TIME = TIME - Song.Info.Offset
print("FINAL = TIME - OFFSET = "..TIME)]]
--[[local BPS = BPM / 60
local secondsToNextMeasure = 4 / BPS
local Time = secondsToNextMeasure * measure
Time = Time + (beatTime * secondsToNextMeasure)
return Time - offset
end]]
if i.Long then
i.LongEnd = convertBeatTime(Song.Info.BPM, i.LongBeatTime, i.LongMeasure, Song.Info.Offset)
--print(i.LongEnd)
end
end
end
end
if Song.Info.File and love.filesystem.getInfo(Song.Info.File).type == "file" then
print("Playing music")
love.audio.newSource(Song.Info.File, "stream"):play()
end
-- Some Judgement stuff
ShowJudgement = false
JudgementTimer = 2
JudgementText = ""
function judgementFunc(judge)
ShowJudgement = true
JudgementTimer = 2
JudgementText = judge
end
end
-- timeElapsedSinceStart should be used for checking accuracy
function love.update(d)
timeElapsedSinceStart = timeElapsedSinceStart + d
for n, i in next, notes do
if timeElapsedSinceStart <= i.Time + .05 and not i.Hittable then
if i.Link then i.Link() end
table.remove(notes, n)
end
if timeElapsedSinceStart > i.Time + .25 and i.Hittable then
--print("Miss!")
judgementFunc("Miss...")
if i.Link then i.Link() end
table.remove(notes, n)
end
if timeElapsedSinceStart < i.Time - 10 then
break
end
end
if ShowJudgement then
JudgementTimer = JudgementTimer - d
if JudgementTimer < 0 then
ShowJudgement = false
end
end
if Song.OnUpdate then
Song.OnUpdate(timeElapsedSinceStart)
end
end
function love.keypressed(key, scankey)
-- Change this to F11 when this goes standalone
if key == "f11" then
love.window.setFullscreen(not love.window.getFullscreen())
-- Quitting the game by hitting escape.
elseif key == "escape" then
local QuitMessages = {
"See ya!",
"Now get back to work.",
"Quitting...",
"Come back soon!"
}
print(QuitMessages[math.random(#QuitMessages)])
love.event.quit()
end
for n, i in next, keys do
if key == i then
for m, j in next, lanes do
if lanes[n].Input == j.Input then
j.Pressed = true
local availableNotes = 4
for o, k in next, notes do
if not k.Hittable then availableNotes = availableNotes + 1 end
if o > availableNotes then break end
if k.Hittable
and k.Lane == m
and timeElapsedSinceStart >= k.Time - .25
and timeElapsedSinceStart <= k.Time + .25 then
--print("Hit!")
--judgementFunc("Good!")
if k.Link then k.Link() end
if not k.Long then
table.remove(notes, o)
else
table.insert(currentLong, k)
table.remove(notes, o)
end
break
end
end
end
end
end
end
end
-- Made for fancy animations:tm: and for long notes.
function love.keyreleased(key, scankey)
for n, i in next, keys do
if key == i then
for m, j in next, lanes do
if lanes[n].Input == j.Input then
j.Pressed = false
for o, k in next, currentLong do
if timeElapsedSinceStart >= k.LongEnd - .3
and k.Lane == m
and timeElapsedSinceStart <= k.LongEnd + .3 then
--print("Hit!")
--judgementFunc("Good!")
table.remove(currentLong, o)
break
elseif k.Lane == m then
--print("Miss!")
judgementFunc("N.G.")
table.remove(currentLong, o)
break
end
end
end
end
end
end
end
function love.draw()
-- Draw all lanes to the screen.
for n, i in next, lanes do
love.graphics.setColor(i.Color)
if i.Show then
love.graphics.rectangle(
"line",
i.X,
-percentHeight(100),
percentWidth(6.2),
love.graphics.getHeight() + percentHeight(200)
)
end
love.graphics.circle(
i.Pressed and "fill" or "line",
i.X + percentWidth(3.1),
i.Y,
percentWidth(2.8)
)
end
if ShowJudgement then
love.graphics.print( JudgementText, percentWidth(50), percentHeight(60), 0, 2 )
end
for _, i in next, notes do
if timeElapsedSinceStart > i.Time - 5 and i.Show then
if not i.Hittable then
love.graphics.setColor(i.ColorUnhittable)
else
love.graphics.setColor(i.Color)
end
love.graphics.circle(
"fill",
lanes[i.Lane].X + percentWidth(3.1),
(timeElapsedSinceStart - i.Time) * percentHeight(i.Speed) + (lanes[i.Lane].Y),
percentWidth(3)
)
if i.Long then
local xmid = lanes[i.Lane].X + percentWidth(3.1)
local ymid = (timeElapsedSinceStart - i.LongEnd) * percentHeight(i.Speed) + (lanes[i.Lane].Y)
love.graphics.polygon(
"fill",
xmid,
ymid,
xmid + percentWidth(2.8),
ymid + percentHeight(5),
xmid + percentWidth(2.8),
(timeElapsedSinceStart - i.Time) * percentHeight(i.Speed) + (lanes[i.Lane].Y),
xmid - percentWidth(2.8),
(timeElapsedSinceStart - i.Time) * percentHeight(i.Speed) + (lanes[i.Lane].Y),
xmid - percentWidth(2.8),
ymid + percentHeight(5)
)
--[[love.graphics.circle(
"line",
lanes[i.Lane].X + percentWidth(3.1),
(timeElapsedSinceStart - i.LongEnd) * percentHeight(i.Speed) + (lanes[i.Lane].Y),
percentWidth(3)
)]]
end
end
end
for n, i in next, currentLong do
if timeElapsedSinceStart - i.LongEnd <= 0 then
local xmid = lanes[i.Lane].X + percentWidth(3.1)
local ymid = (timeElapsedSinceStart - i.LongEnd) * percentHeight(i.Speed) + (lanes[i.Lane].Y)
love.graphics.polygon(
"fill",
xmid,
ymid,
xmid + percentWidth(2.8),
ymid + percentHeight(5),
xmid + percentWidth(2.8),
lanes[i.Lane].Y,
xmid - percentWidth(2.8),
lanes[i.Lane].Y,
xmid - percentWidth(2.8),
ymid + percentHeight(5)
)
elseif timeElapsedSinceStart - i.LongEnd > .5 then
--print("Miss!")
table.remove(currentLong, n)
end
end
end