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

Just started using Construct 2? Post your questions here

Post » Sun Mar 16, 2014 12:33 pm

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-) :mrgreen:

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?
B
5
S
1
Posts: 43
Reputation: 655

Post » Sun Mar 16, 2014 2:27 pm

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".
B
17
S
4
G
3
Posts: 172
Reputation: 1,933

Post » Sun Mar 16, 2014 2:37 pm

YES! That worked. Much appreciated. :D

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.)
B
5
S
1
Posts: 43
Reputation: 655

Post » Sun Mar 16, 2014 2:55 pm

Another way to do it would be to destroy the brick if it's on the last frame, otherwise move onto the next frame.

destroyBrickOnLastFrame.PNG
You do not have the required permissions to view the files attached to this post.
B
55
S
29
G
19
Posts: 1,520
Reputation: 25,650

Post » Sun Mar 16, 2014 3:47 pm

Interesting, I didn't know that. Thanks, I'll give it a try.
B
5
S
1
Posts: 43
Reputation: 655


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 0 guests