/
dyke.lua
2015 lines (1861 loc) · 102 KB
/
dyke.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
-- script: lua
function dump(o)
if type(o) == 'table' then
local s = '{ '
for k,v in pairs(o) do
if type(k) ~= 'number' then k = '"'..k..'"' end
s = s .. '['..k..'] = ' .. dump(v) .. ','
end
return s .. '} '
else
return tostring(o)
end
end
function table.shallow_copy(t)
local t2 = {}
for k,v in pairs(t) do
t2[k] = v
end
return t2
end
function textrect(text,x,tey,w)
words = mysplit(text)
tex = x
for _,word in pairs(words) do
tw = print(word, 0, -10, 15, false, 1, true)
if tex + tw > x + w then
tex = x
tey = tey + 6
end
prints(word, tex, tey, 15, false, 1, true)
tex = tex + tw + 6
end
end
function eitheror(a,b,pa,r)
r = (r * 17 + a * 23 + b * -7) * 111 + (r * 11 + a * -3 + b * 29) * 97
if math.abs(r) % 100 > pa * 100 then
return b
else
return a
end
end
function mysplit (inputstr, sep)
if sep == nil then
sep = "%s"
end
local t={}
for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
table.insert(t, str)
end
return t
end
--Prints text where x is the center of text.
function printc(s,x,y,c,fixed,scale,small)
local w=print(s,0,-8,c or 15,true)
prints(s,x-(w/2//6*6),y,c or 15,fixed,scale,small)
end
--Prints text, replaces some symbols with sprites
function prints(s,x,y,c,fixed,scale,small)
scale = scale or 1
print(s:gsub("%$"," "):gsub("/"," "):gsub("#"," "):gsub("%*"," "):gsub("@"," "),x,y+1,c or 15, true,scale,small)
for i = 1, s:len() do
ch = s:sub(i,i)
sp = 0
if(ch == "#") then -- stone
sp = 128
end
if(ch == "/") then -- wood
sp = 129
end
if(ch == "$") then -- score
sp = 130
end
if(ch == "*") then -- time
sp = 131
end
if(ch == "@") then -- card
sp = 132
end
spr(sp,x+(i-1)*6,y,0)
end
end
function timestring(time, compact)
if compact then
return string.format("%d%s", math.floor(time / wt), re_symbols[4])
else
return string.format("%1.1f%s", time / wt, re_symbols[4])
end
end
function coststring(cost, extratime, compact)
extratime = extratime or 0
str = ""
for i = 1,5 do
co = cost[i] or 0
if i ~= 4 and co > 0 then
if string.len(str) > 0 then
if compact then
str = str .. " "
else
str = str .. ", "
end
end
str = string.format("%s%d%s", str, co, re_symbols[i])
end
end
time = (cost[4] or 0) + extratime
if time > 0 then
if string.len(str) > 0 then
if compact then
str = str .. " "
else
str = str .. ", "
end
end
str = str .. timestring(time, compact)
end
return str
end
levels = {
{
name = "Introduction",
introtext = "Welcome to the island! Have a nice time, make yourself at home... but not too much. There's a flood wave coming, see if you can earn 70$ for a ticket to flee!",
outrotext = "Well, that wasn't too hard, right? Let's try another island.",
x = 30,
y = 34,
w = 30,
m = 70,
-- stone, wood, coins, should be cards (not working)
re = {15, 30, 30, 0}
},
{
name = "Level two",
introtext = "Look, there's a lot more space here. Space to plant trees or even herd some sheep. And more space for the flood wave, of course. This time, you need 100$ to get away from here.",
outrotext = "Time for a new challenge, right?",
x = 0,
y = 0,
w = 60,
m = 100,
re = {5, 5, 5, 3}
},
{
name = "Level three",
introtext = "You made it! Your own little house, on a beautiful island, packed with books. If you aint got nothing else to do, you can study them to find more cards @ ! Let's hope those books don't get wet...",
outrotext = "Didn't have much luck with those books, right? Or time to read them? But don't be disgruntled - you survided, and so has the knowlege inside your head!",
x = 87,
y = 0,
w = 53,
m = 130,
re = {10, 10, 10, 5}
},
}
objecttypes = {
dyke={
name="dyke",
cost={1,0,0,60},
desc="stops water and you can walk on it",
sx=1,
sy=1,
sprites={70,38,54,54,54},
isblock=true,
spoutline=70,
spoutlinered=86,
},
rock={
name="rock",
cost={0,0,0,0},
desc="you can harvest stones from it",
sx=2,
sy=2,
sprites={48,48,48,48,48},
isblock=false,
cut = {
verb = "break",
re = 10,
gain = {1,0,0,0},
time = 100
},
draw = function(o)
local x = o.x*8-sx
y = o.y*8
if o.cut.re > 6 then
spr(48,x,y,0, 1, 0, 0, 2, 2)
elseif o.cut.re > 2 then
spr(48,x,y+8,0, 1, 0, 0, 2, 1)
elseif o.cut.re > 0 then
spr(33,x,y+8,0, 1)
end
end
},
chest={
name="chest",
cost={0,0,0,0},
desc="there is a card inside",
sx=1,
sy=1,
sprites={194,194,194,195,195},
isblock=false,
collect = {
verb = "open",
re = 1,
gain = {0,0,0,0,1},
time = 30,
effect = function(o)
destroyobject(o)
end
},
draw = function(o)
local x = o.x*8-sx
y = o.y*8
if o.collect.re > 0 then
spr(194,x,y,0)
else
spr(195,x,y,0)
end
end
},
tree={
name="tree",
cost={0,0,0,180},
desc="you can collect apples from it, or cut it for wood.",
sx=2,
sy=2,
sprites={75,39,11,41,45},
isblock=false,
spoutline=75,
spoutlinered=107,
cut = {
verb = "cut",
re = 0,
gain = {0,5,0,0},
time = 250
},
collect = {
verb = "pick",
re = 0,
gain = {0,0,2,0},
time = 10
},
create = function(o)
o.ttg = 300
o.tta = 400 * appletimemulti
o.state = 2
end,
update = function(o)
if o.ttg > 0 then
o.ttg = o.ttg - 1
elseif o.state == 2 then
o.state = 3
o.cut.re = 1
stopwait()
end
if o.state == 3 then
if o.tta > 0 then
o.tta = o.tta - 1
end
if o.tta <= 0 then
o.tta = 200 * appletimemulti
if o.collect.re < 4 then
stopwait()
end
o.collect.re = math.min(4,o.collect.re+1)
end
end
-- die when it is cut down
if o.state == 3 and o.cut.re == 0 then
o.state = 4
end
-- die when it touches water and is not already cut down
if o.state < 4 then
for xx = o.x, o.x+o.type.sx-1 do
for yy = o.y, o.y+o.type.sy-1 do
if iswater(xx,yy) then
o.state = 5
o.collect.re = 0
o.cut.re = 0
end
end
end
end
end,
canwait = function(o)
return o.state < 4 and o.collect.re < 4
end,
draw = function(o)
local x = o.x*8-sx
y = o.y*8
sp = o.type.sprites[o.state]
if o.ttg > 0 then
sp = 39
end
if o.state == 3 then
n = 0
for xi = 0,1 do
for yi = 0,1 do
off = 0
n = n + 1
if (o.collect.re >= n) then
off = 32
end
spr(sp + xi + 16 * yi + off,x + xi*8,y+yi*8,0, 1)
end
end
else
spr(sp,x,y,0, 1, 0, 0, 2, 2)
end
end
},
well={
name="well",
cost={5,0,0,300},
desc="your plants get their fruit quicker",
sx=1,
sy=2,
sprites={151,150,149,149,149},
isblock=false,
spoutline=151,
spoutlinered=152,
create = function(o)
appletimemulti = appletimemulti * 0.7
end,
},
sheep={
name="sheep",
cost={0,5,10,30},
desc="If gives you wool or meat.",
sx=1,
sy=1,
sprites={192,176,177,177,180},
isblock=false,
spoutline=192,
spoutlinered=193,
cut = {
verb = "butcher",
re = 0,
gain = {0,0,25,0},
time = 200,
effect = function(o)
destroyobject(o)
o.state = 5
o.butchered = true
end
},
collect = {
verb = "shear",
re = 0,
gain = {0,0,5,0},
time = 150
},
create = function(o)
o.ttg = 500
o.tta = 600 * wooltimemulti
o.state = 2
end,
update = function(o)
if o.ttg > 0 then
o.ttg = o.ttg - 1
elseif o.state == 2 then
o.state = 3
o.cut.re = 1
stopwait()
end
if o.state == 3 then
if o.tta > 0 then
o.tta = o.tta - 1
end
if o.tta <= 0 then
o.tta = 600 * wooltimemulti
if o.collect.re < 2 then
stopwait()
end
o.collect.re = math.min(2,o.collect.re+1)
end
end
if o.state < 4 then
for xx = o.x, o.x+o.type.sx-1 do
for yy = o.y, o.y+o.type.sy-1 do
if iswater(xx,yy) then
o.state = 5
o.collect.re = 0
o.cut.re = 0
end
end
end
end
end,
canwait = function(o)
return o.state < 4 and o.collect.re < 4
end,
draw = function(o)
local x = o.x*8-sx
y = o.y*8
sp = o.type.sprites[o.state]
if o.state == 5 then
if o.butchered then
sp = 0
end
end
if o.state == 3 then
if o.collect.re == 0 then
sp = 177
elseif o.collect.re == 1 then
sp = 178
elseif o.collect.re == 2 then
sp = 179
end
end
spr(sp,x,y,0)
end
},
mine={
name="mine",
cost={2,5,0,300},
desc="mine an unlimited supply of stones",
sx=2,
sy=2,
sprites={155,155,155,155,155},
isblock=false,
spoutline=181,
spoutlinered=183,
collect = {
verb = "mine",
re = 999,
gain = {1,0,0,0},
time = 150
},
},
house={
name="house",
cost={2,5,5,300},
desc="study at home to gain knowledge, aka cards",
sx=2,
sy=2,
sprites={153,153,153,153,153},
isblock=false,
spoutline=153,
spoutlinered=153,
collect = {
verb = "study",
re = 10,
gain = {0,0,0,0,1},
time = 240
},
}
}
function definecards()
cards = {
{
title="Book",
text="Read a book. Draw 3 cards.",
cost = {0,0,25,0},
r=234,
effect = function()
for i=1,3 do
drawrandomcard()
end
end,
},
{
title="Boots",
text="With these boots, you can walk 20% faster.",
cost = {0,3,3,0},
ispermanent = true,
effect = function()
walktimemulti = walktimemulti * 0.8
end,
r=235,
},
{
title="Axe",
text="With this improved axe, you can cut trees and rocks 20% faster.",
cost = {1,3,5,0},
ispermanent = true,
effect = function()
cuttimemulti = cuttimemulti * 0.8
end,
r=235,
},
{
title="Well",
text="The well waters all your plants, so their fruit will grow 30% faster.",
r=236,
buildingtype=objecttypes["well"]
},
{
title="Appleseed",
text="You may plant an apple tree.",
r=237,
buildingtype=objecttypes["tree"]
},
{
title="Appleseed",
text="You may plant an apple tree.",
r=237,
buildingtype=objecttypes["tree"]
},
{
title="Mine",
text="It gives you access to an unlimited supply of stones, but they take longer to mine.",
r=237,
buildingtype=objecttypes["mine"]
},
{
title="Sheep",
text="Your sheep gives you wool ($ ) until you butcher it (more $ ).",
r=237,
buildingtype=objecttypes["sheep"]
},
{
title="Sheep",
text="Your sheep gives you wool ($ ) until you butcher it (more $ ).",
r=237,
buildingtype=objecttypes["sheep"]
},
{
title="Woodsale",
text="Someone pays you enormous 35$ if you sell them 10/.",
r=239,
cost={0,10,0,0},
gain={0,0,30,0}
},
{
title="Quickstones",
text="If you need stones quickly, get 5# for 20$.",
r=240,
cost={0,0,20,0},
gain={5,0,0,0}
},
{
title="Gift",
text="Here, have 10$ :)",
r=241,
cost={0,0,0,0},
gain={0,0,10,0}
},
{
title="Wood reserve",
text="You find a lot of wood! It's 10/!",
r=242,
cost={0,0,0,0},
gain={0,10,0,0}
}
}
for i, card in pairs(cards) do
card.y = 14
if card.buildingtype then
card.cost = card.buildingtype.cost
end
end
handcards = {}
for i = 1,5 do
drawrandomcard()
end
end
function paintcard(x,y,w,h,title,text,cost,r,onlybutton, buttoncolor)
if not onlybutton then
paintframe(x,y,w,h,r)
print(title, x*8+6, y*8 + 6, 15)
prints(coststring(cost, 0, true), x*8+6, (y+2)*8)
end
paintcardbutton(x*8+w*4, (y+h-1)*8 - 6, buttoncolor or 9)
if y > 13 or onlybutton then
return
end
textrect(text, x*8+6, (y+4)*8+6, w*8 - 12)
end
function paintcardbutton(x,y,c)
printc("PLAY CARD", x, y, c)
end
function drawrandomcard()
ind = math.random(1, #cards)
trace("Add card " .. ind .. " to hand")
table.insert(handcards, table.shallow_copy(cards[ind]))
cards[ind].y = 14
end
function movecards()
for i, card in pairs(handcards) do
if i == selectedcard then
if card.y > 2 then
card.y = card.y - 1
end
else
if card.y < 14 then
card.y = card.y + 1
end
end
end
end
function paintcards(mx,my,onlybutton, buttoncolor)
ci, button = 0, false
if #handcards > 0 then
-- effective width: 30 - 9 - 2 = 19
if #handcards > 1 then
wpc = 19 // (#handcards - 1)
else
wpc = 0
end
for i, card in pairs(handcards) do
cx = 1 + (i-1) * wpc
paintcard(cx,card.y,9,13,card.title, card.text, card.cost, card.r, onlybutton, buttoncolor)
if mx >= cx and mx <= cx + 9 and my >= card.y and my <= card.y + 13 then
ci = i
if mx >= cx + 1 and mx < cx + 9 - 1 and my >= card.y + 13 - 2 and my < card.y + 13 - 1 then
button = true
end
end
end
end
return ci, button
end
-- TODO: adjust drawing order
-- TIC (using dynamic blue-only-palette):
-- Draw sky with single color
-- Draw water with many colors
-- OVR (using fixed no-blue-palette):
-- Draw level
-- Draw objects
-- Draw UI
-- Draw cursor
function drawsky()
if globalstate == "title" or globalstate == "gamewon" then
cls(10)
else
cls(11)
end
end
function drawwater()
map(levelx,levely+17,levelwidth,levelheight,-sx,0,0)
end
function drawlevel()
map(levelx,levely,levelwidth,levelheight,-sx,0,0)
end
function drawobjects()
for _,o in pairs(objects) do
drawobject(o)
end
end
function drawtitle()
map(120,34,30,levelheight,0,0,0)
prints("Click to start the game", 12*8, 8*8, 12)
print("A game by @LenaSchimmel", 2*8, 14*8, 12, false, 1, false)
print("Made in 72 hours for Ludum Dare 50", 2*8, 15*8, 12, false, 1, true)
end
function drawendscreen()
map(120,34,30,levelheight,0,0,0)
prints("Thank you for playing!", 12*8, 8*8, 12)
print("You won all levels of Dyker", 2*8, 14*8, 12, false, 1, false)
print("Come back later to see if there is a post-jam version.", 2*8, 15*8, 12, false, 1, true)
end
function myspr(sp, x, y)
spr(sp, x*8, y*8, 0)
end
function myrspr(spa, spb, x, y, pa, r)
sp = eitheror(spa, spb, pa, r * 13 + x * 19 + y * -5)
spr(sp, x*8, y*8, 0)
end
function drawobject(o)
ty = o.type
if ty.draw then
ty.draw(o)
else
sp = ty.sprites[o.state]
spr(sp,o.x*8-sx,o.y*8,0, 1, 0, 0, ty.sx, ty.sy)
end
end
function TIC()
drawsky()
drawwater()
-- mouse calc
x,y,l,_,_,sxv = mouse()
-- mouse position in grid coords
mx = math.floor((x+sx) / 8)
mxa = math.floor(x / 8)
my = math.floor(y / 8)
-- update scroll
if x < sb then
sv = sb - x
sx = sx - sv * sv / 400
end
if x > (240 - sb) then
sv = x - (240 - sb)
sx = sx + sv * sv / 400
end
sx = sx + sxv * 2
sx = math.max(sx, 0)
sx = math.min(sx, (levelwidth * 8) - 240)
movecards()
-- update
if wo then
t=t+1
--update objects
for _,o in pairs(objects) do
if o.type.update then
o.type.update(o)
end
end
if px ~= tx then -- still walking
ttw = ttw - 1
if ttw <= 0 then
ttw = pt * walktimemulti
if px < tx then
px = px + 1
pf = 1
else
px = px - 1
pf = 0
end
end
else -- doing something else
if to == 1 then -- walk
wo = false
end
if to == 2 and tb ~= nil then
if tb.state == 1 then -- planned -> building
tb.state = 2
tl = tb.type.cost[4]
elseif tb.state == 2 then -- building -> finished
tl = tl - 1
if tl <= 0 then
if tb.type.name ~= "tree" and tb.type.name ~= "sheep" then
tb.state = 3
end
if tb.type.isblock then
lmset(tb.x,tb.y,3)
end
tb = nil
wo = false
end
end
end
action = nil
if tb then
ty = tb.type
if to == 3 then
action = ty.collect
end
if to == 4 then
action = ty.cut
end
if action then -- collect or cut
if tl <= 0 then -- start doing it
tl = action.time
if to == 4 then
tl = tl * cuttimemulti
end
end
tl = tl - 1
if tl <= 0 then -- finished doing it
if to == 3 then
tb.collect.re = tb.collect.re - 1
end
if to == 4 then
tb.cut.re = tb.cut.re - 1
if tb.cut.re == 0 then -- todo should this be an effect?
destroyobject(tb)
end
end
earn(action.gain)
if action.effect then
action.effect(tb)
end
tb = nil
wo = false
end
end
end
end
if t % wt == 0 then
addwater()
t = 0
end
end
if globalstate == "gamewon" then
return
end
-- draw player
py = yabovefloor(px)
body = 7
legs = 23
pfb = pf -- body flip
if not wo then
if my < py - 4 then
body = 52
elseif mx < px - 4 then
pfb = 0
elseif mx > px + 4 then
pfb = 1
else
body = 53
end
end
if wo and px ~= tx then
legs = 68
if t % 10 >= 5 then
legs = 69
end
end
if wo and to > 1 and to < 5 then
dx = px - 1 + 2 * pf
spr(50,dx*8-sx,(py-1)*8,0, 1, pf) -- arm
if (to == 2 or to == 4) and t % 30 < 15 and px == tx then
spr(to+79,dx*8-sx,(py-1)*8,0, 1, pf, 1) -- tool
else
spr(to+79,dx*8-sx,(py-0)*8,0, 1, pf) -- tool
end
body = 51 -- no double arm
legs = 67
end
spr(body,px*8-sx,(py-1)*8,0, 1, pfb) -- body
spr(legs,px*8-sx,(py-0)*8,0, 1, pf) -- legs
if globalstate == "title" then
map(120,34,30,levelheight,0,0,0)
prints("Click to start the game", 12*8, 8*8, 12)
print("A game by @LenaSchimmel", 2*8, 14*8, 12, false, 1, false)
print("Made in 72 hours for Ludum Dare 50", 2*8, 15*8, 12, false, 1, true)
if l then
globalstate = "levelstart"
end
return
end
end
function OVR()
local x,y,l = mouse()
if globalstate == "title" then
drawtitle()
if l then
globalstate = "levelstart"
end
return
end
if globalstate == "gamewon" then
drawendscreen()
return
end
drawlevel()
drawobjects()
if not l then
clicklock = false
end
if globalstate == "levelstart" or globalstate == "play" or globalstate == "levelend" or globalstate == "restart" then
my = y // 8
-- show resources
te = string.format("%2d# %2d/ %4d$",re[1],re[2],re[3])
prints(te, 6, 8, 12)
end
ct = "" --center text
-- draw cursor, handle potential actions
local sp = 119
if globalstate == "play" then
-- show actions
prints("Action:", 16*6, 8, 12)
for i=1,6 do
spr(95 + i, 132 + 12*i, 8, 0)
if to==i then
spr(104, 132 + 12*i, 8, 0)
end
end
prints(""..#handcards, 212, 8, 14)
if x >= 228 and y < 8 then
myspr(228, 29, 0)
ct = "Restart level"
if l then
globalstate = "restart"
end
else
myspr(227, 29, 0)
end
if to==6 then
sp = 119
local ci, bu = paintcards(x/8, y/8)
if bu then
card = handcards[ci]
mis = canpay(card.cost)
if mis > 0 then
sp = 164
ct = "Not enough " .. re_symbols[mis] .. " to play '" .. card.title .. "'"
paintcards(0,0,true,2)
else
sp = 148
ct = "Play the card '" .. card.title .. "'"
paintcards(0,0,true,5)
if l and not clicklock then
if not card.buildingtype then
pay(card.cost) -- buildings are paid later
end
selectedcard = 0
trace("Remove card " .. ci)
table.remove(handcards, ci)
card.y = 14
if card.effect then
card.effect()
elseif card.gain then
earn(card.gain)
end
if card.ispermanent then
table.insert(permanents, card)
end
if card.buildingtype then
buildingcard = card
buildingtype = card.buildingtype
clicklock = true
to = 2
end
end
end
elseif ci > 0 and selectedcard ~= ci then
ct = "Look at card '" .. handcards[ci].title .. "'"
elseif ci == 0 and selectedcard > 0 then
ct = "Move card out of the way"
end
if l then
selectedcard = ci
clicklock = true
end
end
if my > 2 then -- lower screen part
if wo then
sp = 102
else
if to ~= 6 then
sp = 159 + to -- disabled
end
if to == 1 then -- walk
ly = yabovefloor(mx)