Lost in Space

Download as pdf or txt
Download as pdf or txt
You are on page 1of 21

1/26/23, 11:02 AM Lost in space

Projects

Lost in space
Learn how to program your own animation!

Step 1 Introduction

You are going to learn how to program your own animation!


What you will make

What you will need


Hardware
A computer capable of running Scratch 3
Software
Scratch 3 (either online (https://rpf.io/scratchon) or offline (https://rpf.io/scratchoff))
Downloads
None

https://projects.raspberrypi.org/en/projects/lost-in-space/print 1/21
1/26/23, 11:02 AM Lost in space

What you will learn


Use a repeat loop to animate a sprite in Scratch
Use a forever loop to repeat an animation indefinitely
Understand that loops can be nested within each other

Additional information for educators


If you need to print this project, please use the printer-friendly version (https://projects.raspberrypi.org/e
n/projects/lost-in-space/print).
You can find the completed project here (https://rpf.io/p/en/lost-in-space-get).

https://projects.raspberrypi.org/en/projects/lost-in-space/print 2/21
1/26/23, 11:02 AM Lost in space

Step 2 Animating a spaceship

Your first step will be to create a spaceship that flies towards the Earth!

Open a new Scratch project.


Online: open a new online Scratch project at rpf.io/scratch-new (https://rpf.io/scratchon).

Offline: open a new project in 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).

https://projects.raspberrypi.org/en/projects/lost-in-space/print 3/21
1/26/23, 11:02 AM Lost in space

Add ‘rocketship’ and ‘Earth’ sprites to your Stage.

Add a sprite from the Sprite Library


Click on Choose a Sprite to open the Sprite Library:

You can search for a sprite, or browse for one by category. Click on a sprite to add it to your project.

https://projects.raspberrypi.org/en/projects/lost-in-space/print 4/21
1/26/23, 11:02 AM Lost in space

Add the ‘Stars’ backdrop to your Stage.

Click on your spaceship sprite, and click on the Costumes tab.

Use the arrow tool to click and drag a box around the whole spaceship image. Then click on the circular
rotate handle, and rotate the image until it is on its side.

https://projects.raspberrypi.org/en/projects/lost-in-space/print 5/21
1/26/23, 11:02 AM Lost in space

Add this code to your spaceship sprite:

when clicked

point in direction 0

go to x: -150 y: -150

say Let's go for 2 seconds

point towards Earth

glide 1 secs to x: 0 y: 0

Change the numbers in the code blocks you’ve added so that the code is exactly the same as above.

If you click the green flag, you should see the spaceship speak, turn, and glide towards the centre of the stage.

https://projects.raspberrypi.org/en/projects/lost-in-space/print 6/21
1/26/23, 11:02 AM Lost in space

Challenge!

Challenge: improve your animation


Can you change the numbers in your animation code so that:
The spaceship moves until it touches the Earth?
The spaceship moves more slowly towards the Earth?
You’ll need to change the numbers in this block:

glide 1 secs to x: 0 y: 0

Scratch coordinates
Scratch coordinates
In Scratch, the coordinates x:0, y:0 mark the central position on the Stage.

A position like x:-200, y:-100 is towards the bottom left on the Stage, and a position like x:200, y:100 is
near the top right.

You can see this for yourself by adding the Xy-grid backdrop to your project.

https://projects.raspberrypi.org/en/projects/lost-in-space/print 7/21
1/26/23, 11:02 AM Lost in space

https://projects.raspberrypi.org/en/projects/lost-in-space/print 8/21
1/26/23, 11:02 AM Lost in space

Step 3 Animation using loops

Another way to animate the spaceship is to tell it to move a small amount many times

Delete the glide block from your code. To do this, drag the block off the Code area and drop it back
where the other single code blocks are.

when clicked

point in direction 0

go to x: -150 y: -150

say Let's go for 2 seconds

point towards Earth

glide 1 secs to x: 0 y: 0

https://projects.raspberrypi.org/en/projects/lost-in-space/print 9/21
1/26/23, 11:02 AM Lost in space

Now use a repeat block to move your spaceship towards the Earth.

when clicked

point in direction 0

go to x: -150 y: -150

say Let's go for 2 seconds

point towards Earth

repeat 200

move 2 steps

Test and save your code. Your spaceship should move towards the Earth exactly as before, but this time
it uses a repeat block.

https://projects.raspberrypi.org/en/projects/lost-in-space/print 10/21
1/26/23, 11:02 AM Lost in space

Next add code to your spaceship sprite so that the spaceship changes colour as it moves towards
Earth?
Use this block:

when clicked

point in direction 0

go to x: -150 y: -150

say Let's go for 2 seconds

point towards Earth

repeat 200

move 2 steps

change color effect by 25

Test and save your code.

https://projects.raspberrypi.org/en/projects/lost-in-space/print 11/21
1/26/23, 11:02 AM Lost in space

Can you make your spaceship get smaller as it moves towards Earth?

I need a hint
Your code should look like this:

when clicked

set size to 100 %

point in direction 0

go to x: -150 y: -150

say Let's go for 2 seconds

point towards Earth

repeat 200

move 2 steps

change color effect by 25

change size by -0.3

Test and save your code. Your spaceship should now get smaller as it moves. Test your spaceship a second time.
Is it the right size when it starts?

https://projects.raspberrypi.org/en/projects/lost-in-space/print 12/21
1/26/23, 11:02 AM Lost in space

https://projects.raspberrypi.org/en/projects/lost-in-space/print 13/21
1/26/23, 11:02 AM Lost in space

Step 4 Floating monkey

Now you will add a monkey who’s lost in space to your animation!

Start by adding the ‘monkey’ sprite from the library.

Click on your new monkey sprite and then click on Costumes so that you can edit how the monkey looks.

Set the fill to be transparent by selecting the red line. For the outline, set a white colour by moving the
Saturation slider to 0.

https://projects.raspberrypi.org/en/projects/lost-in-space/print 14/21
1/26/23, 11:02 AM Lost in space

Click on the circle tool and then use it to draw a white space helmet around the monkey’s head.

Can you add code to your monkey sprite so that it spins slowly in a circle forever?

I need a hint
Here’s the code to make your monkey spin:

when clicked

forever

turn 1 degrees

Test and save your project. You’ll have to click on the red stop button to end this animation, as it runs forever!

https://projects.raspberrypi.org/en/projects/lost-in-space/print 15/21
1/26/23, 11:02 AM Lost in space

Step 5 Bouncing asteroid

Now you will add a floating space rock to your animation.

Add a ‘rock’ sprite to your animation.

https://projects.raspberrypi.org/en/projects/lost-in-space/print 16/21
1/26/23, 11:02 AM Lost in space

Can you add code for your rock sprite so that the rock bounces around the stage?

I need a hint
Here’s the code for making your rock bounce around the stage:

when clicked

point towards Earth

forever

move 2 steps

if on edge, bounce

https://projects.raspberrypi.org/en/projects/lost-in-space/print 17/21
1/26/23, 11:02 AM Lost in space

Step 6 Shining star

Now you will combine loops to make a shining star.

Add a ‘star’ sprite to your stage.

https://projects.raspberrypi.org/en/projects/lost-in-space/print 18/21
1/26/23, 11:02 AM Lost in space

Can you add code to your star sprite to make the star repeatedly grow and shrink?

I need a hint
Here’s the code to make your star grow and shrink:

when clicked

forever

repeat 20

change size by 2

repeat 20

change size by -2

https://projects.raspberrypi.org/en/projects/lost-in-space/print 19/21
1/26/23, 11:02 AM Lost in space

Challenge!

Challenge: make your own animation


Stop your space animation, save it, and start a new Scratch project.
Use what you’ve learned in this project to make your own animation. It can be anything you like, but try to make
your animation match the background you choose. Here are some examples:

https://projects.raspberrypi.org/en/projects/lost-in-space/print 20/21
1/26/23, 11:02 AM Lost in space

Step 7 What next?

Try the Ghostbusters (https://projects.raspberrypi.org/en/projects/ghostbusters?utm_source=pathway&u


tm_medium=whatnext&utm_campaign=projects) project! In that project, you will learn how to create a game
with ghosts that appear all over the place and that you need to catch. You will also learn how to add a timer and a
score to the game, so that you can see how many ghosts you are able to catch.

Published by Raspberry Pi Foundation (https://www.raspberrypi.org) under a Creative Commons


license (https://creativecommons.org/licenses/by-sa/4.0/).
View project & license on GitHub (https://github.com/RaspberryPiLearning/lost-in-space)

https://projects.raspberrypi.org/en/projects/lost-in-space/print 21/21

You might also like