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

MAKE APPLY SOLVE PROBLEM IMPLEMENT

Game Design with Scratch (E531C)


Learn game mechanics using graphical programming.

Details of this courseware can be


found at http://chumbaka.asia
2
This book belongs to

Scratch is a project of the Lifelong Kindergarten Group at the MIT Media Lab. It is provided free of charge. With Scratch, you can
program your own interactive stories, games, and animations — and share your creations with others in the online community.
Super Mario is a platform video game developed and published by Nintendo as a pseudo-sequel to the 1983 game, Mario Bros.
Arkanoid is an arcade game released by Taito in 1986. Pac-Man is an arcade game developed by Namco, first released in Japan as
Puck Man in May 1980 and was licensed for distribution in the United States by Midway Games and released in October 1980. Angry
Birds is a video game franchise created by Finnish company Rovio Entertainment. Pivot Animator is a stickman animation software
that is provided free for personal and commercial use. Piskel is a free online editor for animated sprites or pixel art.

The information in this manual has been obtained from sources believed to be reliable. The author does not guarantee the accuracy
or completeness of any information presented herein, and shall not be responsible for any errors, omissions or damages as a result of
the use of this information. No part of this manual may be reproduced, copied, or distributed in any form or by any means without
expressed written consent from Chumbaka Sdn Bhd.

© 2016 – 2019 Chumbaka Sdn Bhd Version A.01.02

3
Read Me First
Before starting the lesson, please have the following items ready.

1. Computer (with heavy use of mouse or touchpad) running Windows or macOS with
Google Chrome browser

2. E531C Mentor Folder.zip (download from https://forum.chumbaka.asia  mentor’s


thumb drive student’s desktop)

3. Internet connection for mentor

4
This page is intentionally left blank.

5
Lesson Scorecard
A1 - Play the Super Mario game.
Software Setup Set up Scratch Desktop. 10
Play Super Mario Get a feel of the Super Mario game. 11
Scanner and Plotter Plot coordinate values on paper with your buddy. 13
B1 - Learn about variables and programming multiple sprites.
Pong Game Create a bouncing ball game. 22
Two-Player Pong Remix the Pong game into a two-player game. 30
C1 - Learn motion sensing and use variables to flag conditions.
Photo Booth Add funny props to a photo. 44
Air Mouse Interact with sprites by waving your hands in front of 55
your computer’s webcam.
D1 - Learn about animation and graphic design.
Create 2D Animation Learn the basic features of Pivot Animator. 64
Animate with Piskel Create more advanced 2D animation. 73
E1 - Learn about projectile motion.
Jump Up in Space Simulate motion when there’s no gravity. 86
Jump Up on Earth Simulate motion when there is gravity. 88
Jump at an Angle Simulate motion when jumping at an angle. 90
F1 - Learn about X-Y coordinates, flowcharts, and Boolean.
Navigation Make a sprite walk and jump. 96
Ground or Air Program the sprite to interact with ground. 100
Animation Animate the sprite to appear to be walking or falling. 104
G1 - Learn about relative movement for animation.
Relative Movement Animate with relative movement. 122
World Construction Create the world for your game. 126
H1 - Learn about hiding sprites, broadcasting, and using text-to-speech.
Music Add background music and sound effects. 146
Collision Detection Detect which part of the sprite collides with other sprites. 149
I Spy Game Play a guessing game with your friends. 156

6
I1 - Learn to create an end-game condition.
Game Start Create the start screen and actions when the game starts. 166
Game Complete Create the actions when the game is completed. 169
Game Over Implement the actions when the game ends. 175
J1 - Learn to create a scoring system using sprites.
Collect Coins Create a scoring system based on the coins collected. 188
Goomba Add Goomba and program its actions. 196

______
Total Score
of 25

7
Challenge Scorecard
Signature
Project Guardian Mentor Guardian Mentor
Green Challenge Red Challenge

A2 Play Blockly to learn coding concepts. 16

B2 Create an Arkanoid-based game. 36

C2 Create Air Music. 58 – –

D2 Complete each other’s story. 84 – –

E2 Create a projectile-based game. 92

F2 Create a falling mouse game. 108

G2 Create a flight simulator game. 136

H2 Create an Eye-Spy game. 158

I2 Create a Space Invaders-based game. 180

J2 Create your version of Pac-Man. 202

Total Score ______ ______


of 10 of 8

8
Final Project Scorecard
Signature
Project
Guardian Mentor

Present your final project.

______
Total Score
of 1

Digital Badge Criteria

Feedback Completed Completed Completed Completed


Lesson 23 23 23 23
Green Challenge 5 9 9 9
Red Challenge — — 4 8
Final Project — — Completed Completed

To be eligible for a digital badge, you need meet the criteria above. Ask your mentor and guardian
for their signatures as proof of completion. When you’ve completed the programme, take a photo
of these scorecards and upload it to your Chumbaka backpack account.

9
A1 Play the Super Mario game.

Software Setup
Set up Scratch Desktop.

1 Set up Scratch Desktop.

Open E531C Mentor Folder.

For Windows, double-click Scratch Desktop 3.3.0.exe


and follow the instructions.

For macOS, double-click Scratch Desktop 3.3.0.dmg.


Move Scratch Desktop into Applications.

10
Play Super Mario
Get a feel of the Super Mario game.

1 Load the Super Mario game and try it out!

Launch Scratch Desktop.

Open Super Mario


Bros.sb3 from E531C
Mentor Folder.

Start the game.

11
Super Mario Bros is a platform video
game developed and published by
Nintendo as a pseudo-sequel to the
1983 game, Mario Bros.

It is the first of the Super Mario series


of games. In Super Mario Bros., the
player controls Mario, and in a two-
player game, a second player controls Mario's brother Luigi, as he travels
through the Mushroom Kingdom to rescue Princess Toadstool from the
antagonist Bowser.

In 2005, IGN's poll named the "pioneering" and "highly influential" title as
the "greatest game of all time", considering it to have aided in
resurrecting the crashed American video game market of the 1980s. The
game has also sold enormously well, and was the best-selling game of all
time for a single platform for approximately three decades at over 40
million units until Nintendo's Wii Sports took that title.

(Article adapted from Wikipedia)

You will create your own Mario game


by the end of this book!

12
Scanner and Plotter
Plot coordinate values on paper with your buddy.

1 Prepare the materials.

graph paper color pencils/marker

16
15
14
13
12
11
10
9
8
Draw the X-Y axis and
7 number the grid.
6
5
4
3
2
1
0 X
10
11
12
13
14
15
1
2
3
4
5
6
7
8
9
0

13
2 Transfer a simple image between you and your buddy.

With your buddy, decide your roles.

The scanner will transfer a simple


scanner plotter image to the plotter.

16
15
14
13
X X X X X X
12
X X X X
11 Without showing the plotter,
X X X X
10
X X X
draw a simple shape on your
9
X X
8
X X graph paper. Here’s an example.
7
X X
6 Try other simple shapes that
X X
5
X X
you fancy.
4
X X
3
X
2
1
0 X
10
11
12
13
14
15
1
2
3
4
5
6
7
8
9
0

(1, 9), (1,10), (1,11),


(1,12), (2,8), (2,13)…

scanner plotter

If you are a scanner, If you are the plotter, plot the shape
transfer the coordinates on your graph paper.
to the plotter.
When you’re done, show the scanner.
Was the image transferred correctly?
14
3 Swap roles and transfer a more complicated image.

scanner plotter

When you’re done, show the scanner.


Was the image transferred correctly?

15
A2 Play Blockly to learn coding concepts.

Recap
Learning from previous chapter.

1 Watch a video (0:58) of what’s possible with Scratch.

Watch E531C Mentor Folder/Videos/


Scratch 3 Overview.mp4.

2 X-Y coordinates let you determine a point on a map or graph.

Y
The horizontal direction is called X.

The vertical direction is called Y.


(3,2)
×
Point (3,2) is 3 units in X direction
and 2 units in Y direction.

16
Blockly CHALLENGE

Play Blockly levels to understand coding concepts.

1 Launch Blockly.

Open E531C Mentor Folder/blockly-games/


index.html.

This program is also available online at


https://blockly-games.appspot.com. We recommend you use the
Chrome Web browser.

2 Play Maze and learn about sequence.

Complete Maze until level 5.

17
3 Play Bird and learn about conditionals.

Complete Bird until level 3.

4 Play Turtle and learn about loops and angles.

Complete Turtle until level 3.

18
5 Play Movie and learn about x-y coordinates.

Complete Movie until level 1.

19
Blockly Advanced CHALLENGE

Play more Blockly levels to understand more coding concepts.

1 Play Music and learn about functions.

20
2 Continue with the earlier stages and see how far you can go.

21
B1 Learn about variables and programming multiple sprites.

Pong Game
Create a bouncing ball game.

1 Add and modify a backdrop.

Launch Scratch Desktop.

Pick a backdrop you fancy.

If you’ve completed Physical Computing, you may have


created this Pong game before. However, we recommend
you go through all the pages as a form of revision.

22
Pick a color.

Select the
Line tool.

We want a
thick line so
In this example, we increase the
choose red. width.

Draw a red line across the


bottom of the backdrop.

23
2 Add a ball and have it bounce off the edges of the Stage.

Pick a ball sprite you fancy.

Delete the cat.

Make the ball move and then bounce


when it reaches the edges.

Click to run the program. Does the


ball bounce off the edges?

Let’s make things more interesting.

24
Move your ball to a starting position.

Notice the X and Y values change to


where you place the ball.

Make the ball go to its starting


position and start moving at a
45 degree angle.

Try it out! Does the ball bounce all


over the Stage?

25
3 Add a paddle and have it follow your mouse pointer.

Pick a paddle sprite you fancy.

Adjust the size of the paddle.

Make the paddle follow your


mouse pointer.

Try it out!

26
4 Make the ball bounce off the paddle and make a sound.

Make the ball play a


sound when it
touches the paddle.

Then, turn the ball


180 degrees and wait
1 second.

Try it out!

27
5 Stop the game if the ball touches the red line.

Stop the game if the ball


touches the red line.

Pick the right shade of red.

28
6 Create a scoring system.

Create a variable score.

Set the score to zero when


the program starts.

Increase the score if the


ball touches the paddle.

Try it out! Who can get the


highest score?

Save your work! Let’s call it


One-Player Pong. We will
use this again later.

29
Two-Player Pong
Remix the Pong game into a two-player game.

1 Add another line to the backdrop.

Draw another red line.

2 Add another paddle for the second player and modify the controls.

Create a new paddle.

30
Draw an orange paddle.

Resize the orange


paddle to the same size
as the green paddle.

31
Set the starting position of the
two paddles.

Delete this script for both paddles.

We will use the keyboard to control


the paddles.

Create scripts to do the following:

Orange paddle:
Press the Z key to move left.
Press the X key to move right.

Green paddle
Press the left arrow key to move left.
Press the right arrow key to move right.

32
3 Create a scoring system for two players.

Rename this variable to


playerOne.

Create another variable


playerTwo.

Right-click and
duplicate this
script.

Modify such that playerTwo


gets a point when the ball
bounces off the orange
paddle.

33
Try it out! Play
with your buddy
and see who gets
the higher score.

Remember to save your work!


Let’s call this Two-Player Pong.

34
This page is intentionally left blank.

35
B2 Create an Arkanoid-based game.

Recap
Learning from previous chapter.

1 A variable is like a container that holds a name or a number.

Do you know the


answers?

36
2 In Pong, you added ball and paddle objects into the Stage. They are
called sprites.

The game environment is made up of sprites,


where each sprite can be programmed to interact
with each other.

In two-dimensional (2D)
games, sprites can be a
static image or animated.

Sprites can also be resized


and rotated to give the
illusion of three-
dimensional (3D) graphics.

37
Arkanoid CHALLENGE

Create a game based on Arkanoid.

In Arkanoid, you bounce a


ball to destroy the bricks.

1 Add a brick.

Open the one-player


Pong game you created
earlier.

Pick a brick sprite you fancy.

38
Adjust the size to your fancy.

Drag the brick to a starting position.

Notice that the X and Y values change


to the new position.

When the program starts, make the


brick go to its starting position and
show itself.

If the brick touches the ball, make it


disappear after 0.1 second.

Try it out. Have difficulty destroying


the brick? Why is that?

39
2 Change how the ball bounces.

Try different angles. Which


angle works best?

Add these blocks such that the ball bounces off the brick.

When you make changes to a


running program, you need to
STOP and re-START for the
changes to be effective.

40
3 Add more bricks.

Make a copy of the brick.

Drag the new brick to a starting


position you fancy.

Make the new brick go to its


starting position.

41
Add these blocks such that the ball
bounces off either bricks.

Try it out! Does the ball


bounce off all the bricks?

42
Arkanoid Enhanced CHALLENGE

Add more features and capabilities to the game.

1 Enhance the game with at least 3 of the features below or any


other cool features you can think of:

1. Player scores points when a brick is destroyed.

2. The game stops when the ball touches the bottom edge or
when all the bricks have been destroyed.

3. Different bricks score different points.

4. Add sound effects when a brick is destroyed.

5. Create more levels with different brick arrangements.

6. Create starting/ending screens with background music.

Swap games with your buddy.


See if you can add cool
features to your game.

43
C1 Learn motion sensing and use variables to flag conditions.

Photo Booth
Add funny props to a photo.

1 Here’s the photo booth you will create.

Click and drag a prop


to add it to the photo.

Click these controls to


resize the props.

Start a new Scratch


program.

44
2 Take a photo as the backdrop.

Delete this sprite.

Use your webcam to capture a


photo of your buddy.

Do you see a photo appear?

If you don’t have a webcam, you can


also take a photo with your phone.
Save the photo to your computer and
then upload the photo.

45
3 Add a prop: moustache.

Upload sprite from E531C


Mentor Folder/Media/Photo
Booth/moustache.png.

Resize the moustache


and move it here.

46
Move to the starting
position when the
program starts.

Create a clone of the sprite


and wait for 1 second if
the mouse pointer touches
the sprite AND the mouse
is clicked.

Make the clone go to the


frontmost layer and use
variable SizeMoustache
to store the starting size.

Constantly set the


moustache size according
to SizeMoustache.

Try it out! How many


moustaches can you add?

47
4 Add a control: enlarge.

Upload sprite from E531C


Mentor Folder/Media/Photo
Booth/enlarge.png.

Resize and move it here.

Move the control to its


starting position when
the program starts.

Increase value of
SizeMoustache when
the mouse pointer
touches the control AND
the mouse is clicked.

48
Try and click the sprite and observe
how the value change.

Why doesn’t the value increment one unit at


a time?

The program runs so quickly that before you


can release your mouse button, the program
detects you’re still pressing the sprite. As a
result, the value continues to increase.

Let’s fix this.

Add this block such that the button waits


0.25 seconds after increasing the size.

Try it out! Observe the SizeMoustache


variable. Does it increase step-by-step now?

49
5 Add a prop: spectacles.

Upload this sprite from E531C


Mentor Folder/Media/Photo
Booth/spectacles.png.

Resize and position it


accordingly.

Copy these scripts from


moustache.

Modify accordingly for


the spectacles.

Try it out! Can you


resize the spectacles?

You can’t because the


program doesn’t know
which prop is selected.

Let’s fix this.

50
To copy a script from one sprite to another, drag the script and
release it at the destination sprite.

To determine which prop is selected, create the


variable Prop and assign different values to it.

For each sprite, modify


their scripts as follows:

 when moustache is cloned, Prop = 1


 when spectacles is cloned, Prop = 2

51
Increase the
moustache size if
it is selected.

Add these blocks to enlarge


the spectacles if it is selected.

Try it out! Can you enlarge


both props now?

52
6 Add the remaining control: shrink.

Upload this sprite from


E531C Mentor Folder/
Media/Photo Booth/
shrink.png.

Resize and position


accordingly.

Copy this script from


enlarge.

Modify such that the


button can reduce
the size of the
moustache or
spectacles.

Try it out! Can you


shrink the props?

53
7 Add audible feedback for props and controls.

Add a sound you fancy.

Make a sound when the moustache


is cloned.

Add sounds to the remaining prop


and controls.

When you’re
done, try it out!

54
Air Mouse
Interact with sprites by waving your hands in front of your computer’s webcam.

1 Control your webcam.

Start a new Scratch program.

Add the Video


Sensing extension.

Do you see
yourself in the
Stage?

If you don’t have a webcam,


you can substitute with a mouse.

55
2 Try out the webcam.

Run this script.

See how the number change


when you touch the cat.

3 Program the cat to respond to your gestures.

Make a sound when you


touch the cat.

Try it out! Can you hear the cat


meow when you touch it?

56
Make the cat meow louder
when you touch it more
vigorously.

Try it out!

If you don’t have


a webcam,
use the slider to
change loudness. .

Add more animal sprites and


program them to make different
sounds when you touch them.

57
C2 Create Air Music.

Recap
Learning from previous chapter.

1 With a webcam, you can program Scratch to detect


motion over a sprite using this extension.

Watch E531C Mentor Folder/Videos/


Example of Gesture Controls.mp4 for an
example of how gesture control is used in
real-life.

2 A variable can be used to determine (or flag) which sprite is selected.

58
Air Music CHALLENGE

Create a virtual touch pad that you play by moving your fingers in the air.

1 Create a touch pad.

Start a new Scratch program.

Add the Video


Sensing and
Music extensions.

If you don’t have a webcam,


you can substitute with a mouse.

59
Create a new sprite.

Draw a shape you fancy.

Make the sprite change


colour and play a note
when you touch it.

Try it out!

60
2 Select different instruments to play.

Add four musical


instruments you fancy.

You will use your finger


to select the instrument
to play.

To determine which instrument is selected, create the


variable instrument and assign different values to it.

For each instrument, create scripts as follows:

 when keyboard is selected, instrument = 1


 when guitar is selected, instrument = 2
 when trumpet is selected, instrument = 3
 when drum is selected, instrument = 4

61
Set the type of instrument
depending on which
×4 instrument is selected.

×4

×4

×4

3 Create 3 more touch pads.

Make 3 more copies of this sprite.

62
Try it out! Can you play
different notes from different
instruments?

4 Form a band with your buddy.

Each person
plays 4 notes.

Together you can


play one octave
(8 notes).

C(60) D(62) E(64) F(65) G(67) A(69) B(71) C(72)

Working together, perform a


song to the class!

63
D1 Learn about animation and graphic design.

Create 2D Animation
Learn the basic features of Pivot Animator.

1 Watch a video (15:14).

Watch E531C Mentor Folder/


Videos/Pivot Animator
Tutorial.mp4 for a quick
introduction to Pivot Animator.

Source: http://bit.ly/2Qaz9nG

2 Install Pivot Animator.

Open E531C Mentor Folder.

Double-click Pivot Animator v4.2.6.msi


and follow the instructions.

Work with your buddy if


you do not have a
Windows computer.

64
3 Create your first animation.

Click Start and key in pivot animator.


Press Enter to launch the software.

Animate the next frame.

65
c

Drag the red points to move


the stickman’s hands and legs.

Animate the next frame.

Drag the orange point to move


the stickman.

Animate the next frame.

66
c
c
Continue creating more frames.

c
c
c
c
c

c
c

In the last
frame, click
to delete the
stickman.

You can create other


animation you fancy.

67
Start the animation.

68
4 Add the animation to Scratch.

Export your animation.

Select Gif and then Save.

Click OK.

69
Start a new Scratch
program.

Delete this sprite.

Upload the stickman


sprite you created
earlier.

In Costumes, you can see a costume for


every frame of your animation.

70
Move the stickman to the
middle of the Stage.

Add a scary sprite, for example, a ghost.

For the ghost sprite, create


this script.

Try it out. Does the ghost


animate?

71
Select the stickman.

Add two sounds you fancy.

Create this script.

Try out the program and watch the


mini movie you created.

Don’t forget to save your


program so you can watch it
again later.

72
Animate with Piskel
Create more advanced 2D animation.

1 Install and launch Piskel.

Open E531C Mentor Folder.

For Windows, extract Piskel v0.14.0.zip.

Piskel.zip

Open the folder and


double-click this file.
Piskel
Piskel

For macOS, double-click Piskel v0.14.0.dmg.

Piskel.dmg

Piskel Applications

73
2 Create an animation.

Select the Pen tool.

74
Draw this circle using your mouse.

Left-click to draw Right-click to erase

75
Display the color palette.

Drag the slider and click on


the palette to choose yellow.

Draw the fuse.

Complete the drawing


of a bomb.

76
Duplicate this frame 3
times.

Modify the new frames as follows:

77
3 Add the animation to Scratch.

Export your animation.

Save the animation as a GIF.

Name your file and then Save.

78
Start a new Scratch
program.

Delete this sprite.

Upload the bomb sprite


you created earlier.

79
Resize the sprite.

Create this script.

This block sends a message to


another sprite.

80
Upload backdrop from E531C
Mentor Folder/Media/Piskel/
Bomb.jpg.

Create these scripts.

This is triggered from the


bomb sprite.

81
Select this sprite and add these sounds:

Add from the library.

Add from Mentor Folder/Media/


Piskel/Bomb.mp3.

Create a ticking bomb sound.

×4

82
When your program gets more
complex, you can right-click to
clean up the workspace. The
blocks will be rearranged nicely.

83
D2 Create a story using what you learned.

Recap
Learning from previous chapter.

1 Watch a video (0:27) to see how flipbooks work.

Watch E531C Mentor Folder/


Videos/Flipbook Example.mp4.

Source: http://bit.ly/2Qaz9nG

A flipbook has a series of pictures that change gradually from one


page to the next. This is similar to how you created animation with
Pivot Animator and Piskel. When the individual images (or frames) are
shown quickly, the pictures appear to animate.

84
Complete Each Other’s Story CHALLENGE

Create a 2-minute animation.

1 Get some ideas by watching examples of animation created in Scratch.

Scratch World Animation Piano Tutorial Music Video


http://bit.ly/2wKNTh3 http://bit.ly/2wIXYeB http://bit.ly/2wKOpvv

2 You and your buddy start


on the first part of a story.

You then pass on to Team


Team 1 Team 2
2 to complete your story.

Team 2 does the same—passes to you to complete their story.

3 Share your completed story with the class in the next lesson.

85
E1 Learn about projectile motion.

Jump Up in Space
Simulate motion when there’s no gravity.

1 Program the cat to jump.

Start a new Scratch


program.

Shrink the cat and move


it lower on the Stage.

86
When the program starts, move the cat to
its initial position and set its initial
velocity (u).

When space is pressed, move the cat


upwards until it touches the edge of the
Stage.

Try it out!

This is what happens if you jump


and there’s no gravity. You keep
moving unless something stops
you. This is called Newton’s first
law of motion.

87
Jump Up on Earth
Simulate motion when there is gravity.

1 Include gravity into the program.

Set gravity (a).

2 Make the cat jump, with gravity.

Reset the timer when


space is pressed.

With gravity, the velocity (v) will


change over time (t).

Replace u with v, where

v=u+a*t

88
Try out the program and
see how differently the
cat jumps.

With gravity on Earth,


the cat gets pulled back.

3 Simulate jumping on different planets.

Find out what’s the


gravity on different
planets.

Modify your program


accordingly.

Try it out! See what


happens.

Mars

Jupiter

89
Jump at an Angle
Simulate motion when jumping at an angle.

1 Make the cat jump at an angle.

Move the cat to the side.

The cat will jump from this


location.

Modify to the cat’s new


position and reset variable
a to Earth’s gravity.

Define the value for angle.

Breakdown u u(y) u

to horizontal
velocity (u(x))
and vertical
velocity (u(y)).
u(x)

90
Replace with these blocks.

Try it out! Observe the motion of the cat.

Try changing gravity. See what happens.

Remember to save your


work. You will use it again
in the next lesson.

91
E2 Create a projectile-based game.

Recap
Learning from previous chapter.

1 Watch a video (2:18) about projectile motion.

Watch E531C Mentor Folder/


Videos/Projectile
Motion.mp4 to understand
the forces at work when you
throw an object at an angle.

92
Angry Bird CHALLENGE

Create a version of the Angry Bird game.

1 Change the angle using your mouse.

Open the Jump at an


Angle program you
created earlier.

Modify your script such that


angle is set using your mouse
pointer.

Try it out. Set the angle using your mouse


pointer, and then press space.

What angle results in the farthest jump?

93
2 Watch a video (1:06) to see how Angry Bird is played.

Watch E531C Mentor Folder/


Videos/Angry Birds.mp4.

3 Create your version of an Angry Bird game, where you launch


things and mimic their movement using projectile motion.

Ready… aim…

94
Angry Bird Enhanced CHALLENGE

Add more features and capabilities to the game.

1 Enhance the game with at least 3 of the features below or any other
cool features you can think of:

1. Score a point when projectile hits targets.

2. Create sound and graphic effects when projectile hits targets.

3. Add more levels, with increasing difficulty, to the game.

4. Make targets fall, bounce, or roll off when hit.

5. Have the projectile make a smoke trail.

Play each other’s game. Find out who


gets the highest score!

95
F1 Learn about X-Y coordinates, flowcharts, and Boolean.

Navigation You will start creating


Make a sprite walk and jump. your Mario game!

1 Move the cat to the right.

Start a new Scratch


program.

Move the cat to the right


when you press the right
arrow key.

Try it out!

96
2 Move the cat to the left.

Duplicate these blocks.

Modify the duplicated block


such that the cat moves to the
left when you press the left
arrow key.

Can you move the cat left


and right?

97
3 Move the cat up and down.

Duplicate these blocks.

Modify these blocks such that


the cat moves up when you
press the up arrow key and
moves down when you press
the down arrow key.

Can you move the cat around


the Stage?

98
4 Make the cat fall with acceleration.

Initialise velocity when the


program starts.

Change velocity by –0.5 every


time the script loops.

Change value of y by velocity


value.

Try it out! Does the fall look more realistic?

How would you make the cat fall slower?

99
Ground or Air
Program the sprite to interact with ground.

1 Add the Floor sprite to the Stage.

Upload sprite from E531C Mentor


Folder/Media/Terrain/Floor.svg.

Move the Floor to position (0, –160) when


the program starts.

180
y

–240 240
x

Centre of the sprite


is in position
(x=0, y=–160)

–180

100
2 Check if the cat touches the ground.

Assemble these blocks such that


if the cat touches the Floor,
ground = 1 and
velocity = 0.

Otherwise, ground = 0.

With this script running, we can find


out if the cat is on the Floor or in the
air by simply checking the value of
the variable ground.

101
3 The cat falls only when it is in the air.

Make the cat fall


only when it is in
the air.

Try it out! Does the cat stop falling when


it reaches the ground?

102
4 The cat jumps only when it is on the ground.

Replace with these blocks to


make the cat jump only when it
is on the ground.

Try it out! Does the cat jump?

How can you make the cat jump higher?

103
Animation
Animate the sprite to appear to be walking or falling.

1 Add Mario’s costumes.

Upload all Mario’s costumes from


E531C Mentor Folder/Media/
Mario.

Hold the CTRL key and click to


select more than one costume.

104
Delete these costumes.

A flowchart is a type of diagram representing a logical flow or an


algorithm. For example, the script below can be represented by the
flowchart on the right.

Start

Right arrow THEN


pressed? Change x by 10

Change x by –10

Stop

105
Start

Costume=Walk-R1
Wait 0.05s
Right arrow THEN Costume=Walk-R2 To animate Mario, we
key pressed? Wait 0.05s
Costume=Walk-R3
change Mario’s
Wait 0.05s costume quickly when
the right arrow or left
arrow key is pressed.

Costume=Walk-L1
Wait 0.05s
Left arrow THEN Costume=Walk-L2
key pressed? Wait 0.05s
Costume=Walk-L3
Wait 0.05s

Assemble these blocks according to


the flowchart.

×2 Try it out! See how Mario moves


when you press the arrow keys.

You may notice that Mario still


appears to walk when he’s up in
×6
the air.

Let’s fix this.

×6

106
Start The fix is to add an IF-THEN-ELSE block such that
 IF ground=0 (Mario is jumping), show his jump costume
 ELSE ground=1 (Mario is on the Floor), show his walk
costume
ground=0 THEN
?

Costume=Walk-R1
Wait 0.05s
THEN THEN
Right arrow Costume=Walk-R2 Right arrow
key pressed? key pressed? Costume=Jump-R
Wait 0.05s
Costume=Walk-R3
Wait 0.05s

Costume=Walk-L1
Wait 0.05s THEN
Left arrow THEN Costume=Walk-L2 Left arrow Costume=Jump-L
key pressed? Wait 0.05s key pressed?
Costume=Walk-L3
Wait 0.05s

Based on this flowchart, modify the


earlier script by adding these
blocks.

Try it out! See how Mario moves


when you press the arrow keys.
×2

Remember to save your work.

×2

107
F2 Create a falling mouse game.

Recap
Learning from previous chapter.

1 X-Y coordinates let you position objects on the Stage.

180
y

–240 240
x

–180

Every point on the Stage is You can also measure


represented by X and Y distance of the points from
coordinates. This lets you the X- and Y-axis, which
position sprites exactly allows you to move sprites
where you want them. across the Stage.

108
Watch E531C Mentor Folder/
Videos/Coordinate Plane
Song.mp4 to understand
more about X-Y coordinates.

Source: https://goo.gl/Yxed7K

2 A flowchart is a graphical representation of a logical flow or an


algorithm.

There are two advantages to using flowcharts:


 help non-programmers understand what’s going on inside a
program
 help programmers see if there are any logic errors in their program

Source: http://smbc-comics.com/

109
3 Boolean has two possible values: TRUE or FALSE.

false
If d = 700, this Boolean expression is _____________

If d = 100, this Boolean expression is _____________

4 AND is used to process multiple Boolean data.

For this expression to be TRUE, the first and the second Boolean
must be TRUE.

If d = 50, this Boolean expression is _____________

If d = 20, this Boolean expression is _____________

5 OR is used to process multiple Boolean data.

For this expression to be TRUE, the first or the second Boolean


must be TRUE.

If d = 100, this Boolean expression is _____________

If d = 50, this Boolean expression is _____________


110
Falling Mouse CHALLENGE

Create a game using concepts learned earlier.

You will create a game where you


catch a falling mouse with a
trampoline.

1 Move the trampoline.

Start a new Scratch


program.

111
Add a sprite you
fancy and delete the
cat.

Resize the sprite to your fancy.

Start

Right THEN
arrow key Change x by 10
pressed?

Left arrow
×2
THEN
key Change x by –10
pressed?

Assemble these blocks according to the ×2


flowchart.

Try it out! Can you control the trampoline?

112
2 Make a mouse fall down the Stage.

Add a sprite you fancy.

Start

Go to the
starting
coordinates

Move Mouse
down the Stage

Assemble these blocks according to the flowchart.

Try it out! Does the mouse fall down the Stage?

113
3 After reaching the bottom, make the mouse reappear at a
random position on top of the Stage.

Mouse appears at a
random position and
falls down the Stage.

Start

Go to the
starting
coordinates

Move Mouse
down the Stage

Mouse at the THEN Move Mouse to a


bottom? random position

Move Mouse to the


top of the Stage

Refer to the flowchart and include these


blocks into your original script.

Try it out! Does the mouse appear at


different positions?

114
4 Play a sound when the trampoline catches the mouse.

When the trampoline catches the


mouse, a sound plays and the mouse
reappears at a random position on
top of the Stage.

Start

Go to the
starting
coordinates

Move Mouse
down the Stage

Mouse at the THEN Move Mouse to a


bottom? random position

Move Mouse to the


top of the Stage

Mouse touch THEN


Play a sound Refer to the
Trampoline?
flowchart and
include these blocks
Move Mouse to a into your script.
random position on
top of the Stage

Try it out! Can you


hear the sound?

115
Remember to save your
program.

5 Publish your game.

scratch.mit.edu Visit the Scratch website.

Follow the instructions to join the Scratch community.

116
Complete signing up.

Check your email for a message from Scratch.


Confirm your email address so you can share your
projects.

117
Start a new project.

Choose the game you


saved earlier.

Let the world discover


your game!

118
Falling Mouse Enhanced CHALLENGE

Add more features and capabilities to the game.

1 Enhance the game with at least 3 of the features below or any


other cool features you can think of:

1. Scoring system.

Score a point when


you catch the mouse.

119
2. Gravity effect.

Make the mouse fall


with acceleration.

3. More falling objects.

Add more animals.

Play music in the


background.

Different animals gives you


different points.

120
4. Fall at different speeds.

Different animals fall at


different speeds.

End the game when the


timer runs out.

121
G1 Learn about relative movement for animation.

Relative Movement
Animate with relative movement.

A B C

We will use a technique called relative movement to give the appearance that an
object is moving inside a world.

In the example above, the dinosaur sprite is actually stationary. Instead, we move the
world around him. This makes the dinosaur appear to be moving.

122
1 Move the Floor in your Mario game.

Open your Mario


game.

123
Modify your script
with these blocks.

124
Add these blocks into your script.

Instead of moving Mario, we move the


world around him. This makes it look like
Mario is moving.

Try out your program. Move


Mario around the game world.

125
World Construction
Create the world for your game.

1 Add more floors.

Make a copy of the Floor sprite.

Change the scrollMap


offset to 650.

126
y = -160
Floor Floor2
x=0 x = 650

Add these blocks such that


ground = 1 and velocity = 0 if
Mario touches either Floor or Floor2.

Try it out! Can you jump across the


gap?

127
2 Add more world sprites.

Make two more copies of


the Floor sprite.

Upload sprite from E531C Mentor


Folder/Media/Terrain/Tube1.svg.

Make a copy of this sprite to get


Tube2.

Upload sprite from E531C Mentor


Folder/Media/Terrain/
Wall3wide.png.

Make a copy of this sprite to get


Wall3wide2.

For each of these sprites, change the


y and offset values according to the
world map on the next page.

The sprites will only appear on the Stage


when they are inside the window, i.e.:
 x within –240 to 240 and
 y within –180 to 180

128
129
×6
Set ground = 1 and velocity = 0
should Mario touch any of the
×6 new sprites you added.

Try it out! Navigate Mario


through the game world.

130
3 Add block sprites.

Upload sprite from E531C Mentor


Folder/Media/Terrain/block.png.

Upload costume from E531C Mentor


Folder/Media/Terrain/block-
costume2.png.

131
Create this script.

Can you guess what it does?

Copy this script from another sprite.

Change the y and offset values to


place the sprite at a position you
fancy.

132
Make a copy of this sprite to get block2.

Change the y and offset values to


place the sprite at a position you
fancy.

133
×2
Add these blocks such that
ground = 1 and velocity = 0
×2
should Mario touch any of the
block sprites you added.

Try it out! Navigate Mario


through the game world.

See what happens when Mario


lands on block and block2.

134
Remember to save your
program.

135
G2 Create a flight simulator game.

Recap
Learning from previous chapter.

1 Have you ever been in a car at a junction, and you look out the window
at the car stopped next to you. Suddenly you feel like your car is going
backward, when in fact you’ve not actually moved. Instead it’s the car
next to you that is moving.

This is called relative movement.

This method is used in the Flight Simulator game you will create next,
as well as in some 2D computer games, to simulate movement.

Vertical scrolling Horizontal scrolling

136
2 The offset value is used to determine the initial position of the
background sprites that make up the game world.

x=0 x = 650

offset

The variable scrollMap is then used to change


the X coordinates of the background sprites.

scrollMap value decreases with


each press of the right arrow key,
hence slowly bringing the sprites
into the window.

137
Flight Simulator CHALLENGE

Create a flight simulator using concepts learned earlier.

1 Navigate the plane.

Start a new Scratch


program.

Upload sprite from E531C


Mentor Folder/Media/Flight
Simulator/plane.sprite3.

Make the plane start at the


center. Move the plane to the
right when you press the right
arrow key.

Try it out! Can you move the


plane?

138
2 Add sprites into the game world and move them instead of the plane.

Modify such that scrollMap


determines how much the
game world sprites move in X
direction

Add a tree sprite and position it to


the bottom of the Stage.

Make the tree start at (0,–130).


The X coordinate of the tree is
determined by scrollMap with
offset.

Try it out! Does the tree move when


you press the right arrow key?

139
Add a cloud sprite and position to
your fancy.

Copy this script from the tree sprite


and modify the y and offset values.

Create a collision detection script


such that collision = 1 if the plane
touches either the tree or the
cloud.

The variable collision shows if the


plane collides with any sprites in the
game world.

140
3 Construct the game world.

1. Add more obstacles. You can add more graph paper to create a
larger game world.

2. For each sprite you add to the world, modify the y and offset
values.

3. Modify the collision detection script to include all new sprites.

4. Try out your program and explore the world you created.
x=200
x=100
x=0
x= –160

y= –130
y=120

y=0

141
4 Control the plane’s height to avoid obstacles.

Use the arrow keys to


avoid obstacles.

Make the up arrow key move the


×2 plane higher and the down arrow
key move the plane lower.

×2
Try it out! Can you control the plane?

×2

142
The plane tilts upwards and
downwards when it changes
height.

Make the plane


tilt up when it
goes higher
and tilt down when it goes lower.

Try it out! Does the plan tilt when


you move it higher and lower?

143
Flight Simulator Enhanced CHALLENGE

Add more features and capabilities to the game.

1 Enhance the game with at least 3 of the features below or any other
cool features you can think of:

1. Scoring system.

The score increases every time


the player collects a power-up.

2. Special effects.

Make the plane explode when it


collides into any obstacles, with
realistic sound and visual effects.

144
3. Game world continues to scroll.

Make the game world scroll continuously.

4. Add more controls.

Speed up and slow down the plane with


the arrow keys.

145
H1 Learn about hiding sprites, broadcasting, and using text-to-speech.

Music
Add background music and sound effects.

1 Make a sound when Mario jumps.

Open your Mario


game.

Upload sound from E531C Mentor


Folder/Media/Sound/Jump.wav.

146
Make the sound play whenever
Mario jumps.

Try it out!

2 Make a sound when block sprites disappear.

Make a “pop” sound whenever


the block sprite disappears.

Try it out!

147
3 Play background music.

Select Stage.

Upload sound from E531C Mentor


Folder/Media/Sound/
Theme.wav.

Create this script.

Try it out! Bring Mario for a walk


and enjoy the music.

148
Collision Detection
Detect which part of the sprite collides with other sprites.

So far we can detect if Mario touches certain objects, but we can’t tell which part of
the body is involved. For example, if we know the head is hitting a brick wall, we can
have a bounce-back effect to make the motion more realistic.

To do this we will create 3 bars Touching this bar is equivalent to


surrounding Mario to represent touching the top of Mario’s head.
different sides of his body.

1 Create collision detection for top.

Upload sprite from E531C Mentor Folder/


Media/Shield/Topcollide.png.

Shrink and move the


sprite so it’s just
covers Mario’s head.

149
The x position for Topcollide is
the same as Mario, which is
always x = 0.

Make the Topcollide


sprite track Mario’s
Because the movement.
20 Topcollide sprite
needs to be on
top of Mario’s
head, the y
position has an
offset of 20.
x=0

Try it out! Does the Topcollide


sprite track Mario?

Broadcast a CollideTop
message if the Topcollide
sprite touches any of these
sprites:
 Wall3wide
 Wall3wide2
 Floor4

×2

×3

150
Create a bounce-back effect.

Try it out! Can you see the


bounce-back effect?

A bug is an error which stops your code from working as


expected. There are two main types of bug which can occur:

 Syntax error—happens when the rules of the language have been


broken, for example, by misspelling a command. It usually stops the
code from running. Graphical languages like Scratch provide code in
ready-written blocks, so you won’t make many syntax errors.
 Logic error—your code runs, but doesn’t do what you expect.
Unfortunately, it’s still possible to make logic errors in Scratch!

Finding and fixing these errors in a program is known as debugging.

151
2 Create collision detection for right side.

Upload sprite from E531C Mentor Folder/


Media/Shield/Sidecollide.png.

Shrink and move the


sprite so it just covers
Mario’s head.

152
The x position for Sidecollide
is in front of Mario, x = 15.

Make the Sidecollide


sprite track Mario’s
movement.
Because the
10 Sidecollide sprite
needs to cover
Mario’s face, the
y position has an
offset of 10.
x=0

x = 15

Try it out! Does the Sidecollide


sprite track Mario?

Create this script such that if


Sidecollide touches any of
the sprites below when
moving right, Mario appears
stationary:
 Wall3wide
 Wall3wide2
 Tube1
 Tube2
 block
 block2
 Floor4

153
3 Create collision detection for left side.

Make a copy of Sidecollide.

Make Sidecollide2 to be always on the


left of Mario.

Modify this script such that


if Sidecollide2 touches any
of the sprites below when
moving left, Mario appears
stationary:
 Wall3wide
 Wall3wide2
 Tube1
 Tube2
 block
 block2
Try it out! Does Mario behave  Floor4
correctly when colliding with
other sprites?

154
4 Make the collision detection bars invisible.

Add this block to make


Topcollide invisible (ghosted).

Do you think the ghost effect is


similar to the hide block used
earlier?

Add the same block to these


sprites to make them invisible.

Try it out! Are the collision


detection bars invisible?

Remember to save your program!

155
I Spy Game
Play a guessing game with your friends.

I Spy is a guessing game. One player becomes the spy and selects an object in the
room in secret. The other players have to guess what the object is.

1 Choose someone to be a spy. The rest are the players.

spy players

2 The spy chooses an object in the class that the players can see. Think
about this object and don’t let the players know.

spy players

156
3 The spy gives a hint to the players by saying, “I spy with my little eye
something that…” and finishes the hint with something that describes
the object.

Here are some examples:


I spy with my little eye something that has a tail.
I spy with my little eye something that starts with the letter M.

The players then try to guess.

I spy with my little


eye something
that…

spy players

4 When someone guesses correctly, she becomes the next spy.

157
H2 Create an Eye-Spy game.

Recap
Learning from previous chapter.

1 You make sprites disappear using these blocks.

Ghosted sprites can say things, and other sprites can detect when they
are touching them.

However, hidden sprites can't say anything, and other sprites can't
detect when they are touching them.

Visit https://goo.gl/3X6W9D to
see a demonstration that
compares a ghosted sprite (red
cat) with a hidden sprite
(orange cat).

158
2 The broadcast block triggers actions in other sprites.

Messages are sent throughout the Scratch


program and this lets you trigger actions in
sprites that receive the messages.

For example, how do you make two sprites say the ABCs in the
correct order?

159
Eye-Spy
CHALLENGE

Create a game where the player finds objects according to the hints.

1 Capture a photo for your backdrop.

Start a new Scratch


program.

Capture an interesting photo for


your backdrop.

If you don’t have a webcam, you can


also take a photo with your phone.
Save the photo to your computer and
then upload the photo.

160
2 Add background music.

Pick a music you fancy and make it


play during the game.

3 Create a hint and action.

Add a hint for the


player to guess
which object to
click.

161
If the player guesses correctly, a
red circle appears.

Create a red circle sprite.

At the start, hide the circle


sprite and set variable
found_sprite1 = 0 (not yet
found).

If the player moves the


mouse pointer over the
hidden circle, clicks on it, and
it hasn’t been found, then
show the circle.

Once the circle is found,


found_sprite1 = 1 and play
a sound.

162
Duplicate more sprites for other objects
that matches your hint.

Modify the variables accordingly.

Try it out! Do the circles appear


when you guess correctly?

163
4 Speak the hints.

Add the Text to


Speech extension.

Create a script that


speaks the hints.

164
Eye-Spy Enhanced
CHALLENGE

Add more features and capabilities to the game.

1 Enhance the game with at least 3 of the features below or any


other cool features you can think of:

Show how many


items remain to
be found.

Add more hints so


players have more
objects to guess.

Add a time limit


for each level.

Have more scenes.

165
I1 Learn to create an end-game condition.

Game Start
Create the start screen and actions when the game starts.

1 Create a start screen.

Open your Mario


game.

Draw a new sprite that will be


used as the start screen.

166
You want your start
screen sprite to cover
the whole Stage.

Position the sprite at


(0,0).

Show the start screen sprite at the


foremost layer when you run the
program.

When the spacebar is pressed, the


start screen goes away and
broadcast a startGame message.

167
Allow control for
Mario only when
startGame message is
received.

Try it out! Does the start screen


work as expected?

168
Game Complete
Create the actions when the game is completed.

1 Program what happens when the game is completed.

Upload sprite from E531C Mentor


Folder/Media/Flag/pole.png.

Place the pole at the end of Floor3 sprite.

Use the game world map earlier to work


out the X and Y coordinates for the pole.

169
Upload sprite from E531C Mentor
Folder/Media/Flag/flag.png.

Place the flag on top of the pole.

Resize the sprite and then work out the


X and Y coordinates.

When Mario touches the flag,


it moves down until it touches
the ground.

170
Upload sound from E531C Mentor
Folder/Media/Sound/Stage Clear.wav.

When Mario touches the flag, stop all


sounds and play Stage Clear.

When Mario touches the


flag, change his costume
and follow the flag down.

Try out the game!

171
2 Touch-up the game.

You probably notice that


parts of the sprites that
are beyond the Stage are
still visible on the left and
right sides of the Stage.

We will hide them with 2


white columns.

Create a new sprite.

Change the position of the new sprite


to (0,0).

172
White columns on the
left and right sides of
the Stage.

Use the Rectangle tool to draw two white


columns on both sides of the Stage.

Place the white columns are at the


correct position when the program
starts.

173
Uncheck all variables so they don’t
appear on Stage.

Try it out! Pretty easy to complete


the game, isn’t it? Let’s make things
a bit more difficult for Mario.

174
Game Over
Implement the actions when the game ends.

The game ends when either of these events happen:


 when the game is completed
 when Mario falls and touches the bottom of the Stage

1 Program what happens when Mario touches the bottom of the Stage.

Select this sprite.

Upload sound from E531C Mentor Folder/


Media/Sound/Die.wav.

Broadcast gameOver when


Mario touches the bottom of the
Stage.

The wait option in the broadcast


block is to allow the receiving script to
complete.

175
When the gameOver message is
received, the following actions
happen:
 flag variable endGame
 switch Mario’s costume to Die
 stop all sounds and play Die
 make Mario jump up
 stop the program after a
certain delay

Try zero wait time. Then adjust


the time accordingly.

176
Initialise variable endGame to
zero when the game starts.

Try it out! Does the game end


when Mario falls off the floor?

2 Program what happens when the game is completed.

Set variable endGame to 1 when


Mario touches the flag.

Try it out! Does Mario still move when


the game is over? Let’s fix this.

177
3 Disable control keys when the game ends.

Ensure Mario moves only while


endGame = 0.

178
Ensure Mario animates only
while endGame = 0.

Try it out! The game is almost


complete!

179
I2 Create a Space Invaders-based game.

Recap
Learning from previous chapter.

1 Earlier, you used a variable called endGame to


keep track of the state of the game. This is an
example of a global variable, which means any
sprite can read and change this variable.

However, you can also create a


variable that all sprites can
read but only the owner can
change. This is called a local
variable.

180
Space Invaders
CHALLENGE

Create a game where you shoot invading aliens.

1 Make an alien appear at random positions on the Stage.

Start a new Scratch


program.

Make the alien appear at random


positions.

181
2 Rotate a spaceship using the left and right arrow keys.

Add a spaceship sprite.

Make the spaceship


start at (0,0).

Rotate the spaceship


left when you press the
left arrow key, and
right when you press
the right arrow key.

Try it out! Can you rotate


the spaceship with the left
and right arrow keys?

182
3 Shoot a laser from the spaceship.

Add a laser sprite.

Modify the spaceship


script such that variable
angle stores its direction.

Make the laser


invisible at the start.

When the spacebar is


pressed, the laser
appears, makes a
sound, goes to the
spaceship location,
and point in the
direction of the
spaceship.

Then move the laser


until it touches either
the edges of the
Stage or the alien.

183
Try it out.

For some sprites, the


laser doesn’t shoot in
the right direction.

Use this block to offset


the angle.

Try it out! Does the laser shoot


in the correct direction?

184
4 End the game when the laser touches the alien.

Broadcast a message to end the game


when the laser touches the alien.

Create a script such that when the laser


receives the end game message, hide the
laser and stop the game.

Try it out! Can you shoot


down the alien?

185
Space Invaders Enhanced
CHALLENGE

Add more features and capabilities to the game.

1 Enhance the game with at least 3 of the features below or any


other cool features you can think of:

Increase the score when


you shoot an alien.

End the game after a


certain time limit.

Play music in the


background.

Add sound effects when an


alien is shot and when the
game ends.

186
Make the alien appear at
random lengths of time
before it disappears.

Add more aliens.

Add start and end game screens,


with a story behind the game.

What other creative additions you


can add to your game? Don’t forget
to let your friends try out your game!

187
J1 Learn to create a scoring system using sprites.

Collect Coins
Create a scoring system based on the coins collected.

1 Add the coin sprite and a sound.

Open your Mario


game.

Upload sprite from E531C Mentor


Folder/Media/Coin/coin1.png.

Upload the following costumes from


E531C Mentor Folder/Media/Coin/
 coin2
 coin3
 coin4

188
Upload sound from E531C Mentor
Folder/Media/Sound/Coin1.wav.

2 Program the actions for the coin.

Create this script and modify the


values to position the coin into the
game world. Here’s a possible
location.

Rotate the coin.

Try it out! Does the coin appear to be


spinning?
×4

×4

189
When Mario touches the coin, the
following happens:
 play a sound
 coin disappears
 broadcast message coin

Try it out! Can you capture the coin?

3 Add more coins.

Duplicate more coins.

Modify their scripts to


place them according to
the world map on the next
page.

Try it out! Can you collect


all the coins?

190
191
4 Create a sprite-based scoring system.

Draw a new sprite.

Use the Text tool to create


the number 0.

Resize it to a size
you fancy.

192
Make a copy of this costume.

Select Text tool and


change the number to 1.

Repeat and create numbers 2 to 9.

193
Move the sprite to a position
you fancy.

Make the sprite stay in this


position and the score starts at
0.

Increment the score when the coin


message is received.

Upload sprite from E531C Mentor


Folder/Media/Coin/coin2.png.

194
Add the character X here.

Place the sprite here.

Try it out! Find out what’s


your highest score.

195
Goomba
Add Goomba and program its actions.

The game ends if Mario collides with Goomba. However Mario can kill Goomba by
stepping on it.

1 Add Goomba into the game.

Upload sprite from E531C Mentor Folder/


Media/Goomba/Goomba1.png.

Upload these costumes from E531C


Mentor Folder/Media/Goomba/
 Goomba2
 Goomba3

196
Make Goomba continuously
move left.

Figure out why these blocks are


required.

Use variable goombaDie to


show if Goomba is dead or alive.

If Goomba is alive, change its


costume to look like it’s walking.
Otherwise, change its costume
to a flattened Goomba.

197
When Mario steps on Goomba,
the following happens:
 set variable goombaDie = 1
 make Mario jump

Try it out! Step on Goomba and


see what happens.

How would your program know


if Mario is colliding or
stepping on Goomba?

198
2 Broadcast gameOver when Mario collides with Goomba.

End the game when Mario collides


with Goomba.

Try it out!

199
3 Create the game over screen.

Draw a new sprite.

Use the Text tool and


create a game over screen.

200
Hide the game over screen and position
it at (0,0).

Make the game over screen appear when


the gameOver message is received.

You’ve completed your Mario game!


Try it out! Can you make it to the flag?

201
J2 Create your version of Pac-Man.

Recap
Learning from previous chapter.

1 A quick way to show the score is to use a variable.

You can change how this


variable is displayed. Right-
click and try all the different
styles.

Another way is to use a


sprite with different
costumes. This gives you
more creative ways to
show the score.

202
Pac-Person CHALLENGE

Create a game based on Pac-Man.

1 Create the maze.

Start a new Scratch


program.

Upload backdrop from E531C


Mentor Folder/Media/Pac-Person/
maze.png.

203
2 Add Pac-Person into the game.

Upload sprite from E531C Mentor Folder/


Media/Pac-Person/pac-person01.png.

Upload this costume from E531C Mentor


Folder/Media/Pac-Person/pac-
person02.png.

Make Pac-Person start in the middle of


the Stage and appear with its mouth
open.

204
3 Control Pac-Person with the keyboard.

Make Pac-Person move


to the right when you
press the right arrow key.

Modify the script to move Pac-


Person in these directions.

Try it out! Can you move the


sprite with the arrow keys?

205
Animate Pac-Person when it
moves to the right.

Animate Pac-Person when


moving left, up, and down.

×3

×3

Try it out! Does Pac-Person pass


through the walls? Let’s fix that.

206
4 Pac-Person is not supposed to pass through the walls.

To fix this, we need to make sure that Pac-Person is only allowed to


move when it sees a black background (the walls are blue).

Select this sprite.

For both costumes, draw


this black bar.

Make Pac-Person only move if


the black bar touches the
color black.

Try it out! The sprite


shouldn’t be able to pass
through the walls now!

207
5 Add a dot for Pac-Person to collect.

Create this sprite for Pac-Person


to collect.

Move the dot to a


position you fancy.

Make the dot disappear when Pac-


Person touches it.

208
6 Add more dots and sound effects.

Add more dots.

Each time a dot is eaten,


play a sound effect.

7 Add a time limit to end the game.

Make the game end after a period


of time.

Try it out! Can you collect all


the dots before time runs out?

209
Pac-Person Continued
CHALLENGE

Add ghosts and other game elements.

1 Add a ghost that chooses a random direction to move after


touching a wall.

Upload sprite from E531C Mentor Folder/


Media/Pac-Person/ghost.sprite3.

Place the ghost here. Make sure it


is not touching any walls.

210
Make the ghost go to its starting
position when you run the
program.

Then continue moving up until it


touches the wall (use the color
picker to choose the correct shade of
blue).

After it touches the wall, do a


bounce-back effect.

Try it out! Can you see the


bounce-back effect?

If the ghost doesn’t move, it


must be touching the wall.
Adjust its position and try again.

211
These groups of blocks make the
ghost move in four directions: up,
down, left, and right.

Create a variable to randomly pick a


number between 1 and 4. Each
number represents a direction.

For each direction, move the ghost


accordingly.

Try it out! Does the ghost pick a


random direction to move each
time it touches a wall?

212
2 Enhance the game with at least 3 of the features below or any other
cool features you can think of:

1. Add background music.

2. Create a start screen and a game over screen.

3. Add more bonus dots, with each bonus dot scoring points.

4. Add more ghosts.

5. Add sound effects when Pac-Person captured by ghosts.

6. Create a power-up dot that gives Pac-Person the ability to capture


ghosts.

7. Create more levels with different mazes.

Well done! Now keep on


creating games.

213
This page is intentionally left blank.

214
215
RESPECT
 I will listen when others are sharing.
 I will put up my hand to ask for permission.
 I will be punctual.
 _______________________
 _______________________

RESPONSIBILITY
 I will keep my goals.
 I will take care of all properties.
 I will keep my work space tidy.
 _______________________
 _______________________

RESOURCEFULNESS
 I will check if there are any mistakes in my work.
 I will search for answers before asking for help.
 I will be creative in solving my problems.
 _______________________
 _______________________

Visit chumbaka.asia to explore thousands of interesting projects.

216

You might also like