Unit 1 Introduction to Scratch

Unit 6 Motion – Air Hockey
Evangel College
S.2 ICT
Air Hockey Game
• Have you ever played Air Hockey in
game center? Do you want to create
this game?
Names of components
Puck
Mallet
Center line
Goal
Rail
Puck
How to make a movable puck?
Paint a new sprite and rename it Puck
Add the “move” block to the script area of
Puck. Click on the “move” block.
What do you find?
Puck
How to make the Puck moving continuously?
Add the “forever” block to wrap the “move”
block
What do you find?
Puck
How to make the Puck bounce on the edge
of the air hockey table?
Add the “if on edge, bounce” block at the
end of the stack.
What do you find?
Puck
How to change the direction of the Puck
so that it does not just move left and
right?
Add the “point in direction” before
“forever” block and adjust the direction
value.
What do you find?
Mallet
How to make a mallet?
Paint a new sprite and rename it Mallet
Mallet
How to make the Mallet stick to the mouse?
Add the “go to ” block to the script area of
Mallet
Change the position to “mouse-pointer”.
Wrap it with “forever” block.
What do you find?
Collision detection
How detect collision between two sprites?
The “touching” block can detect collision of
the sprite with other sprites. It can be
used in condition blocks such as “if”
block, “if-else” block or “wait until” block.
Programming Concept: Condition
Conditional statement:
A program may perform
different actions
depending on the
boolean condition
evaluated to be true
or false. It is very
commonly used in
programming.
Key pressed?
Yes
Face the mallet
Turn back
No
Collision detection
What should happen when the puck collides
with the mallet?
Puck
(Start)
x
Mallet
Puck
(Bounce back)
Goal
How to make the goals of two players?
Paint two new sprites and rename them
P1Goal and P2Goal respectively
Goal
What should happen when the puck collides
with the goals of players?
Mix together
Extended Activity
Activity 1 (Initialization):
Add script to reset the position of the
puck to the center (0, 0) of the stage at
the beginning of the game.
Programming Concept:
Initialization
Initialization:
Initialization resets the program to a
certain state.
Challenging Activities
Activity 2 (Randomization):
Add script to add a random turning angle
(ranges from -10 to +10 degrees) after
bouncing from the mallet.