Scratch Lesson 5scratch.ie/sites/all/themes/scratch_theme/resources... · Scratch Primary Lesson 7...

21
Scratch Primary Lesson 7 Good Guy / Bad Guy Game creativecomputerlab.com

Transcript of Scratch Lesson 5scratch.ie/sites/all/themes/scratch_theme/resources... · Scratch Primary Lesson 7...

Page 1: Scratch Lesson 5scratch.ie/sites/all/themes/scratch_theme/resources... · Scratch Primary Lesson 7 Good Guy / Bad Guy Game creativecomputerlab.com. The Game Idea • This is a two

Scratch Primary Lesson 7

Good Guy / Bad Guy Game

creativecomputerlab.com

Page 2: Scratch Lesson 5scratch.ie/sites/all/themes/scratch_theme/resources... · Scratch Primary Lesson 7 Good Guy / Bad Guy Game creativecomputerlab.com. The Game Idea • This is a two

The Game Idea

• This is a two character game. It has a good guy and a bad guy. 

• You (the player) are the good guy.• You start out with 5 lives.• You must escape from the bad guy.• You can move by using the arrow keys.• If the bad guy touches you, you lose one life.

creativecomputerlab.com

Page 3: Scratch Lesson 5scratch.ie/sites/all/themes/scratch_theme/resources... · Scratch Primary Lesson 7 Good Guy / Bad Guy Game creativecomputerlab.com. The Game Idea • This is a two

Choose the Characters

• Start a new Scratch project and delete the cat.• Create new sprites. Search through the sprite folders and find:– A good guy – that will be you.– A bad guy.

creativecomputerlab.com

Page 4: Scratch Lesson 5scratch.ie/sites/all/themes/scratch_theme/resources... · Scratch Primary Lesson 7 Good Guy / Bad Guy Game creativecomputerlab.com. The Game Idea • This is a two

Choose the Characters

• You can choose any characters you’d like. For this example we will use these characters:

• Good guy (or girl): 

• Bad guy (or ghoul):

creativecomputerlab.com

Page 5: Scratch Lesson 5scratch.ie/sites/all/themes/scratch_theme/resources... · Scratch Primary Lesson 7 Good Guy / Bad Guy Game creativecomputerlab.com. The Game Idea • This is a two

Give the Sprites Their Own Names• GoodGirl:

• BadGuy:

• Giving your own name to sprites makes them easier to find when you are making your scripts.

creativecomputerlab.com

Page 6: Scratch Lesson 5scratch.ie/sites/all/themes/scratch_theme/resources... · Scratch Primary Lesson 7 Good Guy / Bad Guy Game creativecomputerlab.com. The Game Idea • This is a two

Moving the Good Guy• First, we will enable the player (good guy) to move around by using the arrow keys.

creativecomputerlab.com

Page 7: Scratch Lesson 5scratch.ie/sites/all/themes/scratch_theme/resources... · Scratch Primary Lesson 7 Good Guy / Bad Guy Game creativecomputerlab.com. The Game Idea • This is a two

Moving the Bad Guy

• Second, we will make the bad guy move around the screen automatically:

creativecomputerlab.com

Page 8: Scratch Lesson 5scratch.ie/sites/all/themes/scratch_theme/resources... · Scratch Primary Lesson 7 Good Guy / Bad Guy Game creativecomputerlab.com. The Game Idea • This is a two

How to Score?

• A score is made when the bad guy touches the good guy. The good guy loses one life.

• We need to make a script that detects when the sprites are touching.

• The script logic is: “If touched by the bad guy, the good guy loses one life”. 

• We will put this script in the good guy’s script area.

creativecomputerlab.com

Page 9: Scratch Lesson 5scratch.ie/sites/all/themes/scratch_theme/resources... · Scratch Primary Lesson 7 Good Guy / Bad Guy Game creativecomputerlab.com. The Game Idea • This is a two

Sprite Sensing

• The sensing blocks help a sprite sense the world around it.

• We want the good guy sprite to know when it is touching the bad guy sprite.

creativecomputerlab.com

Page 10: Scratch Lesson 5scratch.ie/sites/all/themes/scratch_theme/resources... · Scratch Primary Lesson 7 Good Guy / Bad Guy Game creativecomputerlab.com. The Game Idea • This is a two

Good Guy Scoring Script• Use the “if” and “touching” blocks:

• What block do we need to use so that the good guy is always checking whether it is touching the bad guy? 

creativecomputerlab.com

Page 11: Scratch Lesson 5scratch.ie/sites/all/themes/scratch_theme/resources... · Scratch Primary Lesson 7 Good Guy / Bad Guy Game creativecomputerlab.com. The Game Idea • This is a two

Good Guy Scoring Script

• The good guy must keep checking whether the bad guy is touching. This is called “polling”.

• We use the “forever” loop to keep checking constantly: 

creativecomputerlab.com

Page 12: Scratch Lesson 5scratch.ie/sites/all/themes/scratch_theme/resources... · Scratch Primary Lesson 7 Good Guy / Bad Guy Game creativecomputerlab.com. The Game Idea • This is a two

Test the Game• Click the green flag and test whether the good guy says something when it is touched by the bad guy:

creativecomputerlab.com

Page 13: Scratch Lesson 5scratch.ie/sites/all/themes/scratch_theme/resources... · Scratch Primary Lesson 7 Good Guy / Bad Guy Game creativecomputerlab.com. The Game Idea • This is a two

Keeping Score

• We need to write a script to keep score.

• The script must:– Start the game with 5 lives– Subtract 1 life when touched by the bad guy– End the game when good guy runs out of lives

• We must keep the current score in a variable

creativecomputerlab.com

Page 14: Scratch Lesson 5scratch.ie/sites/all/themes/scratch_theme/resources... · Scratch Primary Lesson 7 Good Guy / Bad Guy Game creativecomputerlab.com. The Game Idea • This is a two

Variables and Data• A variable is a place to hold a number or letters so it can be used by the computer.

• The value of the data which the variable is holding can be any value and it can be changed at any time. It is called a variable because its value can vary. 

• In our game, the score is the data. We are going to see how we can create a variable to hold the score…

creativecomputerlab.com

Page 15: Scratch Lesson 5scratch.ie/sites/all/themes/scratch_theme/resources... · Scratch Primary Lesson 7 Good Guy / Bad Guy Game creativecomputerlab.com. The Game Idea • This is a two

Variables in Scratch• Go to the “Data” palette to create a variable. Notice that there are no variables created yet.

• Click the “Make a variable” button.creativecomputerlab.com

Page 16: Scratch Lesson 5scratch.ie/sites/all/themes/scratch_theme/resources... · Scratch Primary Lesson 7 Good Guy / Bad Guy Game creativecomputerlab.com. The Game Idea • This is a two

Make the “Lives” Variable

• Give the new variable the name “Lives”– Make it for all sprites:

creativecomputerlab.com

Page 17: Scratch Lesson 5scratch.ie/sites/all/themes/scratch_theme/resources... · Scratch Primary Lesson 7 Good Guy / Bad Guy Game creativecomputerlab.com. The Game Idea • This is a two

Make the “Lives” Variable

• The variable “Lives” is created with value 0:

• You can:• Set “Lives” to any value.• Change “Lives” by any value.• Hide “Lives”.• Show “Lives”.

creativecomputerlab.com

Page 18: Scratch Lesson 5scratch.ie/sites/all/themes/scratch_theme/resources... · Scratch Primary Lesson 7 Good Guy / Bad Guy Game creativecomputerlab.com. The Game Idea • This is a two

Adding Scoring to The Game• We want to set “Lives” to 5 when the game starts.

• Every time the bad guy touches the good guy, we lose 1 life:

creativecomputerlab.com

Page 19: Scratch Lesson 5scratch.ie/sites/all/themes/scratch_theme/resources... · Scratch Primary Lesson 7 Good Guy / Bad Guy Game creativecomputerlab.com. The Game Idea • This is a two

Adding Scoring to The Game• This is how the project should look:

– Click the check box by the “Lives” variable to show it

creativecomputerlab.com

Page 20: Scratch Lesson 5scratch.ie/sites/all/themes/scratch_theme/resources... · Scratch Primary Lesson 7 Good Guy / Bad Guy Game creativecomputerlab.com. The Game Idea • This is a two

Click the Green Flag and Play The Game

• What happens to the good guy’s lives?

• What new features would you like to put into the game?

creativecomputerlab.com

Page 21: Scratch Lesson 5scratch.ie/sites/all/themes/scratch_theme/resources... · Scratch Primary Lesson 7 Good Guy / Bad Guy Game creativecomputerlab.com. The Game Idea • This is a two

New Features For Good Guy / Bad Guy Game

• End the game when “Lives” becomes equal to 0.• Find a way to win the game:

– Create a timer and see how long you can last.– Create another “health” sprite that adds one life when the good guy touches it.

• Create a game over screen.– Create a “You Lose  ” screen.– Create a “You Win ☺” Screen.

creativecomputerlab.com