Sei sulla pagina 1di 5

Page 1

Making a Basic Game in


Scratch
This tutorial shows you how to make a simple game in
Scratch. In this game, you are in a dungeon. You are trying to
get to the cake at the end of the dungeon. Monsters are
protecting the cake. Don't let them touch you!

Introduction to Scratch
Go to this website: http://o.ooli.ca/en/scratchgames/cake

First, we'll choose


1acharacter
picture for your
in the
2
game. Go to the
New Sprite icon
and click on the
Choose a Sprite
button.

Then, choose a
picture that you 2 The picture will probably be
like. Scratch calls too big. To make it smaller,
these pictures 1 click on the Size box and
sprites. enter a smaller number.

On the left of the


3 4 screen are
commands that
you can give to
sprites. In Scratch,
these commands
are called "blocks."
You can move sprites around by dragging them. Move Click on the "move
your pointer over the sprite, hold down your mouse __ steps" block.
button, and then move the mouse. Let go of the button What does your
when the sprite is in the spot you want. For now, move sprite do when you
your sprite to the left side of the game. click on the block?

There are many types of blocks. At


5 the far left of the screen, you can
change what sort of blocks are
6
shown. Click on "Looks" to show the
blocks for looks. Then click on the
"say __ for __ secs" block. What
happens?

What happens when you click on


In the middle of the screen is a
the "think __ for __ secs" block?
blank area. You can put together
The "hide" block? The "show"
blocks here to make more
block? Can you make your sprite
complicated commands. This is
say "goodbye" instead of "hello?"
called a “program” or “script.”
Page 2
The Bat
The bat guards the dungeon. Let's write a program for the bat so
that it moves up and down.

Click on At the start, we


1 the bat
button in
2movewant the bat to
up. Go to the
the list of "Motion" blocks,
sprites. and drag a "point in
direction" block to
your program.

3 will
Click on the direction number “90”. You
see a circle with an arrow. Drag the 4 Drag a "move __
steps" block to
arrow until it points upwards and the your program.
direction is 0. Afterwards, click on the Click on it. The bat
block you’ve just created so that the moves a little bit,
bat will now point up. but then it stops.

5 Go to the
"Control" blocks. 6 "move
Drag the
__
Drag a "forever" steps" block
block to your into the
program. The forever
"forever" block will block. What
repeat a happens
command until the when you
game ends. click on it?

7 The bat will keep


moving up until it gets 8 9
stuck at the top of the
dungeon. What
happens when you
drag the bat back to
the bottom of the Go to the "Motion" blocks. The bat moves very fast.
dungeon? What Drag a "if on edge, bounce" Instead of having the bat
happens when you block into the forever block. move 10 steps, change
click on the red stop What happens when you click the number of steps to a
button? on the forever block now? smaller number.

10 Let's put everything


together now. Drag all
11 Now, stop your
program by
the blocks together so clicking on the red
that they are under flag. Then restart
the block for when the it by clicking on
green flag is clicked. the green flag.
Page 3
You
Now let's write a program that lets you move around the dungeon.

1theClickspriteon 2 “Motion”Goblocks.
to the

for your Click on the “set


character rotation style
in the list ‘left-right’” block.
of sprites. This prevents
your sprite from
turning upside-
down when
moving around.

3 makeWea program
will now
4
to let us use the
keyboard to
move our sprite.
Go to the
"Events" blocks.
Drag a "when
___ key
pressed" block
into your Click the down arrow, and
program. change the key to "right
arrow."

5 6

Now drag a "move __ steps" block


What should the sprite do when you press the right arrow? It should and put it after the "point in
turn to the right, and then walk. Go to the "Motion" blocks. Drag a direction 90" block. What happens
"point in direction ___" block and attach it to the "when right arrow when you press the right arrow
key pressed" block. If necessary, change the direction angle to 90. key on your keyboard now?

7 What happens when you


press the left arrow key on
your keyboard? Nothing
happens. We need to write a
program for that. Write a
program that moves your
sprite when you press the up,
left, and down arrow keys.
Page 4
Winning and Losing
Right now you can move, but nothing happens if you reach the cake or if the bat catches you. Let's write a
program to handle that.

1 Make sure your


character’s sprite 2 Go to the
"Control" blocks.
is selected. Then, Drag a "forever"
go to the "Events" block and put it
blocks. Drag a after the "when
"when green flag green flag
clicked" block into clicked" block.
your program.

3 4

Now drag a "if __ Go to the "Sensing" blocks. Drag a "touching __?" block into the "if __ then" block.
then" block into the Scratch will only let you do this if the LEFT side of the "touching __?" block is over the
"forever" block. spot where you want it to go.

Click the
5 down arrow
of the
6
"touching
__?" block.
Choose
"Cake."

Go to the "Looks" blocks. Drag a "say ___ for __ secs"


block inside the "if __ then" block. Have it say "you win!"

7 8 9

Click on the green flag. Move Now add some blocks so that if Also add some blocks so that
your sprite so that it touches you're touching the bat, it will say if you're touching the ghoul, it
the cake. What happens? "oh no!" will say "oh no!"
Page 5
The Ghoul
Let's make a more dangerous monster. Let's program the ghoul to chase you.

1 2

Click on the ghoul sprite. Go to the "Control" blocks. Go to the "Motion" blocks. Drag a "point
Drag a "forever" block and towards ___" block into the forever
put it after the "when green block. Click on the down arrow of the
flag clicked" block. block, and choose your sprite.

4 5

Drag a "move ___ steps" Click on the green flag to start the program.
block and put it inside the The Ghoul will quickly chase your sprite.
forever block. Change the number of steps that the ghoul
moves so that it moves very slowly.

Your Turn
Can you add a sound effect if you get the cake? Can you make an explosion or a whirl effect if you get caught?
Can you add more enemies?

* A completed copy of this game is available at http://scratch.mit.edu/projects/25753675/


** Some of the art used in this tutorial is from Scratch and is licensed under CC BY-SA 2.0. Scratch is developed by the Lifelong Kindergarten
Group at the MIT Media Lab. See http://scratch.mit.edu

Potrebbero piacerti anche