Skip to content

Please update your browser

Your browser version is not supported by this site. CS First may not work properly. Learn more

arrow_back Bounce Reaction

Transcript

This add-on video will show you how to make the ball sprite react to being hit by the athlete.

You can make it do something fun, like change colors, or something funny, like say "Ouch."

You'll use another conditional to complete this.

Select the ball sprite and drag out an If block.

The ball sprite will check if it's being hit, which means it's touching the athlete.

Find the Touching block in Sensing and drag it into the Conditions space.

Select Player One from the drop-down menu.

Next, put the ball sprite's reaction inside the conditional.

You can create any type of reaction.

The sprite might change colors or say something or the background could change.

Browse around in the Motion and Looks menus to find something cool for your sprite to do.

The example will show the sprite making a sound when it's hit.

To add a sound to your project, click the Sounds tab.

Then click the Choose Sound From Library.

The example will use "Yeah."

Then go back to scripts.

To add the sound to the conditional, go to Sound and place the Play Sound Until Done block inside the If block.

Add more blocks in here if you would like your project to play different sounds.

If you click this new stack and the ball sprite isn't touching the athlete sprite, it won't do anything.

Drag the ball on top of the athlete sprite and click again.

Yeah Yeah Yeah Sweet, it makes a noise.

Okay, two more things.

First, this new stack needs to run at the same time as the other stack.

Drag out another One Flag Clicked event and snap it on top of your new code stack.

Try running the code now.

It doesn't work.

That's because, when the flag is clicked, the code immediately checks to see if the sprites are touching.

And if they aren't, it stops and doesn't touch again.

That's because, when the flag is clicked, the code immediately checks to see if the sprites are touching.

And if they aren't, it stops and doesn't check again.

To fix this, use a loop.

Add a Forever loop just like you did in the first stack.

That way, the new stack runs for as long as the old one does.

Yeah Yeah Alright, here's the game plan.

Choose a fun action for your sprite to perform when it hits the athlete.

Next, make a new stack for the ball sprite with When Flag Clicked, Forever, If, and Touching blocks.

Place the new actions inside the If block.

Test your code and look back at this video if you need help figuring it out.

Still stuck?

Go ahead and ask your neighbors for help.

Choose an Add-On
Bounce Reaction
Program the ball sprite to do or say something when it bounces.
Second Player
Add a second athlete to make a two player game.
Keep Score
Add a score counter to the game.
Play the Computer
Program a sprite to play against the user.
arrow_backward Back
Next arrow_forward
Instructions
  1. Choose an Add-On, and click "watch" to learn how to build it.
  2. Once you finish one Add-On, try another one below the video!