WEBVTT 00:00:06.950 --> 00:00:12.740 You're going to learn how math, like algebra and geometry, can be used to develop video 00:00:12.740 --> 00:00:13.980 games. 00:00:13.980 --> 00:00:19.590 Some modern video games are incredibly complex, with realistic graphics, physics, artificial 00:00:19.590 --> 00:00:21.980 intelligence and so on. 00:00:21.980 --> 00:00:26.430 Major video games can take large teams of developers years to produce but you can apply 00:00:26.430 --> 00:00:31.840 many of the same concepts that the big developers use to create a simple game of your own. 00:00:31.840 --> 00:00:35.370 Let's start by looking at a fairly simple 2-dimensional game. 00:00:35.370 --> 00:00:40.770 Each of the actors, or sprites, in this game, can be described by their location or movement 00:00:40.770 --> 00:00:42.300 on the screen. 00:00:42.300 --> 00:00:46.430 Your job is to figure out how we can describe the actions of each of these sprites mathematically 00:00:46.430 --> 00:00:49.590 in relation to the coordinate plane. 00:00:49.590 --> 00:00:54.200 Let's take a quick look at the game Plants vs. Zombies as an example. 00:00:54.200 --> 00:00:58.050 If we have a zombie and a flower on the screen, there are a few things we need to know about 00:00:58.050 --> 00:01:00.090 them in order to make the game work. 00:01:00.090 --> 00:01:01.420 Where's the zombie? 00:01:01.420 --> 00:01:04.800 In which direction is it moving?Where's the flower? 00:01:04.800 --> 00:01:07.680 How far apart are they? 00:01:07.680 --> 00:01:11.969 As a player of the game, you might say in general terms that they're on opposite sides 00:01:11.969 --> 00:01:13.100 of the screen. 00:01:13.100 --> 00:01:15.609 Or that the zombie is moving to the left. 00:01:15.609 --> 00:01:19.979 Or that the zombie and the flower are pretty close to each other. 00:01:19.979 --> 00:01:25.030 These might be ok approximations but they really aren't specific enough and they definitely 00:01:25.030 --> 00:01:28.750 aren't stated in a way that a computer can understand. 00:01:28.750 --> 00:01:32.439 Suppose you were talking to your friend on the phone, trying to tell them exactly where 00:01:32.439 --> 00:01:34.200 the dragon is. 00:01:34.200 --> 00:01:38.109 You could use words like on the left but that isn't specific enough. 00:01:38.109 --> 00:01:42.619 If you had a ruler, you could measure from the left side of the screen and tell your 00:01:42.619 --> 00:01:45.990 friend exactly how many inches away the dragon is. 00:01:45.990 --> 00:01:48.549 That is exactly what computers do. 00:01:48.549 --> 00:01:52.759 Using a number line that starts with a 0 on the far left and moving across the right measuring 00:01:52.759 --> 00:01:55.899 the number of pixels on the screen. 00:01:55.899 --> 00:02:00.119 For our video game, we'll place the number line so that the screen runs from 0 on the 00:02:00.119 --> 00:02:03.459 left to 400 on the right. 00:02:03.459 --> 00:02:08.030 We can imagine the image of the dragon, stick it anywhere on the line and measure the distance 00:02:08.030 --> 00:02:13.090 back to the left hand edge of the screen from our dragon. 00:02:13.090 --> 00:02:17.129 Anyone else who knows about our number line will be able to duplicate the exact position 00:02:17.129 --> 00:02:21.599 of the dragon know only the number. 00:02:21.599 --> 00:02:24.450 On the right side of the screen, the dragon is at 400. 00:02:24.450 --> 00:02:27.909 In the center, he's at 200. 00:02:27.909 --> 00:02:30.769 What if we wanted the dragon to be off the edge of the screen? 00:02:30.769 --> 00:02:35.239 We could use numbers bigger than 400 to place him past the right hand side and negative 00:02:35.239 --> 00:02:39.239 numbers to place him past the left hand side. 00:02:39.239 --> 00:02:43.470 But even with a number line, we aren't being quite specific enough. 00:02:43.470 --> 00:02:48.049 Even at 400, the dragon could be at the top of the screen or at the bottom or anywhere 00:02:48.049 --> 00:02:49.049 in between. 00:02:49.049 --> 00:02:54.879 By adding another number line, we can locate a character anywhere on the screen in either 00:02:54.879 --> 00:02:56.189 dimension. 00:02:56.189 --> 00:03:00.790 The first line is called the x axis which runs from left to right. 00:03:00.790 --> 00:03:05.260 The second line which runs up and down is called the y axis. 00:03:05.260 --> 00:03:10.310 A 2-dimensional coordinate consists of both the x and y locations on the axis. 00:03:10.310 --> 00:03:13.420 Suppose we want to locate ninja's position on the screen. 00:03:13.420 --> 00:03:17.069 We can find the x coordinate by dropping a line down from the ninja and read the position 00:03:17.069 --> 00:03:18.420 on the number line. 00:03:18.420 --> 00:03:22.410 The y coordinate is found by running a line to the y axis. 00:03:22.410 --> 00:03:27.209 With two numbers, x and y coordinates, we can describe the location of any sprite on 00:03:27.209 --> 00:03:28.360 our screen. 00:03:28.360 --> 00:03:33.040 And by changing those numbers, we can get our sprites to move around on the screen. 00:03:33.040 --> 00:03:36.980 What we've created is actually quadrant one of the coordinate plane! 00:03:36.980 --> 00:03:40.861 If we zoom out, we can see that there are four different quadrants to the plane: quadrant 00:03:40.861 --> 00:03:46.159 I, which we're using as our screen, contains the points of positive values for x and y. 00:03:46.159 --> 00:03:50.219 Moving counterclockwise we get to quadrant II which contains the points of a negative 00:03:50.219 --> 00:03:52.349 X and positive Y. 00:03:52.349 --> 00:03:57.459 Quadrant III contains all points with negative X and Y and quadrant IV contains all points 00:03:57.459 --> 00:03:59.399 with a positive X and a negative Y.