-
Notifications
You must be signed in to change notification settings - Fork 0
/
planetkiller.p8
586 lines (540 loc) · 21.3 KB
/
planetkiller.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
pico-8 cartridge // http://www.pico-8.com
version 16
__lua__
level_size = 7
block_rights = {}
block_lefts = {}
current_block_right = 0
current_block_left = 0
camera_shake_count = 0
current_block_target = 1 -- red
last_movement = 1 -- right
no_moves_indicator = false
fc_indicator_count = 0
fc_count = 0
otto_anim_count = 0
score_flash_red_count = 0
characters = {"otto", "samurai", "miner"}
current_character = 1
game_over_pause_count = 0
explosions = {}
ending_phrases = {
otto = {
{300,"otto say: you are truly amazing!"},
{200,"otto say: you are wonderful!"},
{100,"otto say: you did a great job!"},
{30,"otto say: you did a good job!"},
{0,"otto say: good try!"}
},
samurai = {
{300,"samurai say: shooting maestro"},
{200,"samurai say: satisfactory"},
{100,"samurai say: meh"},
{30,"samurai say: are you sleeping"},
{0,"samurai say: \139 or \145 to shoot"},
},
miner = {
{300,"miner found a diamond!"},
{200,"miner found an opal!"},
{100,"miner found a sapphire!"},
{30,"miner found a ruby!"},
{0,"miner found nothing :("},
}
}
ending_text = ""
timer = 0
score = 0
-- bomb_animation
-- in_play
-- ?????
game_state = "cutscene"
bomb_animation_counter = 30
-- del by index - keeps order
function idel(t,i)
local n=#t
if (i>0 and i<=n) then
for j=i,n-1 do t[j]=t[j+1] end
t[n]=nil
end
end
function linear(t, b, c, d)
return c * t / d + b
end
function outbounce(t, b, c, d)
t = t / d
if t < 1 / 2.75 then
return c * (7.5625 * t * t) + b
elseif t < 2 / 2.75 then
t = t - (1.5 / 2.75)
return c * (7.5625 * t * t + 0.75) + b
elseif t < 2.5 / 2.75 then
t = t - (2.25 / 2.75)
return c * (7.5625 * t * t + 0.9375) + b
end
t = t - (2.625 / 2.75)
return c * (7.5625 * t * t + 0.984375) + b
end
function gensol()
local sol = {}
local left_count = level_size
local right_count = level_size
for _=1,level_size*2 do
local dir
if (left_count == 0) then
dir = 1
elseif (right_count == 0) then
dir = 0
else
dir = flr(rnd(2))
if (dir == 1) then
right_count -= 1
else
left_count -= 1
end
end
add(sol, dir)
end
return sol
end
function genblocks(sol)
block_rights = {}
block_lefts = {}
-- 1 = red, -1 = blue
local current_letter = -1
for d in all(sol) do
if (d == 1) then
add(block_rights, current_letter)
else
add(block_lefts, current_letter)
end
current_letter = current_letter * -1
end
current_block_left = level_size
current_block_right = level_size
end
-- dir: -1 left, 1 right
function remove_block(dir)
last_movement = dir
if (dir == -1) then
local target_block = block_lefts[current_block_left]
if (target_block == current_block_target) then
local new_explosion = {
side=-1,
pos=current_block_left,
ticks=6
}
current_block_left -= 1
current_block_target = -current_block_target
score += 1
add(explosions, new_explosion)
sfx(24)
otto_anim_count = 3
else
miss()
end
else
local target_block = block_rights[current_block_right]
if (target_block == current_block_target) then
local new_explosion = {
side=1,
pos=current_block_right,
ticks=6
}
current_block_right -= 1
current_block_target = -current_block_target
score += 1
add(explosions, new_explosion)
sfx(24)
otto_anim_count = 3
else
miss()
end
end
if (current_block_left == 0 and current_block_right == 0) then
fc_count += 1
fc_indicator_count = 15
score += 10
new_round()
sfx(23)
elseif ((block_lefts[current_block_left] != current_block_target) and block_rights[current_block_right] != current_block_target) then
game_state = "nomoves"
end
end
function miss()
score -= 5
camera_shake_count = 5
score_flash_red_count = 8
end
function select_ending_phrase()
local character = characters[current_character]
local phrases = ending_phrases[character]
ending_text = phrases[#phrases][2]
for phrase in all(phrases) do
if (score > phrase[1]) then
ending_text = phrase[2]
break
end
end
end
function render_blocks()
-- okay, samurai is at x=60-68
-- and we're going to make the blocks 6x6 pixel
-- and there's a 4 pixel buffer, so we should start at...
-- tweening
clip(0,48,128,80)
local ystart
if (bomb_animation_counter > 0) then
pos = 30 - bomb_animation_counter - 1
ystart = outbounce(pos, 35, 27, 28)
printh(tostr(pos))
else
ystart = outbounce(1, 35, 27, 1)
end
local lstart = 56 - level_size*7
local rstart = 72 + level_size*7
for i=1,current_block_left do
local leftcol = (block_lefts[i] == 1) and 3 or 2
local leftpos = lstart + (i-1)*7
spr(leftcol, leftpos, ystart)
end
for i=1,current_block_right do
local rightcol = (block_rights[i] == 1) and 3 or 2
local rightpos = rstart - (i-1)*7 - 6
spr(rightcol, rightpos, ystart)
end
-- draw explosions
for explosion in all(explosions) do
local exspr = flr(explosion.ticks / 2) + 5
if (explosion.side == -1) then
local leftpos = lstart + (explosion.pos-1)*7
spr(exspr, leftpos, ystart)
else
local rightpos = rstart - (explosion.pos-1)*7 - 6
spr(exspr, rightpos, ystart)
end
end
clip()
end
function hcenter(s)
-- screen center minus the
-- string length times the
-- pixels in a char's width,
-- cut in half
return 64-#s*2
end
function render_nomoves()
local text = "no moves"
print(text, hcenter(text), 32, 8)
local text2 = "press \148 to reset"
print(text2, hcenter(text2), 40, 8)
end
function render_fc()
local text = "full clear! +10"
print(text, hcenter(text), 40, 10)
end
function render_gameover()
local text = "game over"
print(text, hcenter(text), 40, 8)
end
function render_score()
local text = tostr(score)
local colour
if (score_flash_red_count > 0) then
colour = 8
else
colour = 7
end
print(text, hcenter(text), 88, colour)
end
function render_timer()
local timer_in_seconds = timer / 30
local text = tostr(flr(timer_in_seconds))
print(text, hcenter(text), 22, 7)
end
function render_sam()
if (characters[current_character] == "otto") then
local sprite = current_block_target == 1 and 17 or 18
if (otto_anim_count > 0) then
sprite += 2
local sparks = current_block_target == 1 and 21 or 22
spr(sparks, 60, 52, 1.0, 1.0)
end
local flip_x = last_movement == -1
spr(sprite,60,60,1.0,1.0,flip_x)
end
if (characters[current_character] == "samurai") then
local sprite = current_block_target == 1 and 1 or 4
local flip_x = last_movement == -1
spr(sprite,60,60,1.0,1.0,flip_x)
if (otto_anim_count > 0) then
local flip_spark = last_movement == -1 and 1 or 0
local spark_x = last_movement == -1 and 52 or 64
spr(34, spark_x, 60, 1.0, 1.0, flip_spark)
end
end
if (characters[current_character] == "miner") then
local flip_x = last_movement == -1
local sprite
local sparks
if (current_block_target == 1) then
if (otto_anim_count > 0) then
sprite = 51
sparks = 52
else
sprite = 49
sparks = 50
end
else
if (otto_anim_count > 0) then
sprite = 54
sparks = 52
else
sprite = 53
sparks = 50
end
end
spr(sprite, 60, 60, 1.0, 1.0, flip_x)
local spark_x = last_movement == -1 and 52 or 68
spr(sparks, spark_x, 60, 1.0, 1.0, flip_x)
end
end
function render_highscore()
local text = "hi score: ".. tostr(dget(0))
print(text, hcenter(text), 120, 10)
end
function render_ending_message()
print(ending_text, hcenter(ending_text), 110, 7)
end
function new_round()
genblocks(gensol())
current_block_target = 1
game_state = "cutscene"
bomb_animation_counter = 30
end
function render_tutorial()
spr(64, 20, 17, 11, 3)
local text = "\139 \145 fire"
print(text, hcenter(text)-2, 90, 7)
local text2 = "\148 reset"
print(text2, hcenter(text2)-2, 100, 7)
local text3 = "alternate red and blue"
print(text3, hcenter(text3), 110, 7)
end
function _init()
cartdata("ladybug_samuraibombsquad_0")
palt(3, true)
palt(0, false)
genblocks(gensol())
music(0,5)
end
function _draw()
if (camera_shake_count > 0) then
camera(flr(rnd(3))-1, flr(rnd(3))-1)
else
camera(0, 0)
end
rectfill(0,0,128,128,3)
rectfill(0,0,128,48,0)
rectfill(0,80,128,128,0)
render_blocks()
if (timer > 0) then
render_timer()
render_score()
elseif (game_state != "gameover") then
render_tutorial()
end
if (game_state == "gameover") then
render_score()
render_gameover()
render_highscore()
render_ending_message()
elseif (game_state == "nomoves") then
render_nomoves()
elseif (fc_indicator_count > 0) then
render_fc()
end
render_sam()
end
function _update()
if (bomb_animation_counter > 0) then
bomb_animation_counter -= 1
end
if (timer > 0) then
timer -= 1
if (timer == 0) then
game_state = "gameover"
select_ending_phrase()
game_over_pause_count = 30
if (score > dget(0)) then
dset(0, score)
end
end
end
if (camera_shake_count > 0) then
camera_shake_count -= 1
end
for i=#explosions,1,-1 do
explosions[i].ticks -= 1
if (explosions[i].ticks == 0) then
idel(explosions, i)
end
end
if (fc_indicator_count > 0) then
fc_indicator_count -= 1
end
if (otto_anim_count > 0) then
otto_anim_count -= 1
end
if (score_flash_red_count > 0) then
score_flash_red_count -= 1
end
if (game_over_pause_count > 0) then
game_over_pause_count -= 1
end
if (game_state == "cutscene") then
if (bomb_animation_counter < 20) then
game_state = "play"
end
elseif (game_state == "play") then
if ((btnp(0) or btnp(1)) and timer == 0) then
timer = 60*30
score = 0
end
if (btnp(0)) then
remove_block(-1)
elseif (btnp(1)) then
remove_block(1)
end
if (btnp(2)) then
new_round()
end
end
if (game_state == "gameover") then
if (btnp(2) and game_over_pause_count == 0) then
new_round()
score = 0
fc_count = 0
end
end
if (game_state == "nomoves") then
if (btnp(2)) then
new_round()
end
end
if (btnp(3)) then
current_character += 1
if (current_character > #characters) then
current_character = 1
end
end
end
__gfx__
000000003a8888a333cc3333338833333acccca33333333333333333aaaaaa330000000000000000000000000000000000000000000000000000000000000000
0000000038aaaa8331cc1333328823333caaaac3333333333aaaa333a3333a330000000000000000000000000000000000000000000000000000000000000000
0070070088000003cc11cc3388228833cc00000333aa33333a99a333a3333a330000000000000000000000000000000000000000000000000000000000000000
0007700038f0ff08cc11cc338822883338f0ff0833aa33333a99a333a3333a330000000000000000000000000000000000000000000000000000000000000000
00077000388ffff731cc133332882333388ffff7333333333aaaa333a3333a330000000000000000000000000000000000000000000000000000000000000000
007007008888887333cc333333883333888888733333333333333333aaaaaa330000000000000000000000000000000000000000000000000000000000000000
00000000388888833333333333333333388888833333333333333333333333330000000000000000000000000000000000000000000000000000000000000000
00000000377337733333333333333333377337733333333333333333333333330000000000000000000000000000000000000000000000000000000000000000
000000003388388333cc3cc333333333333333333333333333333333000000000000000000000000000000000000000000000000000000000000000000000000
000000003388388333cc3cc33388388333cc3cc33333333333333333000000000000000000000000000000000000000000000000000000000000000000000000
0000000088888888cccccccc88888888cccccccc3333333333333333000000000000000000000000000000000000000000000000000000000000000000000000
0000000085555558c555555c85555558c555555c3333333333333333000000000000000000000000000000000000000000000000000000000000000000000000
0000000085885888c5cc5ccc85555558c555555c3333333333333333000000000000000000000000000000000000000000000000000000000000000000000000
0000000085885888c5cc5ccc85885888c5cc5ccc3333333333333333000000000000000000000000000000000000000000000000000000000000000000000000
0000000085555558c555555c85555558c555555c83388338c33cc33c000000000000000000000000000000000000000000000000000000000000000000000000
0000000088888888cccccccc88888888cccccccc383883833c3cc3c3000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000003333333300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000003333333300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000003333333300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000003393333300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000003933333300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000003393333300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000003333333300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000003333333300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000332222463333333333222233333333333322224633222233000000000000000000000000000000000000000000000000000000000000000000000000
000000003000a003633333333000a003333333333000a0033000a003000000000000000000000000000000000000000000000000000000000000000000000000
00000000322222236333333332222223333333333222222332222223000000000000000000000000000000000000000000000000000000000000000000000000
0000000033f0f0333333333343f0f0333333333333f0f03343f0f033000000000000000000000000000000000000000000000000000000000000000000000000
0000000037ffff833333333337ffff433393333337ffffc337ffff43000000000000000000000000000000000000000000000000000000000000000000000000
00000000481111833333333338111186333393334c1111c33c1111c6000000000000000000000000000000000000000000000000000000000000000000000000
00000000381111733333333338111183639333333c1111733c1111c3000000000000000000000000000000000000000000000000000000000000000000000000
00000000322332233333333332233223639939333223322332233223000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000cc00088000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000cc00088000000000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000bbbbbbbbb00000000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000b0000000b00000000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000b0880cc0b00000000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000b0880cc0b00000000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000b0000000b00000000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000bbbbbbbbb00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000088888888888888880000000000000cccccccccccc0000000000000000000000008000000000000000
0770000770070070077007000700770077700077007770080008080008800080007700777000c0cc00cc000c0000000000000000000000008000000000000000
7007007007070070700707700707007070000700707000080888080880808880070070700700c0c0cc0c0ccc0000000000000000000000008000000000000000
7777007000077770777707070707000077700700707770080008080008800080070070777000c0c0cccc000c0000000000000000000000008000000000000000
7007007007070070700707007707007070000700707000080888080808808880070070707000c0c0cc0c0ccc0000000000000000000000008000000000000000
7007000770070070700707000700770077700077007000080888080880800080007700700700c0cc00cc000c0000000000000000000000008000000000000000
0000000000000000000000000000000000000000000000088888888888888880000000000000cccccccccccc0000000000000000000000008000000000000000
__sfx__
010700200523405242052420523505304053050530405305052340524205242052350530405305000000530405234052420524205235053040530505305000040523405242052420523505304053050000000000
01070000082340824208242082350000000000000000000008234082420824208235000000000000000083060823408242082420823500000000000000000000082340824208242082350f600036050f6400f645
0107002000163000000000000000001630000000000000000f6400364500000000000010300103001630430600163000000000000000001630000000000000050f640036450000000000000000f6030000000000
010700201105514005140551800518055290051b055290051d0552900520055290052405529005270552900529055290052705529005240551100520055290051d055290051b0551d005180551a0051405529005
01070020140550000017055000001b0551f0051e055000002005500000230550000027055000002a055000002c055000002a055000002705500000230550000020055000001e055000001b055000001705500000
013800101d2141d2141d2141d2141d2141d2141d2141d2141d2141d2141d2141d2142021420214202142021400000000000000000000000000000000000000000000000000000000000000000000000000000000
0107000024534245322453224532245352450522105201052453424532245322453224535201051d1050000024534245322453224532245352410522105201052453424532245322453224535201051d1051b105
010700002953429532295322953229535001000010000100245342453224532245322453500100001000010022534225322253222532225350010500100001002053420532205322053220535001000010000100
010700200a2340a2420a2420a235053040530505304053050a2340a2420a2420a235053040530500000053040a2340a2420a2420a235053040530505305000040a2340a2420a2420a23505304053050000000000
010700001d5341d5321d5321d5321d535001000010000100205342053220532205322053500100001000010022534225322253222532225350010500100001002453424532245322453224535001000010000100
01070000225342253222532225322253500100001000010020534205322053220532205350010000100001001d5341d5321d5321d5321d5350010500100001002450424502245022450224505001000010000100
010700200c2340c2420c2420c235053040530505304053050c2340c2420c2420c235053040530500000053040c2340c2420c2420c235053040530505305000040c2340c2420c2420c23505304053050000000000
010700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000350430000000000050000000000000350430000000000000000000035003
010700001d754007040070400704247540070400704007041d754007040070400704247540070400704007041d7541d7040070400704247540070400704007041d75400704007040070424754007040070400704
01100000346113061130611306113061134611346110e611106110e611106110e611106110e6110e611036110e6110e611106110e6110e611106110e6110e611036110e61110611106110561110611056110e611
010100003a75037750327502e7502b7402874026730227301f7201c7201a720187201672014730117200f7200e7100d7100c7100b750057500575005750057500575005750057500575005750057500575005750
0107000019754007040070400704207540070400704007041975400704007040070420754007040070400704197541d7040070400704207540070400704007041975400704007040070420754007040070400704
0107000020754007040070400704277540070400704007042075400704007040070427754007040070400704207541d704007040070427754007040070400704207540070400704007042775400704007041c000
01070000187540070400704007041f754007040070400704187540070400704007041f754007040070400704187541d70400704007041f754007040070400704187540070400704007041f75400704007041c000
01070000167540070400704007041d754007040070400704167541600000704007041d754007040070400704167541d70400704007041d754007040070400704167540070400704007041d75400704007041c000
01070000225342253222532225322253500100001000010020534205322053220532205350010000100001001d5341d5321d5321d5321d5350010500100001001b5341b5321b5321b5321b535001000010000100
010c00001d5501d5401d5301d5201d515110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
011c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011553
010e000024221292201d0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
010300002057320503210002960026600256002360021600206001f6001d6001c6001a60018600186001760015600026001360012600056000f6000d6000c6000a60009600086000760006600046000360006600
0107000035043007040070400704247540070400704007041d754007040070400704247540070400704007041d7541d7040070400704247540070400704007041d75400704007040070424754007040070400704
__music__
01 00024544
00 00024344
00 00024344
00 01024444
00 00024344
00 00024344
00 00024344
00 01024344
00 00020344
00 00020344
00 00020344
00 01020444
00 00020344
00 00020344
00 00020344
00 01020444
00 060d0f44
00 07114044
00 48100944
00 4b0a120c
00 06020019
00 07020111
00 09020813
00 0b021412
02 16021544
02 41424344