You're going to learn how math, like algebra and geometry, can be used to develop video
games.
Some modern video games are incredibly complex, with realistic graphics, physics, artificial
intelligence and so on.
Major video games can take large teams of developers years to produce but you can apply
many of the same concepts that the 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 actors, 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 ok 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 moving across 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, stick 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 know 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 axis.
Suppose we want to locate ninja's position on the screen.
We can find the x coordinate by dropping a line down from the ninja and read 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.
And 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 the points of positive values for x and y.
Moving counterclockwise we get to quadrant II which contains the points of a negative
X and positive Y.
Quadrant III contains all points with negative X and Y and quadrant IV contains all points
with a positive X and a negative Y.