-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcupcake.p8
1292 lines (1238 loc) · 58.9 KB
/
cupcake.p8
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
pico-8 cartridge // http://www.pico-8.com
version 41
__lua__
-- cupcake clicker (intern edition)
-- cpiod for gmtk game jam 2023
-- modes:
-- 0: alarm clock
-- 1: title screen
-- 10: color
-- 11: menu
-- 12: search
-- 13: machine
-- 99: game over
-- ingr: name,sprx,spry,w,h
-- model: nb,coeff
function _init()
camera_x=0
camera_y=0
camera_ox=0
day=1
tuto=1
search_day=2
round_duration=30*60
left=round_duration
ingr={}
nb_machines=0
search=0
models={}
can_search=true
rewards={12,12,30}
-- more stock: id=20
-- new machine: id=30
-- id=40-49: ingredient plus rapide
add(models,{id=11,name="valentine",nb=4,coeff=1})
add(ingr,{id=1,name="strawberry",sprx=0,spry=0,w=10,h=10,spd=1})
add(ingr,{id=2,name="blueberries",sprx=0,spry=16,w=13,h=13,spd=1})
current_quality=0
target=5
current=0
stock=0
radio_state=0
selected_model=1
change_mode(0)
poke(0x5f2d,3) -- enable mouse
poke(0x5f5c,-1) -- no btnp autorepeat
modified_machine=0
current_machine=0
-- typ2spr={[0]=0}
-- typ2col={[0]=8}
selected_ingr=1
selected_model=1
draw_zone_x=7
draw_zone_y=12
draw_zone_width=10+8*8
draw_zone_height=10+4*8
m=add_machine()
-- test
-- m=add_machine()
-- m=add_machine()
-- m=add_machine()
-- m=add_machine()
-- m+="broken"
-- add(models,{id=12,name="special blue",nb=68,coeff=9})
end
-- font
poke(0x5600,unpack(split"8,8,10,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,24,24,24,24,0,24,0,0,54,54,18,0,0,0,0,0,54,127,54,127,54,0,0,24,124,30,60,120,62,24,0,6,102,48,24,12,102,96,0,28,54,54,28,110,54,108,0,24,24,8,0,0,0,0,0,24,12,6,6,6,12,24,0,24,48,96,96,96,48,24,0,24,126,60,24,60,126,24,0,0,24,24,126,24,24,0,0,0,0,0,0,0,12,12,6,0,0,0,126,0,0,0,0,0,0,0,0,0,0,12,0,0,96,48,24,12,6,0,0,0,0,60,118,110,102,60,0,0,0,24,28,24,24,60,0,0,0,62,96,60,6,126,0,0,0,62,96,56,96,62,0,0,0,56,60,54,126,48,0,0,0,126,6,62,96,62,0,0,0,60,6,62,102,60,0,0,0,126,96,48,24,12,0,0,0,60,102,60,102,60,0,0,0,60,102,124,96,60,0,0,0,0,12,0,12,0,0,0,0,0,12,0,12,12,6,48,24,12,6,12,24,48,0,0,0,0,126,0,0,0,0,12,24,48,96,48,24,12,0,0,60,102,48,24,0,24,0,0,60,102,118,110,118,60,0,0,0,60,102,126,102,102,0,0,0,62,102,62,102,62,0,0,0,60,102,6,102,60,0,0,0,62,102,102,102,62,0,0,0,126,6,30,6,126,0,0,0,126,6,30,6,6,0,0,0,124,6,118,102,124,0,0,0,102,102,126,102,102,0,0,0,60,24,24,24,60,0,0,0,96,96,96,102,60,0,0,0,102,54,30,54,102,0,0,0,6,6,6,6,126,0,0,0,66,102,126,126,102,0,0,0,102,110,126,118,102,0,0,0,60,102,102,102,60,0,0,0,62,102,62,6,6,0,0,0,60,102,102,54,108,0,0,0,62,102,126,54,102,0,0,0,124,6,60,96,62,0,0,0,126,24,24,24,24,0,0,0,102,102,102,102,60,0,0,0,102,102,102,60,24,0,0,0,102,126,126,102,66,0,0,0,102,60,24,60,102,0,0,0,102,102,60,24,24,0,0,0,126,48,24,12,126,0,62,6,6,6,6,6,62,0,0,6,12,24,48,96,0,0,62,48,48,48,48,48,62,0,24,60,102,0,0,0,0,0,0,0,0,0,0,0,0,126,12,24,48,0,0,0,0,0,0,60,102,102,126,102,102,0,0,62,102,62,102,102,62,0,0,60,102,6,6,102,60,0,0,62,102,102,102,102,62,0,0,126,6,30,6,6,126,0,0,126,6,30,6,6,6,0,0,124,6,118,102,102,124,0,0,102,102,126,102,102,102,0,0,60,24,24,24,24,60,0,0,96,96,96,96,102,60,0,0,102,54,30,54,102,102,0,0,6,6,6,6,6,126,0,0,66,102,126,126,102,102,0,0,102,110,126,118,102,102,0,0,60,102,102,102,102,60,0,0,62,102,102,62,6,6,0,0,60,102,102,102,54,108,0,0,62,102,102,62,54,102,0,0,124,6,60,96,96,62,0,0,126,24,24,24,24,24,0,0,102,102,102,102,102,60,0,0,102,102,102,102,60,24,0,0,102,102,126,126,102,66,0,0,102,60,24,60,102,102,0,0,102,102,60,24,24,24,0,0,126,48,24,12,6,126,0,56,12,12,6,12,12,56,0,24,24,24,24,24,24,24,24,14,24,24,48,24,24,14,0,44,26,0,0,0,0,0,0,0,28,54,28,0,0,0,0,255,255,255,255,255,255,255,255,85,170,85,170,85,170,85,170,0,195,255,189,189,255,126,0,60,126,255,129,195,231,126,60,17,68,17,68,17,68,17,0,4,12,252,124,62,63,48,32,60,110,223,255,255,255,126,60,102,255,255,255,126,60,24,0,24,60,102,231,102,60,24,0,24,24,0,60,90,24,60,102,60,126,255,126,82,82,94,0,60,110,231,227,227,231,110,60,0,255,153,153,255,129,255,0,56,120,216,24,30,31,14,0,0,126,195,219,219,195,126,0,8,28,62,127,62,28,8,0,0,0,0,0,85,0,0,0,60,118,231,199,199,231,118,60,0,8,28,127,62,28,54,0,127,34,20,8,8,20,42,127,60,126,231,195,129,255,126,60,0,5,82,32,0,0,0,0,0,17,42,68,0,0,0,0,0,126,219,231,231,219,126,0,255,0,255,0,255,0,255,0,85,85,85,85,85,85,85,85,255,129,129,129,129,129,129,255,255,195,165,153,153,165,195,255,0,126,62,30,62,118,34,0,8,28,62,127,127,62,8,62,8,28,28,107,127,107,8,28,28,34,73,93,73,34,28,0"))
-- version with asserts (238 tokens)
-- renaming and world
cmp,has,_ents=pack,rawget,{}
function ent()
-- find the value in components
function _find(self,a)
for _,t in pairs(self) do
if(t[a]!=nil) return t
end
assert(false,"field not found:"..a)
end
-- you can remove this function
-- if you delete the asserts
function check_no_duplicates(self)
for k1,t1 in pairs(self) do
for k2,t2 in pairs(self) do
if k1<k2 then
for f1,_ in pairs(t1) do
for f2,_ in pairs(t2) do
assert(f1!=f2,"duplicated field "..f1.." in "..k1.." and in "..k2)
end
end
end
end
end
end
return add(_ents,
setmetatable({},{
-- check value in components
-- components cannot be accessed directly
__index=function(self,a)
return _find(self,a)[a]
end,
__newindex=function(self,a,v)
_find(self,a)[a]=v
end,
__add=function(self,cmp)
-- two cases: string or table
if type(cmp)=="string" then
-- assert(rawget(self,cmp)==nil,"already existing: "..cmp)
rawset(self,cmp,{})
else
-- check if already existing
local cn=cmp[1]
-- assert(rawget(self,cn)==nil,"already existing: "..cn)
rawset(self,cn,cmp[2])
check_no_duplicates(self)
end
return self
end,
__sub=function(self,cn)
-- double removal is not a problem
return rawset(self,cn,nil)
end}))
end
function sys(cmps,f)
return function(...)
for e in all(_ents) do
for cn in all(cmps) do
if(not has(e,cn)) goto _
end
f(e,...)
::_::
end
end
end
-- machine: nb
-- running
-- broken
-- recipe: ingr quality time rem coeff
-->8
-- draw
function _draw()
mouse_already_drawn=false
if camera_x<camera_ox then
camera_x+=4
elseif camera_x>camera_ox then
camera_x-=4
end
camera(camera_x,camera_y)
if mode==0 then
draw_phone()
elseif mode==1 then
draw_title_screen_base()
draw_title_screen_ui()
elseif mode==10 then
draw_color()
if(tuto==3) draw_tuto()
elseif mode>=11 and mode<90 then
palt(14,true)
draw_menu()
draw_search()
draw_kitchen()
if tuto==1 then
draw_tuto()
elseif camera_ox==128 and tuto==2 then
draw_tuto()
end
elseif mode==99 then
draw_game_over()
end
if mode>=10 and mode<90 then
local l=ceil(left/60*10)
local t=(l/10).."S"
if l%10==0 then
t=(l/10)..".0S"
end
palt(14,true)
palt(0,false)
spr(199,2+camera_x,1)
palt()
nice_print(t,10+camera_x,0,9)
local t="$"..min(target,current\1).."/"..target
nice_print(t,126+camera_x-8*#t,0,current>=target and 11 or 8)
end
draw_mouse()
-- ?mode,110,110
end
function nice_print(t,x,y,c,big,c2)
if(big==nil) big=true
if big then
x=x or 64-#t*4
t="\014"..t
else
x=x or 64-#t*2
end
for dx=-1,1 do
for dy=-1,1 do
if dx==0 or dy==0 then
?t,x+dx,y+dy,c2 or 0
end
end
end
?t,x,y,c or 7
end
function draw_kitchen()
palt(14,true)
palt(0,false)
if camera_x>0 then
draw_one_kitchen(current_machine)
if camera_x<camera_ox then
draw_one_kitchen(current_machine-1)
elseif camera_x>camera_ox then
draw_one_kitchen(current_machine+1)
end
end
palt()
end
function draw_one_kitchen(nb_m)
if nb_m>0 then
sspr(0,72,24,32,47+128*nb_m,15,24*3,32*3)
for e in all(_ents) do
if has(e,"machine") then
if e.nb==nb_m then
local x=0
if(has(e,"running")) x=16
sspr(x,104,16,24,12+128*nb_m,50,16*3,24*3)
if has(e,"running") then
nice_print(get_yield(e).."$/s",12+128*nb_m,60,12)
-- else
-- nice_print("click on\nthe oven\nto use it",55+128*nb_m,80,12)
end
break
end
end
end
spr(200,128*nb_m+5+3*abs(cos(t())),98,1,2)
if nb_m<nb_machines then
spr(200,128*nb_m+115-3*abs(cos(t())),98,1,2,true)
end
end
end
function draw_game_over()
draw_title_screen_base()
nice_print("you failed to",nil,70,9)
nice_print("meet the",nil,79,9)
nice_print("expectations",nil,88,9)
nice_print("game over",nil,110,8)
end
function draw_menu()
for x=0,100 do
for y=0,7 do
spr(229,16*x,16*y,2,2)
end
end
palt(0,false)
palt(14,true)
nice_print("sEARCH",2,110,9)
spr(200,5+3*abs(cos(t())),98,1,2)
nice_print("kITCHEN",70,110,9)
spr(200,115-3*abs(cos(t())),98,1,2,true)
palt()
local l=ceil(left/60*10)
local text=(l/10).."S"
if l%10==0 then
text=(l/10)..".0S"
end
nice_print("player stats",10,30)
nice_print("gOAL:$"..target,10,50,7)
nice_print("cURRENT:$"..min(target,current\1),10,60,7)
if current>target then
nice_print("fRIDGE: $"..(current\1-target),10,40,7)
end
-- nice_print("tIME:"..text,10,20,9)
if current>=target then
nice_print("target reached!",nil,80,10)
-- elseif t()%1<.8 then
-- nice_print("need cupcakes!",nil,80,8)
end
-- local y=50
-- for e in all(_ents) do
-- if has(e,"machine") then
-- if has(e,"running") then
-- ?"machine is running "..(ceil(100*60*e.quality/e.time)/100).."$/s",20,y
-- else
-- ?"machine has no recipe",20,y
-- end
-- y+=10
-- end
-- end
end
function draw_color()
-- drops
-- for d in all(drops) do
-- pal(14,typ2col[d.typ])
-- spr(typ2spr[d.typ],d.x,d.y)
-- end
cls(6)
palt(0,false)
palt(14,true)
-- model
rect(2+camera_x,84,65+camera_x,126,5)
spr(current_base,17+camera_x,93,4,2)
spr(36,17+camera_x,93+16,4,2)
local text=models[selected_model].name.." "..models[selected_model].coeff.."$"
nice_print(text,camera_x+33-#text*2,87,10,false)
if #models>1 then
spr(200,7-3*abs(cos(t()))+camera_x,105,1,2)
spr(200,53+3*abs(cos(t()))+camera_x,105,1,2,true)
end
-- drawing
rect(2+camera_x,9,90+camera_x,82,5)
spr(8,draw_zone_x+5+camera_x,draw_zone_y+5,8,4)
sspr(32,16,32,16,draw_zone_x+5+camera_x,draw_zone_y+5+8*4,64,32)
palt(0,true)
-- ingredients
rect(92+camera_x,9,125+camera_x,82)
for k,i in ipairs(ingr) do
sspr(i.sprx,i.spry,i.w,i.h,109+camera_x-i.w/2,18*k-4)
end
-- mouse
if selected_ingr==nil or not in_draw_zone then
-- pass
else
fillp(░+0b.01) -- to sprite too
local i=ingr[selected_ingr]
sspr(i.sprx,i.spry,i.w,i.h,mouse_x-i.w\2+camera_x,mouse_y-i.h\2)
fillp()
pal()
mouse_already_drawn=true
end
palt(0,false)
palt(14,true)
rect(67+camera_x,84,125+camera_x,126)
nice_print("oven yield",77+camera_x,87,7,false)
-- if previous_recipe then
-- nice_print(get_yield(previous_recipe).."$/s",77+camera_x,97,7,false)
-- end
nice_print(" (paused)",77+camera_x,95,7,false)
spr(215,7+camera_x,71)
nice_print("back",1+camera_x,122,8,false)
if current_recipe.quality>0 then
rectfill(70+camera_x,66,88+camera_x,80,9)
nice_print("bake\n"..get_manual().."$",72+camera_x,68,8,false)
nice_print("quality "..ceil(current_recipe.quality*100).."%",camera_x+5,12,7,false)
local text=current_recipe.time.." steps"
nice_print(text,camera_x+89-4*#text,12,7,false)
nice_print("new:"..get_yield(current_recipe).."$/s",70+camera_x,105,7,false)
rectfill(80+camera_x,115,110+camera_x,123,9)
local text=previous_recipe and "replace" or " save! "
nice_print(text,82+camera_x,117,8,false)
end
palt()
end
function draw_search()
pal()
rectfill(-128,0,0,128,0x5)
nice_print("storage",64-4*7-128,10,4)
rectfill(-110,20,-20,128,4)
fillp(░\1)
rectfill(-105,25,-25,128,0x01)
fillp()
x_sliding=-105
local wait=day<search_day or not can_search
if t12 and day>=search_day and can_search then
x_sliding=-105+50*(t()-.8-t12)
if x_sliding<-105 then
wait=true
end
x_sliding=max(-105,x_sliding)
end
if not wait then
clip(-105+128,25,81,110)
end
if x_sliding<=-25 then
rectfill(x_sliding,25,-25,128,13)
-- ?"slide to open",x+5,50,6
if mode==12 then
?"use a flashlight!",x_sliding+5,50,6
?"finders keepers",x_sliding+5,58,6
if day<search_day then
?"closed today",x_sliding+5,66,5
elseif not can_search then
?"one search a day",x_sliding+5,66,5
end
end
circfill(x_sliding+5,90,3,6)
end
clip()
palt(0,false)
palt(14,true)
spr(200,-13-3*abs(cos(t())),98,1,2,true)
palt()
if search_found then
spr(217,goal_x,goal_y)
if flash==nil then
assert(false)
elseif type(flash)=="string" then
nice_print("you find a",64-128-4*10,50,10)
nice_print(flash,64-128-4*#flash,60,9)
elseif flash<10 then
for i in all(ingr) do
if i.id==flash then
nice_print("new ingredient!",64-128-4*15,50,10)
nice_print(i.name,64-128-4*#i.name,60,9)
sspr(i.sprx,i.spry,i.w,i.h,64-i.w-128,80,2*i.w,2*i.h)
break
end
end
elseif flash<20 then
for m in all(models) do
if m.id==flash then
local t="new $"..m.coeff.." flavor!"
nice_print(t,64-128-4*#t,50,10)
nice_print(m.name,64-128-4*#m.name,60,9)
palt(14,true)
palt(0,false)
spr(m.nb,-128+64-16,80,4,2)
spr(36,-128+64-16,80+16,4,2)
palt()
break
end
end
elseif flash<50 then
for i in all(ingr) do
if i.id+40==flash then
nice_print(i.name,64-128-4*#i.name,50,10)
nice_print("processed faster",64-128-4*16,60,9)
sspr(i.sprx,i.spry,i.w,i.h,64-i.w-128,80,2*i.w,2*i.h)
break
end
end
end
end
end
function draw_mouse()
if not mouse_already_drawn then
if mode==12 and day>=search_day and mouse_x+camera_x>=-105 and mouse_x+camera_x<-105+81 and mouse_y>25 then
fillp(◆)
circfill(mouse_x+camera_x,mouse_y,3,9)
fillp()
else
spr(2,mouse_x+camera_x,mouse_y)
end
end
end
-->8
-- update
function change_mode(new_mode)
printh("new mode:"..new_mode)
-- exit
if mode==10 then
current_recipe=nil
for e in all(_ents) do
if has(e,"machine") and has(e,"recipe") and e.nb==current_machine then
e+="running"
break
end
end
elseif mode==12 then
can_search=false
search_found=false
elseif mode==0 or mode==1 then
left=round_duration
end
-- enter
if new_mode==11 then
camera_ox=max(0,camera_ox)
elseif new_mode==10 then
for e in all(_ents) do
if has(e,"machine") and e.nb==current_machine then
e-="running"
previous_recipe=has(e,"recipe")
break
end
end
current_base=models[selected_model].nb
setbase()
current_recipe={ingr={},quality=0}
elseif new_mode==0 then
t0=t()
camera_ox=0
camera_x=0
can_search=true
elseif new_mode==99 then
camera_ox=0
camera_x=0
elseif new_mode==12 then
camera_ox=-128
t12=t()
goal_x=ceil(-107+rnd(76))
goal_y=ceil(27+rnd(99))
search_found=false
end
mode=new_mode
end
function _update60()
if left==0 then
left=-1
if current<target then
change_mode(99)
else
day+=1
current-=target
target=5*day*day
change_mode(0)
end
end
mouse_x=stat(32)-1
mouse_y=stat(33)-1
lclick=btnp(5)
rclick=btnp(4)
if(lclick and tuto==1 and mode==11) tuto=2 return
if(lclick and tuto==2 and camera_ox==128) tuto=3 return
if(lclick and mode==10 and tuto==3) tuto=nil return
if tuto==nil and mode>=10 and mode<20 and not search_found then
produce()
left-=1
end
if mode==0 then
if t()-t0>3 and lclick then
if day==1 then
change_mode(1)
else
-- directly to intern access from day 2
change_mode(11)
end
end
elseif mode==1 then
update_title_screen(lclick)
elseif mode==10 then
update_color(lclick)
if(rclick) change_mode(13)
elseif mode==12 then
update_search()
if (lclick and mouse_x+camera_x>-20 and mouse_x+camera_x<-1 and mouse_y>96 and mouse_y<120) or btnp(➡️) then
change_mode(11)
end
elseif mode==11 then
if (lclick and mouse_x>1 and mouse_x<50 and mouse_y>96 and mouse_y<120) or btnp(⬅️) then
change_mode(12)
elseif (lclick and mouse_x<127 and mouse_x>83 and mouse_y>96 and mouse_y<120) or btnp(➡️) then
change_mode(13)
camera_ox=128
current_machine=1
end
elseif mode==13 then
if camera_ox==camera_x then
if lclick and mouse_x>10 and mouse_x<50 and mouse_y>60 then
change_mode(10)
elseif (lclick and mouse_x>1 and mouse_x<50 and mouse_y>96 and mouse_y<120) or btnp(⬅️) then
current_machine-=1
camera_ox-=128
if current_machine==0 then
change_mode(11)
end
elseif (lclick and mouse_x<127 and mouse_x>83 and mouse_y>96 and mouse_y<120) or btnp(➡️) then
if current_machine<nb_machines then
camera_ox+=128
current_machine+=1
end
end
end
end
end
-->8
-- production
function add_machine()
nb_machines+=1
machine=ent()
machine+=cmp("machine",{nb=nb_machines})
return machine
end
function update_all_compute_time()
for e in all(_ents) do
if has(e,"recipe") then
e.time=compute_time(e.ingr)
end
end
end
function compute_time(i)
local out=0
for k,v in pairs(i) do
out+=v*ingr[k].spd
end
return out
end
function create_cupcakes(nb)
current+=nb
if(current>target+stock) current=target+stock
end
produce=sys({"machine","running","recipe"},
function (e)
if e.rem==0 then
e.rem=compute_time(e.ingr)
create_cupcakes(e.quality*e.coeff)
else
e.rem-=1
end
end)
-->8
-- coloring
function get_manual()
return flr(current_recipe.quality*20)
end
function mix(c1,c2)
if(c1==c2) return c1
if(c1==7) return c2
if(c2==7) return c1
if(c1==4 or c2==4) return 4
if(c1>c2) c1,c2=c2,c1
if c1==2 then
local t={[3]=4,[8]=2,[9]=4,[10]=4,[12]=2}
return t[c2]
elseif c1==3 then
local t={[10]=3,[9]=4,[8]=4,[12]=3}
return t[c2]
elseif c1==8 then
local t={[10]=9,[12]=2,[9]=9}
return t[c2]
elseif c1==9 then
local t={[10]=9,[12]=4}
return t[c2]
elseif c1==10 then
local t={[12]=3}
return t[c2]
else
assert(false)
end
end
function update_color(lclick)
-- also used in draw
in_draw_zone=mouse_x>=draw_zone_x
and mouse_y>=draw_zone_y
and mouse_x<draw_zone_x+draw_zone_width
and mouse_y<draw_zone_y+draw_zone_height
if lclick then
for k,i in ipairs(ingr) do
if mouse_x>=107-i.w/2 and mouse_x<111+i.w/2
and mouse_y>=18*k-6 and mouse_y<18*k-2+i.h then
selected_ingr=k
break
end
end
if mouse_x>=1 and mouse_x<=18 and mouse_y>=122 then
change_mode(13)
return
elseif mouse_x>=7 and mouse_x<=15 and mouse_y>=71 and mouse_y<79 then
change_mode(10)
return
end
end
if lclick and in_draw_zone then
local i=ingr[selected_ingr]
applydrop(mouse_x-i.w\2-draw_zone_x-5,mouse_y-i.h\2-draw_zone_y-5,i)
elseif lclick and mouse_x>=70 and mouse_x<88 and mouse_y>=66 and mouse_y<80 then
-- bake
create_cupcakes(get_manual())
change_mode(10) -- reset recipe
elseif lclick and mouse_x>=80 and mouse_x<110 and mouse_y>=115 and mouse_y<123 then
-- save
for e in all(_ents) do
if has(e,"machine") and e.nb==current_machine then
m=_ents[current_machine]
m-="recipe"
m+="running"
current_recipe.rem=current_recipe.time
m+=cmp("recipe",current_recipe)
break
end
end
change_mode(13)
elseif #models>1 then
if (lclick and mouse_x>=3 and mouse_x<13 and mouse_y>=105 and mouse_y<=115) or btnp(⬅️) then
selected_model+=1
if selected_model>#models then
selected_model=1
end
elseif (lclick and mouse_x>=53 and mouse_x<63 and mouse_y>=105 and mouse_y<=115) or btnp(➡️) then
selected_model-=1
if selected_model==0 then
selected_model=#models
end
end
local old=current_base
current_base=models[selected_model].nb
if current_base!=old then
setbase()
update_recipe()
end
end
end
function pgetspr(x,y)
if x&1==0 then
return @(x\2+(y<<6))&15
else
return @(x\2+(y<<6))\16
end
end
function psetspr(x,y,c)
if x>=0 and x<128 and y>=0 and y<32 then
if x&1==0 then
poke(x\2+(y<<6),
c+(@(x\2+(y<<6))&240))
else
poke(x\2+(y<<6),
(c<<4)+(@(x\2+(y<<6))&15))
end
end
end
function setbase()
local base_x=(current_base&15)<<3
local base_y=(current_base\16)<<3
for dx=0,63 do
for dy=0,31 do
local c=pgetspr(base_x+dx\2,base_y+dy\2)
if c==6 or c==5 or c==0 or c==14 or c==13 then
psetspr(64+dx,dy,c)
else
psetspr(64+dx,dy,7)
end
end
end
end
function applydrop(x,y,d)
for dy=0,d.h-1 do
for dx=0,d.w-1 do
local cbase=pgetspr(64+x+dx,y+dy) or 0
local cdrop=pgetspr(d.sprx+dx,d.spry+dy) or 0
if cbase!=0 and cbase!=14 and cbase!=6 and cbase!=5 and cdrop!=0 and cbase!=13 then
psetspr(64+x+dx,y+dy,mix(cbase,cdrop))
end
end
end
local i=current_recipe.ingr
if i[selected_ingr] then
i[selected_ingr]+=1
else
i[selected_ingr]=1
end
update_recipe()
end
function update_recipe()
local ok=0
local total=0
local base_x=(current_base&15)<<3
local base_y=(current_base\16)<<3
for dx=0,63 do
for dy=0,31 do
local cbase=pgetspr(base_x+dx\2,base_y+dy\2)
local cdraw=pgetspr(64+dx,dy)
if cbase!=0 and cbase!=6 and cbase!=5 and cbase!=14 and cbase!=13 then
total+=1
if(cbase==cdraw) ok+=1
end
end
end
-- printh("ok:"..ok.." total:"..total)
local q=ok/total
current_recipe.coeff=models[selected_model].coeff
current_recipe.quality=q*q
current_recipe.time=compute_time(current_recipe.ingr)
end
function get_yield(recipe)
return ceil(recipe.coeff*100/recipe.time*60*recipe.quality)/100
end
-->8
-- search
function update_search()
local dx=mouse_x+camera_x-goal_x
local dy=mouse_y-goal_y
if mouse_x+camera_x<x_sliding and dx*dx+dy*dy<14 and not search_found then
search_found=true
id=rnd(rewards)
flash=id -- by default
-- printh("reward:"..id)
if id!=20 and id!=30 then
while del(rewards,id)!=nil do end
end
if id==2 then
add(ingr,{id=2,name="blueberries",sprx=0,spry=16,w=13,h=13,spd=1})
add(rewards,12)
add(rewards,12)
elseif id==12 then
add(models,{id=12,name="special blue",nb=68,coeff=9})
add(rewards,3)
add(rewards,3)
elseif id==3 then
add(ingr,{id=3,name="moon",sprx=16,spry=8,w=14,h=13,spd=3})
add(rewards,13)
add(rewards,13)
add(rewards,41)
add(rewards,42)
add(rewards,43)
elseif id==13 then
add(models,{id=13,name="desert dessert",nb=72,coeff=3})
elseif id==20 then
stock+=target/2
flash="bigger fridge!"
elseif id==30 then
add_machine()
flash="cupcake oven!"
elseif id<50 then
for i in all(ingr) do
if i.id==(id-40) then
i.spd*=0.8
update_all_compute_time()
break
end
end
end
end
end
-->8
-- phone+title
function draw_phone()
cls(0)
-- ui
local x,y=0,0
if day<2 then
x,y=72,120
elseif day<3 then
x,y=72,124
elseif day<5 then
x,y=80,120
else
x,y=80,124
end
sspr(x,y,8,4,120,2)
if(rnd()<0.02) radio_state=1-radio_state
if radio_state==0 then
sspr(88,120,7,5,111,1)
else
sspr(88,125,7,3,111,3)
end
-- time
if t()%2<1.5 then
rectfill(57,28,59,30,1)
rectfill(57,34,59,36,1)
end
spr(222,40,20,2,3)
spr(220,60,20,2,3)
spr(220,75,20,2,3)
nice_print((7+day).." jULY 2023",nil,45,1,true)
-- alarm
if t()-t0<1 then
spr(218,64-8+10*cos(2*t()),70,2,2)
else
local notifs={}
if day==1 then
add(notifs,pack("'grats for the internship!",7,8))
add(notifs,pack("re:gmtk game jam w/ cpiod",6,10))
add(notifs,pack("news:crypto falling again",6,10))
elseif day==2 then
add(notifs,pack("cupcake malicieux:+86%!",6,10))
add(notifs,pack("are you addicted to phones?",6,10))
add(notifs,pack("[spam] enhance your life",6,10))
elseif day==3 then
add(notifs,pack("re:re:please answer",6,10))
add(notifs,pack("news:cupcake's alleged hack",6,10))
add(notifs,pack("players cannot connect",7,8))
target=0
elseif day==4 then
add(notifs,pack("cupcake malicieux in court",6,10))
add(notifs,pack("news:massive strike",6,10))
add(notifs,pack("hr:report suspicious behavior",7,8))
elseif day==4 then
add(notifs,pack("cupcake malicieux in court",6,10))
add(notifs,pack("news:massive strike",6,10))
add(notifs,pack("hr:report suspicious behavior",7,8))
elseif day==5 then
add(notifs,pack("news:crypto on the rise",6,10))
add(notifs,pack("re:career advice",6,10))
elseif day==6 then
add(notifs,pack("your packages arrived",6,10))
add(notifs,pack("re:cupcake malicieux hq",6,10))
end
if #notifs==0 then
add(notifs,pack("you have (0) notifications",6,10))
end
y=60
for n in all(notifs) do
local text,c,c2=unpack(n)
local x=min(10,300*(t()-t0-1)-10*y+500)
rect(x-2,y-2,x+#text*4,y+6,c)
if x==10 then
?"◆",1,y,c2
end
nice_print(text,x,y,c,false)
y+=10
end
end
if t()-t0>3 then
if (2*t())%2<1.5 then
nice_print("click to unlock",nil,100,13)
end
spr(2,mouse_x,mouse_y)
end
end
function draw_title_screen_base()
cls(9)
for x=0,17 do
for y=0,17 do
if (x+y)&1==0 then
local t0=t()
local sx=x*8+10*t0
local sy=y*8-10*t0
sx%=144
sy%=144
spr(233,sx-16,sy-16,1,1,(t0+x/2)%1<.5)
end
end
end
title={{s=101,w=11,h=4,x=10,y=15,c=9,f=false},
{s=150,w=10,h=3,x=45,y=39,c=10,f=true}}
for s in all(title) do
palt(10,true)
palt(9,true)
palt(s.c,false)
pal(10,4)
pal(9,4)
for dx=-1,1 do
for dy=-1,1 do
if dx==0 or dy==0 then
spr(s.s,s.x+dx,s.y+dy,s.w,s.h,s.f)
end
end
end
pal(10,10)
pal(9,10)
spr(s.s,s.x,s.y,s.w,s.h,s.f)
end
pal()
end
function draw_title_screen_ui()
rectfill(64-4*6,78,64+4*6-2,90,14)
circfill(64-4*6,84,5)
circfill(64+4*6-2,84,5)
nice_print("sTART!",nil,80,10)
nice_print("INTERN ACCESS",75,113,10,false,9)
nice_print("(c) cupcake malicieux 2002-2023",2,121,10,false,4)
if t1 and t()<t1 then
nice_print("sTART!",nil,80,5)
rectfill(64-30,83,64+28,84,0)
nice_print("an intern",nil,50,8)
nice_print("must work,",nil,59,8)
nice_print("not play!!",nil,68,8)
nice_print("use intern access",nil,91,8,false)
palt(0,false)
palt(14,true)
spr(231,60,98,2,2)
palt()
end