-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshell_tactic.p8
1760 lines (1616 loc) · 68 KB
/
shell_tactic.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 18
__lua__
-- TODO move all this into a global
s_turret=5
m_turret=7
h_turret=9
winner = 0
mapWon = false
interactCooldown = 10
nextInteract = 0
canInteract = true
state = 0 -- 0 menu, 1 game, 2 help, 3 color selector, 4 map select, 5 campaing
select = 0 -- 0 game, 1 help
clr_select = 0 -- 0 none, 1 plr 1, 2 plr
clr_selector = 0
colors = {1,2,3,4,6,8,9,10,11,12,13,14,15}
clr_player = 0 -- ply 1 select, plr 2 select
level_selector = 0
drop_rnd = 100
next_drop = 0
drop_in = 0
enemySpawnPoints = {}
playerSpawnPoints = {}
playerCount = 1 -- todo 2,3,4
campaingLevel = 1
enemiesSpawned = 0
spawnIndex = 1
nextSpawn = 0
enemiesKilled = 0
player1 = {
id = 0,
x = 5,
y = 1,
sp = 0,
-- 0 frame 1, 1 frame 2
sp_def = 1,
speed = 0.1,
direction = 2,
-- 0 up, 1 left, 2 down, 3 right
turret = s_turret,
turret_color = 14,
life = 1,
bullets = 7,
shield = 0,
wpcd = 0,
tpe = "player",
active = true
}
player2 = {
id = 1,
x = 5,
y = 14,
sp = 0,
-- 0 frame 1, 1 frame 2
sp_def = 1,
speed = 0.1,
direction = 0,
-- 0 up, 1 left, 2 down, 3 right
turret = s_turret,
turret_color = 12,
life = 1,
bullets = 4,
shield = 1,
wpcd = 0,
tpe = "player",
active = true
}
players={}
add(players,player1)
add(players,player2)
crect = {
x1 = 0,
x2 = 0,
y1 = 0,
y2 = 0
}
entities={}
particles={}
upgrades={}
bullets={}
foliageCollection={}
add(entities,player1)
add(entities,player2)
-- TODO maybe do this in an iteration
wallIDList = {64,65,67,68,69}
waterIDList = {80,81,82,96,97,98,112,113,114}
playerSpawnIndicatorList = {48,49,50,51}
-- campaing map strings
campainMapCollection = {
"64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,52,0,0,0,67,23,39,39,55,67,0,0,0,0,64,64,0,65,65,0,0,23,39,39,55,0,0,67,0,48,64,64,0,65,0,66,66,23,39,39,55,65,0,67,0,50,64,64,0,0,0,67,66,23,39,39,55,65,0,66,66,0,64,64,52,0,0,67,66,23,39,39,55,65,0,65,65,65,64,64,0,0,0,67,66,23,39,39,55,65,0,66,66,0,64,64,0,65,0,66,66,23,39,39,55,65,0,67,0,49,64,64,0,65,65,0,0,23,39,39,55,0,0,67,0,51,64,64,52,0,0,0,67,23,39,39,55,67,0,0,0,0,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"
}
campaignMapSpawnNumbers = {10}
campaignMapSpawnCooldown = {3}
function parse_map(_mapString)
local mapString = _mapString
local actualMap = {}
while #mapString > 0 do
local firstToken=sub(mapString,1,1)
local cut = 2
if (firstToken!=",") then
local workString = sub(mapString,2)
local secondToken = sub(workString,1,1)
if (secondToken!=",") then
local workString = sub(mapString,3)
local thirdToken = sub(workString,1,1)
if (thirdToken!=",") then
local actualToken = firstToken..secondToken..thirdToken
add(actualMap,actualToken)
cut = 4
else
local actualToken = firstToken..secondToken
add(actualMap,actualToken)
cut = 3
end
else
add(actualMap,firstToken)
cut = 2
end
end
mapString=sub(mapString,cut)
end
return actualMap
end
function load_campaing_map(_index)
local mapString = parse_map(campainMapCollection[_index])
x = 0
y = 0
for id in all(mapString) do
id = tonum(id)
for wallID in all(wallIDList) do
if id == wallID then
mset(y,x,id)
end
end
for waterID in all(waterIDList) do
if id == waterID then
mset(y,x,id)
end
end
-- if id = 66 create foliage
if id == 66 then
add_foliage(y,x,66)
end
-- load enemy spawn point
if id == 52 then
local point = {
xPos = y,
yPos = x
}
add(enemySpawnPoints,point)
end
-- load player spawn point
for spawnPointID in all(playerSpawnIndicatorList) do
if id == spawnPointID then
local point = {
xPos = y,
yPos = x
}
add(playerSpawnPoints,point)
end
end
x += 1
if (x > 15) then
x = 0
y +=1
end
end
spawn_players(playerCount)
end
function unload_map()
-- reset map
for x=0,15 do
for y=0,15 do
mset(x,y,0)
end
end
-- reset player spawn points
playerSpawnPoints = {}
-- reset enemy spawn points
enemySpawnPoints = {}
-- unload all the stuff
entities={}
particles={}
upgrades={}
bullets={}
foliageCollection={}
end
function _init()
code()
for player in all(players) do
player.life = 3
player.bullets = 8
player.shield = 0
player.turret = s_turret
end
winner = 0
end
function spawn_players(count)
local spawnedPlayers = 0
player1.x = playerSpawnPoints[1].xPos
player1.y = playerSpawnPoints[1].yPos
add(entities,player1)
end
function reset_option()
clr_player = 0
level_selector = 0
clr_select = 0 -- 0 none, 1 plr 1, 2 plr
clr_selector = 0
end
function code()
local mapstring = ""
for x=0,15 do
for y=0,15 do
mapstring = mapstring..mget(x,y)..","
end
end
--add(mapstring,12)
--printh(tostr(mapstring))
--printh(mapstring)
end
function collide_map(object,width,heigth,direction,flag)
local x = object.x*8
local y = object.y*8
local w = width
local h = heigth
local x1 = 0
local x2 = 0
local y1 = 0
local y2 = 0
if direction==0 then --left
x1=x-1 y1=y
x2=x-1 y2=y+h-1
elseif direction==1 then --rigth
x1=x+w y1=y
x2=x+w y2=y+h-1
elseif direction==2 then --up
x1=x y1=y-1
x2=x+w-1 y2=y-1
elseif direction==3 then --down
x1=x y1=y+h
x2=x+w-2 y2=y+h
end
crect.x1 = x1
crect.x2 = x2
crect.y1 = y1
crect.y2 = y2
x1/=8
x2/=8
y1/=8
y2/=8
if fget(mget(x1,y1), flag)
or fget(mget(x1,y2), flag)
or fget(mget(x2,y1), flag)
or fget(mget(x2,y2), flag) then
return true
else
return false
end
end
function destroy_bricks(object,width,heigth,direction,flag)
local x = object.x*8
local y = object.y*8
local w = width
local h = heigth
local x1 = 0
local x2 = 0
local y1 = 0
local y2 = 0
if direction==0 then --left
x1=x-1 y1=y
x2=x-1 y2=y+h-1
elseif direction==1 then --rigth
x1=x+w y1=y
x2=x+w y2=y+h-1
elseif direction==2 then --up
x1=x y1=y-1
x2=x+w-1 y2=y-1
elseif direction==3 then --down
x1=x y1=y+h
x2=x+w-2 y2=y+h
end
crect.x1 = x1
crect.x2 = x2
crect.y1 = y1
crect.y2 = y2
x1/=8
x2/=8
y1/=8
y2/=8
local whiteBrick_0 = 67
local whiteBrick_1 = 68
local whiteBrick_2 = 69
if fget(mget(x1,y1), flag) then
if flag == 1 then
mset(x1,y1,0)
for i=0,10,1 do
add_part(x1*8,y1*8,20,{4,2,5},0)
end
elseif flag == 2 then
if mget(x1,y1) == whiteBrick_0 then
mset(x1,y1,whiteBrick_1)
for i=0,10,1 do
add_part(x1*8,y1*8,5,{7,6,5},0)
end
elseif mget(x1,y1) == whiteBrick_1 then
mset(x1,y1,whiteBrick_2)
for i=0,10,1 do
add_part(x1*8,y1*8,10,{7,6,5},0)
end
elseif mget(x1,y1) == whiteBrick_2 then
mset(x1,y1,0)
for i=0,10,1 do
add_part(x1*8,y1*8,20,{7,6,5},0)
end
end
end
return true
elseif fget(mget(x1,y2), flag) then
if flag == 1 then
mset(x1,y2,0)
for i=0,10,1 do
add_part(x1*8,y2*8,20,{4,2,5},0)
end
elseif flag == 2 then
if mget(x1,y2) == whiteBrick_0 then
mset(x1,y2,whiteBrick_1)
for i=0,10,1 do
add_part(x1*8,y2*8,5,{7,6,5},0)
end
elseif mget(x1,y2) == whiteBrick_1 then
mset(x1,y2,whiteBrick_2)
for i=0,10,1 do
add_part(x1*8,y2*8,10,{7,6,5},0)
end
elseif mget(x1,y2) == whiteBrick_2 then
mset(x1,y2,0)
for i=0,10,1 do
add_part(x1*8,y2*8,20,{7,6,5},0)
end
end
end
return true
elseif fget(mget(x2,y1), flag) then
if flag == 1 then
mset(x2,y1,0)
for i=0,10,1 do
add_part(x2*8,y1*8,20,{4,2,5},0)
end
elseif flag == 2 then
if mget(x2,y1) == whiteBrick_0 then
mset(x2,y1,whiteBrick_1)
for i=0,10,1 do
add_part(x2*8,y1*8,5,{7,6,5},0)
end
elseif mget(x2,y1) == whiteBrick_1 then
mset(x2,y1,whiteBrick_2)
for i=0,10,1 do
add_part(x2*8,y1*8,10,{7,6,5},0)
end
elseif mget(x2,y1) == whiteBrick_2 then
mset(x2,y1,0)
for i=0,10,1 do
add_part(x2*8,y1*8,20,{7,6,5},0)
end
end
end
return true
elseif fget(mget(x2,y2), flag) then
if flag == 1 then
mset(x2,y2,0)
for i=0,10,1 do
add_part(x2*8,y2*8,20,{4,2,5},0)
end
elseif flag == 2 then
if mget(x2,y2) == whiteBrick_0 then
mset(x2,y2,whiteBrick_1)
for i=0,10,1 do
add_part(x2*8,y2*8,5,{7,6,5},0)
end
elseif mget(x2,y2) == whiteBrick_1 then
mset(x2,y2,whiteBrick_2)
for i=0,10,1 do
add_part(x2*8,y2*8,10,{7,6,5},0)
end
elseif mget(x2,y2) == whiteBrick_2 then
mset(x2,y2,0)
for i=0,10,1 do
add_part(x2*8,y2*8,20,{7,6,5},0)
end
end
end
return true
else
return false
end
end
function add_enemy(_x,_y,_s,_t,_c,_cd)
local enemy = {
x = _x,
y = _y,
sp = 0,
sp_def = 1,
speed = _s,
direction = 0,
turret = _t,
turret_color = _c,
tpe = "enemy",
direction = 2,
life = 1,
wpcd = _cd,
ccd = 0,
active = true
}
add(entities,enemy)
end
function add_part(_x,_y,_maxage,_color,_type)
local particle = {
x = _x,
y = _y,
lifetime = 0,
maxage = _maxage,
color_range = _color,
clr = _color[1],
tpe = _type
}
add(particles,particle)
end
function add_upgrade(_x,_y,_maxage,_type)
local upgrade = {
x = _x,
y = _y,
lifetime = 0,
maxage = _maxage,
tpe = _type
}
--printh("Upgrade placed: ".._x.." ".._y.." type ".._type)
add(upgrades,upgrade)
end
function add_bullet(_x,_y,_dir,_player_id,_dmg)
local bullet = {
x = _x,
y = _y,
direction = _dir,
id = _player_id,
dmg = _dmg
}
add(bullets,bullet)
end
function add_foliage(_x,_y,_spr)
local foliage = {
x = _x*8,
y = _y*8,
spr = _spr
}
add(foliageCollection,foliage)
end
function line_of_sight(x0,y0,x1,y1)
local walls = {49,50,51,52,53}
local sx,sy,dx,dy
if x0 < x1 then
sx = 1
dx = x1 - x0
else
sx = -1
dx = x0 - x1
end
if y0 < y1 then
sy = 1
dy = y1 - y0
else
sy = -1
dy = y0 - y1
end
local err, e2 = dx-dy, nil
for id in all(walls) do
if (mget(x0, y0) == walls) then return false end
end
while not(x0 == x1 and y0 == y1) do
e2 = err + err
if e2 > -dy then
err = err - dy
x0 = x0 + sx
end
if e2 < dx then
err = err + dx
y0 = y0 + sy
end
for id in all(walls) do
if (mget(x0, y0) == walls) then return false end
end
end
return true
end
function place_upgrade()
local placed = 0
occupied = false
while placed == 0 do
repeat
occupied = false
x = flr( 1+(level_selector*16) + (rnd(9)))
y = flr(rnd(14)+1)
if (mget(x,y) == 0) then -- can be placed, this is floor tile
-- check for other bullets
for up in all(upgrades) do
if ((up.x == x) and (up.y == y)) occupied = true -- there is one already
end
else -- not floor tile
occupied = true
end
until not occupied
-- if not occupied, place it
add_upgrade(x,y,300,flr(rnd(4)))
placed = 1
end
end
function move(entity)
entity.sp += 1
if entity.sp > 1 then
entity.sp = 0
end
end
function pickup_upgrade(_player,_upgrade)
if _upgrade.tpe == 0 then
if _player.bullets < 8 then
_player.bullets = 8
end
elseif _upgrade.tpe == 1 then
if _player.shield < 4 then
_player.shield += 1
end
elseif _upgrade.tpe == 2 then
if _player.life < 4 then
_player.life += 1
end
elseif _upgrade.tpe == 3 then
if _player.turret == s_turret then
_player.turret = m_turret
elseif _player.turret == m_turret then
_player.turret = h_turret
end
end
end
function to_rect(sp,w,h)
local r = {}
r.x1 = sp.x * 8
r.y1 = sp.y * 8
r.x2 = sp.x * 8 + w - 1
r.y2 = sp.y * 8 + h - 1
return r
end
function collide_rect(r1,r2)
if((r1.x1 > r2.x2) or
(r2.x1 > r1.x2) or
(r1.y1 > r2.y2) or
(r2.y1 > r1.y2)) then
return false
end
return true
end
-- ========
-- update
-- ========
function move_player(idx)
local id = idx
idx += 1
if players[idx].active == true then
if btn(0,id) then
add_part(players[idx].x*8+8,players[idx].y*8+4,20,{13,5},0)
if (not collide_map(players[idx],8,8,0,0)) players[idx].x -= players[idx].speed
move(players[idx])
players[idx].direction = 1
sfx(0)
elseif btn(1,id) then
add_part(players[idx].x*8,players[idx].y*8+4,20,{13,5},0)
if (not collide_map(players[idx],8,8,1,0)) players[idx].x += players[idx].speed
move(players[idx])
players[idx].direction = 3
sfx(0)
elseif btn(2,id) then
add_part(players[idx].x*8+4,players[idx].y*8+8,20,{13,5},0)
if (not collide_map(players[idx],8,8,2,0)) players[idx].y -= players[idx].speed
move(players[idx])
players[idx].direction = 0
sfx(0)
elseif btn(3,id) then
add_part(players[idx].x*8+4,players[idx].y*8,20,{13,5},0)
if (not collide_map(players[idx],8,8,3,0)) players[idx].y += players[idx].speed
move(players[idx])
players[idx].direction = 2
sfx(0)
end
if btnp(5,id) then
if winner > 0 then
reload(0x2000, 0x2000, 0x1000)
state = 4
winner = 0
camera(0,0)
elseif players[idx].wpcd <= 0 then
if players[idx].turret == m_turret then
dmg = 2
elseif players[idx].turret == h_turret then
dmg = 3
end
if state == 5 then
add_bullet(players[idx].x,players[idx].y,players[idx].direction,id,dmg)
players[idx].wpcd = 20
else
if players[idx].bullets > 0 then
local dmg = 1
add_bullet(players[idx].x,players[idx].y,players[idx].direction,id,dmg)
players[idx].bullets -= 1
players[idx].wpcd = 20
end
end
end
end
if btnp(4,id) then
if winner > 0 then
reload(0x2000, 0x2000, 0x1000)
state = 0
camera(0,0)
end
end
if players[idx].wpcd > 0 then
players[idx].wpcd -= 1
end
if not mapWon then
if players[idx].life <= 0 then
if players[idx].id == 0 then
mapWon = true
nextInteract = time() + interactCooldown
winner = 2
else
mapWon = true
nextInteract = time() + interactCooldown
winner = 1
end
end
end
for up in all(upgrades) do
if (collide_rect(to_rect(players[idx],7,7),to_rect(up,7,7))) then
pickup_upgrade(players[idx],up)
del(upgrades,up)
end
end
end
end
function _update()
if state == 0 then
update_menu()
elseif state == 1 then
if not mapWon then
update_game()
end
if nextInteract < time() then
canInteract = true
end
elseif state == 2 then
update_help()
elseif state == 3 then
update_clr_select()
elseif state == 4 then
update_map_select()
elseif state == 5 then
if not mapWon then
update_campaing()
end
if nextInteract < time() then
canInteract = true
end
end
end
function update_map_select()
if btnp(4) then
state = 1
for player in all(players) do
player.x = 5 + (level_selector*16)
end
players[1].y = 1
players[1].direction = 2
players[2].y = 14
players[2].direction = 0
_init()
end
if btnp(2) then
level_selector -= 1
if level_selector < 0 then
level_selector = 7
end
elseif btnp(3) then
level_selector += 1
if level_selector > 7 then
level_selector = 0
end
end
end
function update_clr_select()
if btnp(1) then
clr_selector += 1
if clr_selector > 13 then
clr_selector = 0
end
elseif btnp(0) then
clr_selector -= 1
if clr_selector < 0 then
clr_selector = 13
end
end
if btnp(5) then
if clr_select == 0 then
clr_select = 1
clr_player = 1
players[1].turret_color = colors[clr_selector+1]
elseif clr_select == 1 then
clr_select = 2
players[2].turret_color = colors[clr_selector+1]
elseif clr_select == 2 then
clr_select = 0
clr_player = 0
clr_selector = 0
end
end
if btnp(4) then
state = 4
end
end
function update_help()
cls()
if btnp(4) then
state = 0
end
end
function update_menu()
if btnp(4) then
if select == 1 then -- game select
state = 3 -- color selector
reset_option()
elseif select == 0 then -- campaing
state = 5
unload_map()
load_campaing_map(campaingLevel)
else
state = 2
end
end
if btnp(2) then
select -= 1
if select < 0 then
select = 2
end
elseif btnp(3) then
select += 1
if select > 2 then
select = 0
end
end
end
function update_game()
for idx=0,1,1 do
move_player(idx)
end
--update_enemy()
update_particle()
update_upgrade()
update_bullet()
if time() > next_drop then
place_upgrade()
next_drop = time()+rnd(drop_rnd)
end
if time() < next_drop then
drop_in = (next_drop - time())/30
next_drop -= 1
end
end
function update_campaing()
for idx=0,1,1 do
move_player(idx)
end
update_enemy()
update_particle()
update_bullet()
for player in all(players) do
if player.life <= 0 then
player.active = false
end
end
end
function update_particle()
for particle in all(particles) do
if particle.tpe == 0 then
particle.x = particle.x + sin(rnd())
particle.y = particle.y + sin(rnd())
particle.lifetime += 1
if particle.lifetime > particle.maxage then
del(particles,particle)
else
if #particle.color_range == 1 then
particle.clr = particle.color_range[1]
else
local idx = particle.lifetime / particle.maxage
idx = 1 + flr(idx*#particle.color_range)
particle.clr = particle.color_range[idx]
end
end
elseif particle.tpe == 1 then
particle.lifetime += 1
if particle.lifetime > particle.maxage then
del(particles,particle)
else
if #particle.color_range == 1 then
particle.clr = particle.color_range[1]
else
local idx = particle.lifetime / particle.maxage
idx = 1 + flr(idx*#particle.color_range)
particle.clr = particle.color_range[idx]
end
end
elseif particle.tpe == 2 then
particle.lifetime += 1
if particle.lifetime > particle.maxage then
del(particles,particle)
else
if #particle.color_range == 1 then
particle.clr = particle.color_range[1]
else
local idx = particle.lifetime / particle.maxage
idx = 1 + flr(idx*#particle.color_range)
particle.clr = particle.color_range[idx]
end
end
end
end
end
function update_upgrade()
for upgrade in all(upgrades) do
upgrade.lifetime+=1
if upgrade.lifetime > upgrade.maxage then
del(upgrades,upgrade)
end
end
end
function update_bullet()
local spd = 0.3
for bullet in all(bullets) do
if (bullet.direction == 0) then
bullet.y -= spd
if (rnd() > 0.2) add_part(bullet.x*8+3,bullet.y*8+5,10,{10,9,8},1)
if collide_map(bullet,8,6,2,0) then
destroy_bricks(bullet,8,8,2,1)
destroy_bricks(bullet,8,8,2,2)
for i=0,10,1 do
add_part(bullet.x*8+4,bullet.y*8+4,8,{7,9,10},0)
end
del(bullets,bullet)
sfx(1)
end
elseif bullet.direction == 1 then
bullet.x -= spd
if (rnd() > 0.2) add_part(bullet.x*8+5,bullet.y*8+3,10,{10,9,8},1)
if collide_map(bullet,8,8,0,0) then
destroy_bricks(bullet,8,8,0,1)
destroy_bricks(bullet,8,8,0,2)
for i=0,10,1 do
add_part(bullet.x*8+4,bullet.y*8+4,8,{7,9,10},0)
end
del(bullets,bullet)
sfx(1)
end
elseif bullet.direction == 2 then
bullet.y += spd
if (rnd() > 0.2) add_part(bullet.x*8+3,bullet.y*8+2,10,{10,9,8},1)
if collide_map(bullet,8,8,3,0) then
destroy_bricks(bullet,8,8,3,1)
destroy_bricks(bullet,8,8,3,2)
for i=0,10,1 do
add_part(bullet.x*8+4,bullet.y*8+4,8,{7,9,10},0)
end
del(bullets,bullet)
sfx(1)
end
elseif bullet.direction == 3 then
bullet.x += spd
if (rnd() > 0.2) add_part( bullet.x*8+2 , bullet.y*8+3,10,{10,9,8},1)
if collide_map(bullet,8,8,1,0) then
destroy_bricks(bullet,8,8,1,1)
destroy_bricks(bullet,8,8,1,2)
for i=0,10,1 do
add_part(bullet.x*8+4,bullet.y*8+4,8,{7,9,10},0)
end
del(bullets,bullet)
sfx(1)
end
end
for player in all(players) do
if (collide_rect(to_rect(bullet,7,7),to_rect(player,7,7))) and ((not (player.id == bullet.id)) or bullet.id == "e") then
if player.shield > 0 then
player.shield -= bullet.dmg
else
player.life -= bullet.dmg
end
for i=0,10,1 do
add_part(bullet.x*8+4,bullet.y*8+4,20,{10,9,8,2,5},0)
end
sfx(1)
del(bullets,bullet)
end
end
for enemy in all(entities) do
if enemy.tpe == "enemy" then
if (collide_rect(to_rect(bullet,7,7),to_rect(enemy,7,7)) and (bullet.id == 0 or bullet.id == 1)) then
enemy.life -= 1
for i=0,10,1 do
add_part(bullet.x*8+4,bullet.y*8+4,20,{10,9,8,2,5},0)
end
sfx(1)
del(bullets,bullet)
end
end