-
Notifications
You must be signed in to change notification settings - Fork 0
/
zom8.p8
1535 lines (1310 loc) · 57.1 KB
/
zom8.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__
-- main
-- 0 = title, 1 = game loop, 2 = death
state=0
function _init()
map_width=64
map_height=48
m={}
spawners={}
walls={}
barriers={}
vending={}
z_id=0
cost = 500
text_frames=0
msg={text='',dx=0}
coinmsg=false
shakestart=false
pal(10, 1+128, 1)
pal(12, 5+128, 1)
--player init
p=make_player(6,7)
crs=make_cursor()
crs:update_cursor(p)
cam=make_camera()
--enemies init
zombies={}
--map init
m=make_map()
walls=make(7)
barriers=make(8)
vending=make_vending()
--projectile init
proj={}
--bombs init
bombs={}
-- laser init
lasers={}
-- particles init
particles={}
--spawner init
spawners=make(6)
frict=0.9
end
function _draw()
if(state == 0) then
cls()
map(0,0)
print_3D_map(m, p)
rectfill(0, 45, 130, 80, 0)
local lastx
for tx = 39, 41 do
lastx = print('<', tx,55,7)
end
lastx += 1
for tx = 43, 47 do
lastx = print('<', tx,55,7)
end
lastx += 2
lastx = print('zom8', lastx, 55, 7)
lastx += 2
for tx = lastx, lastx + 4 do
lastx = print('>', tx,55,7)
end
lastx -= 2
for tx = lastx, lastx + 2 do
lastx = print('>', tx, 55,7)
end
print('< press ❎ or 🅾️ to begin >', 10, 65, 7)
end
if(state == 1) then
cls()
map(0,0)
--player
p:draw(crs)
crs:draw_cursor()
--map
-- print_map(m)
cam:draw()
--zombie
for zombie in all(zombies) do
zombie:draw()
end
print_3D_map(m, p)
crs:draw_box_barrier(barriers, p)
crs:draw_box_wall(walls, p)
crs:draw_box_vending(vending, p)
if(text_frames > 0)then
draw_ui_prompt(msg.text, p.x*8 + msg.dx, p.y*8 + 58)
end
-- projectile
for projectile in all(proj) do
projectile:draw()
end
for bomb in all(bombs) do
bomb:draw()
end
for laser in all(lasers) do
laser:draw()
end
-- particles
for particle in all(particles) do
particle:draw()
end
--debug
p:ui()
-- -- print(p.x,p.x*8-62,p.y*8-62,8)
-- -- print(p.y,p.x*8-62,p.y*8-56,8)
-- print(p.dx,p.x*8-62,p.y*8-50,8)
-- print(p.dy,p.x*8-62,p.y*8-44,8)
end
end
function _update()
if(state == 0) then
cam:update(p.x, p.y)
m=make_map()
distmap()
if btnp(❎) or btnp(🅾️) then
state = 1
end
end
if(state == 1) then
if text_frames > 0 then
text_frames-=1
elseif text_frames == 0 then
coinmsg=false
end
p:control(crs)
p:update()
crs:update_cursor(p)
-- map
m=make_map()
distmap()
cam:update(p.x, p.y)
--zombie
for zombie in all(zombies) do
-- player collide
enemy_collide(p, zombie)
-- projectile collide
for projectile in all(proj) do
projectile_collide(zombie, projectile, p)
end
-- actions
zombie:getPath()
zombie:control()
end
-- projectiles
for projectile in all(proj) do
projectile:update()
end
for bomb in all(bombs) do
bomb:update(p)
end
for laser in all(lasers) do
laser:update(p)
end
-- spawners
for spawner in all(spawners) do
spawner:spawn_zombie()
end
-- walls
for wall in all(walls) do
wall:degrade()
end
-- particle
for particle in all(particles) do
particle:update()
end
end
end
-->8
-- player and zombies
function make_player(x, y)
-- everything is in a table
-- units are in tiles, where each tile is 8x8 pixels
pl={
-- fields
x=x,
y=y,
w=0.45,
h=0.45,
dx=0,
dy=0,
max_dx=0.3,
max_dy=0.3,
accel=0.1,
health=9,
regen_timer=450,
shielded=false,
invincible_frames=0,
sp=17,
sp_frames=0,
sp_flip=false,
facing=1,
-- 0 = pistol, 1 = shotgun, 2 = bomb, 3 = laser
weapon=0,
reload_frames=0,
laser_charging=false,
laser_timer=0,
coins=0,
-- functions
control=function(self, c)
if btn(⬅️) then
self.dx-=self.accel
end
if btn(➡️) then
self.dx+=self.accel
end
if btn(⬆️) then
self.dy-=self.accel
end
if btn(⬇️) then
self.dy+=self.accel
end
if btnp(❎) then
self.facing+=1
if self.facing > 4 then
self.facing = 1
end
end
if btnp(🅾️) and c.boxed_wall then
mset(c.x, c.y, 2)
make_particles(c.x, c.y, 13)
start_wall_timer(walls, c.x, c.y)
shakestart = true
elseif btnp(🅾️) and c.boxed_barrier then
if (self.coins >= cost) then
bar = in_set(barriers, c.x, c.y)
destroy_barrier(bar)
self.coins -= cost
cost *= 2
shakestart = true
break_surprise_barriers()
else
coinmsg = true
set_msg('< not enough coins! >', -40)
end
elseif btnp(🅾️) and c.boxed_vending then
vend = in_set(vending, c.x, c.y)
if(self.coins >= vend.cost) then
make_particles(vend.x1, vend.y1, 9)
if(vend.perk == 1) then
if(self.health < 9) then
self.health += 1
else
coinmsg = true
set_msg('< at full health! >', -40)
self.coins += vend.cost
end
elseif(vend.perk == 2) then
self.weapon = 1
elseif(vend.perk == 3) then
self.invincible_frames = 300
self.shielded = true
elseif(vend.perk == 4) then
self.weapon = 2
elseif(vend.perk == 5) then
self.weapon = 3
end
self.coins -= vend.cost
self.laser_charging = false
else
coinmsg = true
set_msg('< not enough coins! >', -40)
end
elseif btnp(🅾️) then
if self.facing == 1 then -- right
if(self.weapon == 0) then
make_projectile(self, 1, 0)
elseif(self.weapon == 1 and self.reload_frames == 0) then
make_shotgun_proj(self, 1, 0, 0, 0.3)
elseif(self.weapon == 2 and self.reload_frames == 0) then
make_bomb(self, 0.5, 0)
end
elseif self.facing == 2 then -- down
if(self.weapon == 0) then
make_projectile(self, 0, 1)
elseif(self.weapon == 1 and self.reload_frames == 0) then
make_shotgun_proj(self, 0, 1, 0.3, 0)
elseif(self.weapon == 2 and self.reload_frames == 0) then
make_bomb(self, 0, 0.5)
end
elseif self.facing == 3 then -- left
if(self.weapon == 0) then
make_projectile(self, -1, 0)
elseif(self.weapon == 1 and self.reload_frames == 0) then
make_shotgun_proj(self, -1, 0, 0, 0.3)
elseif(self.weapon == 2 and self.reload_frames == 0) then
make_bomb(self, -0.5, 0)
end
else -- up
if(self.weapon == 0) then
make_projectile(self, 0, -1)
elseif(self.weapon == 1 and self.reload_frames == 0) then
make_shotgun_proj(self, 0, -1, 0.3, 0)
elseif(self.weapon == 2 and self.reload_frames == 0) then
make_bomb(self, 0, -0.5)
end
end
if(self.weapon == 3 and #lasers == 0 and not self.laser_charging) then
self.laser_timer = 60
self.laser_charging = true
end
end
if(self.laser_timer == 0 and self.laser_charging) then
self.laser_charging = false
if self.facing == 1 then -- right
make_laser(self.x + 1, self.y - 1.5, self.x + 16, self.y + 0.5)
elseif self.facing == 2 then -- down
make_laser(self.x - 1.5, self.y + 1, self.x + 0.5, self.y + 16)
elseif self.facing == 3 then -- left
make_laser(self.x - 16, self.y - 1.5, self.x - 2, self.y + 0.5)
else -- up
make_laser(self.x - 1.5, self.y - 16, self.x + 0.5, self.y - 2)
end
end
-- ensures player doesnt exceed max dx or dy in any direction
self.dx=mid(-self.max_dx, self.dx, self.max_dx)
self.dy=mid(-self.max_dy, self.dy, self.max_dy)
end,
draw=function(self,c)
if(self.laser_timer % 8 == 0 and self.laser_charging) then
add(particles, make_explosion(c.x, c.y, rnd(6), 7))
end
-- drawing self sprite
self.sp_frames+=1
if(self.sp_frames == 30) then
self.sp_frames = 0
end
self.sp = 19
-- facing up or down
if(abs(self.dx) < 0.1 and abs(self.dy) < 0.1) then
self.sp = 17
end
if(self.facing == 4) then
self.sp += 4
end
if (self.sp_frames >= 15) then
self.sp += 1
end
if self.invincible_frames > 0 and not self.shielded then
self.sp = 25
elseif self.invincible_frames > 0 and self.shielded then
print('<', self.x*8-8,self.y*8-2,7)
print('<', self.x*8-7,self.y*8-2,7)
print('>', self.x*8+4,self.y*8-2,7)
print('>', self.x*8+5,self.y*8-2,7)
end
-- facing left or right
self.sp_flip = self.facing == 3 or (self.dx < 0 and self.facing == 4)
spr(self.sp,(self.x*8)-4,(self.y*8)-4, 1, 1, self.sp_flip)
end,
update=function(self)
-- invincibility
if self.invincible_frames > 0 then
self.invincible_frames -= 1
end
if(self.invincible_frames == 0) then
self.shielded = false
end
if self.reload_frames > 0 then
self.reload_frames -= 1
end
if self.laser_timer > 0 then
self.laser_timer -= 1
end
if(self.health < 9 and self.regen_timer > 0) then
self.regen_timer -= 1
end
if(self.health < 9 and self.regen_timer == 0) then
self.health += 1
self.regen_timer = 450
end
-- wall collide
if not (solid_area(self.x+self.dx,self.y,self.w,self.h) or solid_area_player_only(self.x+self.dx,self.y,self.w,self.h)) then
self.x+=self.dx
else
self.dx*=-0.25
self.x+=self.dx
end
if not (solid_area(self.x,self.y+self.dy,self.w,self.h) or solid_area_player_only(self.x,self.y+self.dy,self.w,self.h)) then
self.y+=self.dy
else
self.dy*=-0.25
self.y+=self.dy
end
self.dx*=frict
self.dy*=frict
end,
lose_health=function(self)
self.health-=1
self.invincible_frames=30
end,
ui=function(self)
rectfill(self.x*8-64, self.y*8-51, self.x*8+66, self.y*8-62, 0)
print('< health:', self.x*8-58,self.y*8-59,7)
draw_health(self, -20, 1, -59, -55)
end_bracket = print('coins:'..self.coins,self.x*8+10,self.y*8-59,7)
print(' >', end_bracket,self.y*8-59,7)
end
}
return pl
end
function make_zombie(x, y)
add(zombies,{
id=z_id,
x=x,
y=y,
w=0.4,
h=0.4,
dx=0,
dy=0,
max_dx=0.12,
max_dy=0.12,
accel=0.075,
health=2,
hit=false,
sp=4,
sp_frames=0,
sp_flip=false,
pathToP={},
getPath=function(self)
self.pathToP = pathfind(self)
end,
control=function(self)
if #self.pathToP > 0 then
local nextTile = self.pathToP[#self.pathToP] -- Get the next tile in the path
if flr(self.x) < nextTile.x then
self.dx += self.accel
elseif flr(self.x) > nextTile.x then
self.dx -= self.accel
end
if flr(self.y) < nextTile.y then
self.dy += self.accel
elseif flr(self.y) > nextTile.y then
self.dy -= self.accel
end
-- ensures player doesnt exceed max dx or dy in any direction
self.dx=mid(-self.max_dx, self.dx, self.max_dx)
self.dy=mid(-self.max_dy, self.dy, self.max_dy)
-- Check if the zombie has reached the next tile
if flr(self.x) == nextTile.x and flr(self.y) == nextTile.y then
del(path) -- Remove the reached tile from the path
else
zombie_collide(self)
--map collide
if not solid_area(self.x+self.dx,self.y,self.w-0.3,self.h-0.3) then
self.x+=self.dx
end
if not solid_area(self.x,self.y+self.dy,self.w-0.3,self.h-0.3) then
self.y+=self.dy
end
end
end
end,
draw=function(self)
-- for t in all(self.pathToP) do
-- print("p", t.x*8, t.y*8, 7)
-- end
-- Drawing sprites
self.sp_frames+=1
if(self.sp_frames == 30) then
self.sp_frames = 0
self.hit = false
end
self.sp = 33
if (self.dy < 0) then
self.sp = 35
end
if(self.sp_frames >= 15) then
self.sp += 1
end
if self.hit then
self.sp = 37
end
-- Setting up facing
self.sp_flip = self.dx < 0
spr(self.sp,(self.x*8)-4,(self.y*8)-4, 1, 1, self.sp_flip)
-- Drawing health
draw_health(self, -2, 0, -6, -7)
end,
lose_health=function(self, pl, amt)
self.health-=amt
self.hit=true
make_particles(self.x, self.y, 8)
if self.health == 0 then
pl.coins+=200
del(zombies, self)
end
end
})
z_id+=1
end
function make_camera()
cam={
cx=0,
cy=0,
shake=2,
shakex=0,
shakey=0,
dirx=0,
diry=0,
update=function(self,x,y)
self.cx=x*8-62
self.cy=y*8-62
end,
draw=function(self)
if(shakestart) then
self.dirx = rnd()
self.diry = rnd()
self.shakex=6+rnd(9)
self.shakey=6+rnd(9)
if(self.dirx < 0.5) self.shakex *= -1
if(self.diry < 0.5) self.shakey *= -1
shakestart = false
end
self.shakex*=self.shake
self.shakey*=self.shake
camera(self.cx+self.shakex,self.cy+self.shakey)
self.shake = self.shake*0.80
if (self.shake<0.10) then
self.shake = 2
self.shakex = 0
self.shakey = 0
end
end
}
return cam
end
function make_cursor(p)
crs={x=0,
y=0,
px=0,
py=0,
boxed_wall=false,
boxed_barrier=false,
boxed_vending=false,
draw_cursor=function(self)
spr(49,self.px,self.py)
end,
update_cursor=function(self,p)
self.x=p.x
self.y=p.y
self.px=(p.x*8)
self.py=(p.y*8)
if p.facing == 1 then -- right
self.px+=4
self.py-=4
self.x+=1
elseif p.facing == 2 then -- down
self.px-=4
self.py+=5
self.y+=1
elseif p.facing == 3 then -- left
self.px-=13
self.py-=4
self.x-=1
elseif p.facing == 4 then-- up
self.px-=4
self.py-=12
self.y-=1
end
local spr_under = mget(self.x, self.y)
self.boxed_wall = spr_under == 7
self.boxed_barrier = spr_under == 8
self.boxed_vending = spr_under >= 50 and spr_under <= 54
end,
draw_box_wall=function(self, p)
if(self.boxed_wall) then
wall = in_set(walls, flr(self.x), flr(self.y))
rect(wall.x1 * 8, wall.y1 * 8, wall.x2 * 8 - 1, wall.y2 * 8 - 1, 7)
if(not coinmsg) then
set_msg('< build wall? 🅾️ >', -32)
end
end
end,
draw_box_vending=function(self, p)
if(self.boxed_vending) then
vend = in_set(vending, flr(self.x), flr(self.y))
rect(vend.x1 * 8, vend.y1 * 8, vend.x2 * 8 - 1, vend.y2 * 8 - 1, 7)
if(not coinmsg) then
set_msg('< '..vend.msg..' 🅾️ cost:'..vend.cost..' >', vend.text_offset)
end
end
end,
draw_box_barrier=function(self,p)
if(self.boxed_barrier) then
bar = in_set(barriers, flr(self.x), flr(self.y))
rect(bar.x1 * 8, bar.y1 * 8, bar.x2 * 8, bar.y2 * 8,7)
if(not coinmsg) then
set_msg('< break barrier? 🅾️ cost:'..cost..' >', -58)
end
end
end
}
return crs
end
function draw_health(e, x1, width, y1, y2)
incrementor=x1
iterator=0
while (iterator < e.health) do
rectfill((e.x*8)+incrementor,(e.y*8)+y1,(e.x*8)+incrementor+width,(e.y*8)+y2,8)
iterator+=1
incrementor+=2+width
end
end
function draw_ui_prompt(str, x, y)
rectfill(p.x*8-64, p.y*8+55, p.x*8+66, p.y*8+66, 0)
print(str, x, y, 7)
end
function set_msg(t, disx)
text_frames = 50
msg.text = t
msg.dx = disx
end
function make_particles(mainx, mainy, colour)
local numparticles = flr(rnd(6)) + 1
for i=0, numparticles do
local dx = -0.4 + rnd(0.8)
add(particles, make_particle(mainx, mainy, dx, -rnd(1)+0.1,colour))
end
end
function make_particle(mainx, mainy, ddx, ddy, col)
local particle = {x = mainx,
y = mainy,
inity = mainy,
dx = ddx,
dy = ddy,
colour = col,
accely = 0.1,
draw=function(self)
circfill(self.x*8, self.y*8, 1, self.colour)
end,
update=function(self)
self.dy += self.accely
self.x += self.dx
self.y += self.dy
if(self.y*8 >= self.inity*8 + 8) then
del(particles, self)
end
end
}
return particle
end
function make_explosions(mainx, mainy, colour)
local numparticles = flr(rnd(6)) + 1
for i=0, numparticles do
add(particles, make_explosion(mainx + (-0.75 + rnd(1.5)), mainy + (-0.75 + rnd(1.5)), rnd(15), colour))
add(particles, make_smoke(mainx + (-0.75 + rnd(1.5)), mainy + (-0.75 + rnd(1.5)), rnd(11)))
end
end
function make_explosion(mainx, mainy, r, col)
ex_particle = {x = mainx,
y = mainy,
colour = col,
rad = r,
radx = 0.5,
draw=function(self)
circfill(self.x*8, self.y*8, self.rad, self.colour)
end,
update=function(self)
if(self.rad > 0) then
self.rad -= self.radx
else
del(particles, self)
end
end
}
return ex_particle
end
function make_smoke(mainx, mainy, r)
smoke = {x = mainx,
y = mainy,
dx = 0.25,
dy = 0.25,
rad = r,
radx = 0.5,
draw=function(self)
circfill(self.x*8, self.y*8, self.rad, 7)
end,
update=function(self)
self.x += self.dx
self.y -= self.dy
if(self.rad > 0) then
self.rad -= self.radx
else
del(particles, self)
end
end
}
return smoke
end
function make_projectile(p, pdx, pdy)
add(proj,{
sp=49,
x=p.x,
y=p.y,
w=0.25,
h=0.25,
dx=pdx,
dy=pdy,
offset=rnd(0.30)-0.15,
draw=function(self)
spr(self.sp,(self.x*8)-4,(self.y*8)-4)
end,
update=function(self)
-- wall colission, destroy self
if not solid_area(self.x+self.dx,self.y,self.w,self.h) then
self.x+=self.dx
self.y+=self.offset
else
del(proj, self)
end
if not solid_area(self.x,self.y+self.dy,self.w,self.h) then
self.y+=self.dy
self.x+=self.offset
else
del(proj, self)
end
end}
)
end
function make_shotgun_proj(p, mainx, mainy, offsetx, offsety)
add(particles, make_smoke(p.x + mainx, p.y + mainy, 3 + rnd(6)))
add(particles, make_smoke(p.x + mainx + offsetx, p.y + mainy + offsety, 3 + rnd(6)))
make_projectile(p, mainx, mainy)
make_projectile(p, mainx+offsetx, mainy+offsety)
make_projectile(p, mainx-offsetx, mainy-offsety)
p.reload_frames = 20
end
function make_bomb(p, pdx, pdy)
add(bombs, {sp=64,
x=p.x,
y=p.y,
w=0.25,
h=0.25,
dx=pdx,
dy=pdy,
timer = 20,
draw=function(self)
rect(self.x*8 - 16, self.y*8 - 16, self.x*8 + 16, self.y*8 + 16, 7)
spr(self.sp,(self.x*8)-4,(self.y*8)-4)
end,
update=function(self, pl)
if not solid_area(self.x+self.dx,self.y,self.w,self.h) then
self.x+=self.dx
else
self.dx*=-0.5
self.x+=self.dx
end
if not solid_area(self.x,self.y+self.dy,self.w,self.h) then
self.y+=self.dy
else
self.dy*=-0.5
self.y+=self.dy
end
self.dx *= (frict-0.3)
self.dy *= (frict-0.3)
self.timer -= 1
if(self.timer == 0) then
make_explosions(self.x, self.y, 9)
make_explosions(self.x, self.y, 1)
del(bombs, self)
for zombie in all(zombies) do
if(self.x - 2 <= zombie.x and zombie.x <= self.x + 2) and
(self.y - 2 <= zombie.y and zombie.y <= self.y + 2) then
zombie:lose_health(pl, 2)
shakestart=true
end
end
end
end
})
p.reload_frames = 30
end
function make_laser(x1, y1, x2, y2)
add(lasers, {x1 = x1,
y1 = y1,
x2 = x2,
y2 = y2,
timer = 30,
draw=function(self)
rectfill(self.x1 * 8, self.y1 * 8, self.x2 * 8 + 8, self.y2 * 8 + 8, 7)
end,
update=function(self, pl)
self.timer -= 1
for zombie in all(zombies) do
fzx = flr(zombie.x)
fzy = flr(zombie.y)
if(self.x1 - 0.5 <= fzx and fzx <= self.x2 + 0.5) and
(self.y1 - 0.5 <= fzy and fzy <= self.y2 + 0.5) then
zombie:lose_health(pl, 2)
shakestart=true
end
end
if(self.timer == 0) then
laser_close(self.x1, self.x2, self.y1, self.y2)
del(lasers, self)
end
end
})
end
function laser_close(x1, x2, y1, y2)
for j=y1, y2 do
for i=x1, x2 do
add(particles, make_smoke(i, j, rnd(12)))
end
end
end
function make(spr)
arr={}
for j=0, map_height do
for i=0, map_width do
if(spr == 6 and mget(j,i) == 6) then
add(arr, get_spawner(j,i))
elseif(spr == 7 and mget(j,i) == 7) then
add(arr, get_wall(j,i))
elseif(spr == 8 and mget(j,i) == 8 and in_set(arr,j,i) == nil) then
add(arr, get_barrier(j,i))
end
end
end
return arr
end
function get_spawner(j, i)
spawner={x=j,
y=i,
timer= 90 + flr(rnd(200)),
spawn_zombie=function(self)
if(self.timer > 0) then
self.timer -= 1
elseif(self.timer == 0 and m[self.y][self.x] > 0) then
self.timer = 90 + flr(rnd(200))