 Okay, welcome everyone to level up how to add levels to your games by Tokyo EdTech. That is me So today we're going to be talking about different levels in a game and some of the topics are what is a level? It seems kind of silly or basic But a lot of people just don't know what they mean by a level and then we got to talk about what causes a level Change and this is this is going to be different in every game And then also, what do we need to keep in mind when there is a level change and before I get started I want to give a big shout out to my first member ever Kevin 16-bit member and speaking of leveling up 8-bit member Paul has now upgraded to a 16-bit membership. So thank you so much for that Paul appreciate it And if you'd like to join you can click the join button down below So what I want to do is I'm going to talk about what a level is people often ask me on my channel How do I add levels and I think the first question they have to ask answer for themselves is what do you mean by a level? So here are some different level types and this is not all different level types So here's some ideas So for example in a level you might increase the speed of your player increase the speed of the game I'm actually going to walk you through a little bit of code today to do that in my sneak tutorial You might increase your strength You might increase your magic for example or the power of your weapons You could add more enemies in your level you could add more obstacles for the player You could add goals bonuses and you know stronger weapons, which is something we see in a lot of RPGs Very typical thing is to change the map So we finished level one like like say Pac-Man or you go to the next screen or Donkey Kong classic games Or let's say level two you get an extra life or level three whatever that case may be So you really have to think first what is a level for that particular game now if it's say chess You might just increase the you know the power of the AI and give it more processing time for example So yeah, you got a first thing about what type of level you want to do Then you got to think about well what causes a level change So for example, oops, let me make that big for you And so for a level change for example, you might change a level when you reach a certain score When you've killed all the enemies on a particular level when you've killed the level boss or bosses Reach a certain point on a map, which is something again very common with RPGs You hit the door you hit the exit and it takes you to the next level which is a next screen or a next challenge Or you could have some type of countdown timer going on where you know it hits zero and You know your time's up for that level Or you reach a certain score before a levels of four timers up There's there's all kinds of different options here So let's take a look at what that might look like and some things you need to think about when you do Leveling so this is just gonna be a little bit of pseudocode and like I said later I'll show you how to do that with the snake game a little example So basically when you make a game where you make a program like this you tend to have like your initial setup So this is where you set like you know the score of the game is going to be zero You know your your player, you know, this is where you set up your player equals blah blah blah blah blah You just basically set up the game set up the screen and you have your first thing So when you start the game, you're gonna have level probably equals one Okay, and then you know you have some other code you have your functions You have your keyboard bindings or whatever depending on you know the type of game that you're doing and then you're gonna of course Have at some point. You're gonna have your main game loop And this is the part of the game or part of the program rather that runs the game And it runs it does everything all the collision checking all the keyboard all the keyboard checking depending on how your program set up And this is what controls how your game is working So typically this would be a while true loop or some kind of while loop that would keep your game going now You know, so then you've got checking your collisions, etc. Etc. So that gets us to You know levels So or deal with levels. So, you know when the game starts as you can see here We're in level one So what we'd have to do is put subtype of code in here to deal with that So as I said earlier, we could say reach a certain score. So let's go ahead and do that one. So If what we gotta do is put so if score Equals let's say a hundred for example, then we're gonna say the level plus Equals one we're gonna increase the level and then we have to think about well, what does that mean for this particular game? So, you know, again, we could increase the speed increase strength magic, etc. Etc. So let's do just do lives and this isn't real code. This is kind of pseudo code So if we want to add lives we'll say, you know, for example, we might say something like player lives plus equals one Okay, so every time so if you had a hundred you get lives now This code is not gonna work correctly It's not gonna do exactly what you think it's going to do because what's gonna happen is if your score is 100 You add a level you add players lives you go through the loop again your score is still a hundred So you're gonna get another life and another or another level another life another level another level another okay, so on and so forth so Based with the level system generally speaking if you're gonna do a scoring type thing you have a couple choices here You could either do something like this, you know score plus equals You know 100 you get a hundred point bonus for hitting level ones target score Now this would work in a case where there's it's not possible to lose points Because we have a game where you could lose points You wouldn't want to do that because you could go back to a hundred points and you're already on level one So probably the best way to do this would be to make two conditions. So if the score equals 100 and level equals one Okay, then you get lives something like that Then you do something like L if L if score equals 200 and level equals two Then you go up to level plus equals one that take you to level three And then maybe a level two instead of player lives maybe The game delay so which is slowing down the game You subtract a little bit from that minus equals zero point one whatever whatever that number might be There's all types of things as I said here different types of level types We could add let's say we could add something enemy So we could do something like or maybe at 200 level two we add our first boss And we say and you know the enemies list you know list of enemies dot append And then maybe he's got a boss class You know you're gonna get the boss of zero comma zero And let's say it's got a hundred hit points and you know, there's all kinds of things you can do here It's really gonna depend on the game, but this is like the general pattern at least for a score-based type of You know leveling up and then you know if it was say it was a timer Sorry, if it was say I'll kill all the enemies. Okay, so if You know, this might be something if length of enemies if you have a list of enemies Equals zero and level equals one then you do your level one stuff so level one you get lives Or if it's something like point on the map, so if you know player dot location You know equals Exit or whatever that might be actually use exit and said door and level equals one then boom you go to You say like you know player location equals You know level two Open opening. Yeah, whatever whatever that might be. How are you your game particularly works? Okay, so you need to think about what an actual level means in your game So let's see this code like done With an actual game, so I'm gonna go ahead and I was coding there. I didn't switch the screen. Sorry about that So yeah, here's the code. I was typing so if the player location equals door And then level equals one then player location equals level two opening and then you know player You know player level plus equals one something like that So you really just got to think about what's going to happen I tell my students all the time Coding is comes down to if this then that so if you're on level one and you reach the door Then you go to the level two opening and increase the level. It's basically that's all it is if this then that So if you remember that if remember nothing else in this tutorial, that's that that's a good thing Let's go ahead and take a look at the snake game and this is a tutorial I have and it'll be a link down below so I go ahead and run that and let's take a look at what that looks like So basically you got a snake And I got a score nice keeping track of the high scores etc. Etc. And I've really Pretty detailed tutorial for this one if you want to check that out later if you haven't done that already and yeah So basically got this game. I hit the wall score zero everything's reset so What I might want to do is Every time I hit Yeah, so let's say I hit a certain score. I'm gonna increase. I'm gonna take the delay and reduce it So my current delay is 0.1 So I could subtract something from that to make the game run a little faster Okay, so what I can do here is you know levels and Let's go ahead and put set up a level here So I'm gonna say level equals one so when I start the game I got level one and then down here. I'm gonna put my code for levels. So if level equals one and score equals Let's just keep it simple. Let's just do it for 10 Because we don't want to wait test it and this is something I tell my students all the time So like let's say normally we'd want to do this You know every 50 points for example and then my students will do this and then they'll test it And then they have to eat five apples every time and then they have to eat 10 apples and 20 to test something So it's much easier if you just set it to something simple and then test it So we'll say level plus equals one and delay minus equals zero point So zero point one so eight zero point zero one. So that's ten percent essentially and then I'm gonna go ahead and copy this and just do this for the first three levels and Two three and so it's 20 and 30 Okay, so let's see if that works. Hopefully it'll be noticeable. I don't know if it will or not So here we go. Oh Wow, you can definitely see it sped up there Okay, so yeah, that's pretty effective. So we got some levels there now You might want to print the levels on the screen So we got score high score up here and I'm gonna make the font a little smaller so I can squeeze in a level here and So level Doop and Level let's go ahead and run that see what happens. Okay, and I didn't do it initially, but Okay, well, I don't see score level. Where is level at? That is annoying update score display Okay, I do this down here, too So I'm gonna go ahead and just copy this out Can't copy So we're gonna have a level we might want to display that for our players And well, I got a bunch of different places. That's not very efficient and Yeah, I'm up to here That one's zero. I'm gonna go ahead and put level because we're always gonna start at level one There's an extra space there. I should do that with all of them And level okay, let's try that again. Okay, so there we go and oops Well, it's still a little too big. Let's go ahead and Fix that. Oh, I didn't change the the font size and the other ones did I This is this is this is why you should not do what I just did Okay, there's 16 And just this is why you should have everything in like one any time you've repeated code you should put it into a function Okay, there we go Okay You know the level didn't go up. There is level two level three So you can see how we set different levels For this particular game. All right, so I'm gonna go down to here and now that it's working What I could do is then I could say, okay, I want this to happen at 50 points 100 points and then see 150 points and so on and so forth The other thing I could do is instead of subtracting 0.01. I could do the I could do this This is a little bit of math thing times equals 0.9 So that'll subtract 10 percent from the current delay And then once the delay gets smaller the change will be a little bit smaller as well Because it's so it's 0.1 times 0.9 will be whatever that is and then whatever that is times 0.9 So your delay is going down by 10 percent each time, but the 10 percent is a little bit smaller Okay, so let's go ahead and do our final test And We're gonna get to 50 so we're still on level one and here we go We should get the level two and it should speed up a little bit. Okay, you kind of notice that there. Oh I missed that miss the turn Okay, now you see something here. See the level is now set to two Okay, so something went wrong. So I need to reset the level I forgot to do that so This is this is why testing is really important level equals one is when the game restarts Now I've changed something and I have to now Test it again. It looks so far so good. You know, I have some code somewhere to align that but I didn't put on this version Oh, that's gonna be a tough one. Okay. I don't know if you noticed the speed picked up there when I hit 50 I'm on level two now Okay, I did not make the turn and Still on level two, why is that that's annoying Level equals one Okay So I've got a couple different places. I think where I reset the game. That's probably why yeah Reset the level again, here we go and test it equals one And let's go ahead and take a look at that and hopefully this will do a trick And I should have done this when I had everything set to 10 20 30 instead of 50 100 150 And here goes the speed. Okay. Yeah, you can see the speed change there for sure Yeah, so that is that that is an example of how to do leveling and now again There's some other things you can do with the modulus, but that's a bit more advanced You know, I gotta think that one through so you can see here. We need to check in this case We're using the score as our trigger for a level change We've chosen a particular score for level one to go to level two and then we in this case What we're doing what a level means is that we are delaying Or we are reducing the delay time which speeds up the game. So it makes a little bit more challenging So we got different levels now. This could be you know, 100 doesn't matter You choose whatever you want, but if you're gonna do score You got to make sure that your score is gonna get there If you have like a if it's possible that 51 is a score and it never actually gets to 50 Then you really got to be careful for that for that to work. Okay, so Thinking about levels going back to kind of what we started on You know, there's different types of levels You know different types of things that you can do to make a level and that's gonna really depend on your game And then you've got different types of triggers for level changes So in the example, we just did was reaching a certain score But you need to keep track of two things your score and the current level So you know how things should be changed and that's as the programmer you get to make that decision So yeah, so that's that so thanks for watching and hope you learned something from it If you haven't subscribed subscribe if you can become a member it's even better and comment below Let me know what you think take care. Bye. Bye