Sound effects are a great way to improve a game or story. In this baseball game we'll add in sound effects for hitting the ball and the crowd.
Create a new Scratch project and delete the cat sprite.
Go to the Scratch website using the link below and click on the 'Create' link in the blue bar at the top.
By default, each new project starts with the cat sprite already added. To delete the cat click on the x in the blue circle beside the cat in the sprite list.
Ass the Baseball 2 backdrop from the backdrop library.
To add a backdrop from the backdrop library follow these steps:
You can use search box or the filter links (Fantasy, Music, Sports etc) to locate your backdrop.
Add the Batter sprite from the sprite library and then add the following code to make her swing bat when you press the space bar.
when green flag clicked
go to x (169) y (37)
switch costume to [batter-a v] // start with this costume
when [space v] key pressed
switch costume to [batter-b v]
wait (.1) seconds
switch costume to [batter-c v]
wait (.1) seconds
switch costume to [batter-d v]
wait (.1) seconds
If you're using a tablet or iPad without a physical keyboard, you won't be able to use keyboard keys like the arrow keys in your project. Instead, we'll add simple on-screen buttons (using sprites) that you can tap to do the same things. This keeps your project working great! Just follow these steps wherever the lesson talks about pressing a key.
First, add a new sprite for your button:
Now, program your button sprite to make things happen when you tap it. Here's how it works for different situations:
Example 1: If the lesson uses a key to trigger an action on a specific sprite (like making something move, turn, or jump)
Instead of code like this on your target sprite:
when [left arrow v] key pressed
change x by (-10) // or any action
Or this:
if < key [left arrow v] pressed? > then
change x by (-10) // or any action
end
Add this code to your new button sprite:
when this sprite clicked
broadcast [do action v]
Then, on your target sprite, add this to receive the message:
when I receive [do action v]
change x by (-10) // or any action
Tap the button on the screen, and the action will happen, just like pressing the key! Use a unique broadcast name for each different action or key.
Example 2: If the lesson uses a key to change a variable (like adding to a score or setting a value)
Instead of code like this:
when [space v] key pressed
change [score v] by (1)
Or this:
if < key [space v] pressed? > then
change [score v] by (1)
end
Add a new button sprite. Then, put this code on the button sprite:
when this sprite clicked
change [score v] by (1)
(If the variable is "for this sprite only," make sure it's set to "for all sprites" so the button can change it.)
Tap the button, and the variable changes, no message needed since it's something shared!
Add the Baseball sprite from the sprite library and give it the following code to set it up for the start and make it move towards the batter.
when green flag clicked
show
set size to (25) %
go to x (-210) y (45) // the middle of the left hand side
forever
change x by (10) // make it move to the right
end
To add a sprite from the sprite library follow these steps:
You can use search box or the filter links (Animals, People, Fantasy etc) to locate your sprite.
When the ball touches the bat we will play a hit sound. To detect if the ball touches the bat we will use a touching color ? block and use the colour of the bat.
Add the following code to the Baseball sprite, underneath the change x by 10 block.
when green flag clicked
show
set size to (25) %
go to x (-210) y (45)
forever
change x by (10) // add new code under here
if < touching color (#ffc800) ? > then
end
end
Some of the sensing blocks allow you to set a colour to decide what they should do.
< touching color [#3e7144] ?>
< color [#ff6666] is touching [#4d86c1] ?>
You can choose which colour to use by clicking on the colour in the block and either using 'Color', 'Saturation' and 'Brightness' sliders to set the color.
Or you can use the eye dropper tool to choose a colour.