Have you ever wondered how math, like algebra and geometry, is used to create video games? Some modern video games are super complex, with amazing graphics, realistic physics, and smart artificial intelligence. Big video games can take huge teams of developers years to make, but you can use some of the same ideas to create a simple game yourself!
Let’s start with a simple 2D game. In this game, each character, or sprite, can be described by where they are or how they move on the screen. Your task is to figure out how to describe these actions using math and the coordinate plane.
Think about the game “Plants vs. Zombies.” Imagine there’s a zombie and a flower on the screen. To make the game work, we need to know a few things: Where is the zombie? Which way is it moving? Where is the flower? How far apart are they? As a player, you might say the zombie is on the left or moving to the right, but that’s not specific enough for a computer to understand.
Imagine you’re telling a friend exactly where a dragon is on the screen. Saying “on the left” isn’t precise. If you had a ruler, you could measure how many inches from the left the dragon is. Computers do something similar using a number line. This line starts at 0 on the left and goes to the right, measuring the number of pixels on the screen.
For our game, let’s say the screen runs from 0 on the left to 400 on the right. We can place the dragon anywhere on this line and measure its distance from the left edge. If the dragon is at 400, it’s on the right side. In the center, it’s at 200.
What if we want the dragon to be off the screen? We can use numbers bigger than 400 to place it past the right edge and negative numbers to place it past the left edge. But even with a number line, we need more detail. The dragon could be at the top or bottom of the screen. By adding another number line, we can locate a character anywhere on the screen in two dimensions.
The first line is the x-axis, running left to right. The second line, running up and down, is the y-axis. A 2D coordinate consists of both x and y positions on these axes. To find the ninja’s position, drop a line down to find the x-coordinate and run a line to the y-axis for the y-coordinate.
With x and y coordinates, we can describe any sprite’s location on the screen. By changing these numbers, we can move sprites around. What we’ve created is actually quadrant one of the coordinate plane!
If we zoom out, we see four quadrants on the plane. Quadrant I, our screen, has positive x and y values. Moving counterclockwise, Quadrant II has negative x and positive y. Quadrant III has negative x and y, and Quadrant IV has positive x and negative y.
Understanding these concepts helps us see how math is used in video games, making them both fun and educational!
Design a simple 2D game using graph paper to represent the coordinate plane. Place characters or objects at specific coordinates and create rules for how they move. Share your game with classmates and explain how you used the coordinate plane to determine positions and movements.
Work in pairs to create a scavenger hunt on a large coordinate plane drawn on the classroom floor. Hide objects at specific coordinates and give your partner a list of coordinates to find them. Use the x and y axes to navigate and locate each item.
Choose your favorite video game character and plot their position on a coordinate plane. Use different coordinates to show how the character moves during gameplay. Present your graph to the class and explain the character’s movements using x and y coordinates.
Create a piece of art using only points on a coordinate plane. Plot points to form shapes or patterns, and connect them to create a picture. Share your artwork with the class and describe how you used the coordinate plane to design it.
Explore all four quadrants of the coordinate plane by plotting points in each one. Create a story or scenario that involves moving through different quadrants, and explain how the coordinates change as you move. Present your story to the class, highlighting the use of positive and negative values.
You’re going to learn how math, such as algebra and geometry, can be used to develop video games. Some modern video games are incredibly complex, featuring realistic graphics, physics, artificial intelligence, and more. Major video games can take large teams of developers years to produce, but you can apply many of the same concepts that big developers use to create a simple game of your own.
Let’s start by looking at a fairly simple 2-dimensional game. Each of the characters, or sprites, in this game can be described by their location or movement on the screen. Your job is to figure out how we can describe the actions of each of these sprites mathematically in relation to the coordinate plane.
Let’s take a quick look at the game “Plants vs. Zombies” as an example. If we have a zombie and a flower on the screen, there are a few things we need to know about them in order to make the game work: Where’s the zombie? In which direction is it moving? Where’s the flower? How far apart are they? As a player of the game, you might say in general terms that they’re on opposite sides of the screen, or that the zombie is moving to the left, or that the zombie and the flower are pretty close to each other. These might be okay approximations, but they really aren’t specific enough and they definitely aren’t stated in a way that a computer can understand.
Suppose you were talking to your friend on the phone, trying to tell them exactly where the dragon is. You could use words like “on the left,” but that isn’t specific enough. If you had a ruler, you could measure from the left side of the screen and tell your friend exactly how many inches away the dragon is. That is exactly what computers do, using a number line that starts with a 0 on the far left and moves across to the right, measuring the number of pixels on the screen.
For our video game, we’ll place the number line so that the screen runs from 0 on the left to 400 on the right. We can imagine the image of the dragon, place it anywhere on the line, and measure the distance back to the left-hand edge of the screen from our dragon. Anyone else who knows about our number line will be able to duplicate the exact position of the dragon using only the number. On the right side of the screen, the dragon is at 400. In the center, he’s at 200.
What if we wanted the dragon to be off the edge of the screen? We could use numbers bigger than 400 to place him past the right-hand side and negative numbers to place him past the left-hand side. But even with a number line, we aren’t being quite specific enough. Even at 400, the dragon could be at the top of the screen or at the bottom or anywhere in between. By adding another number line, we can locate a character anywhere on the screen in either dimension.
The first line is called the x-axis, which runs from left to right. The second line, which runs up and down, is called the y-axis. A 2-dimensional coordinate consists of both the x and y locations on the axes. Suppose we want to locate the ninja’s position on the screen. We can find the x-coordinate by dropping a line down from the ninja and reading the position on the number line. The y-coordinate is found by running a line to the y-axis.
With two numbers, x and y coordinates, we can describe the location of any sprite on our screen. By changing those numbers, we can get our sprites to move around on the screen. What we’ve created is actually quadrant one of the coordinate plane! If we zoom out, we can see that there are four different quadrants to the plane: quadrant I, which we’re using as our screen, contains points with positive values for x and y. Moving counterclockwise, we get to quadrant II, which contains points with negative x and positive y. Quadrant III contains all points with negative x and y, and quadrant IV contains all points with positive x and negative y.
Math – The study of numbers, quantities, shapes, and patterns. – In math class, we learned how to solve equations using algebra.
Algebra – A branch of mathematics that uses symbols to represent numbers and quantities in formulas and equations. – We used algebra to find the value of x in the equation 2x + 3 = 7.
Coordinate – A set of values that show an exact position on a graph or grid, usually written as (x, y). – The coordinate (3, 4) tells us the location of the point on the graph.
Plane – A flat, two-dimensional surface that extends infinitely in all directions. – The x-y plane is where we plot points and draw graphs in algebra.
Axis – A reference line used in a graph or coordinate system, typically the x-axis or y-axis. – The x-axis is horizontal, and the y-axis is vertical on a coordinate plane.
Sprite – A graphical object that can be moved and manipulated in a coordinate plane, often used in computer graphics and games. – In our coding project, we programmed the sprite to move across the screen using coordinates.
Quadrant – One of the four sections of a coordinate plane, divided by the x-axis and y-axis. – The point (5, -3) is located in the fourth quadrant of the coordinate plane.
Number – A mathematical object used to count, measure, and label. – We used the number line to find the distance between two numbers.
Dimensions – Measurements that define the size or extent of an object, often in terms of length, width, and height. – In geometry, we learned how to calculate the dimensions of a rectangle.
Distance – The amount of space between two points, often measured in units like meters or kilometers. – We calculated the distance between the points (2, 3) and (5, 7) using the distance formula.
Cookie | Duration | Description |
---|---|---|
cookielawinfo-checkbox-analytics | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics". |
cookielawinfo-checkbox-functional | 11 months | The cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional". |
cookielawinfo-checkbox-necessary | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary". |
cookielawinfo-checkbox-others | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other. |
cookielawinfo-checkbox-performance | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance". |
viewed_cookie_policy | 11 months | The cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data. |