scratch program puff collector - mrms...

24
Scratch Program Puff Collector By G. Mullin and D. CartyTable of Contents

Upload: others

Post on 18-Jul-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Scratch Program Puff Collector - MRMS Techmrmstech.weebly.com/uploads/5/1/8/5/518583/puff_collector.pdfwe have to create a Variable called ‘Points’. Click the ‘Variables’ tab

Scratch Program

Puff Collector

By G. Mullin and D. CartyTable of Contents

Page 2: Scratch Program Puff Collector - MRMS Techmrmstech.weebly.com/uploads/5/1/8/5/518583/puff_collector.pdfwe have to create a Variable called ‘Points’. Click the ‘Variables’ tab

Step 1. Rename our Sprite ................................................................................................ 3

Step 2. Shrink the Cat ............................................................................................................. 3

Step 3. Controlling the Cat ............................................................................................... 3

Step 4. Saving your work ................................................................................................... 4

Step 5. Stopping the Cat going upside down ............................................ 5

Step 6. Adding a Baddie ....................................................................................................... 5

Step 7. Rename and Shrink the Baddie ............................................................ 6

Step 8. Programming the Baddie ............................................................................. 6

Step 9. Test .......................................................................................................................................... 6

Step 10. Creating Lives ............................................................................................................. 6

Step 11. Setting the number of Lives ..................................................................... 7

Step 12. Losing Lives ................................................................................................................... 8

Step 13. Losing the Game .................................................................................................... 9

Step 14. Collecting Cheesy Puffs ................................................................................ 10

Step 15. Hiding the Puffs ..................................................................................................... 10

Step 16. Getting Points for Puffs .................................................................................. 11

Step 17. Lots of Puffs .................................................................................................................12

Step 18. Winning the Game ...............................................................................................12

Step 19. Stopping the Baddie .......................................................................................... 13

Page 3: Scratch Program Puff Collector - MRMS Techmrmstech.weebly.com/uploads/5/1/8/5/518583/puff_collector.pdfwe have to create a Variable called ‘Points’. Click the ‘Variables’ tab

Step 20. Adding a Background ...................................................................................... 14

Step 21. Play the game!! ........................................................................................................ 16

Step 22. Time Limit ....................................................................................................................... 16

Module Library ......................................................................................................................................18

TASK …………………………………………………………………………..20

Page 4: Scratch Program Puff Collector - MRMS Techmrmstech.weebly.com/uploads/5/1/8/5/518583/puff_collector.pdfwe have to create a Variable called ‘Points’. Click the ‘Variables’ tab

Step 1. Rename our Sprite

At first, our Cat is called ‘Sprite1’ - Change his name to ‘Cat’.

This will stop you getting mixed up once we start using other Sprites.

Step 2. Shrink the Cat

Our Cat is way too big, but we can make him smaller.

Select the ‘Shrink Sprite’ tool

Now click the Cat a few times – you will see him get smaller with each click.

Step 3. Controlling the Cat

In this game, we control the Cat with the mouse. We must tell the Cat to follow the mouse, so we must give it instructions to do so.

Construct the following module:

The instruction blocks are colour

coded – yellow blocks are under the ‘Control’ tab and blue blocks are under the ‘Motion’ tab.

It is very important to make sure the instruction blocks go in the correct

order.

This tells the Cat that: “When the green flag is clicked (i.e the game starts), point towards the mouse pointer and move 3 steps)

The ‘Forever’ instruction tells the cat to repeat these actions forever.

Try it! Click the green flag and watch as the Cat follows your mouse

movements!

Page 5: Scratch Program Puff Collector - MRMS Techmrmstech.weebly.com/uploads/5/1/8/5/518583/puff_collector.pdfwe have to create a Variable called ‘Points’. Click the ‘Variables’ tab

Step 4. Saving your work

Now is a good time to save your work.

Select from the Menu at the top.

The following dialog box appears:

Call your file ‘Puff Collector’ but DO NOT CLICK OK.

Note: It is VERY important to save your file to the correct location –

otherwise you won’t find it next time.

Your teacher will show you where to Save your file. (Usually in your ‘My Documents’ folder)

Next time, to open your file, simply load scratch and click

A similar dialog box will appear – you can use this to find your

file (remember where you saved it) and load it.

Page 6: Scratch Program Puff Collector - MRMS Techmrmstech.weebly.com/uploads/5/1/8/5/518583/puff_collector.pdfwe have to create a Variable called ‘Points’. Click the ‘Variables’ tab

Step 5. Stopping the Cat going upside down

You may have noticed that when the Cat follows your mouse movements, it sometimes turns upside down.

Click this button

This will make sure the Cat only faces left and right.

Step 6. Adding a Baddie

Click the ‘Choose New Sprite’ button:

The following window appears:

Double Click the ‘Fantasy’ Folder.

Choose the first Sprite then click OK.

Page 7: Scratch Program Puff Collector - MRMS Techmrmstech.weebly.com/uploads/5/1/8/5/518583/puff_collector.pdfwe have to create a Variable called ‘Points’. Click the ‘Variables’ tab

Step 7. Rename and Shrink the Baddie

Just the way we did with the Cat, rename this Sprite ‘Baddie’, and shrink him down to the same size as the cat.

(Look at Steps 1 and 2 if you get stuck)

Step 8. Programming the Baddie

The Baddie’s job is to chase the Cat.

We must give him instructions to do this.

Construct the following module for the Baddie:

This tells the baddie to point towards the Cat and move 2

steps – forever.

Note – It is important that the Baddie is

slower than the Cat – otherwise he

will always catch the Cat!!

Step 9. Test

Click the green flag to start the game – you should see that the Baddie chases the Cat, and we now have the basis for our computer game.

Step 10. Creating Lives

At the moment, if the Baddie touches the Cat, nothing happens.

To make the game interesting, the Cat should lose a life if he gets caught by the Baddie.

To do this, we need to create a Variable called Lives. A Variable is something

which holds information that can change, like ‘number of lives’

Page 8: Scratch Program Puff Collector - MRMS Techmrmstech.weebly.com/uploads/5/1/8/5/518583/puff_collector.pdfwe have to create a Variable called ‘Points’. Click the ‘Variables’ tab

Click the Variables Tab, then ‘Make a Variable’

The following box appears – type in ‘Lives’, then click OK

You will see the ‘Lives’

Displayed: -

Step 11. Setting the number of Lives

At the moment, the number of Lives is set to 0.

We must give our Cat 3 Lives each time the game starts

(i.e the green flag is clicked).

Double click the Baddie

and add the following

module:

Make sure you change this to ‘3’.

This makes sure that every time the game starts, ‘Lives’ is set to 3.

Page 9: Scratch Program Puff Collector - MRMS Techmrmstech.weebly.com/uploads/5/1/8/5/518583/puff_collector.pdfwe have to create a Variable called ‘Points’. Click the ‘Variables’ tab

Step 12. Losing Lives

Every time the Baddie touches the Cat, two things should happen:

1. The Cat should lose a life

2. The Baddie should go back to the corner of the screen.

We will use a ‘FOREVER IF’ statement.

Add these instructions to the module so it looks like this:

You will find the ‘touching’ block

under the ‘sensing’ tab.

This tells the Baddie: If touching the

Cat, change lives by -1 (take away 1 life) and go to the corner of the screen. (x = -195, y = 111 are the co-ordinates of the top left corner of the screen)

TRY IT!

Click the green flag and watch what happens to the number of lives when the

Baddie touches the Cat.

Page 10: Scratch Program Puff Collector - MRMS Techmrmstech.weebly.com/uploads/5/1/8/5/518583/puff_collector.pdfwe have to create a Variable called ‘Points’. Click the ‘Variables’ tab

Step 13. Losing the Game

At the moment, if the Cat loses all 3 lives, the game continues – the lives will just decrease, showing -1, -2, -3 etc.

We want the game to stop if Lives = 0.

From the Control tab, drag in:

Now connect a Forever IF:

From the Numbers tab, drag in

The ‘equals’ condition and drop it next to the ‘IF’

From the Variables tab, drag

In ‘Lives’ and drop it into the ‘equals’ condition

Now type in 0, so we have

‘FOREVER IF Lives = 0’

From the Control tab, drag in ‘Stop All’ – this ends the

game.

We have just told the computer:

“If Lives is ever equal to 0, stop the game.”

Page 11: Scratch Program Puff Collector - MRMS Techmrmstech.weebly.com/uploads/5/1/8/5/518583/puff_collector.pdfwe have to create a Variable called ‘Points’. Click the ‘Variables’ tab

Step 14. Collecting Cheesy Puffs

We will now give our Cat something to ‘collect’ while he avoids the Baddie. He likes Cheesy Puffs, so we will add this Sprite to our game:

Click the ‘Add New Sprite’ Button (Look at Step 5 if you forgot)

From the ‘Things’ folder, choose ‘Cheesy Puffs’, then ‘OK’.

You will see a very large bowl of cheesy puffs appear.

Rename this sprite ‘Puffs’, then shrink it down until it is very small. (smaller then the Cat)

Step 15. Hiding the Puffs

Every time the Cat touches the Puffs, they should ‘Hide’ or go invisible.

We must give them instructions to do this.

Create the following module for the Puffs.

This tells the Puffs to ‘Hide’ every time they are touched by the Cat.

Note: To make sure the puffs re-appear at the start of the game, we must

add the following module:

Page 12: Scratch Program Puff Collector - MRMS Techmrmstech.weebly.com/uploads/5/1/8/5/518583/puff_collector.pdfwe have to create a Variable called ‘Points’. Click the ‘Variables’ tab

Step 16. Getting Points for Puffs

Every time the Cat collects Puffs, he should get a point. In order to do this, we have to create a Variable called ‘Points’.

Click the ‘Variables’ tab and select ‘Make a Variable’.

Call it ‘Points’:

Double click the ‘Puffs’ Sprite.

Change the

module so it looks like this:

This sets the points to 0 at the start

This adds 1 to ‘Points’ each time the Puffs touch the Cat

Page 13: Scratch Program Puff Collector - MRMS Techmrmstech.weebly.com/uploads/5/1/8/5/518583/puff_collector.pdfwe have to create a Variable called ‘Points’. Click the ‘Variables’ tab

Step 17. Lots of Puffs

Now that we have created one ‘working’ bowl of puffs, we want to make lots of copies of this Sprite.

In the Sprite List window, right click the ‘Puffs’ and select ‘Duplicate’:

Note: The new bowl of puffs might appear on top of the first bowl – separate

them with the mouse.

Repeat this until you have 16 bowls of cheesy puffs in total. (You don’t have to rename each one)

Space them out evenly.

You should also note that when you duplicate a Sprite, it’s Scripts are also duplicated – so each bowl of Puffs has the same instructions as the first one.

Step 18. Winning the Game

When the Cat collects all the Puffs, he wins the game. We want him to say

‘Yipee I Win!’ when this happens.

Double click the Cat and add the following module: (Look at Step 13 if you forgot how to put this together)

As there are 16 bowls of Puffs available,

when the Cat gets 16 points, he wins the game.

Page 14: Scratch Program Puff Collector - MRMS Techmrmstech.weebly.com/uploads/5/1/8/5/518583/puff_collector.pdfwe have to create a Variable called ‘Points’. Click the ‘Variables’ tab

Step 19. Stopping the Baddie

When the game is won (ie the Cat has 16 points), the Baddie should stop chasing.

To do this, we have to change the module that we created for the Baddie in

Step 8.

Double click the Baddie Sprite.

We want to tell the Baddie:

‘REPEAT chasing the Cat UNTIL he has 16 points” For this, we need to use a “Repeat Until” Loop.

This is a special type of Loop. It is called a Conditional Loop.

This means that the instructions inside this loop are repeated over and over

again UNTIL A CONDITION IS MET.

In this case, the condition is:

Change the module as shown:

Change to

Now the Baddie will stop chasing the Cat when points = 16.

Page 15: Scratch Program Puff Collector - MRMS Techmrmstech.weebly.com/uploads/5/1/8/5/518583/puff_collector.pdfwe have to create a Variable called ‘Points’. Click the ‘Variables’ tab

Step 20. Adding a Background

In the Sprite Manager window, select the ‘Stage’:

Now select

‘Backgrounds’, then ‘Paint’:

The following

window appears:

Select ‘Import’

Page 16: Scratch Program Puff Collector - MRMS Techmrmstech.weebly.com/uploads/5/1/8/5/518583/puff_collector.pdfwe have to create a Variable called ‘Points’. Click the ‘Variables’ tab
Page 17: Scratch Program Puff Collector - MRMS Techmrmstech.weebly.com/uploads/5/1/8/5/518583/puff_collector.pdfwe have to create a Variable called ‘Points’. Click the ‘Variables’ tab

The following window appears.

Double click the ‘nature’ folder.

Now select the ‘Woods’ background and click OK.

Page 18: Scratch Program Puff Collector - MRMS Techmrmstech.weebly.com/uploads/5/1/8/5/518583/puff_collector.pdfwe have to create a Variable called ‘Points’. Click the ‘Variables’ tab

Your game should now have a ‘gloomy woods’ background’.

Page 19: Scratch Program Puff Collector - MRMS Techmrmstech.weebly.com/uploads/5/1/8/5/518583/puff_collector.pdfwe have to create a Variable called ‘Points’. Click the ‘Variables’ tab

Step 21. Play the game!!

Your game should now be working.

Click the green flag to start the game – see how many puffs you can collect before losing your 3 lives!

Extension Exercise

(Ask your teacher if you should do this exercise)

Step 22. Time Limit

It might make the game more interesting if there was a time limit of around 30 seconds to collect all the puffs.

We need to make a variable called ‘Time’.

Select the Stage from the Sprite Manager window.

From the Variables tab, click ‘Make a Variable’.

Name the variable “Time”, then click ‘OK’.

Page 20: Scratch Program Puff Collector - MRMS Techmrmstech.weebly.com/uploads/5/1/8/5/518583/puff_collector.pdfwe have to create a Variable called ‘Points’. Click the ‘Variables’ tab

Construct the following module

This sets the time to ‘30’ when the game starts.

We want the time to decrease by one every second. Add the following instructions so your module looks like this:

This tells the program to take 1 from ‘Time’

every second.

Note: At this point, the game will not stop when time runs out – it will simply continue decreasing using negative numbers.

We want the game to stop when time = 0.

To do this, construct the following module:

This comes from the ‘numbers’ tab

This comes from ‘Variables’

Try it! Run your game and watch what happens when time runs out.

Well done! You have just created your own Computer Game!

Page 21: Scratch Program Puff Collector - MRMS Techmrmstech.weebly.com/uploads/5/1/8/5/518583/puff_collector.pdfwe have to create a Variable called ‘Points’. Click the ‘Variables’ tab

Module Library

Here you will find all the modules we used and what they do.

Get a Sprite to follow your mouse movements

Get a Sprite to chase another Sprite

Losing Lives when touched by

another Sprite

(This then moves the Sprite to

the top left corner of the screen)

Ending the game when the Lives run out

Cheesy Puffs

This makes the puffs vanish when ‘eaten’ by the Cat

This makes sure the Puffs

re-appear at the start of the next game

Page 22: Scratch Program Puff Collector - MRMS Techmrmstech.weebly.com/uploads/5/1/8/5/518583/puff_collector.pdfwe have to create a Variable called ‘Points’. Click the ‘Variables’ tab

Gaining Points when the Puffs are collected

Setting a Time Limit

Ending the game when time

runs out.

Get the Baddie to stop chasing

when the points = 16 (The game is Won)

Page 23: Scratch Program Puff Collector - MRMS Techmrmstech.weebly.com/uploads/5/1/8/5/518583/puff_collector.pdfwe have to create a Variable called ‘Points’. Click the ‘Variables’ tab
Page 24: Scratch Program Puff Collector - MRMS Techmrmstech.weebly.com/uploads/5/1/8/5/518583/puff_collector.pdfwe have to create a Variable called ‘Points’. Click the ‘Variables’ tab

TASK

You should now use what you have learned to create your very own computer game, similar to ‘Puff Collector’.

It should have the following features:

The main character should:

• Be controlled by the mouse

• Be chased by a baddie • Collect items and gain points

• Have 3 Lives at the start of each game • Lose a life when he is caught by the baddie

The game should end when the lives run out.

Use “Game Assessment Checklist 1” to make sure your game meets all the

requirements. (Your teacher will give this to you)

You can use any Sprites you wish.

Good Luck!

Show your teacher when you are finished.