-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathmain.lua
More file actions
1640 lines (1479 loc) · 56.5 KB
/
Copy pathmain.lua
File metadata and controls
1640 lines (1479 loc) · 56.5 KB
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
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
love.window.setIcon(love.image.newImageData('assets/icon.png'))
love.mouse.setVisible(false)
require 'Zenitha'
local oldColorKeys = {
'DR', 'dR', 'R', 'lR', 'LR',
'DF', 'dF', 'F', 'lF', 'LF',
'DO', 'dO', 'O', 'lO', 'LO',
'DY', 'dY', 'Y', 'lY', 'LY',
'DA', 'dA', 'A', 'lA', 'LA',
'DK', 'dK', 'K', 'lK', 'LK',
'DG', 'dG', 'G', 'lG', 'LG',
'DJ', 'dJ', 'J', 'lJ', 'LJ',
'DC', 'dC', 'C', 'lC', 'LC',
'DI', 'dI', 'I', 'lI', 'LI',
'DS', 'dS', 'S', 'lS', 'LS',
'DB', 'dB', 'B', 'lB', 'LB',
'DP', 'dP', 'P', 'lP', 'LP',
'DV', 'dV', 'V', 'lV', 'LV',
'DM', 'dM', 'M', 'lM', 'LM',
'DW', 'dW', 'W', 'lW', 'LW',
}
local newColorKeys = {
'd4RS', 'd1RS', 'l2RS', 'l4RS', 'l6RS',
'd4RyS', 'd1RyS', 'l2RyS', 'l4RyS', 'l6RyS',
'd4YrrS', 'd1YrrS', 'l2YrrS', 'l4YrrS', 'l6YrrS',
'd4YS', 'd1YS', 'l2YS', 'l4YS', 'l6YSS',
'd4YggS', 'd1YggS', 'l2YggS', 'l4YggS', 'l6Yggs',
'd4GyS', 'd1GyS', 'l2GyS', 'l4GyS', 'l6Gys',
'd4GcS', 'd1GcS', 'l2GcS', 'l4GcS', 'l6Gc',
'd4CggS', 'd1CggS', 'l2CggS', 'l4CggS', 'l6CggS',
'd4CS', 'd1CS', 'l2CS', 'l4CS', 'l6CS',
'd4CbbS', 'd1CbbS', 'l2CbbS', 'l4CbbS', 'l6CbbS',
'd4BcS', 'd1BcS', 'l2BcS', 'l4BcS', 'l6BcS',
'd4BmS', 'd1BmS', 'l2BmS', 'l4BmS', 'l6BmS',
'd4MbbS', 'd1MbbS', 'l2MbbS', 'l4MbbS', 'l6MbbS',
'd4MS', 'd1MS', 'l2MS', 'l4MS', 'l6MS',
'd4MrrS', 'd1MrrS', 'l2MrrS', 'l4MrrS', 'l6MrrS',
'd4RmS', 'd1RmS', 'l2RmS', 'l4RmS', 'l6RmS',
}
for i = 1, #oldColorKeys do COLOR[oldColorKeys[i]] = CLR[newColorKeys[i]] end
ZENITHA.setMainLoopSpeed(240)
ZENITHA.setRenderRate(50)
ZENITHA.setAppInfo("Zenith Clicker", SYSTEM .. " " .. (require 'version'.appVer))
ZENITHA.setClickDist(62)
ZENITHA.setFirstScene('joining')
ZENITHA._cursor.speed = 1600
STRING.install()
SCR.setSize(1600, 1000)
local gc = love.graphics
local gc_push, gc_pop = gc.push, gc.pop
local gc_translate, gc_scale = gc.translate, gc.scale
local gc_rotate, gc_setShader = gc.rotate, gc.setShader
local gc_setColor, gc_setLineWidth, gc_setLineJoin = gc.setColor, gc.setLineWidth, gc.setLineJoin
local gc_draw, gc_line = gc.draw, gc.line
local gc_mRect = GC.mRect
ZENITHA.globalEvent.drawCursor = NULL
ZENITHA.globalEvent.clickFX = NULL
function ZENITHA.globalEvent.fileDrop(file)
local data = file:read('data')
local suc, res = pcall(gc.newImage, data)
if suc then
if AVATAR then AVATAR:release() end
AVATAR = res
love.filesystem.write('avatar', data)
IssueAchv('identity')
SFX.play('supporter')
MSG('dark', "Your avatar was updated!")
else
MSG('dark', "Invalid image file")
end
file:close()
file:release()
if SCN.cur == 'stat' then RefreshProfile() end
end
function ZENITHA.globalEvent.resize()
BgScale = math.max(SCR.w / 1024, SCR.h / 640)
StarPS:reset()
StarPS:moveTo(0, -GAME.bgH * 2 * BgScale)
StarPS:setEmissionArea('uniform', SCR.w * .626, SCR.h * .626)
StarPS:setSizes(SCR.k * 1.626)
local dt = 1 / StarPS:getEmissionRate()
for _ = 1, StarPS:getBufferSize() do
StarPS:emit(1)
StarPS:update(dt)
end
end
local function task_saveConf()
TASK.yieldT(2.6)
SaveConf()
end
local function confUpdate()
TASK.removeTask_code(task_saveConf)
TASK.new(task_saveConf)
end
local KBisDown = love.keyboard.isDown
function ZENITHA.globalEvent.keyDown(key, isRep)
if isRep then return end
if KBisDown('lctrl', 'rctrl') then return end
if key == 'f12' then
if TASK.lock('dev') then
MSG('check', "Zenith Clicker is powered by Love2d & Zenitha, not Web!", 6.26)
else
ZENITHA.setDebugMode(not ZENITHA.getDebugMode() and 1 or false)
end
elseif key == 'f11' then
CONF.fullscreen = not CONF.fullscreen
love.window.setFullscreen(CONF.fullscreen)
confUpdate()
MSG('dark', "Fullscreen: " .. (CONF.fullscreen and "ON" or "OFF"), 1)
elseif key == 'f10' then
CONF.syscursor = not CONF.syscursor
SetMouseVisible(true)
ApplySettings()
confUpdate()
MSG('dark', "Star Force: " .. (CONF.syscursor and "OFF" or "ON"), 1)
elseif key == 'f9' then
if not GAME.zenithTraveler then CONF.bg = not CONF.bg end
confUpdate()
MSG('dark', "BG: " .. (CONF.bg and "ON" or "OFF"), 1)
elseif key == 'f8' then
if CONF.bgBrightness < 80 then
CONF.bgBrightness = MATH.clamp(CONF.bgBrightness + 10, 30, 80)
confUpdate()
MSG('dark', "BG " .. CONF.bgBrightness .. "%", 1)
end
elseif key == 'f7' then
if CONF.bgBrightness > 30 then
CONF.bgBrightness = MATH.clamp(CONF.bgBrightness - 10, 30, 80)
confUpdate()
MSG('dark', "BG " .. CONF.bgBrightness .. "%", 1)
end
elseif key == 'f5' then
if CONF.cardBrightness > 80 then
CONF.cardBrightness = MATH.clamp(CONF.cardBrightness - 5, 80, 100)
confUpdate()
MSG('dark', "Card " .. CONF.cardBrightness .. "%", 1)
end
elseif key == 'f6' then
if CONF.cardBrightness < 100 then
CONF.cardBrightness = MATH.clamp(CONF.cardBrightness + 5, 80, 100)
confUpdate()
MSG('dark', "Card " .. CONF.cardBrightness .. "%", 1)
end
elseif key == 'f3' then
if CONF.sfx > 0 then
TempSFX = CONF.sfx
CONF.sfx = 0
else
CONF.sfx = TempSFX or 60
TempSFX = false
end
confUpdate()
MSG('dark', CONF.sfx > 0 and "SFX ON" or "SFX OFF", 1)
ApplySettings()
SFX.play('menuclick')
elseif key == 'f4' then
if CONF.bgm > 0 then
TempBGM = CONF.bgm
CONF.bgm = 0
else
CONF.bgm = TempBGM or 100
TempBGM = false
end
confUpdate()
MSG('dark', CONF.bgm > 0 and "BGM ON" or "BGM OFF", 1)
ApplySettings()
end
end
function ZENITHA.globalEvent.quit() SaveStat() end
local function task_autoSoundOff()
coroutine.yield()
while true do
local dt = coroutine.yield()
local v = math.max(love.audio.getVolume() - dt * 2.6, 0)
love.audio.setVolume(v)
if v == 0 then return end
end
end
local function task_autoSoundOn()
coroutine.yield()
while true do
local dt = coroutine.yield()
local v = math.min(love.audio.getVolume() + dt * 2.6, 1)
love.audio.setVolume(v)
if v == 1 then return end
end
end
function ZENITHA.globalEvent.focus(f)
if not CONF.autoMute then return end
if f then
TASK.removeTask_code(task_autoSoundOff)
TASK.new(task_autoSoundOn)
else
TASK.removeTask_code(task_autoSoundOn)
TASK.new(task_autoSoundOff)
end
end
for i = 1, 4 do SCN.scenes._console.widgetList[i].textColor = COLOR.D end
WIDGET.setDefaultOption {
checkBox = {
w = 40,
labelPos = 'right',
labelDist = 8,
lineWidth = 2,
sound_on = 'menuclick',
sound_off = 'menuclick',
},
slider = {
lineWidth = 2,
_approachSpeed = 1e99,
},
}
function WIDGET._prototype.button:draw()
gc_push('transform')
gc_translate(self._x, self._y + (SCN.cur == 'tower' and self.pos[1] == .5 and DeckPress or 0))
if self._pressTime > 0 then
gc_scale(1 - self._pressTime / self._pressTimeMax * .0626)
end
local w, h = self.w, self.h
local fillC = self.fillColor
local frameC = self.frameColor
-- Background
gc_setColor(fillC)
gc_mRect('fill', 0, 0, w, h)
-- Frame
gc_setLineWidth(3)
gc_setColor(frameC[1] * .42, frameC[2] * .42, frameC[3] * .42)
gc_line(-w / 2, h / 2, w / 2, h / 2, w / 2, -h / 2 - 1.5)
gc_setColor(.2 + frameC[1] * .8, .2 + frameC[2] * .8, .2 + frameC[3] * .8)
gc_line(-w / 2, h / 2 + 1.5, -w / 2, -h / 2, w / 2 - 1.5, -h / 2)
-- Drawable
gc_setColor(self.textColor)
WIDGET._alignDraw(self, self._text, 0, 0, 0, 1.2, 1.2 - 2.4 * GAME.revTimer)
-- Highlight
if self._hoverTime > 0 then
gc_setColor(1, 1, 1, self._hoverTime / self._hoverTimeMax * .0626)
gc_mRect('fill', 0, 0, w - 3, h - 3)
end
gc_pop()
end
function WIDGET._prototype.checkBox:draw()
gc_push('transform')
gc_translate(self._x, self._y)
local w = self.w
gc_setLineWidth(self.lineWidth)
if self.disp() then
-- Active
gc_setColor(self.frameColor)
gc_mRect('fill', 0, 0, w, w, 2)
gc_setColor(0, 0, 0, .42)
gc_line(-w / 2, w / 2, w / 2, w / 2, w / 2, -w / 2)
gc_setColor(1, 1, 1, .62)
gc_line(-w / 2, w / 2, -w / 2, -w / 2, w / 2, -w / 2)
gc_setLineWidth(self.lineWidth * 2)
gc_setLineJoin('bevel')
gc_setColor(1, 1, 1)
gc_line(-w * .355, 0, 0, w * .355, w * .355, -w * .355)
else
-- Background
gc_setColor(self.fillColor)
gc_mRect('fill', 0, 0, w, w, 2)
gc_setColor(0, 0, 0, .626)
gc_line(-w / 2, w / 2, -w / 2, -w / 2, w / 2, -w / 2)
gc_setColor(1, 1, 1, .0626)
gc_line(-w / 2, w / 2, w / 2, w / 2, w / 2, -w / 2)
end
-- Drawable
local x2, y2 = w * .5 + self.labelDist, 0
gc_setColor(self.textColor)
WIDGET._alignDraw(self, self._text, x2, y2, nil, self.textScale)
-- Highlight
gc_setColor(1, 1, 1, self._hoverTime / self._hoverTimeMax * .0626)
gc_mRect('fill', 0, 0, w, w, 2)
gc_pop()
end
function WIDGET._prototype.slider:draw()
local x, y = self._x, self._y
local x2 = x + self.w
local rangeL, rangeR = self._rangeL, self._rangeR
local frameC = self.frameColor ---@cast frameC -string +Zenitha.Color
-- Axis
gc_setColor(frameC)
gc_setLineWidth(self.lineWidth * 2)
gc_line(x, y, x2, y)
local fillC = self.fillColor
-- Block
local pos = MATH.clamp(self._pos, rangeL, rangeR)
local cx = x + self.w * (pos - rangeL) / self._rangeWidth
local bw, bh = 26, 30
GC.ucs_move(cx, y)
gc_setColor(fillC)
gc_mRect('fill', 0, 0, bw, bh, self.cornerR)
gc_setLineWidth(self.lineWidth)
gc_setColor(0, 0, 0, .26)
gc_line(-bw / 2, bh / 2, bw / 2, bh / 2, bw / 2, -bh / 2)
gc_setColor(1, 1, 1, .1)
gc_line(-bw / 2, bh / 2, -bw / 2, -bh / 2, bw / 2, -bh / 2)
GC.ucs_back()
end
WIDGET.newClass('button_invis', 'button').draw = NULL
UTIL.time("Load & Configure & Customize Zenitha", true)
--------------------------------------------------------------
CHAR = require 'module/char'
require 'data/init'
require 'module/texture'
UTIL.time("Load gamedata & Initialize Textures", true)
--------------------------------------------------------------
Metatable = {
best_highscore = { __index = function() return 0 end },
best_speedrun = { __index = function() return 1e99 end },
}
CONF = {
keybind = {
"q", "w", "e", "r", "t", "y", "u", "i", "o",
"a", "s", "d", "f", "g", "h", "j", "k", "l",
"space", "z", "x", "c"
},
fullscreen = true,
syscursor = false,
cardBrightness = 90,
bgBrightness = 40,
boardOpacity = 50,
damageShakiness = 50,
bg = true,
sfx = 60,
bgm = 100,
autoMute = false,
oldHitbox = false,
}
SR = {}
LB = {}
UTIL.time("Prepare storage", true)
--------------------------------------------------------------
-- Vars: System
TestMode = false
DiscordState = {}
Cards = {} ---@type Map<Card>
CRprogress = {
f10 = 0,
sr = 0,
achvGet = 0,
achvAll = 0,
}
Daily = {
history = {},
historyDisp = {},
actived = false,
available = false,
needSubmit = false,
}
SHADER = require 'module/shader'
GAME = require 'module/game'
-- Vars: VFX
FloatOnCard = nil ---@type number?
GigaSpeed = {
r = 0,
g = 0,
b = 0,
alpha = 0,
bgAlpha = 0,
textTimer = false,
isTera = false,
}
BoardColor = { 1, 1, 1 }
ImpactGlow = {}
DeckPress = 0
ThrobAlpha = {
card = 0,
bg1 = 0,
bg2 = 0,
}
Wind = {}
WindBatch = GC.newSpriteBatch(GC.load { w = 1, h = 1, { 'clear', 1, 1, 1, 1 } }, 260, 'static')
for i = 1, 62 do
Wind[i] = { math.random(), math.random(), MATH.clampInterpolate(1, 0.5, 260, 2.6, i) }
WindBatch:add(0, 0)
end
BgScale = 1
-- Vars: Music
---@enum (key) ZC.bgmName
BgmData = {
--[[
# F0 (Watchful Eye) 4|4 ♩ = 184 C Minor
# F1 (Divine Registration) 4|4 ♩ = 184 C Minor
# F2 (Zenith Hotel) 4|4 ♩ = 110 D Major / B Minor
# F3 (Empty Prayers) 12|8 ♩.= 120 C Major / A Minor
# F4 (Crowd Control) 5|8 ♪ = 180 F♯ Minor
# F5 (Phantom Memories) 4|4 6|8 ♩ = 130 ♩.= 130 E Minor
# F6 (Echo) 4|4 ♩ = 65 A Minor
# F7 (Cryptic Chemistry) 4|4 ♩ = 120 A+50 Minor
# F8 (Chrono Flux) 4|4 ♩ = 150 E Minor
# F9 (Broken Record) 4|4 ♩ = 160 E Minor
# F10 (Deified Validation) 4|4 ♩ = 98 C Major / C Minor
# Hyper (Schnellfeuer Bullet) 4|4 ♩ = 240 C♯ Minor
]]
f0 = { meta = '4|4 184 BPM C Minor ', bar = 4, bpm = 184, toneFix = 0.0, loop = { 0, 114.7826 } },
f1 = { meta = '4|4 184 BPM C Minor ', bar = 4, bpm = 184, toneFix = 0.0, loop = { 18.261, 91.304 }, introLen = 1.304, teleport = { -1, 7.826 } },
f2 = { meta = '4|4 110 BPM D Major & B Minor ', bar = 4, bpm = 110, toneFix = -1., loop = { 26.181, 113.454 } },
f2r = { meta = '4|4 110 BPM D Major & B Minor ', bar = 4, bpm = 110, toneFix = -1., loop = { 26.181, 113.454 } },
f3 = { meta = '12|8 120 BPM C Major & A Minor', bar = 4, bpm = 120, toneFix = -1., loop = { 56, 128 } },
f3r = { meta = '12|8 120 BPM C Major & A Minor', bar = 4, bpm = 120, toneFix = -1., loop = { 56, 128 } },
f4 = { meta = '5|8 180 BPM F# Minor ', bar = 5, bpm = 180, toneFix = 1.0, loop = { 13.333, 93.333 } },
f4r = { meta = '5|8 180 BPM F# Minor ', bar = 5, bpm = 180, toneFix = 1.0, loop = { 13.333, 93.333 } },
f5 = { meta = '4|4 6|8 130 BPM E Minor ', bar = 4, bpm = 130, toneFix = -1., loop = { 51.692, 155.077 } },
f5r = { meta = '4|4 6|8 130 BPM E Minor ', bar = 4, bpm = 130, toneFix = -1., loop = { 51.692, 155.077 } },
f6 = { meta = '4|4 130 BPM A Minor ', bar = 4, bpm = 130, toneFix = 2.0, loop = { 29.538, 103.384 } },
f6r = { meta = '4|4 130 BPM G Minor ', bar = 4, bpm = 130, toneFix = 0.0, loop = { 29.538, 103.384 } },
f7 = { meta = '4|4 120 BPM A+50c Minor ', bar = 4, bpm = 120, toneFix = 2.5, bpmData = { 60, 32, 120 }, loop = { 128, 192 } },
f7r = { meta = '4|4 120 BPM A+50c Minor ', bar = 4, bpm = 120, toneFix = 2.5, bpmData = { 60, 32, 120 }, loop = { 128, 192 }, teleport = { 8, 32 } },
f8 = { meta = '4|4 150 BPM E Minor ', bar = 4, bpm = 150, toneFix = -1., loop = { 38.4, 134.4 } },
f8r = { meta = '4|4 150 BPM E Minor ', bar = 4, bpm = 150, toneFix = -1., loop = { 38.4, 134.4 } },
f9 = { meta = '4|4 160 BPM E Minor ', bar = 4, bpm = 160, toneFix = -1., loop = { 36, 144 } },
f9r = { meta = '4|4 160 BPM E Minor ', bar = 4, bpm = 160, toneFix = -1., loop = { 36, 144 } },
f10 = { meta = '4|4 196 BPM C Major & C Minor ', bar = 4, bpm = 196, toneFix = 0.0, bpmData = { 49, 19.592, 98 }, loop = { 213.673, 311.632 } },
f10r = { meta = '4|4 196 BPM C Major & C Minor ', bar = 4, bpm = 196, toneFix = 0.0, bpmData = { 49, 19.592, 98 }, loop = { 213.673, 311.632 } },
fomg = { meta = '4|4 180 & 200 BPM Bb Minor ', bar = 4, bpm = 200, toneFix = 3.0, bpmData = { 90, 10.667, 180, 25.333, 200 }, loop = { 38.4 - 11.862, 144 - 11.862 } },
tera = { meta = '4|4 240 BPM C# Minor ', bar = 4, bpm = 240, toneFix = 1.0, loop = { 76, 140 }, introLen = 2, teleport = { -1, 20 } }, -- 4 endings at 140/142/144/146
terar = { meta = '4|4 240 BPM C# Minor ', bar = 4, bpm = 240, toneFix = 1.0, loop = { 84 - 15.565, 172 - 15.565 }, teleport = { 0, 18 - 15.565 } },
}
for _, v in next, BgmData do
v.meta = STRING.trim(v.meta)
if not v.bpmData then v.bpmData = { v.bpm } end
end
BgmSet = {
f0 = {
'piano',
'arp', 'bass', 'guitar', 'pad', 'staccato', 'violin',
'expert', 'rev',
'piano2', 'violin2',
},
f1 = { 'f1', 'f1ex', 'f1rev' },
}
BgmPlaying = false ---@type ZC.bgmName | false
SongNamePlaying = false -- Same as BgmPlaying, but this distinguishes f0(r) and f1(r) for album page
BgmLooping = false
BgmNeedSkip = false
BgmNeedStop = false
MusicBeat = 0 ---@type number 0-1, envelope: /|/|/|
-- Vars: Daily Challenge extras
VALENTINE = false
VALENTINE_TEXT = "FLOOD THE TOWER SIDE BY SIDE WITH WHAT COULD BE"
XMAS = false
ZDAY = false
-- Vars: Cursor
MX, MY = -260, 0 -- Mouse position
CursorProgress = 0
CursorHide = true
local M = GAME.mod
-- Functions: Cursor
function SetMouseVisible(bool)
if CONF.syscursor then
love.mouse.setVisible(bool)
else
CursorHide = not bool
end
end
-- Functions: Save Data
function SaveBest()
if TestMode then return end
love.filesystem.write('best.luaon', 'return' .. TABLE.dumpDeflate(BEST))
end
function SaveStat()
if TestMode then return end
STAT.modTime = os.time()
love.filesystem.write('stat.luaon', 'return' .. TABLE.dumpDeflate(STAT))
end
function SaveAchv()
if TestMode then return end
love.filesystem.write('achv.luaon', 'return' .. TABLE.dumpDeflate(ACHV))
end
function SaveConf()
if TestMode then return end
love.filesystem.write('conf.luaon', 'return' .. TABLE.dumpDeflate(CONF))
end
function SaveSR()
if TestMode then return end
love.filesystem.write('speedrun.luaon', 'return' .. TABLE.dumpDeflate(SR))
end
-- Create BEST, STAT, ACHV tables, only called when launching and on resetall
function InitProfile()
BEST = {
highScore = setmetatable({}, Metatable.best_highscore),
speedrun = setmetatable({}, Metatable.best_speedrun),
}
STAT = {
mod = 'vanilla',
version = nil, -- will be set after loading
system = SYSTEM,
modTime = os.time(),
srTimer_life = 0,
srTimer_game = 0,
srMilestone = {},
srActive = true,
joinDate = os.date("%b %Y"),
hid = os.date("%d%S%m%M%y%H") .. math.random(26000, 42000) .. math.random(42000, 62000),
uid = "ANON-" .. os.date("%d_") .. math.random(2600, 6200),
aboutme = "Click the Zenith!",
maxFloor = 1,
maxHeight = 0,
heightDate = "NO DATE",
minTime = 2600,
timeDate = "NO DATE",
zp = 0,
dzp = 0,
peakZP = 0,
peakDZP = 0,
dailyBest = 0,
dailyFast = 1e99,
dailyMastered = false,
lastDay = 0,
vipListCount = 0,
clockOutCount = 0,
clicker = false,
totalGame = 0,
totalTime = 0,
totalQuest = 0,
totalPerfect = 0,
totalHeight = 0,
totalBonus = 0,
totalFloor = 0,
totalFlip = 0,
totalAttack = 0,
totalGiga = 0,
totalF10 = 0,
totalKO = 0,
totalRevive = 0,
badge = {},
}
ACHV = {}
AchvNotice = {}
end
function LoadSave()
-- Fill BEST, STAT, ACHV tables with actual save data, only called after InitProfile()
local stat = FILE.safeLoad('stat.luaon', '-luaon')
if stat then
TABLE.update(STAT, stat)
if not STAT.srTimer_game then
STAT.srTimer_game, STAT.srTimer_life = STAT.totalTime, MATH.roundUnit(STAT.totalTime * 1.26, .001)
end
end
TABLE.update(BEST, FILE.safeLoad('best.luaon', '-luaon') or NONE)
TABLE.update(ACHV, FILE.safeLoad('achv.luaon', '-luaon') or NONE)
end
-- Functions: Game Progress
local function norm(x, k) return 1 + (x - 1) / (k * x + 1) end
function CalculateCR()
local deck = ModData.deck
local hs, sr = BEST.highScore, BEST.speedrun
local s
s = 0
for i = 1, #deck do
local id = deck[i].id
if hs[id] >= Floors[9].top then s = s + 1 end
if hs['r' .. id] >= Floors[9].top then s = s + 1 end
end
CRprogress.f10 = s
s = 0
for i = 1, #deck do
local id = deck[i].id
if sr[id] < 1e26 then s = s + 1 end
if sr['r' .. id] < 1e26 then s = s + 1 end
end
CRprogress.sr = s
local p, P = 0, 0
for i = 1, #Achievements do
local A = Achievements[i]
if A.type == 'competitive' then
P = P + 5
if ACHV[A.id] then
local rank = math.floor(A.rank(ACHV[A.id]))
p = p + rank
end
end
end
CRprogress.achvGet, CRprogress.achvAll = p, P
local cap = 25000
local cr = 0
-- Best height (5K)
cr = cr + 5000 * norm(MATH.icLerp(50, 6200, STAT.maxHeight), 6.2)
-- Best time (5K)
cr = cr + 5000 * norm(MATH.icLerp(420, 76.2, STAT.minTime), -.5)
-- Mod completion (3K)
cr = cr + 3000 * norm(MATH.icLerp(0, #deck * 2, CRprogress.f10), .62)
-- Mod speedrun (2K)
cr = cr + 2000 * norm(MATH.icLerp(0, #deck * 2, CRprogress.sr), .62)
-- Zenith point (3K)
cr = cr + 3000 * norm(MATH.icLerp(0, 26e4, STAT.zp), 4.2)
-- Daily challenge (2K)
cr = cr + 2000 * norm(MATH.icLerp(0, 6200, STAT.dzp), 2.6)
-- Achievement (5K)
cr = cr + 5000 * norm(MATH.icLerp(0, CRprogress.achvAll, CRprogress.achvGet), 2.6)
-- ACHV Wreath (competitive achievement count)
for i = 1, #Achievements do
local A = Achievements[i]
if A.type == 'competitive' then
cap = cap + 1
local r = A.rank(ACHV[A.id] or A.noScore or 0)
if r == 5.9999 then
cr = cr + 1
end
end
end
if not STAT.badge.champion and cr >= 25000 then IssueSecret('champion', true) end
return MATH.round(cr), cap
end
function RankAvailable()
return STAT.totalTime / 60 + STAT.totalFloor / 9 + STAT.totalGiga / 2 > 62
end
local msgTime = 0
local bufferedMsg = {}
local saveAchvTimer = false ---@type number | false
function IssueAchv(id, silent)
if TestMode then return end
local A = Achievements[id]
if not A or ACHV[id] then return end
if not silent then
table.insert(bufferedMsg, { 'achv_issued', {
AchvMsgStyle[6].fg, A.name .. "\n",
COLOR.dL, A.desc .. "\n",
COLOR.LD, A.quote,
}, 1 })
if not GAME.playing then
ReleaseAchvBuffer()
end
end
ACHV[id] = 0
AchvNotice[id] = true
saveAchvTimer = .26
return true
end
local wreathName = {
[false] = "",
[0] = "",
[1] = "T100-",
[2] = "T50-",
[3] = "T25-",
[4] = "T10-",
[5] = "T5-",
[6] = "T3-",
}
---@return true? success
function SubmitAchv(id, score, silent, realSilent)
if TestMode then return end
local A = Achievements[id]
if not A then return end
local oldScore = ACHV[id] or A.noScore or 0
local R0, R1 = A.rank(oldScore), A.rank(score)
-- printf("%s: %.1f(%.2f) -> %.1f(%.2f)", id, oldScore, R0, score, R1)
if R1 == 0 or not A.comp(score, oldScore) then return end
if not silent and R1 >= 1 then
local rank = math.floor(R1)
local wreath = R1 >= 5 and math.floor(MATH.clampInterpolate(0, 0, .9999, 6, R1 % 1)) or 0
local scoreText = A.scoreSimp(score) .. (A.scoreFull and " " .. A.scoreFull(score) or "")
local oldScoreText = A.scoreSimp(oldScore) .. (A.scoreFull and " " .. A.scoreFull(oldScore) or "")
table.insert(bufferedMsg, { wreath > 0 and 'wreath_' .. wreath or AchvMsgStyle[rank].id, {
AchvMsgStyle[rank].fg, wreathName[wreath] .. A.name .. " >> " .. scoreText,
COLOR.LD, (ACHV[id] and " Previous: " .. oldScoreText or "") .. "\n",
COLOR.dL, A.desc .. "\n", COLOR.LD, A.quote,
}, rank <= 2 and 1 or rank <= 4 and 2 or 3 })
if not GAME.playing then
ReleaseAchvBuffer()
end
end
ACHV[id] = score
if not realSilent then
AchvNotice[id] = true
end
saveAchvTimer = .26
return true
end
function IssueSecret(id, silent)
if not STAT.badge[id] then
STAT.badge[id] = true
if not silent then
table.insert(bufferedMsg, { 'bright', "YOU DID A THING!\n", 0 })
if not GAME.playing then
ReleaseAchvBuffer()
end
end
end
end
function IssueSpeedrunMilestone(id)
if not STAT.srMilestone[id] then
local t = MATH.roundUnit(STAT.srTimer_game, .001)
STAT.srMilestone[id] = t * (STAT.srActive and 1 or -1)
if STAT.srActive then
if t < (SR[id] or 1e99) then
SR[id] = t
SaveSR()
end
end
if t < 3600 * 2.6 then
MSG('speedrun', SpeedrunData[id].name .. ": " .. STRING.time(STAT.srMilestone[id]), 6.26)
end
end
end
function ReleaseAchvBuffer()
if TestMode then return end
for i = 1, #bufferedMsg do
local msg = bufferedMsg[i]
msgTime = TASK.lock('achv_bulk', 1) and 6.2 or msgTime + 2.6
MSG { msg[1], msg[2], time = msgTime, last = true, alpha = .75 }
if msg[3] == 0 and TASK.lock('achv_sfx_allclear', .08) then
SFX.play('allclear')
elseif TASK.lock('achv_sfx_' .. msg[3], .08) then
SFX.play('achievement_' .. msg[3], .7)
end
end
TABLE.clear(bufferedMsg)
end
-- Functions: Music
function Tone(pitch)
return pitch + (URM and M.GV == 2 and 3 or M.GV) + BgmData[BgmPlaying].toneFix
end
function RevMusicMode()
return
URM and M.EX == 2 or -- uEX
GAME.anyRev and GAME.comboZP >= 2.6 or -- rev run with 2.6x ZP
GAME.anyUltra and GAME.comboZP >= 1.2 -- ultra run with 1.2x ZP
end
---@param name ZC.bgmName
---@param force? boolean speedrun or music player
function PlayBGM(name, force)
if GAME.teramusic and not force then return end
SongNamePlaying = name
local last = BgmPlaying
if GAME.playing and RevMusicMode() then name = name .. 'r' end
if name == 'fomgr' then name = 'fomg' end
if name == 'f0r' then
BgmPlaying = 'f0'
elseif name == 'f1r' then -- Note: 'f1ex' is only a track name, not musicID
BgmPlaying = 'f1'
else
BgmPlaying = name
end
if not BgmData[BgmPlaying] then return end
BgmNeedStop = false
if BgmPlaying == 'f0' then
BgmLooping = false
BgmNeedSkip = BgmData[BgmPlaying].teleport
BGM.play(BgmSet.f0)
RefreshBGM(name)
elseif BgmPlaying == 'f1' then
BgmLooping = BgmData[BgmPlaying].loop
BgmNeedSkip = BgmData[BgmPlaying].teleport
BGM.play(BgmSet.f1, force and '' or '-sdin')
local start = math.random(3, 5) * BgmData.f1.introLen
BgmNeedSkip[1] = start + BgmData.f1.introLen
BGM.set('all', 'seek', start)
RefreshBGM(name)
elseif name == 'tera' then
BgmLooping = BgmData[BgmPlaying].loop
BgmNeedSkip = BgmData[BgmPlaying].teleport
BGM.play('tera', '-sdin')
local startFrom
if last then
---@cast last string
startFrom = tonumber(last:match("%d+"))
if startFrom then startFrom = startFrom - 1 end
end
local start = (GAME.playing and GAME.floor or startFrom or math.random(0, 9)) * BgmData.tera.introLen
BgmNeedSkip[1] = start + BgmData.tera.introLen
BGM.set('all', 'seek', start)
RefreshBGM()
elseif BGM.play(name, force and '' or '-sdin') then
BgmLooping = BgmData[BgmPlaying].loop
BgmNeedSkip = BgmData[BgmPlaying].teleport
RefreshBGM()
end
end
function RefreshBGM(mode)
if not BGM.isPlaying() then return end
local pitch = M.GV > 0 and 2 ^ ((URM and M.GV == 2 and 3 or M.GV) / 12) or 1
if GAME.slowmo then pitch = pitch / 2 end
if GAME.nightcore then pitch = pitch * 2 end
local justBegin = BGM.tell() < 1
BGM.set('all', 'pitch', pitch, justBegin and 0 or .26)
BGM.set('all', 'highgain', M.IN == 0 and 1 or M.IN == 1 and .8 or not URM and .626 or .55, justBegin and 0 or .626)
if BgmPlaying == 'f0' then
local revMode = mode == 'f0r' or RevMusicMode()
BGM.set('all', 'volume', revMode and 0 or 1, 2.6)
BGM.set('expert', 'volume', M.EX > 0 and 1 or 0, .26)
BGM.set('piano', 'volume', M.NH == 0 and 1 or M.NH == 1 and .26 or 0)
BGM.set('piano2', 'pitch', 2 * pitch, 0)
BGM.set('piano2', 'volume', (M.DP > 0 or VALENTINE and not revMode) and .626 or 0, .26)
BGM.set('violin', 'volume', M.DP == 2 and 1 or 0, .26)
BGM.set('violin2', 'volume', M.DP == 2 and 1 or 0, .26)
BGM.set('rev', 'volume', revMode and (M.DP > 0 and .5 or .7) or 0, revMode and 1.6 or 2.6)
elseif BgmPlaying == 'f1' then
local revMode = mode == 'f1r' or RevMusicMode()
BGM.set('f1', 'volume', 1)
BGM.set('f1ex', 'volume', M.EX > 0 and 1 or 0, 0)
BGM.set('f1rev', 'volume', revMode and 1 or 0, 0)
end
end
function Task_MusicEnd(manual)
BgmLooping = false
local D = BgmData[BgmPlaying]
local outroStart
if BgmPlaying == 'f1' or BgmPlaying == 'f1r' then
outroStart = D.loop[2] + 4 * 60 / D.bpm
BgmNeedStop = outroStart + 8 * 60 / D.bpm
elseif BgmPlaying == 'f2' or BgmPlaying == 'f2r' then
outroStart = D.loop[2]
BgmNeedStop = outroStart + 8 * 60 / D.bpm
elseif BgmPlaying == 'f3' or BgmPlaying == 'f3r' then
if BGM.tell() < D.loop[1] then
outroStart = D.loop[2] + 0
else
outroStart = D.loop[2] + 8 * 60 / D.bpm
end
BgmNeedStop = outroStart + 8 * 60 / D.bpm
elseif BgmPlaying == 'f4' or BgmPlaying == 'f4r' then
outroStart = D.loop[2]
BgmNeedStop = outroStart + 10 * 60 / D.bpm
elseif BgmPlaying == 'f5' or BgmPlaying == 'f5r' then
outroStart = D.loop[2] + 32 * 60 / D.bpm
BgmNeedStop = outroStart + 8 * 60 / D.bpm
elseif BgmPlaying == 'f6' or BgmPlaying == 'f6r' then
outroStart = D.loop[2]
BgmNeedStop = outroStart + 8 * 60 / D.bpm
elseif BgmPlaying == 'f7' or BgmPlaying == 'f7r' then
outroStart = D.loop[2]
BgmNeedStop = outroStart + 8 * 60 / D.bpm
elseif BgmPlaying == 'f8' or BgmPlaying == 'f8r' then
outroStart = D.loop[2]
BgmNeedStop = outroStart + 8 * 60 / D.bpm
elseif BgmPlaying == 'f9' or BgmPlaying == 'f9r' then
outroStart = D.loop[2]
BgmNeedStop = outroStart + 8 * 60 / D.bpm
elseif BgmPlaying == 'f10' or BgmPlaying == 'f10r' then
local t = BgmPlaying == 'f10' and 4.2 or 6.2
if BGM.tell() < 56 * 4 * 60 / D.bpm then
BGM.stop(t)
TASK.yieldT(t)
elseif BGM.tell() < 118 * 4 * 60 / D.bpm then
BGM.set('all', 'seek', 118 * 4 * 60 / D.bpm)
BgmNeedStop = BGM.tell() + 10 * 60 / D.bpm
elseif BGM.tell() < 154.5 * 4 * 60 / D.bpm then
BGM.stop(t)
TASK.yieldT(t)
else
outroStart = D.loop[2]
BgmNeedStop = outroStart + 8 * 60 / D.bpm
end
elseif BgmPlaying == 'fomg' then
if BGM.tell() < D.loop[1] then
outroStart = D.loop[2] + 32 * 60 / D.bpm
BgmNeedStop = outroStart + 16 * 60 / D.bpm
else
outroStart = D.loop[2]
BgmNeedStop = outroStart + 26 * 60 / D.bpm
end
elseif BgmPlaying == 'tera' then
outroStart = D.loop[2] + math.random(0, 3) * 8 * 60 / D.bpm
BgmNeedStop = outroStart + 8 * 60 / D.bpm
elseif BgmPlaying == 'terar' then
outroStart = D.loop[2] + 96 * 60 / D.bpm
BgmNeedStop = outroStart + 30 * 60 / D.bpm
else
BgmNeedStop = BGM.tell() + 4 * 60 / D.bpm
end
if outroStart then BGM.set('all', 'seek', outroStart) end
BgmLooping, BgmNeedSkip = false, false
if BgmNeedStop then
repeat TASK.yieldT(.0626) until not BgmNeedStop
else
repeat TASK.yieldT(.0626) until not BGM.isPlaying()
end
if not manual then
PlayBGM('f0')
GAME.refreshRPC()
end
end
-- Functions: System
require 'module/initialize'
local pressValue = 0
local function starCursor(x, y)
if CursorHide or GAME.zenithTraveler then return end
gc_translate(x, y)
gc_scale(1.42)
gc_rotate(MATH.lerp(-.626, -1.2, pressValue))
gc_scale(.8 + .2 * pressValue, 1)
local l = .626 + .374 * pressValue
gc_setColor(l, l, l)
gc_draw(TEXTURE.star0, 0, -6, 0, .14, .3, TEXTURE.star1:getWidth() * .5, 0)
gc_scale(.12, .26)
gc_setShader(SHADER.coloring)
gc_setColor(1, .626, .5)
gc_draw(TEXTURE.star0, -150, 0)
if CursorProgress <= .384626 then