In this screen cast you'll learn
how to add sound effects to your projectile sprite
so it makes a noise when it touches
your main character sprite.
The starter code already includes a make noise block
but it doesn't do anything
because it hasn't yet been defined.
If you remember from day one of this club,
when you create a custom block,
you also need to tell the computer
what it should do when the block is used.
So drag out a play sound block
and place it under the define make noise block.
Choose one of your sounds from the drop down.
Run the code to see what happens.
The sound plays when a projectile sprite
hits the main character sprite.
You want the sprite to make a different noise
for each of its four costumes.
To make that happen use an if/then statement
from the control menu.
This statement needs to check if the costume
equals a certain costume number, then play a sound.
To do this, click on the operator menu
and put an equals operator block inside the if statement.
Under the looks menu, drag the costume number block
into the operator block
and type a one into the value box of the operator block.
The code now reads, if the costume number equals one,
then play a certain sound.
Try it out.
If costume number one, the dog, is shown,
then the dog sound plays.
Otherwise, no sound plays at all.
You want a sound to play for each costume,
so right click on the if statement and choose duplicate,
then change the values of your costume number
and the play sound block.
This will make a different sound play for each costume.
You can always click back on the costumes tab
to see the number for any costume.
(creaking) (dog barking)
(bell clanging) (dog barking)
Now it's your turn.
Add an if/then block to the define make noise stack
and create code that says,
if the costume equals one, then play a sound.
Do this for all four projectile sprite costumes
so each one plays a different sound.
Sign in to save your project and track your progress.