From 079627b65990e25ac86d884412dc4075f865618d Mon Sep 17 00:00:00 2001 From: James Turk Date: Tue, 25 Apr 2023 04:02:37 -0500 Subject: [PATCH] explosion ripples --- games/boybomb.p8 | 70 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 62 insertions(+), 8 deletions(-) diff --git a/games/boybomb.p8 b/games/boybomb.p8 index f1a417b..0013990 100644 --- a/games/boybomb.p8 +++ b/games/boybomb.p8 @@ -147,7 +147,6 @@ function start_level(n) level = levels[n] puzzle_grid = {} for y=1,GRID_H do - printh(y) puzzle_grid[y] = {0, 0, 0, 0, 0, 0, 0, 0} for x=1,GRID_W do puzzle_grid[y][x] = mget(x+level.mapx-1, y+level.mapy-1) @@ -158,8 +157,52 @@ function start_level(n) bomb_spr = make_sprite(bomb_x*8, bomb_y*8, "bomb_s", 0) end +particles = {} +function add_explosion(gx, gy) + local x = gx*8+4 + local y = gy*8+4 + for i=0,50 do + local angle = rnd() + add(particles, { + x=x, y=y, + vx=(rnd(1)+1)*cos(angle), + vy=(rnd(1)+1)*sin(angle), + age=rnd(5), + }) + end +end + +function draw_explosions() + for p in all(particles) do + pset(p.x, p.y, p.color) + end +end + +function update_explosions() + for i=#particles,1,-1 do + local p = particles[i] + p.x += p.vx + p.y += p.vy + p.age += 1 + if p.age > 25 then + deli(particles, i) + elseif p.age > 20 then + p.color = 10 + elseif p.age > 15 then + p.color = rnd({9, 10}) + elseif p.age > 10 then + p.color = 9 + elseif p.age > 5 then + p.color = rnd({8, 9}) + else + p.color = 8 + end + end +end + function draw_level() cls() + -- HUD map(0, 8, 0, 0, 16, 16) for y=1,GRID_H do for x=1,GRID_W do @@ -175,6 +218,7 @@ function draw_level() bomb_spr.x = bomb_x * 8 bomb_spr.y = bomb_y * 8 draw_sprite(bomb_spr) + draw_explosions() end function can_move(dx, dy) @@ -196,7 +240,7 @@ function update_level() fall_speed /= 2 if bomb_spr.speed == 0 and bomb_spr.anim then bomb_spr.anim = nil - puzzle_grid[bomb_y][bomb_x] = GRID_EXPLODE + puzzle_grid[bomb_y][bomb_x] = 0 end end if t() - last_gravity > fall_speed then @@ -204,18 +248,22 @@ function update_level() for y=1,GRID_H do for x=1,GRID_W do -- explode + if puzzle_grid[y][x] == GRID_EXPLODE_NEXT then + add_explosion(x, y) + puzzle_grid[y][x] = GRID_EXPLODE + end if puzzle_grid[y][x] == GRID_EXPLODE then if y > 1 and puzzle_grid[y-1][x] == BOX_FIRE then - puzzle_grid[y-1][x] = GRID_EXPLODE + puzzle_grid[y-1][x] = GRID_EXPLODE_NEXT end if y < GRID_H and puzzle_grid[y+1][x] == BOX_FIRE then - puzzle_grid[y+1][x] = GRID_EXPLODE + puzzle_grid[y+1][x] = GRID_EXPLODE_NEXT end if x > 1 and puzzle_grid[y][x-1] == BOX_FIRE then - puzzle_grid[y][x-1] = GRID_EXPLODE + puzzle_grid[y][x-1] = GRID_EXPLODE_NEXT end if x < GRID_W and puzzle_grid[y][x+1] == BOX_FIRE then - puzzle_grid[y][x+1] = GRID_EXPLODE + puzzle_grid[y][x+1] = GRID_EXPLODE_NEXT end puzzle_grid[y][x] = 0 end @@ -238,6 +286,11 @@ function update_level() if exploding then update_sprite(bomb_spr) + if bomb_spr.frame > 10 and bomb_spr.anim then + add_explosion(bomb_x, bomb_y) + puzzle_grid[bomb_y][bomb_x] = GRID_EXPLODE + end + update_explosions() -- exploding means we're done return end @@ -270,7 +323,7 @@ end function explode() exploding = true - explode_time = t() + explosion_time = t() bomb_spr.speed = 0.1 end @@ -291,7 +344,8 @@ BOX_FIRE = 139 BOX_FROG = 140 BOX_NUKE = 141 BOX_WATER = 142 -GRID_EXPLODE = 76 +GRID_EXPLODE = -1 +GRID_EXPLODE_NEXT = -2 animations = { boy_walk={frames={[0]=2, 0, 4, 0}, w=2, h=2},