Create a Simple Game in Scratch

47
Create a Simple Game Create a Simple Game in Scratch in Scratch Rochelle Lawrence Jones, Danielle Rochelle Lawrence Jones, Danielle Jones, & Jones, & Barb Ericson (Georgia Tech) Barb Ericson (Georgia Tech) June 2009 June 2009

description

Create a Simple Game in Scratch. Rochelle Lawrence Jones, Danielle Jones, & Barb Ericson (Georgia Tech) June 2009. Goals. Learn about event handling simple sequential execution loops variables conditionals parallel execution message passing. Game Description. - PowerPoint PPT Presentation

Transcript of Create a Simple Game in Scratch

Page 1: Create a Simple Game  in Scratch

Create a Simple Game Create a Simple Game in Scratchin Scratch

Create a Simple Game Create a Simple Game in Scratchin Scratch

Rochelle Lawrence Jones, Danielle Jones, &Rochelle Lawrence Jones, Danielle Jones, &Barb Ericson (Georgia Tech)Barb Ericson (Georgia Tech)

June 2009June 2009

Page 2: Create a Simple Game  in Scratch

Goals• Learn about

– event handling– simple sequential execution– loops– variables– conditionals– parallel execution– message passing

Page 3: Create a Simple Game  in Scratch

Game Description• We will make a

game where the player controls a witch using the arrow keys to catch a falling pumpkin. If the witch misses the pumpkin the game is over.

Page 4: Create a Simple Game  in Scratch

Start up Scratch• Click on Scratch.exe

Page 5: Create a Simple Game  in Scratch

Delete the Cat• Click on the

scissors and your cursor turns to scissors and then click on the cat to delete it

• Or right click on the cat and pick delete

Page 6: Create a Simple Game  in Scratch

Add the Witch• Click on the button with the

picture of folder with a star in it– if you hover over it, it says "Choose

new sprite from file"

Page 7: Create a Simple Game  in Scratch

Select the Fantasy Folder

Page 8: Create a Simple Game  in Scratch

Scroll to the Witch• Click on the witch and then OK

Page 9: Create a Simple Game  in Scratch

Resize Your Sprite!• You can make your sprite larger or

smaller by using the “grow sprite” or “shrink sprite” icons.

• You click on one of these icons, then click on your sprite until it is the size you’d like. shrink

grow

Page 10: Create a Simple Game  in Scratch

Move the Sprite • Select (click on the arrow and then

on the sprite) and click and drag the sprite to the bottom of the window

Page 11: Create a Simple Game  in Scratch

Add a Background• Click on the Stage in

the area that shows the sprites and stage

• Click on the Backgrounds tab

• Click on the import button

• Pick a background– Like night-city in

outdoors

Page 12: Create a Simple Game  in Scratch

Event Handling• We want to control the witch using the

arrow keys– When we click the left arrow the witch

should move left– When we click the right arrow the witch

should move right

• This is a form of event handling– Responding to user actions like mouse

clicks and key presses

Page 13: Create a Simple Game  in Scratch

The Scratch Stage• The Scratch stage is 480 pixels wide

and 360 pixels high.

-240 240

180

-180

0,0at the center of the stage

Moving right increases the x valueMoving left decreases the x value

Page 14: Create a Simple Game  in Scratch

Programming the Witch• Click on the witch

sprite in the view of the sprites and stage– Bottom right section

• Click on the Scripts tab– In the center area– This allows us to

create scripts (programs) for the witch

Page 15: Create a Simple Game  in Scratch

Respond to Arrow Keys• Click on Control (orange) and then

drag out "when space key pressed"

Page 16: Create a Simple Game  in Scratch

Respond to Right Arrow• Click on down arrow next to

space and select right arrow

• Click on Motion (blue) and drag out "move 10 steps"

Page 17: Create a Simple Game  in Scratch

Change the move amount

• Click on the 10– it will highlight in blue

• Type 5 and press enter

Page 18: Create a Simple Game  in Scratch

Respond to Arrow Keys• Click on Control (orange)• Drag out "when space key

pressed"• Change "space" to "left

arrow"• Click on Motion• Drag out "move 10 steps"• Change it to -5 (to move

left)• Click on the stage and try

out the left and right arrow keys– Does the sprite leave the

window?

Page 19: Create a Simple Game  in Scratch

Paint a Pumpkin• Click on the paint brush and star

– It will say "Paint new sprite" if you hover over it

Page 20: Create a Simple Game  in Scratch

Draw the Pumpkin• Click the circle tool

– and then use the eyedropper to pick an orange color

– and then click in the drawing area and drag to create the pumpkin

• Click the line tool– And then use the

eyedropper to pick black– And then click in the

drawing area and drag to create a line

Click ok when done

Circle and eyedroppper tools

Drawing area

Page 21: Create a Simple Game  in Scratch

Size the pumpkin as desired and move it to

the top• Click and drag the pumpkin to the

top of the window

Page 22: Create a Simple Game  in Scratch

Make the Pumpkin Fall• When the green flag is clicked we

want the pumpkin to always start at the top and fall down– Click on Control (orange)– Drag out "When green flag clicked"

Page 23: Create a Simple Game  in Scratch

Start the Pumpkin• Click on Motion (blue)

• Drag out “go to x # y # “– this will always start the pumpkin at its

current position (Scratch doesn’t automatically put it back for you).

Page 24: Create a Simple Game  in Scratch

Sequential Execution• One block is

executed after the other

• In order from top to bottom

• When the green flag is clicked– the pumpkin will go to

the specified x and y location

Page 25: Create a Simple Game  in Scratch

Loops• We want the pumpkin to continue to

move down unless the witch catches it

• How do we make this happen? – We could use lots of blocks one after the

other– But, that would be slow and repetitive

• We need a way to repeat a block or set of blocks– This is called a loop or iteration– In scratch we can use a forever loop

• Executes the blocks inside of it until the script is stopped

Page 26: Create a Simple Game  in Scratch

Make the pumpkin fall• Click on Control

(orange)– drag out "forever"

• Click on Motion (blue)– drag out “change y

by 10” – Change it to -1

• Try it out!

Page 27: Create a Simple Game  in Scratch

Catch the pumpkin!

• If the pumpkin touches the witch then it is caught

• Let's track how many pumpkins we have caught with a score– We will increment the score each

time we catch a pumpkin

Page 28: Create a Simple Game  in Scratch

Variables• If we are going to keep track of

the score – We want something to hold the

current score– And we want to be able to change

the score– We want the value to change or vary

• This is called a variable

Page 29: Create a Simple Game  in Scratch

Track the score• When we start the

game set the score to 0

• Click on Variables (red)

• Click on Make a Variable

• Name it score

Page 30: Create a Simple Game  in Scratch

Set score to 0• Highlight the pumpkin

sprite• Drag the “forever”

down• Drag out "set score to

0“• Drag the “forever”

back up• Notice the score

showing on the window

Page 31: Create a Simple Game  in Scratch

Conditionals• We want to increase the score if

the witch caught the pumpkin– So this action will only occur only if

some condition is true– This is called a conditional or an “if”

Page 32: Create a Simple Game  in Scratch

Did we catch the pumpkin?

• From Control drag out an “if”

• Check if the pumpkin is touching the witch– Get this in Sensing

• If this is true increment the score– From Variables

Page 33: Create a Simple Game  in Scratch

Increment the score• Try it out!

– is this what you expected?

• Computers do what you tell them to do– Now what you

want them to do

Page 34: Create a Simple Game  in Scratch

Reset the Pumpkin• If we caught the

pumpkin– Increment the

score– And move the

pumpkin to some random spot at the top of the window

Page 35: Create a Simple Game  in Scratch

Reset the Pumpkin• Click on Number

– drag out "pick random 1 to 10"

– drop on the x value after “go to x:”

– change the 1 to -235 and change 10 to 235

– change the y value to match the y in the first “go to x # y #”

Page 36: Create a Simple Game  in Scratch

Adding Losing• If the witch doesn't catch the

pumpkin it just gets stuck at the bottom of the screen

• Let's tell the player that he or she lost

Page 37: Create a Simple Game  in Scratch

Make the Pumpkin Speak

• When a pumpkin is caught, make it say, “You caught me.”

• After if touching witch, – Add say block and include the text

for 1 second.

Page 38: Create a Simple Game  in Scratch

Add text sprite• Click on the Paint new sprite button

– Click on the T for text– Pick the red color– Modify the font size– Move the square to where you want

the text– Type You Lost!

Page 39: Create a Simple Game  in Scratch

Hide the sprite• We don’t want to tell the player that

she lost when the game starts– So hide the message when the game starts

• Click on Control– drag out "when green flag clicked"

• Click on Looks– drag out “hide”

Page 40: Create a Simple Game  in Scratch

Check if Lost• If the y position gets

near the bottom (near -180)– Drag out an if

• from Control

– Drag out a blank < blank

• From Numbers

– Add a y position • From Motion

Page 41: Create a Simple Game  in Scratch

Broadcast a message• Sprites communicate by passing messages

– One sprite broadcasts the message– Other sprites can listen for it and react to it

when they receive it– Click on Control

• drag out "broadcast blank"• click on the drop down arrow

next to new – name it lost• Add “stop script”

– to stop the forever loop

• Sprites communicate by passing messages – One sprite broadcasts the message– Other sprites can listen for it and react to it

when they receive it– Click on Control

• drag out "broadcast blank"• click on the drop down arrow

next to new – name it lost• Add “stop script”

– to stop the forever loop

Page 42: Create a Simple Game  in Scratch

Receive Lost• Click on the text sprite• Click on Control

– drag out "when I receive blank"

– click on the down arrow and select lost

• Click on Looks– drag out “show”

• Click on Control– drag out “stop all”

• to stop all scripts

Page 43: Create a Simple Game  in Scratch

Parallel Execution• We have several

things happening at the same time when the green flag is clicked

• This is called parallel execution

Page 44: Create a Simple Game  in Scratch

Individual Project #1 (40 points)

• Make the “You Lost!” text glide from upper right corner of the screen to the bottom. (6 pts)

• Add a sound after it reaches the lower left corner (6 pts)

• “Say” something that allows the user to start the game over. (6 pts)

• Create script to enable user to start the game over (10 pts)– At any time during the game and– When the game is over

• Create instructions to your game (see slide “Share Your Game”). (6 pts)

• Share your game. ( 6 pts)

Page 45: Create a Simple Game  in Scratch

Create Instructions• Click on the Show

Project Notes in the upper right corner

• Add the author and instructions

• Press OK

Page 46: Create a Simple Game  in Scratch

Test your game• Click the green flag• If you want, adjust the speed of the

pumpkin– Increase the amount it changes in y

• Modify the sprites using the “Costume” tab

• Save your game with the “Save” button

Page 47: Create a Simple Game  in Scratch

Share your game• You can share your projects at the

scratch web site– http://scratch.mit.edu

• Click on the Share! button• You can also download other

projects and see how they were created