 Okay, welcome back to space arena the ultimate python turtle graphics game tutorial part 11 in this part We're gonna be working on some of the gameplay elements. So so far what we've got if I go ahead and run this is We've got a basic system where we can fly around we can shoot the enemies We can collide with the enemies and all those things are working, but it's not really a game yet It's just it's just a demo of the physics really So if I shoot it, you know, it just disappears, but we notice we have the health meter So let's go ahead and do some stuff with the health and see what we can do to get this game to actually work like a game So what I'm gonna do is I'm gonna go down to the part we've already created and I'm gonna say So we already talked about the collisions. So if The sprite is an enemy and it collides with the player We could do that But let's do what have let's do shooting the enemy first. I think that's a bit more interesting So I'm gonna go ahead and change this so when I shoot the enemy think about it. What happens to the Enemy so almost the enemy's health gonna go down. So I'm gonna say sprite Dot health so healthy up minus equals and Let's do ten for now. Let's make it easy. So let's see what happens. That's a very simple change Let's go ahead and run that and see if it does what I wanted to do Okay, just I don't know if you can see it, but it's going down Okay, see it's going down now. It's gonna take a while because it's a the health is a hundred but So you see now I can shoot it and it's Very hard to kill actually So what I'm gonna do is I'm gonna go over to the I'm gonna go to the enemy and I'm gonna make It's default health Okay self that health self that max health This is something we'll be able to change when we change levels. Let's say let's make it. Oh 15. Well, I'll make it 30 Well, hmm, let's make it 20. So you gotta shoot it twice And then self that health equals 20 That's not the health that equals self max health. That's all that'll be our default for now Okay, so let's go ahead and shoot this guy Yeah, let's see. I remember it's max health is 20. We're taking away 10 Okay, so it went down and Yeah, I missed it somehow. I Hope my collisions aren't off Okay, so now it's health is down to zero. I believe now it's into negative territory So we got to fix that. Okay, so what do we want to happen? When an enemy's health gets below a certain level. So what I'm gonna do is I'm gonna go ahead and Borrow how can I say I'm gonna borrow the update method from the sprite class. I'm gonna go ahead and copy it and I'm gonna go ahead and put that into the enemy class because what we have to do with it now is We also have to check its health now So watch what what should I do here? It doesn't matter when I do it, but I can do it here. So check health use So I'm gonna say if self dot health is less than or equal to zero and What I could do here. I'm gonna try this. I'm gonna say self dot Equals not I'm not sure if that's gonna work. I'm gonna try it. That's my that's my that's my guess And we'll see if that that's what I needed to do and that did not do what I needed to do All right, well live learn. I thought that would destroy it But what I'm gonna have to do is I'm gonna have to do self dot Reset and I'm gonna have to make a reset method deaf reset self And I'm just gonna say self dot We can just move it actually doesn't really matter of what we do is probably what we're gonna actually need to do is self Dot we're gonna have to give it a state Equals I'm gonna call it inactive. That's the same thing as being dead. So One way is I'm gonna go up to my sprite class And I'm just gonna give them all a different a state so sprites They self dot state equals active Now remember the missile has different states ready and I think active or ready in fire. I can't remember what we did So because it it sometimes isn't active as has ready and active, okay? So I'm gonna do with my enemy sprite is I'm gonna change its state to inactive So if it is inactive, I don't want to do anything with it. So in my update method. I'm gonna say if self Dot state Equals active. So if it's active, then I do all these things It's not active. I just ignore it Same thing with render. Okay, so I go to my renders render here If self that state equals active Then we render it. Otherwise, we're not gonna render it. So that'll that'll keep it off the screen So we don't see it and then we also there's a couple other things We got it. We got to think about these there's maybe a more elegant way to do it, but We got so If it's an enemy and The sprite that state equals active So we got to do a check here because we don't want to collide with Sprites that are not no longer active now We could again, I could have taken them out of the list or done stuff like that And we will once we change levels. So I thought this might be an easier way to do it So let's test that and see if that works. I've got an error Line 271 for the quotation mark You guys probably saw that let's go ahead and run it Yeah, let's see if they can Shoot this person Okay, and now it is gone So at this point what should happen? Hopefully you're saying yourself is well, why can't I go to the next level? Because we have a program it so What I'm gonna have to do here is it doesn't matter where exactly I put it I can put it You know down here or wherever, but I just got to put it in this main loop. So check for end of level So what I'm gonna do is I want to put End of level equals true So what I'm gonna do is I'm gonna assume that it is the end of level and So what I do now is go through four sprites in sprites And I'm gonna look for an active enemy So I say if sprites Sorry, I say if is instance Sprites if it's an enemy And Okay, so it's active sprites sprite that state equals active say end of level equals False because as long as there's one enemy sprite the level is not done And the level equals false So what I do At this point now at this point I can do I could do break and get out of this But we'll just worry about we won't worry about that. So then I say if end of level So if the end of level is true, that means I've killed all the act all the active enemies are gone If end of level then I'm gonna say game dot level Plus equals one we add one to the level and then game dot What I call it start level So let me explain that real quick once again. So what we do is we assume that the level is over But all we have to do is find one sprite one enemy sprite that's still active So if we find an enemy and that enemy is active Then we know it's not the end of the level. So the end of level is false Guess we go through we look now if we are at the end of the level. So if that's true, we add one to the level and then we start That level, let's see if that works Okay, there we go Now we actually have functioning levels that that's pretty cool. I'm pretty happy about that Yeah, it's one see if we get to level three Okay, so we can see how the game now is getting more complex The thing is like we could do anything at that at that border of the game We could do we could change the size of the arena. We could Add speed. There's all kinds of stuff we could do at this point, but you can see now how We actually have kind of a functioning game at this point sort of we haven't dealt with power ups and all that sort of thing But you see what we did there. So let's just kind of do a quick review of that and I'm gonna call this gameplay You know killing enemies gameplay essay, let's go gameplay enemies. How's that? That's what we'll call that one So just just a quick review Again, you might want to watch this just to make sure you know what's going on Just all the different little things that we changed. So in the play or in the enemy class We recreated the update method. We checked if the state was active or not and if it was active then we updated it and We also in our sprite class We only render something if it's active Okay, so we don't we don't render a ready missile. We don't render an inactive sprite We only render something if it's active and then We use the health So every time the missile hit it we subtracted 10 now We could also give the missile some strength and then that's something we could do we could level up later in the game But for now, we'll just keep it at this and we just remove the health That's all we have to do here is just lower the health and then we let the update method for the enemy deal with the health You know we have to do is if The health is less than or equal to zero we reset it and we set it state to active Not gonna just put self that state equals inactive here But we might want to do some other things here later now, so we'll keep it consistent Okay, so thanks for tuning in keep on coding subscribe for updates