How do I smash a block after it's hit twice?

0 favourites
  • 5 posts
From the Asset Store
Merge Blocks - Full Game
$19.60 USD
60% off
Place blocks on a board, join them together to form even bigger blocks!
  • My Breakout-game is coming along great, and now it's time to smash some blocks. The regular ones are easy enough. On collision with ball, simply play a sound and smash them (in that order, so I'm sure the sound is played.) But the harder blocks?

    What I've done so far is that I have a zero-speed block-animation with two frames (the undamaged and cracked block), then simply change the frame from 1 to 0 when the ball hits (as the animation starts with frame 0.) I do this by first creating a local variable called Smashing when the block is created and set it to 2, then set it to 1 when the ball hits. This works fine. I've tried having three of those solid blocks plus a few normal blocks in a level, and everything works fine. (note: It's tempting to set the frame directly to 1 when the ball hits, but by using a variable, I can have as many frames as I want. I could require a block to be smashed ten times this way, if I wanted to be a bit evil. But I wouldn't do that. Nope. Not at all. Most likely-)

    However, how do I smash the harder blocks the second time they are hit? It should be simple enough to check the variable of the block once it's hit, then destroy it if the variable is set to 1. But... how? Much as I love Construct2, I can't seem to figure out how to make an event have three steps instead of just two. (ball hit -> check variable -> smash it if necessary.) All I can do is check the variable if the ball hits. I simply can't find a "Check variable" anywhere?

  • It sounds like you want to want to compare an instance variable. You do that as an event and not an action. So add an event, and double click the object that has the instance variable that you want to create a condition from. You should then have an option to "compare instance variable".

  • YES! That worked. Much appreciated.

    For reference, if others struggle with the same:

    I first set the variable Smashing to 2 when the block is created. Then when the ball hits the block, I subtract 1 from the variable Smashing.

    Next, I create one event where I Compare the variable, and check if it's set to 1. If it is, I change the animation frame to 1 (to get the cracked block).

    Finally, I check again in a new event, and see if the variable is 0. If it is, destroy the block.

    This way, I can use multiple blocks pr level, as they all use individual variables. Adding more frames (to make the blocks harder) is a bit tricky, as you'll need to check for every single number of the variable, and take actions accordingly.

    Also, I set all of this on a General Stuff-event sheet, then include it on every Level-specific event sheets. This way I only need to create the events for each block once, and I can do fun stuff with each individual level if I want to (like scripting sequences etc.)

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Another way to do it would be to destroy the brick if it's on the last frame, otherwise move onto the next frame.

    [attachment=0:3g0vsjy0][/attachment:3g0vsjy0]

  • Interesting, I didn't know that. Thanks, I'll give it a try.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)