Adding the blocks

Now, we need to add blocks to the game. Click on the block sprite and add a Physics behavior.

Adding the blocks

Put the block in front of the cannonball and test it out by firing the cannon! This is shown in the following screenshot:

Adding the blocks

Destroying the cannonball on a complete stop

The cannonball just sits on the screen and doesn't move. We should then add some logic to destroy it after it hits a block. Add a Compare velocity event to the cannonBall sprite.

Destroying the cannonball on a complete stop

The velocity that we are going to compare is Overall velocity, and we are going to set Comparison to ≤ Less or equal with value 0.1. This is shown in the following screenshot. The reason we don't want to set the value to zero is that our object may still have a tiny amount of velocity (for instance, of value 0.00001); but as it has not quite made it to zero, the event would not be activated.

Destroying the cannonball on a complete stop

When the cannonball almost comes to a complete stop, we want to destroy it. Add a Destroy object action to the event, as shown in the following screenshot:

Destroying the cannonball on a complete stop

Delaying cannonball destruction

Run the game. When the cannonball stops, it is reset very abruptly. In order to make this easier for the game to handle, we will add a Wait action.

Delaying cannonball destruction

Let's wait for a few seconds; we will set the value of Seconds to 2.5 seconds, as shown in the following screenshot:

Delaying cannonball destruction

We also need to move the action up in the order of actions. Highlight it and drag it to the top. Remember that the actions are read line by line, which means that the first action will happen first, and so on. In this case, it will wait for 2.5 seconds and then destroy the object. Run the game and try it out.

Delaying cannonball destruction
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.142.166.31