Home Store Project Ideas Project Guide Ask An Expert Blog Careers Teachers Parents Students

Want to Make a Video Game? Here's How!

Difficulty
Time Required Long (2-4 weeks)
Prerequisites None
Material Availability To do this science fair project, you'll need to download and install Scratch, a free programming language from MIT Media Labs. For more information, see the Experimental Procedure section.
Cost Very Low (under $20)
Safety No issues

Abstract

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!

Objective

To program a simple video game that can be customized, as desired, and to determine the factors that affect the game's score.

Credits

Ian Slutz, Planet Moon Studios

Amber Hess

Sandra Slutz PhD, Science Buddies

  • Scratch is a trademark of the Massachusetts Institute of Technology.

Cite This Page

MLA Style

Science Buddies Staff. "Want to Make a Video Game? Here's How!" Science Buddies. Science Buddies, 15 Oct. 2014. Web. 23 Nov. 2014 <http://www.sciencebuddies.org/science-fair-projects/project_ideas/Games_p023.shtml>

APA Style

Science Buddies Staff. (2014, October 15). Want to Make a Video Game? Here's How!. Retrieved November 23, 2014 from http://www.sciencebuddies.org/science-fair-projects/project_ideas/Games_p023.shtml

Share your story with Science Buddies!

I did this project I Did This Project! Please log in and let us know how things went.


Last edit date: 2014-10-15

Introduction

Note: This Science Buddies project idea was written using Scratch version 1.4. A new version, Scratch 2, is now available. You can use an online version of Scratch 2 in your web browser at scratch.mit.edu, or you can download an offline version.

While Scratch 2 offers improvements over Scratch 1.4, the layout and some features have changed slightly. This means that the procedure below will not exactly match the new features of Scratch 2. If you need help using Scratch 2, you should go to the official Scratch help page. If you would like to follow our directions exactly, you can still download Scratch 1.4 here.

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.

screenshot of Scratch showing a cat sprite with code for two scripts
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!

Terms and Concepts

  • Program
  • Programmer
  • Sprite
  • Scratch
  • Script
  • Variable
  • Tune
  • Ratio
  • Constant
  • Code

Questions

  • 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?

Bibliography

These resources will introduce you to Scratch:

For help creating graphs, try this website:

More information about ratios can be found at this website:

News Feed on This Topic

 
, ,
Reading level:
Note: A computerized matching algorithm suggests the above articles. It's not as smart as you are, and it may occasionally give humorous, ridiculous, or even annoying results! Learn more about the News Feed

Materials and Equipment

Note: This Science Buddies project idea was written using Scratch version 1.4. A new version, Scratch 2, is now available. You can use an online version of Scratch 2 in your web browser at scratch.mit.edu, or you can download an offline version.

While Scratch 2 offers improvements over Scratch 1.4, the layout and some features have changed slightly. This means that the procedure below will not exactly match the new features of Scratch 2. If you need help using Scratch 2, you should go to the official Scratch help page. If you would like to follow our directions exactly, you can still download Scratch 1.4 here.

  • Personal computer with Internet access and Scratch installed; see the Experimental Procedure for details on installing Scratch for free.
  • Lab notebook
  • Graph paper
  • Optional: Scratch programming reference book, Scratch Programming for Teens by Jerry Lee Ford, Jr. (at www.amazon.com)

Disclaimer: Science Buddies occasionally provides information (such as part numbers, supplier names, and supplier weblinks) to assist our users in locating specialty items for individual projects. The information is provided solely as a convenience to our users. We do our best to make sure that part numbers and descriptions are accurate when first listed. However, since part numbers do change as items are obsoleted or improved, please send us an email if you run across any parts that are no longer available. We also do our best to make sure that any listed supplier provides prompt, courteous service. Science Buddies does participate in affiliate programs with Amazon.comsciencebuddies, Carolina Biological, and AquaPhoenix Education. Proceeds from the affiliate programs help support Science Buddies, a 501( c ) 3 public charity. If you have any comments (positive or negative) related to purchases you've made for science fair projects from recommendations on our site, please let us know. Write to us at scibuddy@sciencebuddies.org.

Share your story with Science Buddies!

I did this project I Did This Project! Please log in and let us know how things went.

Experimental Procedure

Note: This Science Buddies project idea was written using Scratch version 1.4. A new version, Scratch 2, is now available. You can use an online version of Scratch 2 in your web browser at scratch.mit.edu, or you can download an offline version.

While Scratch 2 offers improvements over Scratch 1.4, the layout and some features have changed slightly. This means that the procedure below will not exactly match the new features of Scratch 2. If you need help using Scratch 2, you should go to the official Scratch help page. If you would like to follow our directions exactly, you can still download Scratch 1.4 here.

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.

Installing and Getting Started with Scratch

  1. To start this science fair project, you should go to the Scratch download page at scratch.mit.edu/download and follow the instructions there to download and install Scratch for free. If you need help installing it, read the Science Buddies Installing & Getting Started with Scratch page. This short guide will familiarize you with Scratch.
  2. If this is your first time using Scratch or if you need a refresher, read the Science Buddies Scratch User Guide.

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.
    1. Click on the "Shrink sprite" button in the toolbar (it is near the top right, with four arrows pointing inward). The button will turn a faint blue color when it is "active." Note: If you are ever confused about where something is on the interface (the screen), look at the Scratch interface explanation in the Scratch Reference Guide (found on the Scratch Support page).
    2. Once the "Shrink sprite" button is active, move your cursor over the cat and click several times—you will see the cat shrinking.
    3. Shrink the cat until it is approximately 1 inch tall when you see it in presentation mode.
      • Press the "enter presentation mode" button to enter presentation mode.
  3. 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
when green flag clicked Scratch block icon
Control Runs script below it when green flag is clicked.
when key pressed Scratch block icon
Control Runs script below it when specified key is pressed.
forever Scratch block icon
Control Runs the blocks inside over and over.
point in direction Scratch block icon
Motion Points sprite in the specified direction.
move x steps Scratch block icon
Motion Moves sprite forward or backward when you hold down the assigned key. The number of steps can be changed. Increase the number of steps to make a sprite move faster; decrease the number to make a sprite move slower.
go to X Y Scratch block icon
Motion Moves sprite to specified x and y position on the screen.
Table 1. All the blocks you need in order to add basic movement control to the cat are listed in this table.
  1. When playing a game, it is nice to know that each time you start the game (which is the same as pressing the green flag in Scratch) the player character (the cat in your game) will start in the same place. Modify your cat script(s) so that the cat always starts in the middle of the screen. The block(s) necessary to do this are also listed in Table 1.

Programming the Dog

  1. In your game, the dog will be the computer-controlled character that chases the cat. To create a dog sprite, go to the area containing the new sprite buttons, just below the gameplay screen, and click on the "Choose new sprite from file" button. Figure 2, below, shows the location of the button. From the menu that appears, choose animals (under costumes) and select any dog sprite that you want.


screenshot of Scratch showing where to find new sprite button and the menu that opens when the button is clicked
Figure 2. Clicking on the new sprite button (circled in red) will cause a menu to open from which you can choose sprites. The dog sprite is located in the "animals" folder in the costumes section.
  1. Using the same method as described in step 2 of "Programming the Cat," shrink the dog sprite until the cat and dog are similar sizes.
  2. The programming goal is to have the dog chase the cat continuously. The blocks you'll need to do this are shown in Table 2. Experiment with the blocks until your dog:
    1. Is always in the same starting position at the beginning of the game.
    2. Continuously moves toward the cat, once the game is started.
Block Type of Block Description
when green flag clicked Scratch block icon
Control Runs script below it when green flag is clicked.
forever Scratch block icon
Control Runs the blocks inside over and over.
point towards Scratch block icon
Motion Points sprite in the specified direction.
move x steps Scratch block icon
Motion Moves sprite forward or backward when you hold down the assigned key. The number of steps can be changed. Increase the number of steps to make a sprite move faster; decrease the number to make a sprite move slower.
go to X Y Scratch block icon
Motion Moves sprite to specified x and y position on the screen.
Table 2. All the blocks needed to program the dog are listed in this table.

Programming the End of the Game

The goal of the game is for the player to keep the cat away from the dog—when the dog "catches" the cat, the game is over. The next few steps will help you create sprites and scripts to make the game end when the cat and dog sprites touch.

  1. When the game ends, both the cat and the dog should stop moving. This means you need to tell the program, by editing an existing script, that all the scripts that are currently running need to end. You could place these instructions in either the cat or in the dog's scripts area, but for this science fair project, you'll put it in the cat's script area. All the blocks you need for this step are in Table 3, below. Experiment with the blocks until:
    1. All the scripts will end if the cat and dog sprites touch. As long as the sprites do not touch, the cat will keep moving, exactly as you programmed in the "Programming the Cat" section above.
Block Type of Block Description
when green flag clicked Scratch block icon
Control Runs script below it when green flag is clicked.
Scratch forever if block icon
Control Loops forever and continuously checks if the statement inside the hexagon is true. When the statement becomes true, the program will do the actions inside the loop.
sensing Scratch block icon
Sensing This block checks to see if the sprite is touching another sprite.
broadcast Scratch block icon
or
broadcast and wait Scratch block icon
Control Sends a message to all sprites, triggering them to do something, and then either continues with the next block without waiting for the triggered scripts or waits until the triggered scripts all finish before continuing with the next block.
stop all Scratch block icon
Control Stops all scripts in all sprites.
when receive Scratch block icon
Control Runs script below when it receives the specified broadcast message.
show Scratch block icon
Looks Makes sprite appear on the stage.
hide Scratch block icon
Looks Makes sprite disappear from the stage.
Table 3. All the new blocks needed to program the end of the game are listed in this table.
  1. Once the cat and dog sprites touch, you need to communicate to the player that the game is over. The blocks needed to do this are also listed in Table 3.
    1. Go to the area containing the new sprite buttons and click on the "Paint new sprite" button.
    2. Using the tools you find there, create a text sprite, which reads "Game Over."
    3. Now you need to create scripts that keep the "Game Over" sprite hidden until your "game over" conditions are met (i.e. the cat and dog sprites touch). Experiment with the blocks to do this.
      • Hint: You may find that you have a problem—when the cat and dog sprites touch, all the scripts stop, which means you can't run a script that shows the Game Over sprite. Look up more information about the "broadcast and wait" block. How could this block help solve the problem? Would it go in the scripts for the cat sprite or for the Game Over sprite?
      • Remember to make sure that the Game Over sprite is hidden when you restart the game after losing.

Programming the Score Board

  1. The last part of the program is a metric by which the player can decide how well he or she is doing in the game. Many games keep track of your score, which allows players to compare how well they do relative to other players, or to other times they've played the game.
  2. Since the goal of the game is for the player (as the cat) to avoid getting caught by the dog for as long as possible, you'll use time, in seconds, as the score. You could put the script for scorekeeping in any of the sprites, but since time is independent of the dog, cat, or Game Over sprites, you'll put it in the stage. To write the script, you'll need to create a variable—time.
    1. Click on the Variables button in the block palette, and then on the "Make a variable" button.
    2. When prompted, type "time" for the name of the variable and click OK.
    3. Once you click OK, you'll see the time variable appear in the block palette and on the screen. If you want to make the variable disappear from the screen, uncheck (by clicking on it) the checkbox next to the time variable.
  3. Once you've created the time variable, you will need to write a script using it. Experiment with the blocks to do the following. All the blocks you'll need for this step are shown in Table 4, below.
    1. Display the time on the screen so that the player can see it. Note: This can either be done by keeping the checkbox checked next to the time variable in the variables menu, or by using a block that instructs the program to show the variable.
    2. When the game is started, time should start at zero and increase by 1 every second until the end of the game.
Block Type of Block Description
when green flag clicked Scratch block icon
Control Runs script below it when green flag is clicked.
forever Scratch block icon
Control Runs the blocks inside over and over.
wait x seconds Scratch block icon
Control Waits specified number of seconds, then continues with next block.
show variable Scratch block icon
Variable Shows the variable monitor on the stage.
set variable to x Scratch block icon
Variable Sets the variable to the specified value.
change variable by x Scratch block icon
Variable Changes the variable by specified amount.
Table 4. All the blocks needed to program the end of the game are listed in this table.

Tuning the Game

Congratulations! You've successfully programmed a game! But when you play it, you may find that the game is too easy, too hard, or just not quite "fun" yet. Game makers often have to experiment with the different gameplay variables to make a game feel fun and have just the right level of difficulty, which is called tuning. In this science fair project, there are two gameplay variables that can be tuned: the speed of the dog and the speed of the cat.

  1. Increasing the number of steps a sprite takes makes it move faster. Decreasing the number of steps a sprite takes makes it move slower.
  2. What happens to the score of the game when you increase the speed of both the dog sprite and the cat sprite, but keep the ratio of their speeds constant?
    1. Start with both the cat and the dog moving at a rate of one step.
    2. Play the game at least three times using the "1 step" speed settings. After each round of the game, record your score (which in this case is the number of seconds you can keep the cat away from the dog) in a data table, like Table 5, in your lab notebook. Also take notes on how "fun" you feel the game is using the "1 step" speed settings. Note: If a game lasts longer than 5 minutes, stop and record the game score as >300 (greater than 300 seconds).
    3. Keep increasing the speeds of the cat and dog, but remember to keep the ratio constant; for example, the next speed setting would be 2 steps for each, then 3 steps for each, and so on. For each speed setting, play the game three times and record your scores in your data table. Write down how "fun" you feel the game is at each setting, compared to the other speed settings.
    4. Stop the experiment when you get to a speed setting where the average of your game trials is 5 seconds or less.
    5. Make an XY graph with speed on the x-axis, versus the score on the y-axis. You can make the graph by hand, or use a website like Create a Graph to make the graph on the computer and print it.
    6. What happens to the game score as the speed of the characters increases? What speed setting feels the most fun?
Cat's Speed (# steps) Dog's Speed (# steps) Speed Ratio (Cat:Dog) Game Score (seconds) Notes on how "fun" the game is:
Trial 1 Trial 2 Trial 3 Average of Trials
1 1 1:1          
2 2 1:1          
Table 5. Below is an example of what the data table for the speed changes with a constant cat-to-dog speed ratio should look like. Notice that both the cat and the dog's speeds increase, but the ratio between the speeds of the two characters remains constant.
  1. What happens to the score of the game when you change the ratio between the speeds of the two characters?
    1. From your constant speed ratio experiment in step 2, pick the speed setting that you felt was the most fun, and keep the cat's speed fixed at that speed.
    2. Increase the dog's speed by one step. Play the game three times and record your scores in a data table, like the one in Table 6, in your lab notebook. Also take notes on how "fun" you feel the game is.
    3. Keep increasing the dog's speed, one step at a time, retesting, and recording the scores and "fun" factor in your data table. Repeat this step until you reach a speed ratio where the average game score is less than 5 seconds. Remember, do not change the cat's speed.
    4. Once you've reached a speed ratio where the game ends too quickly (5 seconds or less per game), then go back to the dog speed you started with. This time, keep decreasing the dog's speed, one step at a time, retesting, and recording the scores and "fun" factor in your data table. Stop decreasing when either the average game score is greater than 300 seconds or the dog's speed is 1.
    5. Make an XY graph with the speed ratio on the x-axis, versus the score on the y-axis. To graph the speed ratio, you'll need to convert the ratio to a fraction and then to a decimal value. If you're unsure how to do this, ask your math teacher or consult the website about ratios, listed in the Bibliography.
    6. What happened to the game score as the cat-to-dog speed ratio increased? How about as it decreased? Which speed setting was the most fun?
Cat's Speed (# steps) Dog's Speed (# steps) Speed Ratio (Cat:Dog) Convert Ratio to Decimal Game Score (seconds) Notes on how "fun" the game is:
Trial 1 Trial 2 Trial 3 Average of Trials
3 2 3:2 1.5          
3 3 1:1 1          
3 4 3:4 0.75          
Table 6. Below is an example of what the data table for the speed ratio changes should look like. Notice that the cat's speed remains constant; only the dog's speed increases and decreases.
  1. Using what you learned from your experiments in steps 2 and 3 of this section, choose the most fun speed settings for the dog and the cat characters. Now you've tuned your game!
  2. You can continue to create more additions to make your game even more fun. For example:
    1. Add sound effects.
    2. Make a fun background (stage) for the game to take place on.
    3. Use the "Costumes" feature and different versions of the sprites to try to animate the dog and cat so that they look like they're running.
    4. Try some of the Variations listed below, or think of your own ideas!
  3. If you need help with your program, read the Science Buddies Troubleshooting a Program in Scratch page.

Share your story with Science Buddies!

I did this project I Did This Project! Please log in and let us know how things went.


Variations

  • Make the game more complex by adding another item (like a ball of yarn or a fish) for the player (as the cat) to try to collect. Have the item appear in random locations on the screen. Change the scoring system such that the more items a player collects, the more points he or she accumulates.
  • Modify the game so that the dog's behavior is more complicated. Make the dog wander around randomly until the cat comes "close" to the dog, and then have the dog "chase" the cat. Hint: you'll have to define what "close" is in mathematical terms.
  • Add multiple levels of difficulty, such that the game becomes more difficult the longer someone plays.

Share your story with Science Buddies!

I did this project I Did This Project! Please log in and let us know how things went.

Ask an Expert

The Ask an Expert Forum is intended to be a place where students can go to find answers to science questions that they have been unable to find using other resources. If you have specific questions about your science fair project or science fair, our team of volunteer scientists can help. Our Experts won't do the work for you, but they will make suggestions, offer guidance, and help you troubleshoot.

Ask an Expert

Related Links

If you like this project, you might enjoy exploring these related careers:

Computer programmer typing on a keyboard

Computer Programmer

Computers are essential tools in the modern world, handling everything from traffic control, car welding, movie animation, shipping, aircraft design, and social networking to book publishing, business management, music mixing, health care, agriculture, and online shopping. Computer programmers are the people who write the instructions that tell computers what to do. Read more
NASA flight software engineer

Computer Software Engineer

Are you interested in developing cool video game software for computers? Would you like to learn how to make software run faster and more reliably on different kinds of computers and operating systems? Do you like to apply your computer science skills to solve problems? If so, then you might be interested in the career of a computer software engineer. Read more
Software quality engineer working on database

Software Quality Assurance Engineer & Tester

Software quality assurance engineers and testers oversee the quality of a piece of software's development over its entire life cycle. Their goal is to see to it that the final product meets the customer's requirements and expectations in both performance and value. During the software life cycle, they verify (officially state) that it is possible for the software to accomplish certain tasks. They detect problems that exist in the process of developing the software, or in the product itself. They try and make things not work (try to "break" the software) by creating errors or combinations of errors that a user might make. For example, if a user enters a period or a pound sign for a password, will that break the software? They seek to anticipate potential issues with the software before they become visible. At the end of the life cycle, they reflect upon how problems or bugs arose, and figure out ways to make the software development process better in the future. Read more

News Feed on This Topic

 
, ,
Reading level:
Note: A computerized matching algorithm suggests the above articles. It's not as smart as you are, and it may occasionally give humorous, ridiculous, or even annoying results! Learn more about the News Feed

Looking for more science fun?

Try one of our science activities for quick, anytime science explorations. The perfect thing to liven up a rainy day, school vacation, or moment of boredom.

Find an Activity