Bomb Item, cont.

Hey guys,

The bomb item is now working!

This one was a little challenging, because the explosion collision to clear the tiles wasn’t behaving the way I wanted. It was clearing the bricks along the outside edges of the explosion.

I added a green debugging square that shows the area of the explosion. As you can see from this screen shot, the bricks just outside the square were also cleared, which was not the intended effect.

After some tinkering, I found that Phaser’s Rectangle class performs intersections a little differently than expected.

It’s when the right and bottom edges of a rectangle are calculated, they’re including an extra one unit, instead of subtracting one.

For example, say you have a rectangle located at x=10, and y=14, and it has a width of 16, and height of 5. The right edge would be located at x + width (10 + 16) = 26, and the bottom edge is at y + height (14 + 5 = 19).

I was expecting the right edge to be at 10 + 16 – 1 = 25, and the bottom edge to be at 14 + 5 – 1 = 18. So that extra offset of one was including the bricks around the explosion edge.

Since I didn’t want to modify Phaser’s internal method when determining if two rectangles intersect (it’s solid for everything else; I just needed a specific behavior here), I used a modified version of it by subtracting the offsets from the right and bottom of both rectangles:

!(rect1.right - 1 < rect2.x ||
rect1.bottom - 1 < rect2.y ||
rect1.x > rect2.right - 1 ||
rect1.y > rect2.bottom - 1);

And vwalla! (:

The result was an explosion that did not clear the bricks just outside the explosion! Look at that snug fit! Keep it tight!

 

And the final look is here:

I’ll polish this up later, but for now, I’m moving on to the next items. Stay tuned!

~ C. out.