-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.lua
2443 lines (2385 loc) · 82 KB
/
index.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
local olderror = error
error = function(...)
olderror(debug.traceback(...))
end
DEVMODE, DEFDIRECTORY = false, "app0:"
local Color_new = Color.new
local Graphics_drawImage = Graphics.drawImage
local Graphics_drawImageExtended = Graphics.drawImageExtended
local Graphics_drawRotateImage = Graphics.drawRotateImage
local Graphics_drawScaleImage = Graphics.drawScaleImage
Th,Tm,Ts = System.getTime()
math.randomseed(Th*3600+Tm*60+Ts)
local function getHSV(color)
local r,g,b = Color.getR(color)/255,Color.getG(color)/255,Color.getB(color)/255
local min, max = math.min(r,g,b), math.max(r,g,b)
local v, d, s = max,max-min
if max==min then
return 0,0,v
end
if max==r then
if g>=b then
h = 60*(g-b)/d
else
h = 60*(g-b)/d+360
end
elseif max==g then
h = 60*(b-r)/d + 120
elseif max==b then
h = 60*(r-g)/d + 240
end
if max==0 then
s = 0
else
s = 1-min/max
end
return h,s,v
end
function mod(x,a)
return x-math.floor(x/a)*a
end
local function setHSV(h,s,v)
h = h/360
local i = math.floor(h * 6)
local f, p = h * 6 - i,v * (1 - s)*255
local q, t = v * (1 - f * s)*255,v * (1 - (1 - f) * s)*255
v = v * 255
i = mod(i,6)
if i==0 then return v,t,p
elseif i==1 then return q,v,p
elseif i==2 then return p,v,t
elseif i==3 then return p,q,v
elseif i==4 then return t,p,v
elseif i==5 then return v,p,q end
end
local function execQuery(cmd)
local d, r = Database.open(dbDir)
r = Database.execQuery(d, cmd)
Database.close(d)
return r
end
local Libs = {"fnt","pcl","cfg","thm","lang"}
local Colors = {
Text = Color_new(255, 255, 255),
Pen = Color_new(100,100,100),
Tile = Color_new(255, 255, 255),
Cross = Color_new(0, 148, 255),
Square = Color_new(0, 148, 255),
Background = Color_new(160, 0, 28),
SecondBack = Color_new(200, 0, 64),
X5Lines = Color_new(200,0,0),
Grid = Color_new(0,0,0),
Frame = Color_new(200, 0, 200),
FrameOutline = Color_new(0,0,0),
SideNumbers = Color_new (255,255,255)
}
ColorsTable = {"Text","Pen","Background","SecondBack","SideNumbers","Grid","X5Lines","Tile","Square","Cross","Frame","FrameOutline",}
color_size = 476/#ColorsTable
Options = {nowtheme = "default", animation = "rotating", language = 1, mistakes = 1, cleared = 0}
Options.fps = nil
if System.getLanguage() == 08 then Options.language = 2 end
appDir = DEFDIRECTORY
datDir = appDir.."data/"
libDir = datDir.."lib/"
lvlDir = datDir.."lvl/"
thmDir = datDir.."thm/"
txrDir = datDir.."txr/"
dir = "ux0:data/PiCrest/"
cnfgDir = dir.."config.ini"
clvlDir = dir.."levels/"
dbDir = dir.."save.db"
for i = 1, #Libs do dofile(libDir..Libs[i]..".lua") end
Animations = LOCALIZATION.ANIMATION
Animations.now = 1
local openPCL, updatePCL, createPCL, getTSPCL = PCL_Lib.open, PCL_Lib.update, PCL_Lib.create, PCL_Lib.getToSize
if not System.doesDirExist (dir.."tutorial/") then System.createDirectory (dir.."tutorial/") firstLaunch = true end
if not System.doesDirExist (dir) then System.createDirectory (dir) end
if not System.doesDirExist (clvlDir) then System.createDirectory (clvlDir) end
if not System.doesFileExist (dir.."custom.thm") then MakeTheme(dir.."custom.thm", Colors) end
if not System.doesFileExist (dbDir) then execQuery("CREATE TABLE REC(path varchar(255),ms Bigint);") end
local database_p = execQuery("SELECT path FROM [REC];")
local database_m = execQuery("SELECT ms FROM [REC];")
for i=1, #database_m do
database_m[i].ms = tonumber(database_m[i].ms)
end
if firstLaunch then
tutorial={count=1}
for i=1, 3 do
tutorial[i] = Graphics.loadImage(datDir.."tutorial/"..i..".png")
tutorial[i.."d"],tutorial[i.."g"] = 0,0
end
end
local newVar = true
local tex_but, tile_tex, cross_tex, padlr_tex, padud_tex, squarebut_tex, crossbut_tex,trianglebut_tex, circlebut_tex = Graphics.loadImage(txrDir.."button.png"), Graphics.loadImage(txrDir.."tile.png"), Graphics.loadImage(txrDir.."cross.png"), Graphics.loadImage(txrDir.."padlr.png"),Graphics.loadImage(txrDir.."padud.png"), Graphics.loadImage(txrDir.."squarebut.png"), Graphics.loadImage(txrDir.."crossbut.png"), Graphics.loadImage(txrDir.."trianglebut.png"), Graphics.loadImage(txrDir.."circlebut.png")
local pen_tex = Graphics.loadImage(txrDir.."pen.png")
local lbut_tex, rbut_tex = Graphics.loadImage(txrDir.."lbut.png"),Graphics.loadImage(txrDir.."rbut.png")
local rainbow,light,alpha,right,alpha26,alpha266 = Graphics.loadImage(txrDir.."rainbow.png"),Graphics.loadImage(txrDir.."light.png"),Graphics.loadImage(txrDir.."alpha.png"),Graphics.loadImage(txrDir.."right.png"),Graphics.loadImage(txrDir.."alpha26.png"),Graphics.loadImage(txrDir.."alpha266.png")
local star = Graphics.loadImage(txrDir.."star.png")
local DeltaTimer, newTime, actionTimer, gameTimer = Timer.new(), 0, Timer.new(), Timer.new()
local tile_size = 24
local half_size, square_size, frame_size = tile_size / 2, tile_size - 2, tile_size + 2
local pie, ceil, max, len, floor, sub, sin, cos,upper = math.pi, math.ceil, math.max, string.len, math.floor, string.sub, math.sin, math.cos,string.upper
local lock_time, def_pause, lil_pause = 800, 200, 60
local pause = def_pause
local oldpad, newpad, pad = SCE_CTRL_CROSS, SCE_CTRL_CROSS
local scan_themes, themes = System.listDirectory(thmDir),{now = 1}
local white,black,lowshadow, shadow, highshadow, antishadow = Color_new(255, 255, 255), Color_new(0, 0, 0),Color_new (0, 0, 0, 20),Color_new (0, 0, 0, 100), Color_new(0,0,0,170),Color_new (255, 255, 255, 100)
local mh_rot = pie
local level = {}
local rot_pause = 0
local all_max = 16*pie
local uScreen = 2
local LINE_VERTICAL, LINE_HORIZONTAL = true, false
local now_path = lvlDir
local fileFormat = function (name, format) return sub(name,len(name)-3,len(name)) == format end
local hint_status,hint_gravity,hint_delta,hint_now = false,0,0,0
local allLevels = 0
local clrLevels = 0
local function getRecord (p)
local r = 0
for i=1, #database_p do if database_p[i].path == p then r = database_m[i].ms break end end
return r
end
local function scan_folder(_path)
Timer.pause(DeltaTimer)
allLevels = 0
clrLevels = 0
local tableA,final,k = System.listDirectory(_path),{},1
if _path ~= lvlDir and _path ~= clvlDir then final[1] = {name="...", dir = true} k = 2 end
for i=1, #tableA do
if fileFormat(tableA[i].name,".pcl") then
final[#final+1] = {name = sub(tableA[i].name,1,len(tableA[i].name) - 4), dir = false}
final[#final].realname, final[#final].size = getTSPCL(_path..tableA[i].name)
allLevels = allLevels + 1
if getRecord(_path..tableA[i].name)~=0 then clrLevels = clrLevels + 1 end
elseif tableA[i].directory then
table.insert(final, k,{name = tableA[i].name.."/", dir = true})
k = k + 1
end
end
--table.sort(final, function(a,b) return a.name<b.name and a.dir==b.dir end)
Timer.resume(DeltaTimer)
return final
end
local function Controls_click(BUTTON) return Controls.check(pad, BUTTON) and not Controls.check(oldpad, BUTTON) end
local function changeCLR(c,f)
local gr,gg,gb,ga=Color.getR(c),Color.getG(c),Color.getB(c),Color.getA(c)
if f==0 then return c end
c = 0.3*gr + 0.6*gg + 0.1*gb
return Color_new(gr+f*(c-gr),gg+f*(c-gg),gb+f*(c-gb),ga)
end
local function newAlpha(c,a)
if a==255 then return c end
return Color_new(Color.getR(c), Color.getG(c), Color.getB(c), a)
end
local function updateAllData ()
for i = 1, #scan_themes do
if fileFormat(scan_themes[i].name, ".thm") then
themes[#themes+1] = sub(scan_themes[i].name,1,len(scan_themes[i].name) - 4)
end
end
themes[#themes + 1] = "custom"
readCfg (cnfgDir, Options)
local def_theme = thmDir.."default.thm"
if Options.nowtheme == "custom" then
if System.doesFileExist(dir.."custom.thm") then
def_theme = dir.."custom.thm"
else
Options.nowtheme = "default"
end
else
if System.doesFileExist(thmDir..Options.nowtheme..".thm") then
def_theme = thmDir..Options.nowtheme..".thm"
else
Options.nowtheme = "default"
end
end
AcceptTheme(def_theme, Colors)
for i=1, #themes do if themes[i] == Options.nowtheme then themes.now = i break end end
for i=1, #Animations[1] do if Animations[1][i] == Options.animation then Animations.now = i break end end
updateCfg (cnfgDir, Options)
end
local function updateRecord (p, r)
local id,c,t,db = #database_p + 1,"UPDATE [REC] SET ms = "..r.." WHERE path = '"..p.."';",true
for i=1, #database_p do
if database_p[i].path == p then
id,t = i,false break
end
end
database_m[id] = {ms = r}
database_p[id] = {path = p}
db = Database.open(dbDir)
if t then c = "INSERT INTO REC VALUES ('"..p.."',"..r..");" end
Database.execQuery(db,c)
Database.close(db)
end
local function toDigits (x)
if x<0 then x = -x end
local mt1000 = floor(x / 1000)
local mt60 = floor(mt1000 / 60)
local h = floor(mt60 / 60)
if h > 99 then return "99:59:59" end
local m = mt60 - h * 60
local s = mt1000 - mt60 * 60
local ms = x - h * 3600000 - m * 60000 - s * 1000
if h/10<1 then h = "0"..h end
if m/10<1 then m = "0"..m end
if s/10<1 then s = "0"..s end
if ms/10<1 then ms="0"..ms end
if ms/100<1 then ms="0"..ms end
return h..":"..m..":"..s.."."..ms
end
local function ResetData ()
System.deleteFile(dbDir)
execQuery("CREATE TABLE REC(path varchar(255),ms Bigint);")
database_p = execQuery("SELECT path FROM [REC];")
database_m = execQuery("SELECT ms FROM [REC];")
Options.cleared=0
updateCfg(cnfgDir, Options)
level.recInms = 0
level.record = toDigits(level.recInms)
end
local function drawRect (x, y, w, h, c) c = c or white Graphics.fillRect(x, x + w, y, y + h, c) end
local function drawEmptyRect (x, y, w, h, t, c)
local p = w - 2 * t
drawRect(x, y, t, h, c)
drawRect(x + t, y, p, t, c)
drawRect(x + w - t, y, t, h, c)
drawRect(x + t, y + h - t, p, t, c)
end
local function minus ()
Timer.reset(actionTimer)
pause = lock_time
tile_oldAdd = tile_nowAdd
local time = nowGameTimer + tile_nowAdd * 60000
Timer.setTime(gameTimer,-time)
if tile_nowAdd~=8 then tile_nowAdd = tile_nowAdd*2 end
mh_rot = 0
end
local function updateStacks ()
tile_stackU={}
tile_stackL={}
for i = 0, max(level.width,level.height) - 1 do
if i < level.width then tile_stackU[i] = {[0]=0} end
if i < level.height then tile_stackL[i] = {[0]=0} end
end
local tmp = 0
for i = 0, level.width-1 do
local now, tmp = 0, 0
for j=0, level.height-1 do
if level.map[tmp+i+1] then
tile_stackU[i][now] = tile_stackU[i][now] + 1
else
if tile_stackU[i][now] and tile_stackU[i][now] > 0 then
now = now + 1
tile_stackU[i][now] = 0
end
end
tmp = tmp + level.width
end
if tile_stackU[i][now] == 0 and tile_stackU[i][0] ~= 0 then tile_stackU[i][now]=nil end
end
tmp = 0
for i = 0, level.height-1 do
local now = 0
for j=0, level.width-1 do
tmp = tmp + 1
if level.map[tmp] then
tile_stackL[i][now] = tile_stackL[i][now] + 1
else
if tile_stackL[i][now] and tile_stackL[i][now] > 0 then
now = now + 1
tile_stackL[i][now] = 0
end
end
end
if tile_stackL[i][now] == 0 and tile_stackL[i][0]~=0 then tile_stackL[i][now]=nil end
end
end
local function Update ()
newVar = true
start_x = (960 - level.width * tile_size)/2
start_y = floor((544 - (level.height) * tile_size + 19*ceil(level.height / 2))/2)
newStart_y = (544 - level.height*tile_size)/2
square_start_x = start_x + 1
square_start_y = start_y + 1
level_width, level_height = level.width * tile_size, level.height * tile_size
frame_x = 0
frame_y = 0
frame_old_x,frame_old_y = 0, 0
level.empty = {}
level.recInms = getRecord(level.path)
if level.recInms<0 then
level.perfect = true
level.recInms = - level.recInms
else
level.perfect = false
end
level.record = toDigits(level.recInms)
level.cross = {}
level.square = {}
level.pen = {}
level.penB = {}
level.nowBlocks = 0
level.allBlocks = 0
tile_oldAdd, tile_nowAdd = 1, 1
isRecord = nil
local tmp = 0
for i = 1, level.height do
for j = 1, level.width do
tmp = tmp + 1
level.empty[tmp] = 0
level.square[tmp] = 0
level.cross[tmp] = 0
level.pen[tmp] = false
level.penB[tmp] = 0
if level.map[tmp] then
level.allBlocks = level.allBlocks + 1
end
end
end
updateStacks()
Timer.reset(gameTimer)
Timer.pause(gameTimer)
level.hint = nil
hint_delta = 0
hint_status = true
hint_now = 0
end
local function UpdateCreate()
palette_status = nil
start_x = (960 - level.width * tile_size)/2
start_y = floor((544 - level.height * tile_size)/2)
newStart_y = (544 - level.width*tile_size)/2
square_start_x = start_x + 1
square_start_y = start_y + 1
level_width, level_height = level.width * tile_size, level.height * tile_size
frame_x = 0
frame_y = 0
frame_old_x,frame_old_y = 0, 0
level.empty = {}
level.recInms = getRecord(level.path)
level.record = toDigits(level.recInms)
level.cross = {}
level.square = {}
level.pen = {}
level.penB = {}
level.pmap = {}
tile_oldAdd, tile_nowAdd = 1, 1
local tmp = 0
for i = 1, level.height do
for j = 1, level.width do
tmp = tmp + 1
level.empty[tmp] = 0
level.square[tmp] = 0
level.cross[tmp] = 0
level.pen[tmp] = false
level.penB[tmp] = 0
level.pmap[tmp] = white
end
end
hint_delta = 0
hint_status = false
hint_now = 2
UNDOTABLE = {}
UNDONOW = 1
TableColorize = {}
end
local menu_status, menu_delta, menu_gravity, menu_buttons, menu_now = true, 0, 0, LOCALIZATION.MENU.BUTTONS, 0
local pause_delta, pause_status, pause_gravity, pause_buttons, pause_now = 0, false, 0, LOCALIZATION.PAUSE.BUTTONS, 0
local yes_or_no_delta, yes_or_no_status, yes_or_no_gravity, yes_or_no_now, yes_or_no_buttons = 0, false, 0, 0,LOCALIZATION.YESORNO.BUTTONS
local theme_delta, theme_status, theme_gravity, theme_now, theme_name_y, theme_name_gravity = 0, false, 0, 0, 0, 0
local lselection_delta, lselection_status, lselection_gravity, lselection_now = 0, false, 0, 0
local options_delta, options_status, options_gravity, options_buttons, options_now = 0, false, 0, LOCALIZATION.OPTIONS.BUTTONS , 0
create_delta, create_status, create_gravity, create_buttons, create_now = 0,false,0,LOCALIZATION.CREATE.BUTTONS
create_table_def = {name ="", width = 5, height = 5, map = {}, pmap = {} }
create_table = {name = create_table_def.name, width = create_table_def.width, height = create_table_def.height, map = {}, pmap = {} }
palette_delta, palette_gravity = 0, 0
exit_delta, exit_status, exit_gravity = 0, false, 0
local now_number, number_p_delta, old_color = 0, 0
local lselection_startI, lselection_oldStartI = 1, 1
local systemLevelFolder = scan_folder(now_path)
local holdpath = clvlDir
local head_delta, head_status, head_gravity = 0, true, 0
local Color_pick, Colors_creater = Color_new(0,0,0),{
black,Color_new(29,43,82), Color_new(126,37,83),Color_new(0,134,81),
Color_new(171,81,54),Color_new(95,86,79),Color_new(194,195,199),white,
Color_new(255,0,76),Color_new(255,163,0),Color_new(255,240,35),Color_new(0,232,81),
Color_new(36,176,255),Color_new(130,118,156),Color_new(255,118,170),Color_new(255,204,167),
white,white,white,white,white,white,white,white,
}
local color_now, color_r, color_g, color_b, color_h, color_s, color_v, color_a = 1, 0, 0, 0, 0, 0, 0,255
local cleared,cleared_gravity = 0, 0
local preview = {d=0,s=false,g=0,lvl={}}
local function parseLevel()
if not menu_status and not isColorize and level.nowBlocks == level.allBlocks and newVar then
newVar = false
if checkLevel() then
Timer.pause(gameTimer)
dontPress = true
if not cleared_status then cleared_status = true Options.cleared = Options.cleared + 1 updateCfg(cnfgDir, Options) end
if isRecord == nil then
local time = nowGameTimer
if time == 0 then time = 1 end
if tonumber(level.recInms) == 0 or tonumber(level.recInms) > time then
level.recInms = time
isRecord = true
else
isRecord = false
end
if tile_nowAdd==1 then level.perfect = true end
end
end
end
end
local function return_delta_gravity(status, gravity, delta, rot, add)
if status then
if delta+gravity < 1 then
return delta + gravity, gravity + 0.002*dt,0
else
return 1, 0,rot
end
else
if delta - gravity > 0 then
return delta - gravity, gravity + 0.002*dt,rot
else
return 0, 0,rot
end
end
end
local function return_key_list(now, up_key, down_key, up_limit, down_limit)
if not (up_key or down_key) then return now end
if up_key then
if now + 1 > up_limit then
return down_limit
else
return now + 1
end
elseif down_key then
if now - 1 < down_limit then
return up_limit
else
return now - 1
end
end
end
local function if_now_change(now, i, table, iSize, add, min,max)
table[iSize] = table[iSize] or min
if now == i then
if table[iSize] + add < max then
table[iSize] = table[iSize] + add
else
table[iSize] = max
end
else
if table[iSize] - add > min then
table[iSize] = table[iSize] - add
else
table[iSize] = min
end
end
end
local function down_screen (now, delta, table, lock, ...)
if delta > 0 then
local nt, t, m, add = {...}, 1, 272 * delta, 3
local y, alpha40,alpha100,alpha = 700 - m - 20 * #table[lng],40*delta,100*delta
drawRect(0,544 - m, 960, m, black)
for i=1 ,#table[lng] do
text = table[lng][i]
if nt[t] and i==nt[t] then text = text..nt[t + 1] t = t + 2 end
if lock[i] then alpha = alpha40 else alpha = alpha100 end
FontLib_printExtended (480, y, text,3,3,0, Color_new(255,255,255,alpha),lng)
if now == i then
if number_p_delta ~= 1 then add = 3*number_p_delta end
FontLib_printExtended (480+add, y-add, text,3,3,0, Color_new(255,255,255,delta*(100+155*number_p_delta)),lng)
end
y = y + 40
end
return m
end
end
local function down_buttons (delta, tableNames, tableTex, t)
if delta==1 then
local x, y = 16, 800 - 272*delta
for i=1, #tableNames[lng] do
if t then drawRect(x,y,tableTex[#tableNames[lng]-i+1]:len()*14,26,shadow) end
Graphics_drawRotateImage(x, y, tableTex[#tableNames[lng]-i+1], 0)
FontLib_print(x + 16, y - 6,"- "..tableNames[lng][#tableNames[lng]-i+1], white, lng)
y = y - 26
end
end
end
local function head_screen ()
if head_status or head_delta>0 then
head_delta, head_gravity, rot_pause = return_delta_gravity(head_status, head_gravity , head_delta, rot_pause)
local c2, r, y = Color_new(255, 255, 255, 255 * head_delta), pie / 90 * sin(rot_pause / 2), 272 * head_delta
drawRect(0, 0, 960, y, black)
FontLib_printExtended(480, y - 136, LOCALIZATION.HEAD.HEAD[lng], 5, 5, r, c2,lng)
FontLib_printExtended(480, y - 100, LOCALIZATION.HEAD.TEXT[lng], 3, 1, 0, c2,lng)
if head_delta==1 then
drawRect(0, y, 960, 2, black)
end
local score = Options.cleared
for i=len(score), 7 do score="0"..score end
FontLib_print(16,y-256,LOCALIZATION.SCORE[lng].." : "..score,white,lng)
if (lselection_delta>0 or lselection_status) and now_path~=lvlDir then
local prcntge = math.floor(clrLevels/(allLevels/100))
if prcntge and prcntge==prcntge then
drawEmptyRect(880-53,lselection_delta*272-272+20,106,23,2,white)
drawRect(880-50,lselection_delta*272-272+23,prcntge,17,white)
FontLib_print(880-50+0.69*prcntge,lselection_delta*272-272+24,prcntge,white,0)
end
end
end
end
local function menu_screen()
if (menu_status or menu_delta>0) and options_delta~=1 and create_delta~=1 then
menu_delta, menu_gravity = return_delta_gravity (menu_status, menu_gravity, menu_delta)
if menu_delta == 1 and menu_status and not options_status and not create_status and not lselection_status and not exit_status then
if PAD_DOWN or PAD_UP then number_p_delta = 0 end
menu_now = return_key_list(menu_now, PAD_DOWN, PAD_UP, #menu_buttons[lng], 1)
if pause_status then pause_status = false end
if PAD_CROSS then
if menu_now == 1 then
lselection_status = true
launch = false
elseif menu_now == 3 then
options_status = true
elseif menu_now == 2 then
create_status = true
create_table = {name = create_table_def.name, width = create_table_def.width, height = create_table_def.height, map = {}, pmap = {} }
elseif menu_now==4 then
exit_status = true
end
end
elseif menu_delta == 0 then menu_now = 0 uScreen = -1
end
if not launch then
down_screen (menu_now, menu_delta, menu_buttons,{})
down_buttons (menu_delta,LOCALIZATION.MENU.DOWN_BUTTONS,{crossbut_tex})
FontLib_print(718, 800 - 272*menu_delta,"PiCrest v1.15 by @creckeryop",white)
end
return true
end
end
local function pause_screen ()
if (pause_status or pause_delta>0) and options_delta~=1 then
pause_delta,pause_gravity = return_delta_gravity (pause_status, pause_gravity, pause_delta)
if pause_delta==1 and pause_status and not options_status then
pause_now = return_key_list(pause_now, PAD_DOWN, PAD_UP, #pause_buttons[lng], 1)
if PAD_UP or PAD_DOWN then number_p_delta = 0 end
if PAD_CROSS then
if pause_now==1 then
pause_status,dontPress = false,true
elseif pause_now==2 then
options_status = true
elseif pause_now==3 then
menu_status = true
else
pause_now,number_p_delta = 1,0
end
end
if (PAD_CIRCLE or PAD_START) and theme_delta==0 then
pause_status,dontPress = false,true
end
elseif pause_delta==0 then
pause_now,uScreen = 0,-1
end
down_screen (pause_now, pause_delta, pause_buttons,{})
down_buttons (pause_delta,LOCALIZATION.PAUSE.DOWN_BUTTONS,{crossbut_tex, circlebut_tex})
return true
end
end
local function options_screen ()
if (options_status or options_delta>0) and theme_delta~=1 then
options_delta,options_gravity = return_delta_gravity (options_status, options_gravity, options_delta)
if options_status and not theme_status and options_delta==1 then
if not yes_or_no_status then
options_now = return_key_list(options_now, PAD_DOWN, PAD_UP, #options_buttons[lng], 1)
if PAD_UP or PAD_DOWN then
number_p_delta = 0
if not menu_status and (options_now==2 or options_now==5) then
if PAD_DOWN then
options_now = options_now + 1
elseif PAD_UP then
options_now = options_now - 1
end
end
end
if PAD_CIRCLE or options_now==#options_buttons[lng] and PAD_CROSS then options_status=false end
end
if PAD_LEFT or PAD_RIGHT then
if options_now == 4 then
if PAD_LEFT then
Options.language = lng - 1
else
Options.language = lng + 1
end
if Options.language<1 then Options.language = #FontLib end
if Options.language>#FontLib then Options.language = 1 end
updateCfg(cnfgDir, Options)
elseif options_now == 3 then
Animations.now = return_key_list(Animations.now, PAD_RIGHT, PAD_LEFT, #Animations[1], 1)
Options.animation = Animations[1][Animations.now]
updateCfg(cnfgDir, Options)
elseif options_now == 2 then
Options.mistakes = 1 - Options.mistakes
updateCfg(cnfgDir, Options)
end
end
if PAD_CROSS then
if options_now==2 then
Options.mistakes = 1 - Options.mistakes
updateCfg(cnfgDir, Options)
elseif options_now==1 then
theme_status = true
theme_now = 1
elseif options_now==4 then
Options.language = lng + 1
if Options.language>#FontLib then Options.language = 1 end
updateCfg(cnfgDir, Options)
elseif options_now==5 then
if not yes_or_no_status then
yes_or_no_status = true
yes_or_no_now = 0
elseif yes_or_no_now==0 then
yes_or_no_now = 1
number_p_delta = 0
elseif yes_or_no_now==1 then
local tmpDt = dt
ResetData()
dt = tmpDt
yes_or_no_status = false
elseif yes_or_no_now==2 then
yes_or_no_status = false
end
end
end
elseif options_delta==0 then
options_now = 0
end
local lock = {}
if not menu_status then lock[2],lock[5] = true, true end
down_screen(options_now, options_delta, options_buttons,lock,2," <"..yes_or_no_buttons[lng][2-Options.mistakes]..">",3," <"..Animations[lng][Animations.now]..">")
if options_now==2 then
down_buttons (options_delta,LOCALIZATION.OPTIONS.DOWN_BUTTONS[1],{circlebut_tex, padlr_tex})
else
down_buttons (options_delta,LOCALIZATION.OPTIONS.DOWN_BUTTONS[2],{crossbut_tex, circlebut_tex})
end
if lng == 4 then
FontLib_print(960-34*8-8, 800 - 272*options_delta,"Japanese translation by kuragehime",white)
end
end
end
local function theme_screen()
if theme_delta>0 or theme_status then
theme_delta,theme_gravity = return_delta_gravity (theme_status, theme_gravity, theme_delta)
theme_name_y,theme_name_gravity = return_delta_gravity (false, theme_name_gravity, theme_name_y)
if theme_delta == 1 then
if now_number==0 then
if PAD_LTRIGGER or PAD_RTRIGGER then
themes.now = return_key_list(themes.now, PAD_RTRIGGER, PAD_LTRIGGER, #themes, 1)
local text = thmDir..themes[themes.now]..".thm"
if themes.now == #themes then
text = dir.."custom.thm"
end
AcceptTheme(text, Colors)
Options.nowtheme = themes[themes.now]
updateCfg(cnfgDir, Options)
theme_name_y = 1
elseif PAD_LEFT or PAD_RIGHT then theme_now = return_key_list(theme_now, PAD_RIGHT, PAD_LEFT, #ColorsTable, 1)
elseif PAD_CIRCLE then theme_status = false
elseif PAD_CROSS then now_number = 1 old_color = Colors[ColorsTable[theme_now]]
end
else
now_number = return_key_list(now_number,PAD_RIGHT,PAD_LEFT,6,1)
if PAD_CROSS then
if Colors[ColorsTable[theme_now]] ~= old_color then
MakeTheme(dir.."custom.thm", Colors)
themes.now = #themes
Options.nowtheme = "custom"
updateCfg(cnfgDir, Options)
end
now_number = 0
elseif PAD_CIRCLE then Colors[ColorsTable[theme_now]] = old_color now_number = 0
elseif PAD_UP or PAD_DOWN then
local hex = rgb2hex(Colors[ColorsTable[theme_now]])
local next = tonumber(sub(hex,now_number,now_number),16)
if PAD_UP then
next = next + 1
if next>15 then next = 0 end
number_p_delta = 0
elseif PAD_DOWN then
next = next -1
if next<0 then next = 15 end
number_p_delta = 2
end
Colors[ColorsTable[theme_now]] = Color_new(hex2rgb(sub(hex,0,now_number-1)..string.format("%X",next)..sub(hex,now_number+1,6)))
end
end
end
local start_x = 240
local start_y = 544-(544-32)*theme_delta
local y = start_y+122
local inv = 255*theme_delta
local x = start_x
drawRect(0,0,960,544,Color_new(0, 0, 0, inv))
Graphics_drawImage(start_x,start_y,tex_but,Color_new(255,255,255,inv))
FontLib_printExtended(start_x+240,start_y + 16*theme_name_y + 18, upper(Options.nowtheme),2,2, 0, newAlpha(Colors.Text,inv-255*theme_name_y))
drawRect(start_x,start_y+32,480,416,newAlpha(Colors.Background,inv))
drawRect(start_x + 119, y-1,242,242,newAlpha(Colors.Tile,inv))
drawRect(start_x + 121, y + 119,238,2,newAlpha(Colors.X5Lines,inv))
drawRect(start_x + 239, y + 1,2,238,newAlpha(Colors.X5Lines,inv))
do
local size = ColorsTable[theme_now+16] or 16
local key = ColorsTable[theme_now]
local hex = rgb2hex(Colors[key])
local inv = 255*(size/16-2+theme_delta)
local _max = max(8,len(key))*10
local text_color = newAlpha(Colors.Text,inv)
drawRect(start_x+240-_max,start_y+400-size,2*_max,70, Color_new(0,0,0,inv))
FontLib_printExtended(480,start_y+420-size,upper(key),2,2,0,text_color)
FontLib_printExtended(480,start_y+452-size,"0x"..hex,2,2,0,text_color)
if now_number>0 then
drawRect(430+now_number*16,start_y+436-size,16,30, Color_new(0,148,255))
end
local text = " "
for i=1, 6 do
if i == now_number then text = text..sub(hex,i,i) else text = text.." " end
end
FontLib_printExtended(480+cos(2*rot_pause),start_y+447-size+number_p_delta*5+sin(2*rot_pause),text,2,2,0,text_color)
end
for i=1, #ColorsTable do
local y = i + 16
if_now_change(theme_now, i, ColorsTable, y, dt, 16, 32)
drawRect(x + 3, start_y + 448, color_size - 2, ColorsTable[y], Colors[ColorsTable[i]])
drawRect(x + 3, start_y + 444 + ColorsTable[y], color_size - 2, 4, antishadow)
x = x + color_size
end
for i=0, 9 do
local x = start_x + 120
if floor(i/2) == i/2 then drawRect(start_x, y + 1, 111, 22, newAlpha(Colors.SecondBack,inv)) end
FontLib_print(x - 23, y + 4, "1", newAlpha(Colors.SideNumbers,inv), 0)
drawRect(x-1,y-1,242,2,newAlpha(Colors.Grid,inv))
for j=0, 9 do
if i==0 then
drawRect(x-1,y-1,2,242,newAlpha(Colors.Grid,inv))
if floor(j/2)==j/2 then drawRect(x+1,start_y+32,22,81,newAlpha(Colors.SecondBack,inv)) end
FontLib_print(x + 7 , y - 27,"1",newAlpha(Colors.SideNumbers,inv),0)
end
if i==j then Graphics_drawImage(x + 1, y + 1, tile_tex, newAlpha(Colors.Square,inv)) end
if i>0 and j==0 then Graphics_drawImage(x + 1, y + 1, cross_tex, newAlpha(Colors.Cross,inv)) end
if j==5 and i<5 then Graphics_drawImage(x + 1, y + 1, pen_tex, newAlpha(Colors.Pen,inv)) end
x = x + 24
if i==0 and j==9 then
drawRect(x-1,y-1,2,242,newAlpha(Colors.Grid,inv))
end
end
y = y + 24
end
y = start_y + 122
drawRect(start_x + 120, y + 119, 240,2,Colors.X5Lines)
drawRect(start_x + 239, y, 2, 240,Colors.X5Lines)
drawRect(start_x + 119, y - 1, 242, 2, newAlpha(Colors.Grid,inv))
drawRect(start_x + 119, y + 239, 242, 2, newAlpha(Colors.Grid,inv))
drawEmptyRect(start_x, start_y + 32, 480, 416, 2, Color_new(48,48,48,inv))
drawEmptyRect(start_x, start_y + 32, 480, 420, 6, Color_new(0,0,0,100*theme_delta))
drawEmptyRect(start_x + 335, y -1,26,26,6,newAlpha(Colors.FrameOutline,inv))
drawEmptyRect(start_x + 336, y , 24, 24, 4, newAlpha(Colors.Frame,inv))
if now_number==0 then
down_buttons (theme_delta,LOCALIZATION.THEMES.DOWN_BUTTONS[1],{ crossbut_tex, circlebut_tex, padlr_tex})
else
down_buttons (theme_delta,LOCALIZATION.THEMES.DOWN_BUTTONS[2],{ crossbut_tex, circlebut_tex, padud_tex})
end
end
end
local function create_screen()
if (create_status or create_delta>0) then
create_delta,create_gravity = return_delta_gravity (create_status, create_gravity, create_delta)
if create_delta==1 then
create_now = return_key_list(create_now, PAD_DOWN, PAD_UP, #create_buttons[lng], 1)
if PAD_UP or PAD_DOWN then number_p_delta = 0 end
if PAD_LEFT or PAD_RIGHT then
if create_now == 2 then
create_table.width = return_key_list(create_table.width, PAD_RIGHT, PAD_LEFT, 15, 5)
elseif create_now==3 then
create_table.height = return_key_list(create_table.height, PAD_RIGHT, PAD_LEFT, 15, 5)
end
end
local status = Keyboard.getState()
if edit_name then
if status ~= RUNNING then
if status ~= CANCELED then
create_table.name = Keyboard.getInput()
if create_table.name:find('/') then create_table.name = "" end
end
Keyboard.clear()
edit_name = false
end
end
if status~=RUNNING then
if PAD_CIRCLE then
create_status = false
elseif PAD_CROSS then
if create_now==1 then
Keyboard.show("Input name", create_table.name)
edit_name = true
elseif create_now==4 and create_table.name~="" then
level = create_table
UpdateCreate()
isCreate = true
create_status = false
menu_status = false
end
end
end
elseif create_delta==0 then create_now = 0
end
local m = down_screen (create_now, create_delta, create_buttons,{},2," <"..create_table.width..">", 3," <"..create_table.height..">")
if m then
FontLib_printRotated(480,584-m,"<"..create_table.name..">",0,white)
end
if create_now==2 or create_now==3 then
down_buttons (create_delta,LOCALIZATION.CREATE.DOWN_BUTTONS[1],{padlr_tex,circlebut_tex})
else
local loc = 3
if create_now==1 then loc = 2 end
down_buttons (create_delta,LOCALIZATION.CREATE.DOWN_BUTTONS[loc],{crossbut_tex,circlebut_tex})
end
return true
end
end
local function lselection_screen()
if lselection_status or lselection_delta>0 then
lselection_delta,lselection_gravity = return_delta_gravity(lselection_status,lselection_gravity,lselection_delta)
if lselection_delta==1 then
if PAD_DOWN then
if lvlDir~=now_path then
if lselection_now <#systemLevelFolder then
lselection_now = lselection_now + 1
number_p_delta = 0
end
lselection_oldStartI = lselection_startI
if lselection_now>lselection_startI+4 then lselection_startI = lselection_startI + 1 end
else
if lselection_now<5 then
lselection_now = lselection_now + 1
number_p_delta = 0
end
if lselection_now>4 then lselection_now = 1 end
end
end
if lvlDir~=now_path and #systemLevelFolder>0 then
if PAD_LEFT then
if lselection_now>1 then
lselection_now = lselection_now - 5
lselection_oldStartI = lselection_startI
if lselection_startI>1 then
lselection_startI = lselection_startI - 5
end
number_p_delta = 0
end
if lselection_now<1 then
lselection_now = 1
lselection_startI = 1
end
if lselection_startI<1 then
lselection_startI = 1
end
elseif PAD_RIGHT then
if lselection_now<#systemLevelFolder then
lselection_now = lselection_now + 5
lselection_oldStartI = lselection_startI
if lselection_startI<#systemLevelFolder - 4 then
lselection_startI = lselection_startI + 5
end
number_p_delta = 0
end
if lselection_now>#systemLevelFolder then
lselection_now = #systemLevelFolder
lselection_startI = #systemLevelFolder - 4
end
if lselection_startI+4>#systemLevelFolder then
lselection_startI = #systemLevelFolder - 4
end
end
end
if PAD_UP then
if lvlDir~=now_path then
if lselection_now==0 then
lselection_now = 1
elseif lselection_now>1 then
lselection_now = lselection_now - 1
number_p_delta = 0
end
lselection_oldStartI = lselection_startI
if lselection_now<lselection_startI then lselection_startI = lselection_startI - 1 end
else
if lselection_now>0 then
lselection_now = lselection_now - 1
number_p_delta = 0
end
if lselection_now<1 then lselection_now = 4 end
end
end
if PAD_CIRCLE then lselection_status = false end
if PAD_TRIANGLE then
isCustom = not isCustom
local tmp = holdpath
holdpath = now_path
now_path = tmp
systemLevelFolder = scan_folder(now_path)
lselection_now, lselection_startI, lselection_oldStartI = 1, 1, 1
end
if lselection_now~=0 and #systemLevelFolder~=0 then
if lvlDir~=now_path then
if preview.s and (PAD_UP or PAD_DOWN or PAD_LEFT or PAD_RIGHT or PAD_TRIANGLE) then
if systemLevelFolder[lselection_now].dir or PAD_TRIANGLE then
if not systemLevelFolder[lselection_now].dir then
preview.lvl = openPCL(now_path..systemLevelFolder[lselection_now].name..".pcl")
preview.r = nil
local record = getRecord(now_path..systemLevelFolder[lselection_now].name..".pcl")
if record<0 then record = -record end
if record>0 then
if record>3600000 then
preview.r = false
else
preview.r = true
end
end
end
else
preview.lvl = openPCL(now_path..systemLevelFolder[lselection_now].name..".pcl")
preview.r = nil
local record = getRecord(now_path..systemLevelFolder[lselection_now].name..".pcl")
if record<0 then record = -record end
if record>0 then
if record>3600000 then
preview.r = false
else
preview.r = true
end
end
end
end
if preview.d == 0 or preview.d == 1 then
if PAD_SQUARE and preview.s then
preview.s = false
elseif PAD_SQUARE and not systemLevelFolder[lselection_now].dir then
local dTime = Timer.getTime(DeltaTimer)
preview.s = true