Space Bat Tutorial - Step 4
4. Launch and destroy an object
Add a new Action to a Condition
Our first action will be to add an Action that allows Space Bat to fire a laser. We alreadyhave the rule that has an Action linked to pressing the Space Bar.
Right click the box under Space Bat and select Launch an Object.
The box to the right will open and the object we want to launch is laser fighter, so select that and click OK.
Launch an Object
In the box that opens, select Launch in selected directions… and select to the right in the box that opens.
Now you can press F8 to test your game again and this time when you press the space bar you fire an object.
The next step is to get our Active Object (the blue diamond) to launch the enemy aliens at us on a specific time interval.
Double Click the New condition and the box to the right will open.
Click the timer icon and select Every.
Set a Timed Interval Condition
The box below will open and we can change the Seconds row to 0 and change 1/100 to 50 and then click OK.
The new rule will appear as below.
Now we right click the Active Object box (in the same row as the rule we just made) and select Launch an object.
Launch Object in Multiple Directions
The box below will open and you will need to select Alien 2 and click OK.
In the next box select Launch in selected directions… and then select the 3 left arrows as shown below.
You can now test your game by pressing F8. You should be able to move Space Bat, fire lasers and enemies will be coming towards you.
The next part of the game will be to create collisions between our laser and the enemy.
Create a Collision between Objects
To create the collision we will need to make a new rule. Click the New condition and the box will open similar to the one below.
Select Laser Fighter and choose Collisions and then Another Object.
The object we want to collide with (or shoot!) will be Alien 2, so click the Alien, then click OK.
You will now have a new rule like the one below.
Destroy an Object
We now have our rule so we can go ahead and add a few actions.
The first thing we will do is right click the Enemy box (remember we are working on the Collision rule) and simply click Destroy.
Press F8 to test the game and you will see that when our laser hits the enemy the enemy object disappears.
Add to Score
Next we will add to our score each time we hit the enemy, this is a simple process. Right click the Joystick box and select Score and Add to Score.
In the box that appears add the number 1 and then click OK.
Press F8 to test your game and you will see your score increase with each hit.
Spread the word!
You can share this document using the following buttons.