-
Notifications
You must be signed in to change notification settings - Fork 0
/
space-shooter.p8
452 lines (425 loc) · 22.4 KB
/
space-shooter.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
pico-8 cartridge // http://www.pico-8.com
version 29
__lua__
--space shooter
--fairedesjeux.fr
--reutilisez librement ce code!
function _init()
p={
x=60,y=80,
w=8,h=7,
speed=1.5,
life=3,
invicible=false,
inv_timer=0
}
bullets={}
enemy_bullets={}
enemies={}
explosions={}
create_stars()
score=0
state=0
text_timer=0 --pour onglet 6
end
function _update60()
if (state==0) update_game()
if (state==1) update_gameover()
end
function _draw()
if (state==0) draw_game()
if (state==1) draw_gameover()
end
function update_game()
update_player() --onglet 7
update_bullets() --onglet 1
update_stars() --onglet 2
update_enemies() --onglet 3
update_explosions()--onglet 5
if #enemies==0 then
spawn_enemies(ceil(rnd(7)))
end
end
function draw_game()
cls()
--etoiles
for s in all(stars) do
pset(s.x,s.y,s.col)
end
--ennemis
for e in all(enemies) do
spr(3,e.x,e.y)
end
--vaisseau
draw_player() --onglet 7
--balles
for b in all(bullets) do
spr(2,b.x,b.y)
end
for b in all(enemy_bullets) do
spr(5,b.x,b.y)
end
--explosions
draw_explosions()
--score
print(score,2,2,10)
--life
for i=1,p.life do
spr(4, (i-1)*8, 8)
end
end
-->8
--player & enemy bullets
function shoot()
local new_bullet={
x=p.x+2, y=p.y,
w=4, h=5,
speed=4
}
add(bullets, new_bullet)
sfx(0)
end
function enemy_shoot(enemy)
local angle=angle_to(enemy.x,enemy.y,p.x,p.y)
--angle_to dans onglet 4
local new_bullet={
x=enemy.x+2, y=enemy.y+5,
w=4, h=5,
speed=1,
dx=cos(angle),
dy=-sin(angle)
}
add(enemy_bullets, new_bullet)
end
function update_bullets()
for b in all(bullets) do
b.y-=b.speed
if (b.y<-8) del(bullets,b)
end
for b in all(enemy_bullets) do
b.x+=b.dx*b.speed
b.y+=b.dy*b.speed
if (b.y>128) del(enemy_bullets,b)
end
end
-->8
--stars
function create_stars()
stars={}
for i=1,20 do
local new_star={
x=rnd(128),
y=rnd(128),
col=1,
speed=1+rnd(0.5)
}
add(stars, new_star)
end
for i=1,8 do
local new_star={
x=rnd(128),
y=rnd(128),
col=6,
speed=3+rnd(1)
}
add(stars, new_star)
end
end
function update_stars()
for s in all(stars) do
s.y+=s.speed
if s.y>128 then
s.y=0
s.x=rnd(128)
end
end
end
-->8
--enemies
function spawn_enemies(amount)
gap=(128-8*amount)/(amount+1)
for i=1,amount do
add(enemies,{
x=gap*i + 8*(i-1),
y=-24,
w=8,
h=8,
life=4,
shoot_timer=0
})
end
end
function update_enemies()
for enemy in all(enemies) do
enemy.y += 0.5
if enemy.y > 130 then
del(enemies,enemy)
end
--collision
for b in all(bullets) do
if collision(enemy,b) then
create_explosion(b.x+1.5,b.y+3)
del(bullets,b)
enemy.life-=1
if enemy.life==0 then
del(enemies,enemy)
score+=100
end
end
end
--shoot toutes les 2 secondes
--si l'ennemi n'est pas trop
--en bas de l'ecran
enemy.shoot_timer+=1
if enemy.shoot_timer==120
and enemy.y < 100 then
enemy_shoot(enemy)
enemy.shoot_timer=0
end
end
end
-->8
--tools
function collision(a,b)
--w:width (largeur)
--h:height (hauteur)
return not (a.x > b.x+b.w-1
or a.y > b.y+b.h-1
or a.x+a.w-1 < b.x
or a.y+a.h-1 < b.y)
end
function angle_to(x1,y1,x2,y2)
--angle pour aller du point 1
--au point 2
return atan2(y2-y1,x2-x1)+0.25
--voir atan2 dans le manuel
end
-->8
--explosions
function create_explosion(x,y)
add(explosions,{
x = x,
y = y,
timer = 0
})
sfx(1)
end
function update_explosions()
for boom in all(explosions) do
boom.timer += 1
if boom.timer == 13 then
del(explosions, boom)
end
end
end
function draw_explosions()
for boom in all(explosions) do
circ(boom.x, boom.y,
boom.timer/3, 8+boom.timer%3)
end
end
-->8
--game over
function update_gameover()
text_timer+=1
if (btn(🅾️)) _init()
end
function draw_gameover()
cls(2)
rectfill(31,53,105,79,0)
rectfill(28,50,102,76,1)
local col=9
if text_timer%8>4 then
col=10
end
print("score:"..score,38,56,col)
print("🅾️/c:reessayer",38,66,10)
end
-->8
--player
function update_player()
if (btn(➡️)) p.x+=p.speed
if (btn(⬅️)) p.x-=p.speed
if (btn(⬇️)) p.y+=p.speed
if (btn(⬆️)) p.y-=p.speed
if (btnp(❎)) shoot()
--collision joueur-ennemis
for e in all(enemies) do
if collision(e,p) then
if not p.invincible then
p.life-=1
p.invincible=true
end
end
end
--collision joueur-balles
for b in all(enemy_bullets) do
if collision(b,p) then
if not p.invincible then
p.life-=1
p.invincible=true
create_explosion(b.x+1.5,b.y+4)
del(enemy_bullets,b)
end
end
end
if p.invincible then
p.inv_timer+=1
--on desactive apres 90 frames
if p.inv_timer>90 then
p.inv_timer=0
p.invincible=false
end
end
--game over
if (p.life<=0) state=1
end
function draw_player()
--permet de faire clignoter
--le vaisseau si le timer
--d'invincibilite est en cours
if p.inv_timer%4<2 then
spr(1,p.x,p.y)
end
end
__gfx__
0000000000600600a00a000000000000000000000ee0000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000600600a00a00000bb00bb006666660e22e000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0070070006dc7d609009000000b33b0006555560e22e000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0007700006dccd600000000003bbbb30065555600ee0000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00077000d66dd66d90090000038bb830065555600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00700700d666666d00000000003bb300006556000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000050dd0500000000002033020000660000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000e00e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
__label__
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000010000000000000000000000000000000000000000000000000000000000000000000000000000000090090000000000000000000000000000000000
00aaa0aaa0aaa0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000
00a000a0a0a0a0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00aaa0a0a0a0a0000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000a0a0a0a0a0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00aaa0aaa0aaa0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
06666660066666600666666000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
06555560065555600655556000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
06555560065555600655556000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
06555560065555600655556000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00655600006556100065560000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00066000000660000006600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000060000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000010000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000bb00bb0000000000000000000000000000bb00bb0000000000000000000000000000bb00bb000000000000000000000000000
0000000000000000000000000000b33b000000000000000000000000000000b33b000000000000000000000000000000b33b0000000000000000000000000000
0000000000000000000000000003bbbb300000000000000000000000000003bbbb300000000000000000000000000003bbbbaaa0000000000000000000000000
00000000000000000000000000038bb83000000000000000000000000000038bb83000000000000000000000000000038bba300a000000000000000000000000
00000000000000000000000000003bb30000000000000000000000000000003bb30000000000000000000000000000003bba000a000000000000000000000000
00000000000000000000000000020330200000000000000000000000000002033020000000000000000000000a00a002033a200a000000000000000000000000
0000000000000000000000000000e00e000000000000000000000000000000e00e00000000000000000000000a00a000e00eaaa0000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000900900000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000900900000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000ee00000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000e22e0000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000e22e0000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000ee00000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000ee00000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000000000000000e22e0000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000ee000000000000e22e0000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000e22e000000000000ee00000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000e22e0000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000006000000ee00000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000a00a00000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000a00a00000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000900900000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000900900000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000001000000000000000000000000000000000000000000000000000000000000060060000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000060060000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000000006dc7d6000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000000006dccd6000000000000006000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000d66dd66d00000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000d666666d00000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000050dd05000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
__sfx__
000100002d5503055032550325502e55029540235401b530145200e5200b510085100651000500005000050000500005000050000500005000050000500005000050000500005000050000500005000050000500
000200002562026630266302662023610206101a61014610006000060000600006000060000600006000060000600006000060000600006000060000600006000060000600006000060000600006000060000600