Jump to main content

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

1
2
3
4
5
1,130 reviews

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!

Summary

Areas of Science
Difficulty
 
Time Required
Long (2-4 weeks)
Prerequisites
None
Material Availability
Computer with internet access
Cost
Very Low (under $20)
Safety
No issues
Credits

Ian Slutz, Planet Moon Studios

Amber Hess

Sandra Slutz PhD, Science Buddies

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

Objective

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

Introduction

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 a short program written in the program Scratch

A cropped screenshot shows 4 coding blocks in a scripts area within the program Scratch. The code blocks for a cat sprite instruct the sprite to move when the right-arrow key is pressed and play a meow sound when the space bar is pressed.


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

Questions

Bibliography

These resources will introduce you to Scratch:

For help creating graphs, try this website:

  • National Center for Education Statistics (n.d.). Create a Graph. Retrieved January 30, 2009.

More information about ratios can be found at this website:

Materials and Equipment

Experimental Procedure

Note: This engineering project is best described by the engineering design process, as opposed to the scientific method. You might want to ask your teacher whether it's acceptable to follow the engineering design process for your project before you begin. You can learn more about the engineering design process in the Science Buddies Engineering Design Process Guide.

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.
    Changing the size value circled in red can shrink or enlarge the sprite.
    Figure 2. Changing the size value circled in red can shrink or enlarge the sprite.
  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
Screenshot of a green flag block in the program Scratch

A cropped screenshot of the green flag block in the program Scratch. This block allows any code within the block to run when the green flag icon in Scratch is clicked.

Events Runs script below it when green flag is clicked.
Screenshot of a when key pressed block in the program Scratch

A cropped screenshot of the when key pressed block in the program Scratch. This block allows any code within the block to run when a specific key on the keyboard is pressed, the key can be set using a drop-down menu.

Events Runs script below it when specified key is pressed.
Screenshot of a forever loop block in the program Scratch

A cropped screenshot of the forever block in the program Scratch. This block will continously run any code within the block in a loop without stopping.

Control Runs the blocks inside over and over.
Screenshot of a point in direction block in the program Scratch

A cropped screenshot of the point in direction block in the program Scratch. This block will turn an object or sprite in the Scratch program to face a specific direction. The direction can be set with a drop-down menu in the block header.

Motion Points sprite in the specified direction.
Screenshot of a move x steps block in the program Scratch

A cropped screenshot of the move x steps block in the program Scratch. This block will move an object or sprite a certain number of steps, the number of steps can be typed into the block header.

Motion Moves sprites 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.
Screenshot of a go to coordinates block in the program Scratch

A cropped screenshot of the go to coordinates block in the program Scratch. This block will move an object or sprite to a different x-y coordinate in the Scratch program. The x and y coordinates can be set in the block header.

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 3 shows the location of the button. From the menu that appears (Figure 4), choose animals (under costumes) and select any dog sprite that you want.
Screenshot shows a new sprite being uploaded in the program Scratch

A screenshot of the program Scratch shows a new sprite button under the viewer window on the right side of the program.


Figure 3. Clicking on the new sprite button (circled in red) will cause a menu to open from which you can choose sprites.

Screenshot shows a new sprite being uploaded in the program Scratch

When the new sprite button is pressed a file explorer window is opened and a new image can be uploaded from a computer to import as a sprite into Scratch.


Figure 4. 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
Screenshot of a green flag block in the program Scratch

A cropped screenshot of the green flag block in the program Scratch. This block allows any code within the block to run when the green flag icon in Scratch is clicked.

Events Runs script below it when green flag is clicked.
Screenshot of a forever loop block in the program Scratch

A cropped screenshot of the forever block in the program Scratch. This block will continously run any code within the block in a loop without stopping.

Control Runs the blocks inside over and over.
Screenshot of a point in direction block in the program Scratch

A cropped screenshot of the point in direction block in the program Scratch. This block will turn an object or sprite in the Scratch program to face a specific direction. The direction can be set with a drop-down menu in the block header.

Motion Points sprite in the specified direction.
Screenshot of a move x steps block in the program Scratch

A cropped screenshot of the move x steps block in the program Scratch. This block will move an object or sprite a certain number of steps, the number of steps can be typed into the block header.

Motion Moves sprites 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.
Screenshot of a go to coordinates block in the program Scratch

A cropped screenshot of the go to coordinates block in the program Scratch. This block will move an object or sprite to a different x-y coordinate in the Scratch program. The x and y coordinates can be set in the block header.

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
Screenshot of a green flag block in the program Scratch

A cropped screenshot of the green flag block in the program Scratch. This block allows any code within the block to run when the green flag icon in Scratch is clicked.

Events Runs script below it when green flag is clicked.
Screenshot of a forever if loop block in the program Scratch

A cropped screenshot of the forever if block in the program Scratch. This block will continously run any code within the block in a loop without stopping if a certain condition is met. The condition can be set by dropping a conditional block into the header of the forever if block.

Control Runs the blocks inside over and over.
Checks whether a particular condition is true, and if it is, it executes the code inside the block.
Control Checks whether a particular condition is true, and if it is, it executes the code inside the block.
Screenshot of a touch sensing block in the program Scratch

A cropped screenshot of the touch sensing block in the program Scratch. This block will check is a sprite is touching another sprite in Scratch.

Sensing This block checks to see if the sprite is touching another sprite. Make sure to set the color to the color of the dog spite.
Screenshot of a broadcast block in the program Scratch

A cropped screenshot of the broadcast block in the program Scratch. This block will send a message or command to all sprites in Scratch.

or
Screenshot of a broadcast and wait block in the program Scratch

A cropped screenshot of the broadcast and wait block in the program Scratch. This block will send a message or command to all sprites in Scratch and will wait for the scripts to finish running before moving onto the next block.

Event 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.
Screenshot of a stop all block in the program Scratch

A cropped screenshot of the stop all block in the program Scratch. This block will stop all scripts for all sprites.

Control Stops all scripts in all sprites.
Screenshot of a when I receive block in the program Scratch

A cropped screenshot of the when I receive block in the program Scratch. This block will run a script when it receives a specific broadcast message. The broadcast message can be changed in the block header.

Event Runs script below when it receives the specified broadcast message.
Screenshot of a show block in the program Scratch

A cropped screenshot of the show block in the program Scratch. This block will make a sprite appear on the stage.

Looks Makes sprite appear on the stage.
Screenshot of a hide block in the program Scratch

A cropped screenshot of the hide block in the program Scratch. This block will make a sprite disappear from the stage.

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
Screenshot of a green flag block in the program Scratch

A cropped screenshot of the green flag block in the program Scratch. This block allows any code within the block to run when the green flag icon in Scratch is clicked.

Event Runs script below it when green flag is clicked.
Screenshot of a forever loop block in the program Scratch

A cropped screenshot of the forever block in the program Scratch. This block will continously run any code within the block in a loop without stopping.

Control Runs the blocks inside over and over.
Screenshot of a wait x seconds block in the program Scratch

A cropped screenshot of the wait x seconds block in the program Scratch. This block will pause for a set number of seconds before moving onto the next block.

Control Waits specified number of seconds, then continues with next block.
Screenshot of a show variable block in the program Scratch

A cropped screenshot of the show variable block in the program Scratch. This block will show a variable monitor on the stage for a specific variable which can be chosen in the block header.

Variable Shows the variable monitor on the stage.
Screenshot of a set variable block in the program Scratch

A cropped screenshot of the set variable block in the program Scratch. This block will set a variable to a specified value. Both the variable and value can be changed in the block header.

Variable Sets the variable to the specified value.
Screenshot of a change variable block in the program Scratch

A cropped screenshot of the change variable block in the program Scratch. This block will change a variable by a specified value. Both the variable and value can be changed in the block header.

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.
icon scientific method

Ask an Expert

Do you have specific questions about your science project? 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.

Global Connections

The United Nations Sustainable Development Goals (UNSDGs) are a blueprint to achieve a better and more sustainable future for all.

This project explores topics key to Industry, Innovation and Infrastructure: Build resilient infrastructure, promote sustainable industrialization and foster innovation.

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.

Careers

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

Career Profile
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

News Feed on This Topic

 
, ,

Cite This Page

General citation information is provided here. Be sure to check the formatting, including capitalization, for the method you are using and update your citation, as needed.

MLA Style

Science Buddies Staff. "Want to Make a Video Game? Here's How!" Science Buddies, 11 Jan. 2024, https://www.sciencebuddies.org/science-fair-projects/project-ideas/Games_p023/video-computer-games/how-to-make-video-games. Accessed 19 Mar. 2024.

APA Style

Science Buddies Staff. (2024, January 11). Want to Make a Video Game? Here's How! Retrieved from https://www.sciencebuddies.org/science-fair-projects/project-ideas/Games_p023/video-computer-games/how-to-make-video-games


Last edit date: 2024-01-11
Top
We use cookies and those of third party providers to deliver the best possible web experience and to compile statistics.
By continuing and using the site, including the landing page, you agree to our Privacy Policy and Terms of Use.
OK, got it
Free science fair projects.