Make a simple game is a video in a series of video tutorials under the Help tab on the Scratch main head bar. It describes how to use the loudness value to make a functioning game with sprites and scripts.
[0:00] Today, we'll look at games. Now to win this game, we have to get the crab to the key without touching the witch cause if you touch the witch, we lose! Let's play this game one more time. This time, we win.
[0:15] Let's find out how this is done.
[0:18] To begin with, I will delete the cat. Done.
[0:23] Now, I will get a new sprite by clicking on the new sprites link.
[0:28] I will find a sprite that looks like the witch from a list of sprites and then click OK.
[0:35] Now the size of the sprite is way to big for my game, so I will click on the reduce size button, and then click on the witch. The sprite size gets smaller each time I click on the witch.
[0:47] OK that looks good.
[0:49] So I want the witch to move constantly as it were guarding the key.
[1:09] I also want my game to start after I click on the green flag, so I will get that block also.
[1:16] OK, so the witch is moving, but not in the direction we want. To rectify this, I will get the point in direction block and make our sprite point upwards.
[1:33] Here I would like to highlight that the point in direction block is outside the forever. The point in direction block runs only once, which is enough to set the direction of the sprite before the forever loop starts.
[1:46] Let's run the game one more time. That's much better.
when gf clicked point in direction (0 v) forever move (10) steps if on edge, bounce end
[1:52] Next, I will get a new sprite that looks like a crab by clicking on the new sprite link.
[2:03] And now we'll reduce its size also.
[2:08] OK, so I want the crab to move every time I hit the left or the right arrow key on my keyboard.
[2:14] To do this I will grab the when key pressed block and select right arrow from the dropdown. When this event happens, I want the crab to move right, so I will get the move block and change the value of the number of steps to thirty.
[2:28] Now I need to do a similar thing with the left arrow key, so I will just copy the set of blocks by clicking on the duplicate item, and then clicking on the blocks I want to create a copy of. Boom, done!
[2:40] Here, I will change the right arrow to left arrow, and the value of the number of steps to minus thirty.
when [right arrow v] key pressed move (30) steps when [left arrow v] key pressed move (-30) steps
[2:51] Let's run this program to see what happens. So the witch is still moving up and down, and hey, the crab moves every time I hit the left or right arrow key on my keyboard, although nothing happens when the witch touches the crab.
[3:03] So to fix this, I will click on the witch underneath the sprite list, and add logic which says, "If the witch touches the crab, do something".
[3:17] The touching block can tell if two sprites are touching each other. So, if the witch touches the crab, the player loses.
[3:27] And to indicate this, I will play a sound. I will click on the sounds link and get a new sound called the "Dirty Whir". You can get any sound you like.
[3:38] And then, I will go back to the scripts tag and get the play sound until done block.
[3:56] Finally, since we need to check if the witch is touching the crab constantly, I will put this code inside the forever.
when gf clicked point in direction (0 v) forever move (10) steps if on edge, bounce if <touching [Crab v]?> then play sound [dirty whir v] until done stop [all v] end end
[4:04] Now, let's see how our game is doing.
[4:09] Hey, that's some good progress.
[4:14] Now, we need a new sprite that looks like a key, so I will add a new sprite and get one that looks like a key from the list of sprites.
[4:23] And because I want to rotate this key, I will click on the costumes link and do just that. Done.
[4:31] Now, a player wins our game when the crab touches the key.
[4:35] To do this, I will click on the crab from our little sprite list, and I will add blocks that will wait until the crab touches the key.
[4:47] Once the key does touch they key however, I will add a block to broadcast a new message.
[4:56] I will call this new message "Victory". This message will be received by the key as a prompt to do something.
when gf clicked wait until <touching [Key v]?> broadcast [victory v]
[5:05] And to make this key receive this message, I will click the key under the sprites list, and grab up one receive message block.
[5:13] Now when the key receives the victory message, the player has one the game, and to indicate this, I will play a congratulatory sound.
[5:25] And since the player has won, I will also make the game stop.
when I receive [Victory v] play sound [fairydust v] until done stop [all v]
[5:33] OK, let's run the game again.
[5:39] Oh no, I lost. Let me restart it.
[5:42] You see, when I hit the green flag, I want the crab to go back to its original location.
[5:47] To do this, I will click on the crab under the sprites list, and add the go to a certain location block.
when gf clicked go to x: (-180) y: (0) wait until <touching [Key v]?> broadcast [victory v]
[6:00] Let's play the game again.
[6:08] Once again, I lose. Let's restart.
[6:14] Woohoo, This time, I win.
[6:15] Finally, to make the game more difficult, I can add another witch in the path of the crab. How would you continue to make changes to this game?