-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.lua
1118 lines (1058 loc) · 31.7 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
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
--------------------------------------------------------------
-- Smart Bingo
-- Game by MrZ, 26F-Studio
-- Original idea from an image of QQ grounp, it has no credit
--------------------------------------------------------------
require 'Zenitha'
SCR.setSize(500, 1000)
ZENITHA.setMaxFPS(100)
ZENITHA.setUpdateFreq(100)
ZENITHA.setDrawFreq(26)
ZENITHA.setVersionText('')
ZENITHA.globalEvent.drawCursor = NULL
LANG.add {
zh = 'lang_zh.lua',
en = 'lang_en.lua',
}
LANG.setDefault('zh')
local DATA = {
zh = true,
sound = true,
win = 0,
passDate = false,
tickMat = {},
maxTick = false,
minTick = false,
}
for i = 1, 5 do DATA.tickMat[i] = TABLE.new(0, 5) end
local suc, res = pcall(FILE.load, 'data.json', '-json')
if suc then TABLE.update(DATA, res) end
SFX.setVol(DATA.sound and 1 or 0)
BGM.load('naive', 'audio/naive.ogg')
TASK.new(function()
TASK.yieldT(.626)
if DATA.sound then
BGM.play('naive')
end
end)
SFX.load({
tick = 'audio/tick.ogg',
untick = 'audio/untick.ogg',
solve = 'audio/solve.ogg',
copy = 'audio/copy.ogg',
paste = 'audio/paste.ogg',
error = 'audio/error.ogg',
})
FONT.load('unifont', 'unifont.otf')
FONT.setDefaultFont('unifont')
BG.set('color')
BG.send('color', COLOR.HEX 'EDEDED')
local rnd, min = math.random, math.min
local ins, rem = table.insert, table.remove
local gc = love.graphics
local ruleColor = {
COLOR.R,
COLOR.B,
{ 0, 0, 0 },
COLOR.G,
{ .9, .7, 0 },
COLOR.O,
COLOR.V,
COLOR.lR,
COLOR.C,
}
local cellColor = {
[false] = { COLOR.HEX 'EDEDED' },
{ 1, 0, .26 },
COLOR.B,
COLOR.D,
COLOR.G,
{ .9, 1, 0 },
COLOR.O,
{ .8, 0, 1 },
{ 1, .62, .82 },
{ 0, .8, .8 },
}
local cellColorHard = TABLE.copyAll(cellColor)
for _, v in next, cellColorHard do
v[1] = v[1] * .7023
v[2] = v[2] * .7023
v[3] = v[3] * .7023
end
local board = {
X = 20,
Y = 50,
W = 460,
H = 800,
titleW = 226,
infoH = 300,
CW = 92,
CH = 100,
}
local titleColor = { 0, 0, 0 }
-- local debugColor
local dailyMode ---@type boolean only save on today
local date = os.date('!%y%m%d')
local correct
local saveTimer
local activeRules = {}
local ruleMat = {}
local activeRuleTexts = {}
local targetText = gc.newText(FONT.get(15))
local versionText = gc.newText(FONT.get(20))
versionText:set(require 'version'.appVer)
local egg = {
bingo_clicker = 0,
bingo_target = 1,
}
local function freshRuleText()
activeRuleTexts = {}
for i = 1, #activeRules do
activeRuleTexts[i] = gc.newText(FONT.get(20))
activeRuleTexts[i]:setf(Text.rules[activeRules[i]], board.W - board.titleW - 10, 'left')
end
targetText:setf(Text.target, board.W - board.titleW - 10, 'left')
end
local function setLang(zh)
local l = zh and 'zh' or 'en'
Text = LANG.set(l)
freshRuleText()
WIDGET._reset()
end
local function safeGet(t, x, y)
if t[y] then return t[y][x] end
return 0
end
local function checkLine()
for y = 1, 5 do
if TABLE.count(DATA.tickMat[y], 1) == 5 then
return true
end
end
for x = 1, 5 do
local count = 0
for y = 1, 5 do
if DATA.tickMat[y][x] == 1 then count = count + 1 end
end
if count == 5 then
return true
end
end
local count1, count2 = 0, 0
for i = 1, 5 do
if DATA.tickMat[i][i] == 1 then count1 = count1 + 1 end
if DATA.tickMat[i][6 - i] == 1 then count2 = count2 + 1 end
end
return count1 == 5 or count2 == 5
end
local function checkCell(rule, tickMat, x, y)
if rule == 1 or rule == 2 or rule == 6 or rule == 7 then
local count = 0
for _x = x - 1, x + 1 do
for _y = y - 1, y + 1 do
if (_x ~= x or _y ~= y) and safeGet(tickMat, _x, _y) == 1 then count = count + 1 end
end
end
if rule == 1 then
return count >= 1
elseif rule == 2 then
return count <= 2
elseif rule == 6 then
return count % 2 == 0
elseif rule == 7 then
return count % 2 == 1
end
elseif rule == 3 then
return tickMat[y][x] == 1
elseif rule == 4 then
local xCount, yCount = 0, 0
for _x = 1, 5 do if tickMat[y][_x] == 1 then yCount = yCount + 1 end end
for _y = 1, 5 do if tickMat[_y][x] == 1 then xCount = xCount + 1 end end
return xCount == yCount
elseif rule == 5 then
local count1, count2 = 0, 0
for d = -4, 4 do if safeGet(tickMat, x + d, y + d) == 1 then count1 = count1 + 1 end end
for d = -4, 4 do if safeGet(tickMat, x + d, y - d) == 1 then count2 = count2 + 1 end end
return count1 == count2
elseif rule == 8 then
return
tickMat[y][x] ~= 1 or (
safeGet(tickMat, x - 1, y) ~= 1 and
safeGet(tickMat, x + 1, y) ~= 1 and
safeGet(tickMat, x, y - 1) ~= 1 and
safeGet(tickMat, x, y + 1) ~= 1
)
elseif rule == 9 then
return
tickMat[y][x] ~= 1 or (
safeGet(tickMat, x - 1, y) == 1 or
safeGet(tickMat, x + 1, y) == 1 or
safeGet(tickMat, x, y - 1) == 1 or
safeGet(tickMat, x, y + 1) == 1
)
end
end
local function checkAnswer()
correct = false
-- Find Line
if not checkLine() then return end
-- Check Rules
for y = 1, 5 do
for x = 1, 5 do
if ruleMat[y][x] and not checkCell(ruleMat[y][x], DATA.tickMat, x, y) then
return
end
end
end
correct = true
-- Count ticks
local count = 0
for y = 1, 5 do
count = count + TABLE.count(DATA.tickMat[y], 1)
end
-- Win
local needSave
if DATA.passDate ~= date then
if dailyMode then
DATA.win = DATA.win + 1
MSG.new('check', Text.winDaily, 2.6)
else
MSG.new('check', Text.winAny, 2.6)
end
DATA.passDate = date
needSave = true
DATA.maxTick = count
DATA.minTick = count
end
if count > (DATA.maxTick or 0) then
DATA.maxTick = count
MSG.new('check', Text.winMax, 2.6)
needSave = true
end
if count < (DATA.minTick or 6e26) then
DATA.minTick = count
MSG.new('check', Text.winMin, 2.6)
needSave = true
end
if needSave then
SFX.play('solve')
saveTimer = 0
end
end
local function dumpGrid(t)
local n = 0
for y = 1, 5 do
for x = 1, 5 do
if t[y][x] == 1 then
n = n + 2 ^ (5 * (y - 1) + x - 1)
end
end
end
return n
end
local gridConst = {
left = dumpGrid {
{ 0, 0, 1, 0, 0 },
{ 0, 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1, 0 },
{ 1, 1, 1, 1, 0 },
{ 1, 0, 0, 0, 0 },
{ 1, 0, 0, 0, 0 },
},
dumpGrid {
{ 0, 1, 1, 1, 1 },
{ 0, 1, 0, 0, 1 },
{ 0, 1, 1, 1, 1 },
{ 0, 1, 0, 0, 0 },
{ 0, 1, 0, 0, 0 },
},
dumpGrid {
{ 1, 1, 1, 0, 0 },
{ 1, 0, 1, 0, 0 },
{ 1, 1, 1, 0, 0 },
{ 1, 0, 0, 0, 0 },
{ 1, 0, 0, 0, 0 },
},
dumpGrid {
{ 0, 1, 1, 1, 0 },
{ 0, 1, 0, 1, 0 },
{ 0, 1, 1, 1, 0 },
{ 0, 1, 0, 0, 0 },
{ 0, 1, 0, 0, 0 },
},
dumpGrid {
{ 0, 0, 1, 1, 1 },
{ 0, 0, 1, 0, 1 },
{ 0, 0, 1, 1, 1 },
{ 0, 0, 1, 0, 0 },
{ 0, 0, 1, 0, 0 },
},
dumpGrid { -- V
{ 1, 0, 0, 0, 1 },
{ 1, 0, 0, 0, 1 },
{ 1, 0, 0, 0, 1 },
{ 0, 1, 0, 1, 0 },
{ 0, 0, 1, 0, 0 },
},
dumpGrid { -- V
{ 1, 0, 0, 0, 1 },
{ 1, 0, 0, 0, 1 },
{ 0, 1, 0, 1, 0 },
{ 0, 1, 0, 1, 0 },
{ 0, 0, 1, 0, 0 },
},
},
}
local function selectDate(option)
if option == 'prev' then
local y, m, d = date:match('(%d%d)(%d%d)(%d%d)')
d = d - 1
if d == 0 then d, m = 31, m - 1 end
if m == 0 then m, y = 12, y - 1 end
if y == -1 then
y = 99
if TASK.lock('AD_BC') then
MSG.new('check', "We can travel to AD, to BC", 4.2)
end
end
SCN.swapTo('main', 'swipeR', ('%02d%02d%02d'):format(y, m, d))
elseif option == 'next' then
local y, m, d = date:match('(%d%d)(%d%d)(%d%d)')
d = d + 1
if d == 32 then d, m = 1, m + 1 end
if m == 13 then m, y = 1, y + 1 end
if y == 100 then
y = 0
if TASK.lock('AD_BC') then
MSG.new('check', "We can travel to AD, to BC", 4.2)
end
end
if ('%02d%02d%02d'):format(y, m, d) <= os.date('!%y%m%d') then
SCN.swapTo('main', 'swipeL', ('%02d%02d%02d'):format(y, m, d))
else
if TASK.lock('back_to_future') then
MSG.new('check', "Back To The Future", 4.2)
end
end
elseif option == 'now' then
SCN.swapTo('main', 'swipeD', os.date('!%y%m%d'))
elseif option == 'random' then
math.randomseed(math.floor(os.time() + love.timer.getTime() * 100))
local y
repeat
y = rnd(0, 99)
until not MATH.between(y, 24, 35.5)
local m, d = rnd(12), rnd(31)
SCN.swapTo('main', 'fade', ('%02d%02d%02d'):format(y, m, d))
end
end
local function showText(text)
for textDX = -4, 4, 8 do
for textDY = -4, 4, 8 do
TEXT:add {
text = text,
x = 250 + textDX,
y = 580 + textDY,
k = 4,
fontSize = 65,
color = 'D',
duration = 2.6,
style = 'score',
inPoint = .026,
outPoint = .042,
}
end
end
TEXT:add {
text = text,
x = 250,
y = 580,
k = 4,
fontSize = 65,
color = 'L',
duration = 2.6,
style = 'score',
inPoint = .026,
outPoint = .042,
}
end
local function triggerHint()
TEXT:clear()
-- Check Rules
local fault
for cy = 1, 5 do
for cx = 1, 5 do
if ruleMat[cy][cx] and not checkCell(ruleMat[cy][cx], DATA.tickMat, cx, cy) then
fault = true
SYSFX.rect(.4, board.X + (cx - 1) * board.CW + 6, board.Y + board.infoH + (cy - 1) * board.CH + 6,
board.CW - 12,
board.CH - 12, 0, hardMode and .942 or 1, hardMode and .942 or 1, 1.626)
end
end
end
if fault then return end
-- Check line
if checkLine() then return end
TWEEN.new():setOnRepeat(function(n)
local x0, y0 = board.X, board.Y + board.infoH
local dx, dy = board.CW, board.CH
if n <= 5 then
SYSFX.line(.4, x0 + dx * .2, y0 + dy * (n - .5), x0 + dx * 4.8, y0 + dy * (n - .5), 26, 0, 0, 0, .626)
SYSFX.line(.42, x0 + dx * .2 + 3, y0 + dy * (n - .5), x0 + dx * 4.8 - 3, y0 + dy * (n - .5), 20)
elseif n <= 10 then
n = n - 5
SYSFX.line(.4, x0 + dx * (n - .5), y0 + dy * .2, x0 + dx * (n - .5), y0 + dy * 4.8, 26, 0, 0, 0, .626)
SYSFX.line(.42, x0 + dx * (n - .5), y0 + dy * .2 + 3, x0 + dx * (n - .5), y0 + dy * 4.8 - 3, 20)
elseif n == 11 then
SYSFX.line(.4, x0 + dx * .2, y0 + dy * .2, x0 + dx * 4.8, y0 + dy * 4.8, 26, 0, 0, 0, .626)
SYSFX.line(.42, x0 + dx * .2 + 2, y0 + dy * .2 + 2, x0 + dx * 4.8 - 2, y0 + dy * 4.8 - 2, 20)
elseif n == 12 then
SYSFX.line(.4, x0 + dx * 4.8, y0 + dy * .2, x0 + dx * .2, y0 + dy * 4.8, 26, 0, 0, 0, .626)
SYSFX.line(.42, x0 + dx * 4.8 - 2, y0 + dy * .2 + 2, x0 + dx * .2 + 2, y0 + dy * 4.8 - 2, 20)
elseif n == 13 then
showText("?")
end
SFX.play(n < 13 and 'untick' or 'tick', .42)
end):setDuration(.0626):setLoop('repeat', 14):setUnique('hint_noLine'):run()
end
---@type Zenitha.Scene
local scene = {}
local function seed(n)
math.randomseed(date + 0)
for _ = 1, n do rnd() end
end
function scene.load()
if SCN.args[1] then
date = SCN.args[1]
end
-- Check new day
dailyMode = not hardMode and date == os.date('!%y%m%d')
if dailyMode then
if DATA.passDate ~= date then
DATA.passDate = false
DATA.maxTick = false
DATA.minTick = false
for i = 1, 5 do
DATA.tickMat[i] = TABLE.new(0, 5)
end
end
else
DATA.passDate = false
DATA.maxTick = false
DATA.minTick = false
end
-- Rules
local tempRuleList
seed(26)
if hardMode then
tempRuleList = { 1, 4, 5, 6, 7 }
ins(tempRuleList, ({ 2, 8, 9 })[rnd(3)])
else
tempRuleList = { 1, 2, 3, 4 }
local extraRules = { 5, 6, 7, 8, 9 }
for _ = 1, MATH.randFreq { 60, 30, 10 } do
ins(tempRuleList, rem(extraRules, rnd(1, #extraRules)))
end
if #tempRuleList >= 7 then
rem(tempRuleList, ({ 1, 2, 4 })[rnd(3)])
end
end
table.sort(tempRuleList)
-- Tick matrix
seed(35.5)
local tickMat = {}
for i = 1, 5 do tickMat[i] = TABLE.new(0, 5) end
local lineNo = rnd(1, 12) -- Target Line
if lineNo <= 5 then
for i = 1, 5 do tickMat[lineNo][i] = 1 end
elseif lineNo <= 10 then
for i = 1, 5 do tickMat[i][lineNo - 5] = 1 end
elseif lineNo == 11 then
for i = 1, 5 do tickMat[i][i] = 1 end
elseif lineNo == 12 then
for i = 1, 5 do tickMat[i][6 - i] = 1 end
end
for _ = 1, rnd(3, 6) do -- Random
local rx, ry
repeat
rx, ry = rnd(1, 5), rnd(1, 5)
until tickMat[ry][rx] == 0
tickMat[ry][rx] = 1
end
-- for y=1,5 do
-- local s=""
-- for x=1,5 do
-- s=s..(tickMat[y][x] and "O " or ". ")
-- end
-- print(s)
-- end
-- DATA.tickMat = tickMat
local ruleCount = TABLE.new(0, 9)
local pbMat = {}
for i = 1, 5 do pbMat[i] = TABLE.new({}, 5) end
for y = 1, 5 do
for x = 1, 5 do
pbMat[y][x] = {}
for r = 1, #tempRuleList do
local rule = tempRuleList[r]
if checkCell(rule, tickMat, x, y) then
ins(pbMat[y][x], rule)
ruleCount[rule] = ruleCount[rule] + 1
end
end
-- printf("(%d,%d):%s", x, y, table.concat(pbMat[y][x], ' '))
end
end
-- for k, v in next, ruleCount do print(k, v) end
-- Filter impossible rule
local existRule = {}
for i = 1, #ruleCount do
if ruleCount[i] > 0 then
ins(existRule, i)
end
end
-- Color
seed(42)
ruleMat = {}
for i = 1, 5 do ruleMat[i] = TABLE.new(false, 5) end
-- for y = 1, 5 do
-- for x = 1, 5 do
-- ruleMat[y][x] = pbMat[y][x]
-- end
-- end
for i = 1, hardMode and rnd(20, 26) or rnd(8, 15) do
local rule = existRule[i % #existRule + 1]
local pbBlankCells = {}
local pbCells = {}
for y = 1, 5 do
for x = 1, 5 do
if pbMat[y][x] and TABLE.find(pbMat[y][x], rule) then
ins(pbCells, { x, y })
if not ruleMat[y][x] then
ins(pbBlankCells, { x, y })
end
end
end
end
local targetCell
if #pbBlankCells > 0 then
targetCell = pbBlankCells[rnd(#pbBlankCells)]
else
targetCell = pbCells[rnd(#pbCells)]
end
if targetCell then
ruleMat[targetCell[2]][targetCell[1]] = rule
end
end
local usedRuleCount = TABLE.new(0, 9)
for y = 1, 5 do
for x = 1, 5 do
local r = ruleMat[y][x]
if r then
usedRuleCount[r] = usedRuleCount[r] + 1
end
end
end
activeRules = {}
for i = 1, #usedRuleCount do
if usedRuleCount[i] > 0 then
ins(activeRules, i)
end
end
freshRuleText()
checkAnswer()
if DATA.sound and not hardMode then
BGM.set('naive', 'pitch', 1, 0)
end
if hardMode then
BG.send('color', COLOR.HEX '444040')
else
BG.send('color', COLOR.HEX 'EDEDED')
end
collectgarbage()
end
function scene.keyDown(k, rep)
if rep then return end
-- if tonumber(k) then debugColor = tonumber(k) end
if k == 'escape' then
saveTimer = 0
ZENITHA._quit('fade')
elseif k == 'backspace' or k == 'delete' then
for y = 1, 5 do
for x = 1, 5 do
DATA.tickMat[y][x] = 0
end
end
elseif k == 'h' then
triggerHint()
elseif k == 'c' then
local output = ""
for i = 1, 5 do
output = output .. table.concat(DATA.tickMat[i]) .. "\n"
end
love.system.setClipboardText(output)
SFX.play('copy')
if TASK.lock('copy') then
MSG.new('check', "Wow you can even copy", 4.2)
end
elseif k == 'v' then
local input = love.system.getClipboardText()
if input and type(input) == 'string' then
input = input:gsub('%s', '')
if input:find('%D') then
MSG.new('warn', "Can only paste numbers", 4.2)
SFX.play('error')
else
local lastEdit = 0
local pos = 1
for c in input:gmatch("%d") do
if pos > 25 then
lastEdit = 26
break
end
c = tonumber(c)
if c <= 2 then
DATA.tickMat[math.ceil(pos / 5)][(pos - 1) % 5 + 1] = c
lastEdit = pos
else
if TASK.lock('count2+') then MSG.new('warn', "Cannot count over 2", 4.2) end
break
end
pos = pos + 1
end
if lastEdit == 25 then
SFX.play('paste')
else
if lastEdit > 25 then
if TASK.lock('stackoverflow') then MSG.new('warn', "Stack Overflow", 4.2) end
else
if TASK.lock('stackunderflow') then MSG.new('warn', "Stack Underflow", 4.2) end
end
SFX.play('error')
end
end
end
end
return true
end
local function getBoardPos(x, y)
local cx = math.floor((x - board.X) / board.CW + 1)
local cy = math.floor((y - (board.Y + board.infoH)) / board.CH + 1)
return MATH.clamp(cx, 1, 5), MATH.clamp(cy, 1, 5)
end
local holdTimer
local dragging
local dragStart
function scene.mouseDown(x, y, k)
if MATH.between(x, board.X, board.X + board.titleW) and MATH.between(y, board.Y, board.Y + board.infoH) then
local origColor
repeat
origColor = ruleColor[activeRules[rnd(#activeRules)]]
until origColor[1] ~= 0
titleColor = TABLE.copy(origColor)
TWEEN.new(function(t)
titleColor[1] = MATH.lerp(origColor[1], 0, t)
titleColor[2] = MATH.lerp(origColor[2], 0, t)
titleColor[3] = MATH.lerp(origColor[3], 0, t)
end):setDuration(.26):setUnique('titleColorTransition'):run()
local pattern = dumpGrid(DATA.tickMat)
if pattern == gridConst.left then
selectDate('prev')
elseif pattern == gridConst.right then
selectDate('next')
elseif pattern == gridConst.N then
selectDate('now')
elseif TABLE.find(gridConst.R, pattern) then
selectDate('random')
elseif TABLE.find(gridConst.paste, pattern) then
scene.keyDown('v')
elseif pattern == gridConst.up then
local y0 = board.Y
TWEEN.new(function(t)
board.Y = y0 - 12 * t
end):setEase('Linear'):setDuration(.26):setUnique('egg_moveUp'):run()
elseif pattern == gridConst.down then
local y0 = board.Y
TWEEN.new(function(t)
board.Y = y0 + 12 * t
end):setEase('Linear'):setDuration(.26):setUnique('egg_moveDown'):run()
elseif pattern == gridConst.T then
MSG.new('check', "Techmino is fun!", 4.2)
elseif pattern == gridConst.Z then
MSG.new('check', "By MrZ", 4.2)
elseif pattern == gridConst.H or pattern == gridConst.full then
hardMode = not hardMode
if hardMode then
if DATA.sound then
BGM.set('naive', 'pitch', .626, 0)
end
MSG.new('warn', Text.hardMode, 2.6)
else
MSG.new('info', Text.easyMode, 2.6)
end
SCN.swapTo('main', 'flash', date)
else
egg.bingo_clicker = egg.bingo_clicker + 1
if egg.bingo_clicker == 10 * egg.bingo_target then
egg.bingo_target = egg.bingo_target + 1
MSG.new('check', "[username]'s Bingo Card\n" .. egg.bingo_clicker .. " bingos\n ", 2.6)
end
end
elseif MATH.between(x, board.X + board.titleW, board.X + board.W) and MATH.between(y, board.Y, board.Y + board.infoH) then
triggerHint()
else
if k == 1 then
holdTimer = 0
dragging = {}
scene.mouseMove(x, y)
elseif k == 2 then
if dragging then
for xy in next, dragging do
local cx, cy = xy:match('(%d)(%d)')
cx, cy = tonumber(cx), tonumber(cy)
DATA.tickMat[cy][cx] = dragStart
end
elseif MATH.between(x, board.X, board.X + board.W) and MATH.between(y, board.Y + board.infoH, board.Y + board.H) then
local cx, cy = getBoardPos(x, y)
DATA.tickMat[cy][cx] = DATA.tickMat[cy][cx] == 0 and 2 or 0
end
end
end
end
function scene.mouseMove(x, y)
if dragging and MATH.between(x, board.X, board.X + board.W) and MATH.between(y, board.Y + board.infoH, board.Y + board.H) then
local cx, cy = getBoardPos(x, y)
if not dragStart and DATA.tickMat[cy][cx] == 2 then
dragStart = 2
dragging[cx .. cy] = true
elseif not dragging[cx .. cy] and dragStart ~= 2 and (dragStart == nil or dragStart == DATA.tickMat[cy][cx]) then
if not dragStart then
dragStart = DATA.tickMat[cy][cx]
else
holdTimer = false
end
dragging[cx .. cy] = true
DATA.tickMat[cy][cx] = 1 - DATA.tickMat[cy][cx]
SFX.play(DATA.tickMat[cy][cx] == 1 and 'tick' or 'untick')
end
end
end
function scene.mouseUp(_, _, k)
if k == 1 then
holdTimer = nil
dragging = nil
dragStart = nil
checkAnswer()
end
saveTimer = 2.6
end
local firstTouchID
function scene.touchDown(x, y, id)
if not firstTouchID then
firstTouchID = id
scene.mouseDown(x, y, 1)
end
end
function scene.touchMove(x, y, _, _, id)
if id == firstTouchID then
scene.mouseMove(x, y)
end
end
function scene.touchUp(x, y, id)
if id == firstTouchID then
scene.mouseUp(x, y, 1)
firstTouchID = nil
end
end
function scene.update(dt)
if holdTimer then
holdTimer = holdTimer + dt
if holdTimer > .442 then
if next(dragging) then
local cx, cy = next(dragging):match('(%d)(%d)')
cx, cy = tonumber(cx), tonumber(cy)
scene.mouseUp(0, 0, 1)
DATA.tickMat[cy][cx] = DATA.tickMat[cy][cx] ~= 2 and 2 or 0
end
end
end
if saveTimer then
saveTimer = saveTimer - dt
if saveTimer <= 0 then
if dailyMode then
pcall(FILE.save, DATA, 'data.json', '-json')
end
saveTimer = nil
end
end
end
local tick = GC.load { w = 62, h = 62,
{ 'move', 4, 4 },
{ 'setLW', 10 },
{ 'setCL', 0, 0, 0 },
{ 'line', 0, 26, 26, 48, 52, 0 },
{ 'setLW', 4 },
{ 'setCL', COLOR.L },
{ 'line', 2, 28, 26, 48, 50, 3 },
}
local cross = GC.load { w = 62, h = 62,
{ 'move', 4, 4 },
{ 'setLW', 8 },
{ 'setCL', 0, 0, 0 },
{ 'line', 0, 0, 52, 52 },
{ 'line', 0, 52, 52, 0 },
{ 'setLW', 4 },
{ 'setCL', .62, .62, .62 },
{ 'line', 2, 2, 50, 50 },
{ 'line', 2, 50, 50, 2 },
}
function scene.draw()
gc.translate(board.X, board.Y)
-- Board & Separator
if DATA.win > 0 then