 Okay, welcome to space arena the ultimate python turtle graphics game tutorial part two This is where we're going to create our sprite class and our player object So we'll get started with that. Okay real quick a Sprite is just any type of game object that you see on the screen So the player is a sprite the enemy is a sprite the power-ups are sprites even the I think the Probably the stars in the background might even be considered sprites. I can't remember how I programmed it But once we get there, we'll know so what I'm gonna do is I'm gonna create a sprite class Okay, now if you've never done classes before probably this isn't the place to start but Just a quick review to create a class Like say class and I give it a name notice. It's capitalized And right now I'm gonna make that empty So now a sprite is a game object Okay, so what I have to do is I have to talk about or to think about what this object has What properties does it have and what can it do? I'm just gonna make a very basic sprite class to which we can add later but one thing that a class needs is Something called a constructor now in Python. This is the init method and See in it. Well, I'll leave it like this for you. So in it method and I'm gonna put pass there for now pass is just an empty leaves a blank space for you Something to think about here. I've got a class and now I've got something called a constructor. Let me go and put that in there for you So the constructor is a special method that is called when we create an object and I'm gonna show you that in a little bit So thinking about our sprites thinking about our game object They're gonna have an x-coordinate. They're gonna have a y-coordinate They're gonna have a shape and they're going to have a color for now. We'll update all these things later So what I'm gonna do is I'm gonna say self dot x equals x self dot y equals y self dot shape equals shape oops and self dot color equals color So what I'm saying and again if you haven't done this before this is gonna be confusing is That when I create my sprite I have to say this I have to give the sprite some attributes. I'm gonna give it an x-coordinate I'm gonna give it a y-coordinate. I'm gonna give it a shape. I'm gonna give it a color and Self is how we do that and I'm gonna show you that in a second. So what I want to do is I'm gonna go ahead and Create well, let me tell you what let's do. We're also gonna need a couple other methods for this particular sprite And I'm gonna you call one called render And I'll put self and I'm gonna put pen because I'm gonna be using this pen here to draw it So watch what I do here. Let's say pen dot go to self dot x self dot y Say pen dot shape self dot shape Pen dot color self color Now render is what I'm going to use to actually draw the shape Okay, now so I'm gonna go ahead and create my player sprite So watch what I do here say player So I've given it a name. This could be player one if you have a multiplayer game could be player two player three whatever player equals sprite Now what I'm going to put here is This information So I'm gonna go ahead and make my sprite at zero comma zero right in the center of the screen I'm gonna give the shape as square now in this case the shape is the possible shapes for the Turtle object which are square circle turtle triangle and Arrow now later when we add images, it'll actually be the image name So like you know player dot Jeff or something like that actually the player We're gonna keep the triangle and let's make the player. I'm just gonna use white for my spaceship So I'm gonna go ahead and run this And you're gonna be underwhelmed Okay, so good news is no error bad news is nothing's on the screen Okay, so I've created the player and Then I need to render it player render And I need to say I need to send the pen to it So I'm gonna go ahead and run that again And we still don't see it which is bad. What did I do wrong? That shape so ah, that's it and pen dot stamp Stamp actually puts it on to the screen for you so function of five and There is my player. I don't like that square. I think I'm gonna leave it like that So I'm gonna actually make turn it into a triangle because the player is a spaceship Okay, and there we have our spaceship Object Can our player or a player object? I should say now a couple things to think about here now at this point I could start doing things like this. I can do enemy equals sprite Put that at zero one hundred And then make that a square And we'll make the enemy of red square and then we'll say enemy render Pen and then we'll go ahead and do it. We do I do a power up at this point Sprite Say zero comma negative one hundred and we'll make that a circle and we'll make that blue So oops, I got don't can't forget to render it. So power up dot render So we go ahead and run that Okay, so we've got our player. We've got an enemy and we've got a Power up already on the screen. So again, let me explain how classes work Just for those of you haven't done this before We're gonna be using this extensively throughout this particular program and it's gonna make trust me It makes your life a lot easier. So What happens is When I create an object, I got to give it a name. So in this case, I called it player here I called it enemy here. I called it power up. I Said that the player is a member of the sprite class Okay, so this player is a sprite the enemy is a sprite and the power up is also a sprite Okay, so they are game objects in our game So these are the things that these particular objects have in common. They all have an x coordinate They all have a y coordinate. They all have a shape. They all have a color We also need to render each of these objects Okay, using the pen that we created up here So the pen goes to the location of that particular object. That's what self means So when I'm talking about player render Self becomes player. So player goes to here Pen goes to here. It's why it's a little confusing the way this is structured and Then so self so player player player player Okay, so player dot x player dot x Player dot shape player dot color in the case of enemy, of course would be different Self would be enemy enemy dot x enemy dot y enemy dot shape enemy dot color So that's how this whole self thing works now when I create the object the first time That's what this does and remember we want to capitalize these as convention. These are two underscores before and after Don't forget self. So I'm saying at zero x is going to be zero Y is going to be zero I'm gonna draw a triangle and a white triangle and then I'm gonna render it using the render method that I created here Okay, so we run that one more time And we'll leave it like that Okay, so let's go ahead and close that let's stop there the next video I'll show you how to actually move the player around and do some kind of cool stuff with that Okay, so thanks for watching. Stay tuned