-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharea_51_1_1_FINALFINALFINALFINAL22MINUTESLEFTONTHECLOCK.p8
2356 lines (2123 loc) · 90.4 KB
/
area_51_1_1_FINALFINALFINALFINAL22MINUTESLEFTONTHECLOCK.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__
--hazmat havoc by archonic,
--virtuavirtue, pico-8 gamer
last_checkpoint = {8, 184}
spawn = {8, 184}
--spawn = {94*8, 19*8}
--spawn = {90*8, 10*8}
msets = {}
function reset_ents()
for xy in all(msets) do
mset(xy[1], xy[2], 5)
end
end
-- main
-- initialize
function _init()
--screen shake
if break_room then
reset_ents()
msets = {}
spawn = {744, 80}
mset(94, 10, 33) --axe
mset(117, 13, 37) -- crowbar
mset(123, 13, 96) --medkit
end
intensity = 0
shake_fall_factor = 0.8
camera_override = false
logs,ticks,points,fading,fadespeed,bg_col
=
{},0,{},0,5,5
--camera corners
camera_corners = {{0,0}, {1024,1024}}
_init_keycards()
_real_game_keycards_init()
init_dialogue()
_init_interact_events()
_ent_init()
_obj_init()
--ply=new_ent(8,176,1) -- player
ply = new_ent(spawn[1], spawn[2], 1)
px,py=ui_pos()[1],ui_pos()[2]
palt(0,false)
palt(15,true)
poke(24364,3)
place_objects()
_cutscenes_init()
form_poke(1,0)
light=1
if break_room then _init_br() end
if not break_room then
add_dscene(create_dscene("i can't believe", "i dropped my", "keys down", "here...", "well, might as", "well go", "look for them!", "", "🅾️ - interact", "arrows - move"))
add_dscene(create_dscene("i need keycards", "to get around", "this place,", "though.", "i think i", "smelled the 1st", "one up north..."))
end
end
function ui_pos()
return {
mid(ply.x-32, camera_corners[1][1], camera_corners[2][1]) + (rnd()-0.5)*intensity,
mid(ply.y-32, camera_corners[1][2], camera_corners[2][2]) + (rnd()-0.5)*intensity
}
end
function update_screen_shake()
intensity *= shake_fall_factor
if intensity < 0.1 then intensity = 0 end
end
-- update game
function _update()
if gamefinished then return end
if light~=6then
fade_in=fade_in and fade_in+1 or 0
if fade_in%5==0then
light+=1
form_poke(light,0)
end
end
fire_loc_funcs()
-- update each object's head bob
obj_bob = sin(t())/2
camera_override = false
if update_sequence() then
goto finally
end
if break_room then
if #enemies_waiting > 0 then br_alert_check() end
if #enemies_alerted > 0 then update_alerted() end
end
-- handle dialogue
dialogueing=update_dialogue()
if not dialogueing then
--★ place all game update code here! ★
-- update each entitiy
foreach(ents,function(ent)
if not ent.dead then
ent:ai()
ent.iframes = max(ent.iframes and (ent.iframes - 1) or 0)
if ent.attacking == true then
for damagee in all(get_targeted_ents(ent)) do
damage_ent(damagee, ent.item.dmg)
if not (ent.item and ent.item.ind == 1) then
ent.attacking = false
break
end
end
end
end
end)
fire_tile_interactions()
end
::finally::
-- player ui position
if not camera_override then
local uipos = ui_pos()
px = uipos[1]
py = uipos[2]
end
end
function draw_hopscotch(y_off)
--in that one room
for i=1,7 do
local x = i*6 + hro[1] - 5
if i % 2 == 0 then
rect(x, hro[2] - 5 + y_off, x + 4, hro[2] - 1 + y_off, 7)
rect(x, hro[2] + 5 + y_off, x + 4, hro[2] + 1 + y_off, 7)
else
rect(x, hro[2] + y_off, x + 4, hro[2] + 4 + y_off, 7)
end
end
end
-- draw
function _draw()
if gamefinished then
cls(0)
print("hazmat havoc", px+12, py+4, 10)
draw_rotation(ply, false)
print("created by:", px+14, py + 36, 6)
print("virtuavirtue", px+12, py + 42,7 )
print("archonic", px+12, py + 48,7 )
print("pico-8 gamer", px+12, py + 54,7 )
return
end
cls(bg_col)
update_screen_shake()
map()
-- move camera
camera(px + (camera_override and (rnd()-0.5)*intensity or 0), py + (camera_override and (rnd()-0.5)*intensity or 0))
-- ui
healthbar()
keycard_ui()
-- draw entities
if break_room then draw_hopscotch(0) draw_hopscotch(24) end
foreach(ents,_draw_ent)
-- draw objects
foreach(objs,_draw_obj)
-- debugging
-- draw points
--foreach(points, function(point)
--pset(point[1], point[2], point[3])
--end)
points = {}
-- draw dialogue
if dialogueing then
draw_dialogue()
end
draw_sequence()
draw_alerted()
end
function apply_pal(cols)
for pair in all(cols) do
pal(pair[1], pair[2])
end
end
function reset_pal(cols)
for pair in all(cols) do
pal(pair[1], pair[1])
end
end
function q(x, steps) --rounds x to the nearest 1/steps
return flr(x*steps)/steps
end
-- spawn items
-- index - item sprite
-- [1] - item index in array
-- [2] - 1|item - 2|enemy
obj_inds={}
obj_inds[33]='1,1' -- axe
obj_inds[37]='2,1' -- crowbar
obj_inds[41]='3,1' -- gun
obj_inds[96]='4,1' -- medkit
obj_inds[101]='5,1' -- white keycard
obj_inds[97]='6,1'
obj_inds[99]='7,1'
obj_inds[100]="8,1"
obj_inds[98]="9,1"
-- spawn enemies
obj_inds[5]='2,2' -- slimer
-->8
-- entity class
-- draw entitiy
function _draw_ent(ent)
draw_rotation(ent)
end
-- create entity
function new_ent(x,y,ai)
local ent={}
local entdata = ent_arr[ai]
ent.x,ent.y,ent.sprs,ent.ai,ent.z,ent.dh,ent.dv,ent.spd,ent.org_x,ent.org_y,ent.iframes,ent.iframes_max
=
x,y,split(ent_arr[ai][1]),ent_arr[ai][3],0,1,0,0,x,y,0,entdata.iframes
if entdata.atk_len then --if they have this they have all the other atkvals
ent.atk_len,ent.atk_rot_add,ent.attacking,ent.atk_ticks,ent.rest_window=
entdata.atk_len,nil,false,0, entdata.rest_window
end
local stats=split(ent_arr[ai][2])
ent.hp,ent.max_spd
=
stats[1],entdata.spd
add(ents,ent)
return ent
end
-- initialize entities
function _ent_init()
ents={}
end
-- - collision -
-- point colliding
function point_colliding_w_map(x, y)
return fget(mget(x/8, y/8), 0)
end
-- colliding y
function ent_colliding_w_map_y(x,y,w, h,xvel, yvel)
local yorg = (yvel > 0) and y+h or y
for i=x,x+w-8,8 do
if point_colliding_w_map(i, yorg) or
point_colliding_w_map(i+7, yorg) then
--snap collision
return true
end
end
return false
end
-- colliding x
function ent_colliding_w_map_x(x,y,w,h,xvel,yvel)
local xorg = (xvel > 0) and x+w or x
for i=y,y+h-8,8 do
if point_colliding_w_map(xorg, i) or
point_colliding_w_map(xorg, i+7) then
return true end
end
return false
end
-- any collision
function ent_collision_w_map(x, y, w, h, xvel, yvel)
--plot points along x axis
if ent_colliding_w_map_x(x+xvel, y+yvel, w, h, xvel, yvel) then xvel = 0 end
if ent_colliding_w_map_y(x+xvel, y+yvel, w, h, xvel, yvel) then yvel = 0 end
return {x+xvel, y+yvel}
end
-- if flag at tile
function flag_at(x,y,flag)
return fget(tile_at(x,y),flag)
end
-- get tile at position
function tile_at(x,y)
return mget(x,y)
end
function dhdv(z)
z = q(z, 8)
z = (z+0.125)*8
key = {{1, 0}, {1,1}, {0, -1}, {-1, 1}, {-1, 0}, {-1, -1}, {0, 1}, {1, -1}}
return key[z]
end
-- ✽ entities ✽ --
-- array of entities
ent_arr={
-- player
{'1,2,3','3',
function(ent)
if can_atk(ent) then
if btnp(❎) then start_atk(ent)
elseif btnp(1, 1) then
ent.z = 0
start_atk(ent)
elseif btnp(0, 1) then
ent.z = 0.5
start_atk(ent)
elseif btnp(2, 1) then
ent.z = 0.25
start_atk(ent)
elseif btnp(3, 1) then
ent.z = 0.75
start_atk(ent)
end
end
-- control
-- move + collision check
move_ent(ent)
control_ent(ent, true)
if ent.atk_ticks > 0 then
update_atk(ent)
end
-- check if player can pick up items
pick_up(ent,true)
local x,y
=
(ent.x+4)/8,(ent.y+4)/8
local cur_tile=tile_at(x,y)
local pals=tile_pals[cur_tile]
-- check if player on trigger tile
if pals then
if type(pals)=="function"then
pals(x,y,ent)
else
bg_col=pals
end
end
end
,spd=2,rest_window = 1,atk_len=8,iframes=20},
-- slimer
{
'5,6,7','1',
-- update
function(ent)
-- ai
control_ent(ent)
-- move + collision check
move_ent(ent)
-- pick up items
pick_up(ent)
end
,spd=1,atk_len=10,rest_window=10}
}
-- - utility -
-- distance
function dist(x1,y1,x2,y2)
return abs(x1-x2)+abs(y1-y2)
end
-- damage entity
function damage_ent(ent,amm)
-- damage sound
if ent.iframes > 0 then return end
local watcher = get_watcher(ent)
if not (watcher == nil) then
for ent in all(watcher.entities) do
alert_enemy(ent)
end
end
-- damage entity on interval
sfx(ent==ply and 4 or 1)
ent.hp=max(ent.hp-amm)
ent.iframes = (ent.iframes_max or 25)
if ent.hp==0 then
if ent == ply then
if break_room then
ply.x = 93*8
ply.y = 10*8
_init()
else
ply.x = last_checkpoint[1]
ply.y = last_checkpoint[2]
end
ply.hp = 2
else
del(ents,ent)
ent.dead=true
ent.spd = 0
if ent.persist then --break roojm
persist_enemies_left -= 1
if persist_enemies_left <= 0 then
unlock_doors()
end
end
end
end
end
-- ai/player modules -
-- check if player or entity can pick up item
function pick_up(ent,but)
if not (ent == ply) then return end
-- run checks
for obj in all(objs) do
if (dist(obj.x, obj.y, ent.x, ent.y) < 10) and not (obj.owner == ent) and btnp(🅾️) then
-- make sure enemies can't take from player
if(not but and (ent.item or obj.owner or ent.ammo==-2))break
sfx(2)
-- auto use
if obj.type==1 then
obj.use(obj,ent)
return
end
-- drop current item
if(ent.item)drop_item(ent)
-- replace current object owner
if(obj.owner)obj.owner.item=nil
obj.owner=ent
-- sort it to front of rendering table
del(objs,obj)
add(objs,obj)
ent.item=obj
return
end
end
-- update player item
if ent.item then
-- update item stats
update_player_item(ent)
-- check for buttons
if but then
-- throw item
if btnp(❎,1)then
drop_item(ent)
elseif btnp(❎)then
ent.item.use(ent.item,ent)
end
end
end
end
atk_rot_speed = 1.3/30
--update attack values (called while attacking)
function update_atk(ent)
ent.atk_ticks -= 1
ent.atk_rot_add = (ent.atk_rot_add + atk_rot_speed) % 1
if abs(ent.atk_rot_add - ent.z) <= atk_rot_speed then
ent.atk_rot_add = ent.z
end
if ent.attacking then
if ent.atk_ticks <= 0 then
ent.attacking = false
ent.atk_ticks = ent.rest_window
end
elseif ent.atk_ticks <= 0 then
ent.atk_rot_add = nil
end
end
function can_atk(ent)
return ent.atk_ticks <= 0 and ent.item
end
--start atk
function start_atk(ent)
ent.atk_ticks = ent.atk_len
ent.atk_rot_add = (ent.z - 0.25) % 1
ent.attacking = true
end
-- move
function move_ent(ent)
-- direction
if ent.spd>0.01then
local dir_x,dir_y
=
cos(ent.z_dir)*ent.spd,sin(ent.z_dir)*ent.spd
-- collision
local loc=ent_collision_w_map(ent.x,ent.y,8,8,dir_x,dir_y)
-- movement
ent.x=loc[1]
ent.y=loc[2]
end
end
atk_reach = 7.5
function ent_is_targeted(ent, xy)
local x = mid(ent.x, xy[1], ent.x+(ent.w or 8))
local y = mid(ent.y, xy[2], ent.y+(ent.h or 8))
return x==xy[1] and y==xy[2]
end
function get_targeted_ents(ent)
local atk_reach = (ent.item and ent.item.ind == 1) and atk_reach*0.7 or atk_reach
local targeted = {}
local point = get_point_ahead(ent,atk_reach)
local point2 = get_point_ahead(ent, atk_reach*0.5)
for target in all(ents) do
if not (target == ent) then
if ent_is_targeted(target, point) or ent_is_targeted(target, point2) then
add(targeted, target)
end
end
end
return targeted
end
-- get ent from spawned tile
function get_spawned_ent(org_mx, org_my)
for ent in all(ents) do
if ent.org_x\8 == org_mx and ent.org_y\8 == org_my then
return ent
end
end
end
-- control entity
function control_ent(ent,but)
if ent.locked then return end
-- init
local ph,pv,dh,dv,but
=
false,false,false,false,but or false
-- player ai
if but then
-- handle movement presses
if(btn(1)) then ph=1 end
if(btn(0))ph=-1
if(btn(2))pv=-1
if(btn(3))pv=1
-- handle look presses
if ent.atk_ticks > 0 then
local dh_dv = dhdv(ent.z)
dh,dv = dh_dv[1],dh_dv[2]
else
if(btn(1))dh=1
if(btn(0))dh=-1
if(btn(2))dv=-1
if(btn(3))dv=1
end
-- if look direction pressed
if dh or dv then
if not (ent.atk_ticks > 0) then ent.z=atan2(dh,dv) end
ent.dh,ent.dv
=
dh or 0,dv or 0
end
-- if movement direction pressed
if ph or pv then
ent.z_dir,ent.ph,ent.pv
=
atan2(ph,pv),ph or 0,pv or 0
-- accel
accel_ent(ent)
-- footstep sound effect
ent.walk_tick=ent.walk_tick and ent.walk_tick+1 or 0
if ent.walk_tick%7==0then
sfx(6)
end
-- slow player
else
accel_ent(ent,true)
end
return
-- enemy ai
else
dist_ply=dist(ent.x,ent.y,ply.x,ply.y)
-- check if player in range
if (dist_ply<30 or ent.persist) and not ply.dead then
-- damage player
if dist_ply<6 then
damage_ent(ply,(break_room and 0.5 or 0.3))
return
end
-- handle target position
if(ent.x>ply.x+3)ph=-1
if(ent.x<ply.x-3)ph=1
if(ent.y<ply.y-3)pv=1
if(ent.y>ply.y+3)pv=-1
else
ph,pv
=
0,0
end
-- move enemy
if(ph!=0)or(pv!=0)then
ent.dh,ent.dv
=
ph or 0,pv or 0
ent.z=atan2(ph,pv)
ent.z_dir=atan2(ent.dh,ent.dv)
accel_ent(ent)
-- slow entity
else
accel_ent(ent,true)
end
return
end
end
-- accelerate entity
function accel_ent(ent,bool)
bool=bool or false
if not bool then
ent.spd=mid(0, ent.spd+.1, ent.max_spd)
logs = {}
add(logs, ent.spd)
else
ent.spd=max(ent.spd-.1)
end
if ent == ply and ent.spd > 0 then
end
end
-- - collision -
-- point colliding
function point_colliding_w_map(x, y)
return fget(mget(x/8, y/8), 0)
end
--this value narrows collision by po pixels
po = 2
-- ent colliding y
function ent_colliding_w_map_y(x,y,w, h,xvel, yvel)
local yorg=(yvel>0)and y+h-po or y+po
-- point offsets in order to narrow collision
for i=x,x+w-8,8 do
if point_colliding_w_map(i+po, yorg) or
point_colliding_w_map(i+7-po, yorg) then
--snap collision
return true
end
end
return false
end
-- ent colliding x
function ent_colliding_w_map_x(x,y,w,h,xvel,yvel)
local xorg=(xvel>0)and x+w-po or x+po
for i=y,y+h-8,8 do
if point_colliding_w_map(xorg, i+po) or
point_colliding_w_map(xorg, i+7-po) then
return true end
end
return false
end
--loc is x or y, vel is assoc. velocity
function snapvel(loc, vel) --snap collision deprecated
return 0
end
-- entity collision with map
function ent_collision_w_map(x, y, w, h, xvel, yvel)
--plot points along x axis
if ent_colliding_w_map_x(x+xvel, y, w, h, xvel, yvel) then xvel = snapvel(x, xvel) end
if ent_colliding_w_map_y(x, y+yvel, w, h, xvel, yvel) then yvel = snapvel(y, yvel) end
return {x+xvel, y+yvel}
end
-->8
-- object class
-- create entity
function new_obj(x,y,ind)
local obj={}
local index=objects[ind]
local sprs=split(index[1])
local data=split(index[2])
obj.x,obj.y,obj.sprs,obj.use,obj.z,obj.ammo,obj.type,obj.name,obj.ind,obj.cols,obj.dmg
=
x,y,sprs,index[3],0.125,data[2],data[3],data[1],ind,index.cols,index.dmg
obj.org_frame=obj.frame
if obj.ammo<0 then
obj.z=0
end
add(objs,obj)
return obj
end
-- initialize entities
function _obj_init()
objs={}
obj_bob = 0
end
-- draw objects
function _draw_obj(obj)
local r = false
if not (obj.cols == nil) then
apply_pal(obj.cols)
r = true
end
draw_rotation(obj, (obj.owner == nil))
if r then reset_pal(obj.cols) end
end
function keycard_func(ind)
local func = function(obj, entity)
collect(obj.ind) --todo does this work
local keycards_left = keycards_left()
if keycards_left == 0 then
sfx(12)
add_dscene(create_dscene("oh look...","that was the","last one..."))
add_dscene(create_dscene("now i can", "unlock those", "gates...", "", "yay..."))
elseif keycards_left == 3 then
sfx(9)
add_dscene(create_dscene("a keycard!", "now to make", "my way to", "that " .. keycard_name_map[obj.ind], "gate!"))
elseif keycards_left == 2 then
sfx(9)
elseif keycards_left == 1 then
sfx(9)
--add_dscene(create_dscene("hey look!", "the cards that", "i didn't get!"))
--add_dscene(create_dscene("i mean...", "i would've", "gotten them...", "", "if i didn't", "bust open this", "break room..."))
--add_dscene(create_dscene("i almost", "feel bad", "for the poor", "guys..."))
end
del(objs, obj)
end
return func
end
-- objects array
-- object type structure
-- 1: str: sprite number(s) separated by commas for rotatable sprites
-- 2: str: param collection, first is name. rest: who nose!!
-- 3: use function: called when the object is used
-- cols: an array of color pairs (2 item arrs) to be swapped on draw
objects={
-- fire axe (1)
{'32,33,34,35','fire axe,1,0',
-- use
function(obj,ent)
melee(obj,ent)
end
,dmg=1},
-- crowbar (2)
{'36,37,38,39','crowbar,1,0',
-- use
function(obj,ent)
melee(obj,ent)
-- box destruction is in tab 5
end
,dmg=0.5},
-- pistol (3)
{'40,41,42,43','gun,10,0',
-- use
function(obj,ent)
end
},
-- medkit (4)
{'96','medkit,-1,1',
-- use
function(obj,ent)
ent.hp+=2
del(objs,obj)
end
},
-- 5 white keycard (enemies can't take)
{'101','tutorial_keycard,-2,1',
-- use
function(obj,ent)
keycards_collected[1]=true
del(objs,obj)
if not gate_unlocked then
gate_unlocked = true
sfx(9)
add_dscene(create_dscene("who left","this keycard","lying around?"))
mset(x,y,0)
return
end
end
},
{'97','red_keycard,-2,1', --6 red keycard
keycard_func(6)
},
{'99','green_keycard,-2,1', --7 green keycard
keycard_func(7)
},
{'100','orange_keycard,-2,1', --8 orange keycard
keycard_func(8)
},
{'98','blue_keycard,-2,1', --9 blue keycard
keycard_func(9)
},
}
-- - utility -
-- drop item
function drop_item(ent)
ent.item.owner,ent.item
=
nil,nil
end
-- update player's item
function update_player_item(ent)
local obj
=
ent.item
obj.x,obj.y,obj.z
=
ent.x+ent.dh*5,ent.y+ent.dv*5,ent.z
end
-- initiate melee swing
function melee(obj,ent)
if can_atk(ent) then
start_atk(ent)
end
end
-- spawn items and enemies
function place_objects()
for x=0,128do
for y=0,32do
local mg=mget(x,y)
local obj=split(obj_inds[mg])
-- spawn item at position
if obj then
if obj[2]==1then
new_obj(x*8,y*8,obj[1])
mset(x,y,254)
else
new_ent(x*8,y*8,obj[1])
mset(x,y,0)
end
end
end
end
end
-->8
-- dialogue system
-- variables
char_len=4
line_spacing=6
box_size_max=29
side_margin=4
box_speed=3
max_lines=3
-- dialogue init
function init_dialogue()
box_size=0
current_dialogue=nil
dialogue_queue={}
dialogueing=false
end
-- create dialogue scene
function create_dscene(...)
local table=pack(...)
local dscene={lines={}}
for i,lin in ipairs(table)do
add(dscene.lines,{str=lin,x=33-(char_len*#lin\2),y=line_spacing*(i-0.4)})
end
return dscene
end
-- add dialogue scene
function add_dscene(dscene)
if current_dialogue==nil then
current_dialogue=dscene
else
add(dialogue_queue,dscene)
end
end
-- update dialogue scene
function update_dscene(dscene, advance)
if advance then
sfx(11)
deli(dscene.lines, 1)
if #dscene.lines == 0 then return true
elseif #dscene.lines == max_lines-1 then
deli(dscene.lines, 1)
return true
else
for lin in all(dscene.lines) do
lin.y -= line_spacing
end
return false
end
end
end
-- update dialogue
-- should be called every frame. returns true if dialogue is active
function update_dialogue()
if current_dialogue==nil then
if box_size>0 then box_size=max(box_size-box_speed,0)
else return false end
return true
else
if box_size>=box_size_max then
if update_dscene(current_dialogue,btnp(🅾️))then
current_dialogue=dialogue_queue[1]
if #dialogue_queue>0then deli(dialogue_queue,1)end
end
else
box_size=min(box_size+box_speed,box_size_max)
end
return true
end
end