I am creating a tiled game (2D top down) and I created explosions working this way:

enter image description here

The blue lines are walls, the white grid is accessable space. The red dot is the origin of the explosion with the green explosion radius. The orange lines are how I am doing raycasting (I am using Box2d) at the moment to ensure that only accessable things are hit (nothing behind the blue walls should be hit).

I cant just draw a circular sprite over the whole area as I dont want to let the explosion look like it is going over walls and stuff. My solution: I will draw an explosion tile over each tile that is in the radius.

This is how I want the explosion to look like:

enter image description here

Everything in the yellow "polygon" should be drawn as an explosion.

There are some issues seen here in the purple circles:

enter image description here

In "real life" the explosion will go around corners.

My question simply is: Do you have any idea on how to find all tiles that should be drawn as an explosion? Or maybe you do have a better approach!

The effect I want reminds me of minecraft water physics but in 2d.

Thank you!


1 Answer 1


This looks like a perfect usage case for flood fill. Recursively visit all neighbouring tiles, starting from the explosion origin, that are not a wall and still in the explosion radius.

All tiles that are visited this way are part of the explosion by your logic.

If you want the explosion to only go around corners a certain distance, you can track how far the path from the explosion origing to the tile is, only taking those tiles where the path length is less or equal to your explosion radius.

  • \$\begingroup\$ yes the solution was right in front of my eyes haha. Thank you! \$\endgroup\$ Feb 24, 2018 at 5:48
  • \$\begingroup\$ @MarcoZielbauer Glad my answer was helpful! Please accept the answer then (the little checkmark below the voting buttons), so the question is marked as solved. \$\endgroup\$
    – LukeG
    Feb 26, 2018 at 18:12
  • \$\begingroup\$ sry I did mark it but I accidentaly removed it yesterday ^ \$\endgroup\$ Feb 27, 2018 at 5:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .