COMP 10-LESSON 5-ADDING INTERACTIVITY
COMP 10-LESSON 5-ADDING INTERACTIVITY
10
LESSON 5:
ADDING
INTERACTI
VITY
COMPUTER 10
LEARNING
OBJECTIVES:
1. Create interactive programs using
Scratch.
2. Learn the value collaboration.
COMPUTER 10
INTERACTIVE
PROGRAM
When a program responds according to human input, a
program is said to be interactive.
For example, in a video game, pressing the arrow keys
moves our characters. Ultimately, when we do something
with our computers' input devices, they respond
accordingly.
COMPUTER 10
INTERACTIVE
PROGRAM
1. Prepare the backdrop and sprites.
• Insert the title text in the white backdrop.
• Insert the Blue Sky 2 backdrop. However, select the
white backdrop with title text as our beginning
backdrop.
• Insert the Button2 sprite but use the button2-b
costume
• Insert text in the button as shown on the right.
COMPUTER 10
INTERACTIVE
PROGRAM
1. Prepare the backdrop and sprites.
• Draw a new sprite. The new sprite is a simple
orange-colored box
• Rename the sprite as box.
• Insert the ball sprite from the sprite library
COMPUTER 10
INTERACTIVE
PROGRAM
2. Prepare the home page of the game.
• Insert the script on the right for the ball and box
sprite. This hides the sprites when Go is clicked
since we do not want to see these sprites on the
home page.
• For the Button2 sprite, insert the script on the right.
This makes sure that we are using the first backdrop
when Go is clicked. This also hides the button first
for 1 second before showing the button for the user
to click. COMPUTER 10
INTERACTIVE
PROGRAM
2. Prepare the home page of the game.
• Insert the script below also in the Button2 sprite.
3. Show the ball and box sprites.
• Insert the script below into the ball and box sprites,
respectively.
• Use the drop-down arrows on the trigger block to
select the correct option
COMPUTER 10
INTERACTIVE
PROGRAM
• The scripts inserted for each sprite are a bit similar.
Using the trigger block above, the sprites will only
appear when the backdrop is switched to the Blue
Sky 2 backdrop. The sprites will go to their
beginning position in the stage specified above.
COMPUTER 10
INTERACTIVE
PROGRAM
4. Make the ball sprite move using the arrow keys. Insert
the following script in the ball sprite to make it move.
• The when () key pressed trigger block is used to
execute commands when a certain key on the
keyboard or a click on the mouse is pressed. Let us
change the values for the trigger and motion blocks
and see what happens with the ball.
COMPUTER 10
INTERACTIVE
PROGRAM
5. Create an action for the ball sprite when it touches the
box sprite.
• Connect the boxed script as shown on the next page
into the previous script in the ball sprite.
• The if () then wrap block is used to execute
conditions only when a certain condition is met. In
this case, the condition is the Boolean block
touching () found in the Sensing palette.
COMPUTER 10
INTERACTIVE
PROGRAM
5. Create an action for the ball sprite when it touches the
box sprite.
• Select the box sprite from the options to execute a
certain script only when the ball sprite touches the
box sprite.
COMPUTER 10
INTERACTIVE
PROGRAM
The program on the left shows these commands or
instructions:
-The script inside the if () then block instructs the ball
sprite to say, "You touched the box!" for 2 seconds. It
stops all the scripts.
-The if () then block and the blocks inside it are placed
inside a forever block.
COMPUTER 10
INTERACTIVE
PROGRAM
-While the game is running, the program continuously
checks if the box sprite is being touched or not.
COMPUTER 10
INTERACTIVE
PROGRAM
Instead of the touching () block, let us insert the
touching color () block.
• Click the colored box inside the block.
• Click the box sprite to pick up the color of this
sprite.
COMPUTER 10
INTERACTIVE
PROGRAM
The condition then checks if the ball sprite is touching
that specific color, not necessarily the box sprite.
COMPUTER 10
Any questions?
THANK
YOU,
CLASS!