From d33aca6f9fea1ffdead1603677f87850da6db349 Mon Sep 17 00:00:00 2001 From: James Turk Date: Sun, 30 Apr 2023 02:39:24 -0500 Subject: [PATCH] explode grid --- games/boybomb.p8 | 115 ++++++++++++++++++++++++++--------------------- 1 file changed, 63 insertions(+), 52 deletions(-) diff --git a/games/boybomb.p8 b/games/boybomb.p8 index 8e4e708..5182a85 100644 --- a/games/boybomb.p8 +++ b/games/boybomb.p8 @@ -161,24 +161,25 @@ end levels = { {name="lobby 1", - mapx=16, mapy=8, - par=2, boss=8, + mapx=16, mapy=8, par=1, boss=8, message="there's no way he'll\nclear these boxes" }, {name="lobby 2", - mapx=25, mapy=8, - par=2, boss=8, + mapx=25, mapy=8, par=2, boss=8, message="this one should take a\ndozen explosions" }, {name="lobby 3", - mapx=31, mapy=8, bomb_x=6, bomb_y=7, - par=2, boss=8, + mapx=31, mapy=8, par=8, boss=8, message="maybe he'll wear himself\nout?" }, - {name="lab 1", - mapx=26, mapy=8, bomb_x=6, bomb_y=7, - par=5, boss=10, + {name="lobby 4", + mapx=39, mapy=8, par=2, boss=8, + message="being hit by a block\nwill make him explode" }, + {name=" lab 1", + mapx=48, mapy=8, par=2, boss=8, + message="we need to be careful\nof chain reactions", + } } function start_level(n) start_scene("level") @@ -192,7 +193,9 @@ function start_level(n) bomb_y = 4 -- load puzzle puzzle_grid = {} + explode_grid = {} for y=1,GRID_H do + explode_grid[y] = {nil, nil, nil, nil, nil, nil, nil, nil} 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) @@ -211,7 +214,7 @@ function start_level(n) end particles = {} -function add_explosion(gx, gy, colors) +function add_particles(gx, gy, colors) sfx(0) local x = gx*8+4 local y = gy*8+4 @@ -287,43 +290,52 @@ end function explosion_adjacent(x, y) -- called when the block next door explodes local block = puzzle_grid[y][x] - if block == BOX_WOOD then - puzzle_grid[y][x] = 0 - elseif block == BOX_FIRE then - puzzle_grid[y][x] = GRID_EXPLODE_NEXT + puzzle_grid[y][x] = 0 + if block == BOX_FIRE then + -- TODO: add explosion end end function process_block(x, y) -- called on each block each frame local block = puzzle_grid[y][x] - if block == GRID_EXPLODE_NEXT then - add_explosion(x, y, {4, 15}) -- wood - puzzle_grid[y][x] = GRID_EXPLODE - elseif block == GRID_EXPLODE then - local ys = {0} - local xs = {0} - if y > 1 then - add(ys, -1) + local explode = explode_grid[y][x] + if explode then + -- grid items are {countdown, colors} + explode.countdown -= 1 + printh("CD: "..x..", "..y.." "..explode.countdown) + if explode.countdown == 0 then + -- blow up the box (if present) + puzzle_grid[y][x] = 0 + add_particles(x, y, explode.colors) + -- 4, 15 for box + explode_grid[y][x] = nil end - if y < GRID_H then - add(ys, 1) - end - if x > 1 then - add(xs, -1) - end - if x < GRID_W then - add(xs, 1) - end - for xx in all(xs) do - for yy in all(ys) do - if xx~=0 or yy~=0 then - explosion_adjacent(x+xx, y+yy) - end - end - end - puzzle_grid[y][x] = 0 end + -- elseif block == GRID_EXPLODE then + -- local ys = {0} + -- local xs = {0} + -- if y > 1 then + -- add(ys, -1) + -- end + -- if y < GRID_H then + -- add(ys, 1) + -- end + -- if x > 1 then + -- add(xs, -1) + -- end + -- if x < GRID_W then + -- add(xs, 1) + -- end + -- for xx in all(xs) do + -- for yy in all(ys) do + -- if xx~=0 or yy~=0 then + -- explosion_adjacent(x+xx, y+yy) + -- end + -- end + -- end + -- puzzle_grid[y][x] = 0 + -- end end @@ -342,6 +354,7 @@ function update_level() bomb_y = 0 end end + printh("===") if t() - last_gravity > fall_speed then last_gravity = t() for y=GRID_H,1,-1 do @@ -371,8 +384,8 @@ function update_level() if exploding then if bomb_spr.frame > 10 and bomb_spr.anim then -- when explosion hits last frame, particles / update grid - add_explosion(bomb_x, bomb_y, {8, 9, 10}) - puzzle_grid[bomb_y][bomb_x] = GRID_EXPLODE + --add_particles(bomb_x, bomb_y, {8, 9, 10}) + explode_grid[bomb_y][bomb_x] = {countdown=1, colors={8, 9, 10}} end -- exploding means we're done before input comes return @@ -442,8 +455,6 @@ BOX_FIRE = 139 BOX_FROG = 140 BOX_NUKE = 141 BOX_WATER = 142 -GRID_EXPLODE = -1 -GRID_EXPLODE_NEXT = -2 animations = { boy_walk={frames={[0]=2, 0, 4, 0}, w=2, h=2}, @@ -717,16 +728,16 @@ b2b2b2b2b2b2b2b2b2b8b8b8b8b8b8b80000000000b8b8b8b8b80000000000000000000000000000 b2b2b2b2b2b2b2b2b2b0b0b0b0b0b0b00000000000b0b0b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 c0c1c1c1c1c1c1c1c1c2c3c4c4c4c4c588888888888888880000888888888888888800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 -d0d1d1d1d1d1d1d1d1d2e3e4e4e4e4e500000000000000000000880088888888888889008900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 -d0d1d1d1d1d1d1d1d1d2c3c4c4c4c4c500000000000000000000880088888888888889988900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +d0d1d1d1d1d1d1d1d1d2e3e4e4e4e4e500000000000000000000880088888888888889008900000000890000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +d0d1d1d1d1d1d1d1d1d2c3c4c4c4c4c500000000000000000000880088888888888889988900008989890000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 d0d1d1d1d1d1d1d1d1d2d300000000d500000000000000000000888888888888888889898900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 -d0d1d1d1d1d1d1d1d1d2d300000000d500000000000000000000880000008888888889898900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 -d0d1d1d1d1d1d1d1d1d2d300000000d500000000000000000000880000000000888889898900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 -d0d1d1d1d1d1d1d1d1d2d300000000d500000000000000000000880000000000888889898900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 -d0d1d1d1d1d1d1d1d1d2d300000000d588888888888888880000880000000000888889898900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 -d0d1d1d1d1d1d1d1d1d2d300000000d588888988898888880089889888888988888889898900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 -d0d1d1d1d1d1d1d1d1d2d300000000d588888998898888880089888988888900888889898900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 -d0d1d1d1d1d1d1d1d1d2d3d4d4d4d4d588888989898888880089898989898988888889898900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +d0d1d1d1d1d1d1d1d1d2d300000000d500000000000000000000880000008888888889898900008888880000880000008800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +d0d1d1d1d1d1d1d1d1d2d300000000d500000000000000000000880000000000888889898900008888888800888888008800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +d0d1d1d1d1d1d1d1d1d2d300000000d500000000000000000000880000000000888889898900000000000000000000008800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +d0d1d1d1d1d1d1d1d1d2d300000000d588888888888888880000880000000000888889898900000000000000000000008800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +d0d1d1d1d1d1d1d1d1d2d300000000d588888988898888880089889888888988888889898900000000000000000000008889000000890000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +d0d1d1d1d1d1d1d1d1d2d300000000d5888889988988888800898889888889008888898989000089000088880000890088898b008b890000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +d0d1d1d1d1d1d1d1d1d2d3d4d4d4d4d588888989898888880089898989898988888889898900008989898888898989008889898989890000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 d0d1d1d1d1d1d1d1d1d2d3d4d4d4d4d500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 e0e1e1e1e1e1e1e1e1e2e3e4e4e4e4e500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 c3c4c4c4c4c4c4c4c4c4c4c4c4c4c4c500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000