Purple Sky Profile Header
Do you love playing video and computer games? Do you dream of someday creating your own? With this science fair project you can turn that "someday" wish into a "today" reality!

AREAS OF SCIENCE

Video & Computer Games

DIFFICULTY

 

METHOD

 Engineering Design Process

TIME REQUIRED

Long (2-4 weeks)

To program a simple video game that can be customized, as desired, and to determine the factors that affect the game's score.
  • Program
  • Programmer
  • Sprite
  • Scratch
  • Script
  • Variable
  • Tune
  • Ratio
  • Constant
  • Code
  • What is an "if" statement? There are two types of "if" blocks in Scratch an "if-then" block and a "if-then-else" block; how do they differ?
  • What are the different ways you can get an action (or series of actions) to happen repeatedly in Scratch?
  • What is a variable and how are variables used in programming?

How would you like to make your very own video game? Sound impossible? Well it isn't! This science fair project will walk you through the steps of creating a simple video game. And once you've done that, you can take what you've learned and use it to come up with a game idea of your own, modify the game you've already created, or just sit back and enjoy playing your creation from this science fair project.

Video games are basically made up of a set of instructions, called a program, which tells the computer (or game console) what to do. The instructions include information like what characters, or other art, to display on the screen; what should happen when the player presses different buttons; and when specific sounds or songs should be played. If you were giving a set of instructions to a person, you'd probably write them down using a language that the person understood.

For example, the Experimental Procedure for this science fair project is a list of instructions, written in English, telling you how to do this project. Similarly, programmers (people who write programs) use special languages to write computer instructions. These programming languages are specifically built to take advantage of how computers process information. Just as there are many different human languages, there are also many different programming languages. Different programming languages have different advantages and disadvantages—some are good for telling computers how to display images, while others are better at allowing the computer to do mathematical calculations quickly. Programmers choose which programming language to use based on the tasks they want the computer to perform, and which languages the programmer knows.


scratch-scripts-cat-sprite
Figure 1. This program, in Scratch, has two scripts written for the cat sprite.

In this science fair project you'll create a video game using an easy-to-use programming language called ScratchTM. Scratch was created by researchers at the Massachusetts Institute of Technology (MIT) and is specifically made for beginning programmers—so even if you've never programmed anything before, you'll be able to use Scratch! Scratch uses blocks (simple instructions), which you can hook together, by dragging and dropping with your mouse, to make longer and more complex instructions. Each set of blocks is called a script. In the Scratch program shown in Figure 1, above, there are two scripts—one that instructs the computer to make the cat "walk 10 steps when the player hits the right arrow key" and another script that instructs the computer to "play a meow sound when the player hits the space bar."

The game you will create in this science fair project is a game of chase between a cat and a dog. The cat will be controlled by the player, and the dog will be controlled by the computer. The game will end when the dog catches the cat. Ready to program? Let's get started! The references in the Bibliography and in the Experimental Procedure, below, will teach you all the programming skills you need to know to make this game. Once you've made the game, you may surprise yourself with all the fun additions and variations you can add to the game using your new programming skills!

The instructions below divide the process of programming this video game into several manageable pieces. For each piece, you'll be given programming objectives and told which blocks are necessary to create the program. It'll be your task in this science fair project to figure out how the blocks should be hooked together to achieve the programming goals. Once the game is running, you'll make final changes to the game to improve the gameplay experience.

Getting Started with Scratch

  1. The first thing you should do is sign onto Scratch. If you do not have an account yet, click on 'Sign Up' to create an account.
  2. If this is your first time using Scratch or if you need a refresher, read the Getting Started with Scratch guide from the Raspberry Pi foundation.

Programming the Cat

  1. When you open Scratch, the default screen is a project file that already contains one sprite (all characters and objects in Scratch are referred to as sprites). The sprite for this game is a cat, which will be the character that the player controls during the game.
  2. The cat sprite takes up a large amount of screen space. To make sure there is enough space on the screen to have the dog and the cat running around, you'll need to shrink the size of the cat sprite, as in Figure 2.
    1. Click on the Sprite in the button right corner of the screen. You can then adjust the size of the sprite by changing the 'Size' value. It has a default value of 100, and if you increase it the sprite will become larger, and if you decrease it the sprite will become smaller.
    2. Shrink the cat until it is at a size of 80.
scratch-size-cat-sprite
  1. Figure 2. Changing the size value circled in red can shrink or enlarge the sprite.
  2. Now you're ready to add blocks to control how the player moves the cat around the game screen. The order of the scripts does not matter, as they will all happen simultaneously. Use the blocks shown in Table 1, below, to create the following movements. Experiment with the blocks until your cat can do the following movements:
    1. Once the game is started (i.e. the green flag is clicked), the cat is always in motion.
    2. When the up arrow key is pressed, the cat will change direction so that it moves up.
    3. When the down arrow key is pressed, the cat will change direction so that it moves down.
    4. When the right arrow key is pressed, the cat will change direction so that it moves to the right.
    5. When the left arrow key is pressed, the cat will change direction so that it moves to the left.
Block
Type of Block
Description
block1
Events

Runs script below it when green flag is clicked.