Clone Wars
Clone Wars
Clone Wars
Clone wars
Create a game in which you have to save the Earth
from space monsters
Step 1 Introduction
In this project you will learn how to create a game in which you have to save the Earth from space monsters.
What you will make
Score as many points as you can by shooting flying space-hippos. If you get hit by a hippo or by an orange
dropped by the bats, you lose a life.
If you have a Scratch account you can make a copy by clicking Remix.
Offline: download the starter project from rpf.io/p/en/clone-wars-go (https://rpf.io/p/en/clone-war
s-go), and then open it using the offline editor.
If you need to download and install the Scratch offline editor, you can find it at rpf.io/scratchoff (http
s://rpf.io/scratchoff).
Add this code to the spaceship sprite to make the spaceship move left if the left arrow is pressed:
when clicked
forever
change x by -4
The x-axis goes from the left side of the Stage to the right side. This means that the spaceship moves to
the left when you subtract from the value of the spaceship sprite’s x position. So this code block is the
part that makes your spaceship move left:
change x by -4
Add some more code inside the forever block to make your spaceship move to the right if the right
arrow key is pressed.
I need a hint
Here is the code you need to add below the other code inside the forever block:
change x by 4
Test your project by clicking the green flag. Can you press the arrow keys to make your spaceship move
left and right?
Step 3 Lightning bolts
Now you are going to give the spaceship the ability to fire lightning bolts!
You can search for a sprite, or browse for one by category. Click on a sprite to add it to your project.
When the game starts, the Lightning sprite should be hidden until the spaceship fires its laser
cannons.
Add this code to the Lightning sprite:
when clicked
hide
At the moment, the lightning bolt is really big compared to the spaceship!
Below the code that the Lightning sprite already has, add some blocks to make the sprite smaller and
to turn it upside down.
set size to 25 %
I need a hint
when clicked
forever
go to Spaceship
show
change y by 10
Press the space key to test whether the lightning bolt moves correctly.
Challenge!
Now you’re going to add lots of flying hippos that try to destroy your spaceship.
Create a new sprite with the ‘Hippo1’ image in the Scratch library. Use the shrink tool to make the Hippo
sprite a similar size to the Spaceship sprite.
Set the Hippo sprite’s rotation style to left-right.
Click on the direction and select the rotation style you want.
Add some code to hide the Hippo sprite when the game starts.
when clicked
hide
Add some code to the Stage to create a new Hippo clone every few seconds.
I need a hint
This is what your code should look like:
when clicked
forever
Each new hippo clone should appear at a random x position, and every clone should have a random speed.
Create a new variable called speed that is for the Hippo sprite only.
Type in the name of your variable. You can choose whether you would like your variable to be
available to all sprites, or to only this sprite. Press OK.
Once you have created the variable, it will be displayed on the Stage, or you can untick the
variable in the Scripts tab to hide it.
When you’ve done this correctly, the variable has the name of the sprite next to it, like this:
When each Hippo clone starts, pick a random speed and starting place for it. Then show the clone on
the screen.
show
Test your code. Does a new hippo appear every few seconds?
Each hippo should move around randomly until it gets hit by a lightning bolt. To make that happen,
attach this code below the blocks that are already in the Hippo sprite’s code script:
if on edge, bounce
Test your code again. You should see a new hippo clone appear every few seconds, and each clone
should move at a different speed.
Now test the spaceship’s laser cannon. If a lightning bolt hits a hippo, does the hippo vanish?
Step 5 Spaceship explosion
Draw another costume of an exploding spaceship, and call the new costume ‘hit’.
If you don’t want to draw the explosion, you can select the ‘Sun’ costume from the Scratch library, and
then use the Color a shape tool to change the costume’s colour and face.
Add some code to your Spaceship sprite so that it displays the ‘normal’ costume when the game
starts, and switches to the ‘hit’ costume when it touches a hippo:
when clicked
Test your code. Make the spaceship collide with a hippo. Does the spaceship change to the ‘hit’
costume?
Step 6 Hippos that disappear
When the spaceship explodes, all the hippos should disappear so that players of the game can recover.
Add code to the spaceship sprite to make it broadcast the message “hit” when the spaceship
touches a hippo.
when clicked
broadcast hit
All of the Hippo sprite clones will receive the “hit” message, and you can instruct them to disappear
when the spaceship is hit by adding this code to the Hippo sprite:
After the spaceship explodes, new Hippo clones appear, but the spaceship is still exploded! The spaceship needs
to reset itself after being hit.
Add a wait block at the end of the Spaceship sprite’s code to create a small pause before hippos
begin appearing again. Then add a forever block around all of your code to make the code run
repeatedly.
when clicked
forever
broadcast hit
wait 1 seconds
Challenge!
At the end of the game (or whenever you want to update the high score), you’ll need to check whether you
have a new high score.
Step 7 Space-bat
To make your game a bit harder, you are going to create a bat that throws oranges at the spaceship.
Make the Bat sprite move from left to right at the top of the Stage forever.
when clicked
set size to 50 %
forever
move 10 steps
if on edge, bounce
If you look at the bat’s costumes, you can see that it has four different ones:
Use the next costume block to make the bat flap its wings as it moves.
I need a hint
Your code should look like this:
when clicked
set size to 50 %
forever
move 10 steps
if on edge, bounce
next costume
Add code to your bat so that when the flag is clicked, the Bat sprite forever waits for a
random length of time between 5 to 10 seconds and then creates a clone of the Orange sprite.
when clicked
forever
when clicked
hide
go to Bat
show
change y by -4
Add some more code to the Orange sprite so that when an Orange clone hits the Spaceship sprite,
the clone also disappears to give the player a chance to reset:
Test your game. What happens if the spaceship gets hit by a falling orange?
Step 8 Game over
Next, you’re going to add a ‘game over’ message at the end of the game.
Your spaceship should start with three lives and lose a life whenever it touches a hippo or an orange.
Your game should stop when the lives run out.
Draw a new sprite called Game Over using the text tool.
On the Stage, broadcast a game over message just before the game ends.
when clicked
hide
show
Because you’ve used a broadcast (game over) and wait block on your Stage, the Stage will wait
for the Game Over sprite to be displayed before ending the game.
Test your game. How many points can you score? If the game is too easy or too hard, can you think of
ways to improve it?
Challenge!
Add health packs that you can collect to gain extra lives.
You’ll use the arrow keys to move your character around in the world.