[MUSIC] This week, things are really starting to get interesting in this class. We're going to take the things that we've learned so far throughout the class and we're going to combine them to build a pretty interesting arcade game. All right, so this is going to be kind of fun, we're going to span two weeks here with this arcade game. So this first week, we're going to focus on some of the basic behaviors of the game. In particular in this lecture, we're going to talk about the spaceship and flying a spaceship around on the screen. Okay, so we're going to look at some of the material that we're going to provide, I'm going to talk about some of the decisions that you're going to need to make. And show you where your code should go and how you should think about developing it, okay. So I think this is going to be pretty fun, now I apologize in advance, I actually lost my voice earlier this week. It's coming back, so I think it should be okay, and I hope you can understand me. Although, is it just me, or is it a little cold in here today? So here's a little preview of part of the game that you're going to be building starting this week. This is just the spaceship, okay, and I want to show you what happens here. Okay, I can thrust by pushing the up arrow. [SOUND] You can see when I thrust I go forward and it draws some flames and it makes some noise, and eventually it slows down and stops after I stop thrusting. I can turn left, I can turn right, I can thrust and turn at the same time. [SOUND] Okay, and, if you watch carefully, you can look in the status area to see which keys I'm pressing to make all of this happen. [SOUND] Now, what you're building this week is going to include more elements than this. But we will provide you with all the art, we'll provide you with the sounds. Okay, you're just going to have to put everything together to make it work. In your final game, you're going to have a whole bunch of images, and each image has a bunch of information associated with it that you will need in order to deal with that image properly. So to help you manage all that information, we've created an image info class. This class stores information about the image, so each image that we give you will also give you an associated image info object, and those objects have the following information. They carry the center of the image, the size of the image, the radius of a circle that completely encloses the image. The lifespan of the image, and whether or not the image is animated. Now the center and the size should be obvious, we've been dealing with that with images before. Okay, what is the radius? Why do I care about that? Well, for the ship for example, this gives you a circle that surrounds the ship. So you can just use that circle to detect collisions with the ship instead of having to worry about the exact shape of the image. Okay, the lifespan, I don't need that for the ship. The ship will always be drawn on the screen, but for other object like missiles that shoot out of the ship. They have a lifespan, okay they should only be drawn for a certain number of times and then you want to stop drawing them and they should go away. All right similarly animated is not useful for the ship, the ship is not animated it's just single, static image. But other objects such as explosions are animated, they are tiled. So you want to stride through the tiles in the tiled image, okay, and show a different image each time. Okay, now, I also want to point out that part of the point of having this image info class is that it has methods to access these fields. You can call get_center or get_size to get the center and the size. So this will make your code clearer and easier to understand. You have something like shipinfo dot getcenter, it will be completely obvious that you're trying to find the center of the ship object. This is the ship class that we're going to provide you to allow you to draw the spaceship. Okay, you can see that it takes several arguments with the under bar, under bar in it, under bar, under bar method, a position, a velocity, an angle an image and some information about that image. Okay, the position, that's the initial position of the ship. The velocity, that's the initial velocity of the ship, angle, that's the initial angle of the ship in radians not degrees. The image, that's the image of the ship and this is actually a tiled image where the first tile is the ship without thrusters, and the second tile is the ship with thrusters on. And info gives information about that image, you'll notice that we store away this information in the fields in the class. But you also notice there's two additional fields that we're initializing, self.thrust and self.angle_vel. Self.thrust is initially set to false, indicating that you're not thrusting in the beginning. So the engines are not turned on so you shouldn't draw the thrust and you shouldn't accelerate. The angular velocity or angle vel is initially set to zero indicating the ship should not be rotating in the beginning all right. Now we've also provided you with two methods, draw and update. And these are just stubs you're going to need to fill these out. The draw method simply draws a circle where the ship is currently located. So you can see this white circle that's the ship, okay, you're going to have to replace that actually drawing the correct image. You're going to either draw the image without the thrusters on or the image with the thrusters on, depending on whether or not the ship is currently thrusting. And you're going to have to draw the ship rotated to the proper angle so that it's facing the way that it should be facing. Okay, the update method you have to write this method to actually modify and update the position, the velocity and the angle of the ship. And you have all the information inside the fields here that you need, and we've talked about how to update the velocity in a previous lecture where we talked about acceleration and friction. Okay, and you know how to update the position based on the velocity from previous projects that we've done in the class. And updating the angle should be pretty similar to the things that you've done updating the position, okay. Now in the update handler that's all you should do, this gets called every time the draw handler for the system is called. You just want to use those values to update it, you do not want to worry about the keys and what people, the human player is doing at any given time. Now these are not the only methods that the ship class could have and a properly designed object on your program each class encapsulates the behaviors of the object. The ship has additional behaviors, right, you can turn the thrusters on and off, you can increase the angular velocity or decrease the angular velocity. Okay, these kinds of things require an additional method. Now, inside the keyboard handlers, right, when you hit the spacebar, I don't want you putting a whole bunch of logic that shoots off a missile, that queries the spaceship class, figures out what to do and launches a missile. Instead, the ship class should have a method that gets called when you hit the space bar, from the keyboard handler, and that does all the calculations relative to the ship and figures out what to do. Same thing with turning the thrust on and off, same thing rotating the ship left and right, and so on. So you're going to need to fill out this class with a few additional methods. You're going to need to complete the methods that are here so that your ship will behave in the way that I showed you at the beginning of this lecture, and that you'll see again when we talk about the final project for this week. Okay, so that's the basics of building your spaceship. Okay, I think that while it may seem like this is a little bit daunting, if you focus on the ship class and implement the behaviors one by one, don't try to do everything at once. Just get little pieces working add things to it one by one you're going to be able to make this work pretty easily. I think that we've taught you a lot, I think you've learned a lot if you've gotten up to this point. So you're going to be able to make it happen, all right. Now, I promise you, once you have a spaceship flying around the screen you're going to be pretty excited. I know when I implemented this I thought it was really cool when I was flying my ship around.