-
Notifications
You must be signed in to change notification settings - Fork 0
/
blob.p8
2156 lines (2046 loc) · 84.8 KB
/
blob.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 35
__lua__
-- blob blob blob!
-- by cpiod for 7drl22
function _init()
show_tuto,w,h,mouse_show_class,hunger_delay,changed_focus,status=true,62,38,nil,50,0,0
t0=t()
poke(0x5f2d, 1) --enable mouse
-- show_controls=false
music(0)
-- srand(2)--todo
cls()
palt(0,false)
menuitem(1,"controls",function() status=status==1 and 12 or status show_controls=true end)
menuitem(2,"toggle map",function() status=status==1 and 12 or status show_map=not show_map end)
end
-- states:
-- 0: main menu
-- 1: tutorial
-- 10: player input
-- 11: monster input
-- 12: end turn
-- 13: blob auto input
-- 14: hunger
-- 20: game over
table_los=split"-1,0,-2,-1,-3,-1,-4,-2,-5,-2,,,,,,,-1,0,-2,0,-3,-1,-4,-1,-5,-1,,,,,,,-1,0,-2,0,-3,0,-4,0,-5,0,,,,,,,-1,0,-2,0,-3,1,-4,1,-5,1,,,,,,,-1,0,-2,1,-3,1,-4,2,-5,2,,,,,,,-1,-1,-2,-2,-3,-3,-4,-4,,,,,,,,,-1,-1,-2,-1,-3,-2,-4,-3,,,,,,,,,-1,1,-2,1,-3,2,-4,3,,,,,,,,,-1,1,-2,2,-3,3,-4,4,,,,,,,,,-1,-1,-1,-2,-2,-3,-3,-4,,,,,,,,,-1,1,-2,2,-2,3,-3,4,,,,,,,,,0,-1,-1,-2,-1,-3,-2,-4,-2,-5,,,,,,,0,1,-1,2,-1,3,-2,4,-2,5,,,,,,,0,-1,0,-2,-1,-3,-1,-4,-1,-5,,,,,,,0,1,0,2,-1,3,-1,4,-1,5,,,,,,,0,-1,0,-2,0,-3,0,-4,0,-5,,,,,,,0,1,0,2,0,3,0,4,0,5,,,,,,,0,-1,0,-2,1,-3,1,-4,1,-5,,,,,,,0,1,0,2,1,3,1,4,1,5,,,,,,,0,-1,1,-2,1,-3,2,-4,2,-5,,,,,,,0,1,1,2,1,3,2,4,2,5,,,,,,,1,-1,1,-2,2,-3,3,-4,,,,,,,,,1,1,2,2,2,3,3,4,,,,,,,,,1,-1,2,-2,3,-3,4,-4,,,,,,,,,1,-1,2,-2,3,-2,4,-3,,,,,,,,,1,1,2,2,3,2,4,3,,,,,,,,,1,1,2,2,3,3,4,4,,,,,,,,,1,0,2,-1,3,-1,4,-2,5,-2,,,,,,,1,0,2,0,3,-1,4,-1,5,-1,,,,,,,1,0,2,0,3,0,4,0,5,0,,,,,,,1,0,2,0,3,1,4,1,5,1,,,,,,,1,0,2,1,3,1,4,2,5,2,,,,,,,"
-- 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"))
--tiny ecs v1.1
--by katrinakitten
--adapted by cpiod
function ent()
return setmetatable({},{
__index=function(self,a)
for k,t in pairs(self) do
local r=t[a]
if(r) return r
end
return nil
end,
__newindex=function(self,a,v)
for k,t in pairs(self) do
local r=t[a]
if(r) t[a]=v return
end
-- printh("not found! "..a)
-- assert(false)
end,
__add=function(self,cmp)
-- assert(cmp._cn)
rawset(self,cmp._cn,cmp)
return self
end,
-- __sub=function(self,cn)
-- assert(rawget(self,cn)!=nil) -- le composant existait
-- self[cn]=nil
-- return self
-- end
})
end
function cmp(cn,t)
t=t or {}
t._cn=cn
return t
end
function sys(cns,f)
return function(...)
-- assert(ents)
for e in all(ents) do
for cn in all(cns) do
if(rawget(e,cn)==nil) goto _
end
f(e,...)
::_::
end
end
end
-->8
-- update
function _update()
-- local restart=true
-- local restart_nb=4
-- while restart and restart_nb>0 do
-- restart=false
-- restart_nb-=1
if status==0 and btn(4) and btn(5) then
music(-1)
cls(0)
msg={}
input[4]=-1
input[5]=-1
consume_inputs()
screen_dx,screen_dy=0,0
show_map,force_map,redraw=false,false,false
points,turn,can_grab=0,0,true
status=show_tuto and 1 or 12
show_tuto=false
xp={[0]=0,0,0,0,0}
ents={}
depth=0
current_blob=nil
mapgen()
elseif status==20 and btnp(4) then
status=0
t0=t()
consume_inputs()
elseif status>0 then
if status==1 and short[4] then
status=12
consume_inputs()
end
if status==12 then
search_next_entity()
if acting_ent.blob then
-- status=
if acting_ent==current_blob then
status=10
else
status=13
end
elseif acting_ent.monster then
status=11
elseif acting_ent.hunger then
local poisoned=false
for e in all(ents) do
if e.blob and e.adj==6 then
local done=false
for e2 in all(ents) do
if e2.monster and los[e2.x+e2.y*42][e] then
done=true
e2+=cmp("suffers",{dmg=1,dmgfrom=e})
end
end
if(done) poisoned=true e+=cmp("suffers",{dmg=1,dmgfrom=""})
end
end
if(poisoned) add_msg("pOISONED...",9)
acting_ent.t+=hunger_delay
-- else
-- assert(false)
end
end
if(status>0) update_input()
if status==10 then
moved=false
local dur=player_input()
if(moved) can_grab=true
consume_inputs()
if(mget(current_blob.x,current_blob.y)==35) mapgen()
check_food()
check_drop()
if(dur>0) then
status=12
acting_ent.t+=dur
-- restart=true
end
elseif status==11 then
local dur=monster_act()
if(dur==0) dur=wait_dur
acting_ent.t+=dur
-- restart=true
status=12
elseif status==13 then
local dur=do_atk(acting_ent)
if(dur==0) dur=wait_dur
acting_ent.t+=dur
-- restart=true
status=12
end
local beforehp=0
for e in all(ents) do
if(e.blob) beforehp+=e.last-e.first+1
end
sys_heal()
sys_suffers()
sys_dead()
-- check deaths
local hp=0
for e in all(ents) do
if(e.blob) hp+=e.last-e.first+1 update_target(e)
end
-- game over
if(hp==0) status=20
if hp<beforehp and hp<=12 then
show_map=true
-- elseif hp!=beforehp and hp>12 then
-- show_map=false
end
-- end
if dirty_cells then
update_tx_ty(ents)
remove_dead_tiles()
create_tiles(ents,true)
dirty_cells=false
update_los_all()
update_class_blobs()
redraw_heavy=true
elseif rerender then
create_tiles_one_blob(current_blob,false)
update_los_one()
redraw_light=true
current_blob.target=search_target(current_blob)
end
rerender=false
end
end
function check_food()
for e in all(ents) do
if e.food and e.x==current_blob.x and e.y==current_blob.y then
del(ents,e)
current_blob+=cmp("healed",{healamount=e.heal})
break
end
end
end
function check_drop()
if(new_class or not can_grab) return -- already in menu
for e in all(ents) do
if e.drop and e.x==current_blob.x and e.y==current_blob.y then
can_grab=false
new_class=e
selected_class=0
break
end
end
end
function try_move(x,y,p,pressed,short,long)
-- wall?
if(not fget(mget(x,y),0)) return 0
e=check_collision(x,y)
-- collision
if e then
if e.blob then
if pressed or short then
if(shake==0) add_msg("mERGING!",nil,15)
shake=3
whoshake={e,current_blob}
return 0
elseif long then
merge(e)
-- else
-- assert(false)
end
else -- not a blob
if short then
if current_blob.rangemin<=1 then
current_blob.target=e
return do_atk(current_blob)
else
add_msg("too close",8)
return 0
end
end
end
end
-- successful move
if short or long then
moved=true
screen_dx=(x-p.x)*5
screen_dy=(y-p.y)*5
p.x=x
p.y=y
-- cells didn't change
rerender=true
return current_blob.movspd
end
return 0
end
function search_next_entity()
local min_turn=nil
for e in all(ents) do
local t=rawget(e,"turn")
if t then
-- assert(t.t>=turn)
if min_turn==nil or t.t<min_turn then
acting_ent=e
min_turn=t.t
end
end
end
turn=min_turn
end
function change_focus()
local min_blob,min_t=nil,nil
for e in all(ents) do
if e!=current_blob
and e.blob!=nil
and (min_t==nil or e.t<min_t) then
min_blob=e
min_t=e.t
end
end
if min_blob!=nil then
current_blob=min_blob
changed_focus=5
end
end
function merge(b2)
local b=current_blob
bm=b2.first>b.first and b2 or b
curr_last=min(b2.last,b.last)
while(bm.first!=curr_last+1) do
local found=false
for e in all(ents) do
-- potentiellement nil
if e.last==bm.first-1 then
found=true
local tmpl=bm.last
bm.last=e.first+(bm.last-bm.first)
bm.first=e.first
e.first=tmpl-(e.last-e.first)
e.last=tmpl
break
end
end
if not found then
bm.first-=1
bm.last-=1
end
end
b.first=min(b2.first,b.first)
b.last=max(b2.last,b.last)
del(ents,b2)
dirty_cells=true
end
function change_class()
local invnb=selected_class+1
current_blob.invnb=invnb
current_blob.class=update_class(inv[invnb][1],inv[invnb][2],current_blob)
changed_focus=5
update_target(current_blob)
end
-->8
-- draw
hx,hy,skip,shake,whoshake=1,1,0,0,{}
function animate(t2)
return 200*max(t2-t()+t0,0)
end
function _draw()
if status==0 then
palt(4,true)
cls(4)
-- title
spr(160,5,5,15,3)
-- blue blob
sspr(40,32,24,16,3-animate(.5),90,48,32)
-- yellow blob
sspr(64,32,32,40,80,16+animate(3)/2,64,80)
-- red blob
sspr(40,72,40,8,60+animate(8)/8,92,80,16)
-- scientist
sspr(0,32,40,48,18+animate(1.5),16,80,96)
-- title (for screenshot)
-- spr(160,5,70,15,3)
if(t()%1<.7) nice_print("press x+z to start",nil,90,12,false)
nice_print("bY A CHEAP PLASTIC IMITATION",nil,115,5,false)
nice_print("OF A GAME DEV (cpiod) / 7DRL22",nil,122,5,false)
palt(4,false)
else
-- keep dithering even if game over
if redraw_light or redraw_heavy or screen_dx!=0 or screen_dy!=0 then
if(screen_dx>0) screen_dx-=1
if(screen_dy>0) screen_dy-=1
if(screen_dx<0) screen_dx+=1
if(screen_dy<0) screen_dy+=1
nodithering(redraw_heavy)
end
dithering(500)
if status!=20 then
draw_background_entities()
draw_xp()
if(show_map) draw_map()
if(show_classes) draw_classes()
-- ?nice_print("T:"..turn,0,121)
draw_mouse()
if(show_controls) draw_controls()
if(new_class) draw_new_class()
if(mouse_show_class) draw_one_class(mouse_show_class,33,20,true)
draw_msg()
if status==1 then
local tuto=split"you are a blob escaped from,a secret laboratory. these,scientists studied you for,years because of your,abilities: you are very,adaptive and you can split,your body at will. show them,what it takes to stop you!,,each color is an archetype.,learn their strengths and,weaknesses!,,press p to show the controls,press z to start"
local y=10
for t in all(tuto) do
nice_print(t,nil,y,7,false)
y+=7
end
end
else
nice_print("game over!",nil,60,8)
nice_print(points.." POINTS",nil,70,8)
nice_print("z TO RESTART",nil,90,6,false)
end
end
end
function draw_xp()
nice_print("xp",121,2,6,false)
local x,y=124,110
rectfill(x-1,y-100,x+1,y+1,5)
line(x,y,x,y-99,0)
for i=0,4 do
if(xp[i]!=0) line(x,y-xp[i]+1,x,y,class_attr[i].c2)
y-=xp[i]
end
end
function draw_mouse()
local mousex,mousey=stat(32),stat(33)
if mousex!=mouse_last_x or mousey!=mouse_last_y then
mouse_last_x,mouse_last_y=mousex,mousey
mouse_last_move=t()
end
if t()-mouse_last_move<2 then
palt(0,true)
spr(25,mousex-1,mousey-1)
palt(0,false)
local found=nil
local tx=(mousex-hx-1)\5
local ty=(mousey-hy-1)\5
local t=tiles[tx+ty*24]
if t then
local mx=t.x
local my=t.y
local mnb=mx+my*42
local y=mousey>64 and mousey-9 or mousey+6
if losb[mnb] then
for e in all(ents) do
local p=rawget(e,"pos")
if p and mx==p.x and my==p.y then
local t=rawget(e,"desc").txt
x=mousex-#t*4
if(x+#t*8>128) x=128-#t*8
if(x<0) x=0
found=e
nice_print(t,x,y)
break
end
end
if not found then
local m=mget(mx,my)
local t=nil
if(m==35) t="nEXT LEVEL!"
if(m==38) t="pREVIOUS LEVEL"
if(t) then
x=mousex-#t*4
if(x+#t*8>128) x=128-#t*8
if(x<0) x=0
nice_print(t,x,y)
end
end
end
end
if found and found.class then
if(time()%1<.5) nice_print("cLICK FOR STATS",nil,115)
if(stat(34)>0) mouse_show_class=found
else
mouse_show_class=nil
end
end
end
function add_msg(text,col,dur)
add(msg,{text,dur or 40,col})
end
function draw_controls()
local t=split"gAMES cONTROLS,10,z (SHORT PRESS),8,aTTACK,10,z (LONG PRESS),8,CHANGE SPECIES,10,x (SHORT PRESS),8,wAIT/NEXT BLOB,10,x (LONG PRESS),8,sPLIT THE BLOB,10,hOVER WITH MOUSE,8,gET MORE INFO,10,aRROWS,8,mOVE/ATTACK,10"
local y=5
for i=1,#t/2 do
local dy=t[2*i]
nice_print(t[2*i-1],nil,y,dy==10 and 7 or 6)
y+=dy
end
end
function nice_print(t,x,y,c,big)
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
?t,x+dx,y+dy,0
end
end
?t,x,y,c or 7
end
function draw_msg()
local y=50
for m in all(msg) do
m[2]-=1
if(m[2]==0) del(msg,m)
nice_print(m[1],nil,y,m[3])
y+=8
end
end
function draw_new_class(right)
local y=2+selected_class*(h+3)
draw_classes(true)
local y2=nil
if selected_class<2 then
y2=y+h+2
else
y2=y-h+2
end
draw_one_class(new_class,1,y,true)
local t=split" a NEW,SPECIES!,z CHANGE,x CANCEL"
for y=1,4 do
nice_print(t[y],0,y2+y*8-8)
end
end
function draw_classes(right)
local nb,x,y=0,right and 65 or 33,2
for cnb in all(inv) do
local c=update_class(cnb[1],cnb[2],nil)
draw_one_class(c,x,y,nb==selected_class)
if nb==selected_class then
nice_print("z CHANGE",0,y+20,nil,false)
nice_print("x CANCEL",0,y+27,nil,false)
end
nb+=1
y+=h+3
end
end
function draw_one_class(c,x,y,hl)
local col=hl and 7 or 6
local col2=hl and class_attr[c.c].c1 or class_attr[c.c].c2
rectfill(x,y,x+w-1,y+h,col2)
rectfill(x+1,y+1,x+w-2,y+h-1,col)
if c.c==-1 then
nice_print("nO SPECIES",x+2,y+8,col2,false)
else
for dy=1,3 do
nice_print(desc[c.adj][dy],x+2,y-4+6*dy,col2,false)
end
color(hl and 5 or 1)
local h=carac_hilite[c.c]
co=function(t)
return h[1]==t and 11 or (h[2]==t and 8 or nil)
end
local t="aTK"
nice_print(t,x+2,y+20,nil,false)
nice_print(c.atk,x+24,y+20,co(t),false)
t="aTKsPD"
nice_print(t,x+30,y+20,nil,false)
nice_print(10-c.atkspd\2,x+57,y+20,co(t),false)
t="aRMOR"
nice_print(t,x+2,y+26,nil,false)
nice_print(c.armor,x+24,y+26,co(t),false)
t="mOVsPD"
nice_print(t,x+30,y+26,nil,false)
nice_print(10-c.movspd\2,x+57,y+26,co(t),false)
t="rANGE"
nice_print(t,x+2,y+32,nil,false)
nice_print(c.rangemin..(c.rangemin==c.rangemax and "" or "-"..c.rangemax),x+24,y+32,co(t),false)
end
end
function draw_map()
-- rectfill(21,21,107,107,0)
for x=0,31 do
local sx=32+2*x
for y=0,31 do
local sy=32+2*y
if seen[x+42*y] then
if(losb[x+42*y]) pal(1,13) pal(5,6)
m=mget(x,y)
if m==33 or m==38 or m>=48 then
rectfill(sx,sy,sx+1,sy+1,m>=48 and 5 or 1)
elseif m==36 or m==35 then
fillp(▒-.5)
rectfill(sx,sy,sx+1,sy+1,m==36 and 0x15 or 0x51)
fillp()
end
pal(1,1)
pal(5,5)
else
if(seen[x-1+42*y]) line(sx,sy,sx,sy+1,0)
if(seen[x+1+42*y]) line(sx+1,sy,sx+1,sy+1,0)
if(seen[x+42+42*y]) line(sx,sy+1,sx+1,sy+1,0)
if(seen[x-42+42*y]) line(sx,sy,sx+1,sy,0)
end
end
end
fillp(▒-.5)
pal(13,1)
for e in all(ents) do
local p=rawget(e,"pos")
if p then
if losb[p.x+42*p.y] then
local sx=32+2*p.x
local sy=32+2*p.y
if rawget(e,"monster") or rawget(e,"blob") then
local c=class_attr[rawget(e,"class").c]
local col=(c.c1<<4)+c.c1
if rawget(e,"blob")==nil then
col=(c.c1<<4)+c.c2
end
if e==current_blob then
rectfill(sx-1,sy,sx+2,sy+1,col)
rectfill(sx,sy-1,sx+1,sy+2,col)
else
rectfill(sx,sy,sx+1,sy+1,col)
end
elseif rawget(e,"food") then
rectfill(sx,sy,sx+1,sy+1,0xff)
end
end
end
end
pal(13,13)
fillp()
end
function draw_background_entities()
palt(1,true)
if(shake>0) shake-=1
-- tiles
for x=0,23 do
for y=0,23 do
local i=x+24*y
-- tile dead ?
-- no tile on frontier
if tiles[i] then
local mx=tiles[i].x
local my=tiles[i].y
local mnb=mx+my*42
if seen[mnb] then
local m=mget(mx,my)
if(m!=0) then
local sx=hx+5*x+1
local sy=hy+5*y
if (screen_dx!=0 or screen_dy!=0) and tiles[i].b==current_blob then
-- if (screen_dx<0 and tiles[i-1].f)
-- or (screen_dx>0 and tiles[i+1].f)
-- or (screen_dy<0 and tiles[i-24].f)
-- or (screen_dy>0 and tiles[i+24].f) then
-- goto skip
-- end
sx+=screen_dx
sy+=screen_dy
end
if shake>0 then
local b=tiles[i].b
if b==whoshake[1] or b==whoshake[2] then
palt(0,true)
sx+=rnd(2)-1
sy+=rnd(2)-1
end
end
if(not losb[mnb]) pal(6,5)
if m==33 then
sspr(9,18,3,3,sx+1,sy+2)
elseif m>48 then
sspr(8*(m-48),25,5,5,sx,sy+1)
else
spr(m,sx,sy)
end
palt(0,false)
pal(6,6)
if losb[mnb] then
for e in all(ents) do
local b=tiles[i].b
local p=rawget(e,"pos")
if p!=nil and mx==p.x and my==p.y then
local ch=rawget(e,"render").char
if rawget(e,"class") then
local col=class_attr[rawget(e,"class").c].c1
local col2=class_attr[rawget(e,"class").c].c2
pal(6,col)
if(b==e) pal(0,col) pal(6,col2)
if(b==e and b==current_blob) pal(0,7)
end
if(b.target==e) circfill(sx+2,sy+3,3+(t()*4)%2,8)
spr(ch,sx,sy)
pal(6,6)
pal(0,0)
end
end
end
end
end
end
::skip::
end
end
palt(1,false)
end
function nodithering(heavy)
redraw_light,redraw_heavy=false,false
-- clip(hx,hy,120,120)
-- not los, not frontier
for tx=0,23 do
for ty=0,23 do
local i=tx+ty*24
local t=tiles[i]
local x=hx+5*tx
local y=hy+5*ty
if t and t.f==0 and not losb[t.x+42*t.y] then
if t.b==current_blob then
x+=screen_dx
y+=screen_dy
-- if (screen_dx<0 and tiles[i-1].f)
-- or (screen_dx>0 and tiles[i+1].f)
-- or (screen_dy<0 and tiles[i-24].f)
-- or (screen_dy>0 and tiles[i+24].f) then
-- else
-- rectfill(x,y,x+4,y+4,1)
-- end
end
if t.b==current_blob or heavy then
rectfill(x,y,x+4,y+4,1)
end
end
end
end
-- los, not frontier
for tx=0,23 do
for ty=0,23 do
local i=tx+ty*24
local t=tiles[i]
local x=hx+5*tx
local y=hy+5*ty
if t and losb[t.x+42*t.y] then
if t.b==current_blob or heavy then
--x+=screen_dx
--y+=screen_dy
-- if (screen_dx<0 and tiles[i-1].f)
-- or (screen_dx>0 and tiles[i+1].f)
-- or (screen_dy<0 and tiles[i-24].f)
-- or (screen_dy>0 and tiles[i+24].f) then
-- else
circfill(x+3,y+3,3,13)
-- end
-- elseif heavy then
-- circfill(x+3,y+3,3,13)
end
end
end
end
-- frontier
-- for tx=0,23 do
-- for ty=0,23 do
-- local t=tiles[tx+ty*24]
-- local x=hx+5*tx
-- local y=hy+5*ty
-- if t and t.f>0 and (t.b==current_blob or heavy) then
-- local colors=class_attr[rawget(t.b,"class").c]
-- local c=t.b==current_blob and colors.c1 or colors.c2
-- circfill(x+3,y+3,2,c)
---- elseif t==nil and heavy then
---- rectfill(x,y,x+4,y+4,0)
-- end
-- end
-- end
clip()
end
function dithering(imax)
for i=1,imax do -- todo imax
local x=rnd(127)
local y=rnd(127)
local c=nil
local r=1
if x<hx or x>=hx+5*24 or y<hy or y>=hy+5*24 then
c=0
else
local dx=flr((x-hx)%5)
local dy=flr((y-hy)%5)
local tx=(x-hx)\5
local ty=(y-hy)\5
local t=tiles[tx+ty*24]
local f=t and ((t.f&1>0 and dx==0)
or (t.f&2>0 and dx==4)
or (t.f&4>0 and dy==0)
or (t.f&8>0 and dy==4))
if t and f then
local thres=.05 -- color
local chance=1
r=0
-- current blob has bigger frontier
if t.b==current_blob then
-- if(imax>200 and changed_focus==0) chance=.5
r=1
thres=.95
end
if rnd()<chance then
local colors=class_attr[rawget(t.b,"class").c]
if rnd()>thres then
c=colors.c2
else
c=colors.c1
end
end
elseif t then
c=losb[t.x+42*t.y] and 13 or 1
else
c=0
end
end
if(c!=nil) circfill(x,y,r,c)
end
if(changed_focus>0) changed_focus-=1
end
-->8
-- map generation
-- flags:
-- 0: traversable
-- 1: transparent
function mapgen()
nice_print("mAP GEN...",nil,60)
flip()
los={}
losb={}
seen={}
for i=0,31 do
for j=0,31 do
los[i+j*42]={}
losb[i+j*42]=false
seen[i+j*42]=false
end
end
depth+=1
first_step()
second_step()
set_bitset_wall()
populate()
rerender=true
end
function first_step()
-- crude mapgen
local dx=100
for x=dx,dx+14 do
for y=0,14 do
mset(x,y,2)
end
end
local seedx=dx+rnd(15)&-1
local seedy=rnd(15)&-1
local free=1
mset(seedx,seedy,1)
while free<100 do
local x=dx+rnd(15)&-1
local y=rnd(15)&-1
local prevx,prevy=nil,nil
while mget(x,y)==2 do
prevx=x
prevy=y
local d=dir[rnd(4)&-1]
x+=d[1]
y+=d[2]
if(x<dx) x=dx
if(y<0) y=0
if(x>dx+14) x=dx+14
if(y>14) y=14
end
if(prevx) mset(prevx,prevy,1) free+=1
end
for x=0,31 do
for y=0,31 do
-- border
if x==0 or y==0 or x==31 or y==31 then
mset(x,y,2)
else
local x2=(x-1)\2
local y2=(y-1)\2
mset(x,y,mget(x2+dx,y2))
end
end
end
end
function second_step()
-- generate layout with automata
local dx=80
for x=0,4 do
for y=0,4 do
mset(x+dx,y,rnd(2)&-1)
end
end
-- modify map
for i=0,500 do
local x=1+rnd(30)&-1
local y=1+rnd(30)&-1
local t=mget(dx+x\10,y\10)
local w=mget(x,y)==2
local k=0
for x2=-1,1 do
for y2=-1,1 do
if((x2!=0 or y2!=0) and mget(x+x2,y+y2)==2) k+=1
end
end
if t==0 then
-- big open space
if(w and k>1 and k<6) mset(x,y,1)
elseif t==1 then
-- pillars
if(x&1==0 and y&1==0 and not w and k==0) mset(x,y,2)
if(w and k>0 and k<3) mset(x,y,1)
end
end
end
function populate()
if current_blob==nil then
spawn_first_blob()
else
reset_blob()
end
update_los_one()
mset(current_blob.x,current_blob.y,38)
local maxdist=nil
local bestx,besty=nil,nil
for i=1,10 do
local x,y=get_empty_space()
local dx=abs(x-current_blob.x)
local dy=abs(y-current_blob.y)
local dist=dx+dy-0.56*min(dx,dy)
if maxdist==nil or dist>maxdist then
maxdist=dist
bestx=x
besty=y
end
end
mset(bestx,besty,35)
for i=1,6+depth do
local cnb=rnd(5)\1
if(depth<=1) cnb=rnd(3)\1
add_monster(cnb)
end
for i=1,2+depth\2 do
add_food()
end
local h=ent()+cmp("hunger",{})
h+=cmp("turn",{t=turn+hunger_delay})
h+=cmp("hunger",{})
add(ents,h)
end
function search_adjacent_space(x,y)
for d in all(dir) do
if(can_move_to(x+d[1],y+d[2])) return x+d[1],y+d[2]
end
return nil
end
function get_empty_space()
local x,y=nil,nil
while mget(x,y)!=33 do
x=rnd(40)&-1
y=rnd(40)&-1
end
return x,y
end