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.

Bomb Item

Hey.

I finished the items that speed up and slow down the ball speed. Now, I’m working on a “Bomb”.

When the gem is collected, it will place a bomb somewhere on the bricks. It will explode a short while later, clearing blocks within its blast area.

Hmm, while I’m not going to get into too much design details with these games for the blog, but I was thinking of three ways of how to place the bomb:

  1. Placing it randomly in the bricks (least challenging to implement, but this would add a random [and intentionally polarizing] factor into the game; sometimes the bomb would appear where you want it, other times, it may appear where no bricks are, and be totally useless, pissing you off in the process – which would make the bomb that much more satisfying when it’s helpful, I think);
  2. Temporarily suspending the game, and letting the player place the bomb wherever they want (moderate challenge); or
  3. Writing an algorithm that will automatically place the bomb where the most bricks are, so it has the best chance of clearing out the most bricks when it blows up (most challenging to implement, but if I did this, I’d make the bomb gem more rare)

What do you think? Or maybe you have a different idea altogether. I’d love to hear your thoughts. Leave a comment below!

– C. out.