A SIMPLE
SCRATCH GAME
(Egg
Catcher)
M. Meyer
BACKGROUND
I. Introduction:
We have talked about the evolution of
high-level programming languages and discussed popular programming paradigms.
We discussed in some detail three of the most popular paradigms:
Today you will create a simple game in Scratch
using the concepts behind these paradigms.
II. Ludology & Funativity:
As you create the game you should make a
determination on whether or not YOU think the game is fun. If you think
it IS fun, why? If you think it IS NOT fun, why? We talked about abstract things
that make a game fun and concrete things that make a game fun. As you create
the game, ask yourself how the following concepts are demonstrated (or NOT
demonstrated):
Abstract (things that make a game fun):
- Spatial Relationships (Physical)
- Pattern Recognition (Mental)
- Social Interaction
Concrete (things that make a game fun):
- Goals (Numerous, Clear, Accomplishable)
- Rewards and Punishments.
- Choice (or the illusion of choice).
PLANNING THE GAME
1. Description of Game:
(Never start a game by sitting down and coding.
Every large programming project needs to be planned out, in as much detail as
possible BEFORE you start coding. The more time, effort and detail you put into
your planning stage, the faster the coding of the game will actually go.)
The game will be called Egg Catcher. In
the game a cat (the player) will attempt to catch the eggs that are dropped by
a flying parrot. The player will control the cat using the mouse.
In the first iteration of the game (what this
tutorial covers), we will have the parrot drop one egg over and over. Each egg
that is caught will add one to the score. If an egg makes it to the bottom of
the screen the game is over.
2. Programming Outline
Plan, plan, plan, before you write a single
line of code! A programming outline will help you see problems, and help
prevent you from making mistakes
Object (Name,
Description) |
Properties (What
are the facts about this object? What
does the object look like? How many images will you need for it? Where does it
start? What are its states (alive, dead, etc.) |
Functions (What
does this object do? Can it
move? Can it change costumes? Can it interact with other objects? Can it
interact with the player?) |
Stage (the
stage itself, which will have a title and a gameplay screen). |
Stage will have three backgrounds. Stage will have two variables: score which will be set to 0 at start. |
Stage will show the title and instructions,
switch backgrounds, broadcast a startgame message to start the actual game,
and then finally switch backgrounds again when it receives the endgame
message. |
Cat (the
player) |
Will have two costumes so that it can appear
to run. |
The cat will move and change costume to
follow the mouse on the screen. The cat will not go up and down only side to
side. |
Parrot (the
opponent AI) |
Will have two costumes so that it can appear
to fly. |
Parrot will fly back and forth across the top
of the screen. |
Egg (will
control score and end of game) |
Has only one costume. |
Will appear next to the parrot, then fall
towards the bottom of the screen. If it touches the Cat the score will go up
by 1. If it reaches the bottom of the screen the game will end. |
CREATING THE GAME
1. Creating the Objects:
By looking at the programming outline, you should be able to see that we need four objects. In SCRATCH these objects are called Sprites.
Egg Catcher: Use the mouse to control the Cat,
and catch the eggs.
Game Over
2. Sequence
The code in SCRATCH is put together using
blocks from the library and is assembled in the Scripts area for each Sprite. The
scripts that are created are read from top down once they are started. We need
a script for the stage, that will initialize all of the variables to 0 (by
convention, 0 means NO and 1 means YES), display the title screen, play a
sound, wait 10 seconds, and then switch to the playscreen. Click on the stage
icon in the sprites area, and then click on the Scripts tab in the center
window. Then drag and drop the code blocks from the library on the left of the
screen, until your script window looks like this:
Once your script looks like the example above,
click on the green flag in the top right of the screen to test it.
2. Procedures (messages)
We need a way for different objects to
communicate with each other in the game. As an example, after the Stage sprite
has switched to its playscreen background we would like it to send out a signal
to all of the other sprites that the game can now start. Later we want the
stage to switch to the game_over screen when it receives a message. Add the
following code to your script in the Scripts window of the Stage sprite.
Once your script looks like the example above,
click on the green flag in the top right of the screen to test it.
2. User Interaction (the player).
Select the Cat sprite. He needs to be put in
his starting place and hidden when the green flag is clicked (that way he will
not appear on the title screen). Then he needs to be appear, and start moving
when the game actually starts. He will turn to face the mouse and make his X
position match the mouse X position.
Once your script looks like the example above,
click on the green flag in the top right of the screen to test it.
2. Repetition
Select the Parrot sprite. She needs to be put
in her starting place and hidden when the green flag is clicked. Then she needs
to appear and move back and forth across the top of the screen, without leaving
the screen. She should move very slowly at first (actually she will not move at
all in the beginning) but then faster and faster as the game progresses.
Once your script looks like the example above,
click on the green flag in the top right of the screen to test it.
2. Selection and Collision Detection
The egg should start at the parrot, and then
fall towards the bottom of the screen. It needs to be able to determine if it
comes in contact with the Cat (add 1 to the score) and if it gets to the bottom
of the screen (game over). Like the parrot, we want the egg to start off moving
slow, but then get faster as the game progresses (but the egg will always be
moving a negative amount in the y direction).
Making
the Game Better:
What could be done to make this game better and
more fun to play? Trying adding some more things to this game:
- Add a difficulty setting.
- Have the egg drop randomly.
- Drop multiple eggs.
- Add a start button after the Title Screen so
that you do not have to wait 10 seconds.
- Add a try again button on the game over
screen.
- Keep track of the players high score.
- Add some more sounds (running, wings
flapping, etc.)