 Okay, welcome back to space arena the ultimate python turtle graphics game tutorial part 10 level set up So as we have the game right now basically, what's gonna happen is We create our player our missile and our enemies Here and our power ups here and that works okay For the beginning, but what's gonna happen is later when we want to go to level 2 or go to level 3 go to level 4 There's gonna be no easy way to do that So what I'm gonna do is I'm gonna take most of this stuff here when I think I take this part And I'm gonna move it up into the game class okay, so Watch what I do here. So I'm gonna go up to the game class And I'm gonna go ahead and create a new method And I'm gonna call it start level and of course because this is an object. I've got to put self So the first thing I want to do at this point, so when we're starting a level, I want to clear the sprites list So what that does is it just basically takes all the sprites and deletes all of their Let's see references to those sprites that are on the list sprites I think at least the player in the missile will still exist I'm not a hundred percent sure about the other sprites, but at least they're off our list So then what I need to do is I need to add the player So I'm gonna sprites dot append player and I need to add the missile I'm gonna sprites dot append Missile and then what I need to do is to also add the enemies and the Powerups so just to make it simple for now What I'm gonna do is I'm going to is I'm going to add basically one enemy per level just to keep it simple And then we can kind of play around with it. Just going to get the principal down Okay, so now I need to keep track of the level So of course the game always starts at level one And so we'll just say the game's level is one. So watch what I do here. So for underscore in range Self dot level So this could have been x it could have been y but since we're not really using it We're just using it as a placeholder. I'm just gonna put an underscore there so If it's level two, this will repeat two times it was level three it will repeat three times course This is level one. It's only going to repeat one time. So what I do is I got to put some enemies in now I need to give the enemies an x coordinate and so What I want to do is randomize where the enemies appear So I'm gonna be using the random module So I'm gonna have to go ahead and oops wrong one I have to go ahead and go all the way up So clear that out. That's annoying. I'm to go all the way up here And I'm gonna have to go ahead and type imports. It's import random Okay, the random module gives us quite a few things we can play with now I want the the enemies to appear somewhere in the game space Now if you recall the game size is controlled by These two values the game width and the game height Remember that is different to the size of the window because our game world is going to be bigger And what we'll get to you know scrolling a lot stuff later. So what I'm going to do here is negative Self because I'm inside the class itself self dot width divided by two and Self dot width divided by two So if the width is a thousand so it's negative five hundred two Positive five hundred And I'm just gonna go ahead and do the same thing with why I'm gonna copy that so if I type in it over again and There's gotta be careful you gotta be careful you do that You got to make sure you change all the right stuff. So why and in this case, it's not gonna be with it's gonna be height Yeah, it's gonna be height and a couple other things we need to do is The dx and dy so I'm gonna do basically the same thing dx equals random Dot rand int and I'm just gonna go ahead negative two to two I Might end up changing this a little bit later, but for now. Let's just keep it consistent To get the idea across and then what I got to do is sprites dot append So it's an enemy Prethesis you can see here. It's telling me. I need an x y shape and color So I'm gonna go ahead and just put x y and the shape will be I think square And we'll make the enemies red for now Okay, and don't forget the second parenthesis because this this parenthesis matches here This parenthesis matches the append statement So that gives us that will give us a certain number of Enemies now one thing here dx and dy were not part of the constructor so I Can either I could go down to The enemy or sorry. Yeah, I got the enemy Sprite thingy here, and I could set it up here Because I don't think it's set up in the sprite class. Let's just check just to make sure Yeah, because dx and dy are set to zero by default so what we can do here is a little nice Python thing so sprites minus one this will give us the very last sprite that was added And since it was definitely going to be this because the next line we can do it like that. I say dx equals dx and sprites negative one Dot dx equals or sorry dy equals dy And that should do it. So what we need to do down here is I Don't need these anymore But I do need to do a couple things. I need to take the sprites and I'm gonna put them Actually, I guess we do it like this way So these things weren't good not going to use anymore because we're doing that in the game thing And then I will say set up the level set up And what I'll do is I'll say game dot So start level they called it level And that's it So that should work. So let's go ahead and test that And we should get one enemy Okay, and see everything's still working. See if I can shoot it or not. Oops. I did bounce. I did collide with it That's good. Oops that collisions are working still. Okay, and I can't shoot it, which is Good. All right Now we need to do the same thing with the power-ups So I'm just gonna go ahead and delete that and I'm gonna go all the way up to here again And I just want to do the same thing with power-ups now for now We'll just go ahead and add one power-up per level just to keep it simple and for testing and We're gonna append a power-up oops Instead of an enemy and it's gonna be a circle and it's gonna be blue. Okay, so let's go ahead and run that test it There is our Player or there's our enemy. I don't see a power-up Which is not a good sign Now it is possible the power-up. Yeah Probably what happened was the power-up started over here and which is balancing up and down. Okay, so that is a possibility So now you can see that the power-up is working, so let's go ahead and just for fun Now what's what makes it cool is that I just go ahead and make the starting level 10 Just for fun and go ahead and run that. Oh my gosh, and there are Dozens, there's 10 enemies and 10 power-ups. So you see we probably don't want that many power-ups per level Well, maybe maybe we'll see how the screen goes Okay, so we can shoot things and It's actually it's fun Yeah, so you see how everything still works so we can add an arbitrary number of Enemies an arbitrary number of power-ups whenever we create a level and put that back to one Okay, so stay tuned for next video where we can talk about how to actually You know when we destroy enough enemies to get to the next level and all that sort of thing And we'll go ahead and go from there. Okay, so thanks for watching subscribe for updates and keep on good