 Okay. Hi everybody. I want to make a quick video to answer two questions that I get all the time. One of which is how do I create a splash screen on my game? Second of which is how do I create an end screen or a game over type screen? And I'm going to answer that today kind of in general, show you some specific examples. So what I have here is I have a kind of skeleton starter program. I'll put a link to that down below that you can download and you can kind of follow along. Now we're not going to be filling everything in today just enough to show how you would divide your program up so that you can do those things. So just basic kind of structure of the program that I've been following. Some of these things you have to do. Some of these things are kind of optional, but you want to start out and import your modules first. I don't know how many of these will actually need today, but those are the ones I imported. Now if you're on PyCharm or one of those other certain IDEs, you might get an error. Because module imported but never used, which is kind of obvious because in this case I've imported math, but I haven't actually used it down here anywhere. I have imported random, but I haven't used it. You can either just ignore that or if it's causing problems with your particular editor, just go ahead and hashtag that out, comment it out until you actually need it. Yeah, so that's kind of an important point. So the next thing you want to think about is if you're going to be using classes in your program, you probably want to put them next. Again, it's the order is somewhat flexible, but not always. But you have to make your classes before you create your objects. Don't know what that means, don't worry. Then I usually create my functions, then define my constants, and you might have put your constants up here again. No hard and fast rules, except certain things have to come before some others. Then you want to set up your screen or set up your game. In this case, I'm using the turtle module and I'm creating a little window, and I'll show you what that looks like in a second. I'm going to be using a pen, and it's actually a turtle object to do the graphics in this game. I actually don't really need this today, but I'll use it a little bit to give you an idea of one option. Then I usually put the keyboard bindings here. This is where you say, all right, if I push the A, do this, if I push B, do that. Then finally is the main game loop, and how this works. This is similar in structure to, say, Pygame, if you use Pygame, where you flip the screen over. What we're going to do here is, everything that's drawn with the pen, we clear it, we run all the game code, so you don't really see that yet. Once you're done with all the game code for that iteration of the loop, then you update the screen. This is what gives us the fast graphics and animation. I'm just going to go ahead and run this. I'm not going to see much, but I'm going to hit function F5. I'm using Genie, which is a free and open source text editor, which I do recommend. I quite enjoy it. I'm going to hit function F5, and all I have here is a blank screen. Now, again, this is not the only way that you can do this, but this way, this is pretty easy. Again, I focus on beginners, I think with my students in mind. What could they understand? What I want to do is I'm going to use the idea of a game state. When I start the game, what state is it in? I'm going to go ahead and create a variable here, and we'll call that game state. Let's call that splash, because what we're going to do in the beginning is we're going to show the splash screen. In my game code down here, I'm going to use that variable, game state, to control what's happening. I'm going to go ahead and type if game state equals splash. What I'm going to do is I'm going to say win.bgpick.jif. What I've done actually, this is one simple way to do this, is I've created three different images. In the Python turtle module, they have to be GIFs. Can't just rename them, you have to use a program to convert them. I used GIMP, for example, because they started out as PNGs. I made them with Google Slides. My splash screen looks like this, called game state demo by Tokyo EdTech, it's my Twitter handle, and it says press S to begin. Once I go to that, I'm going to go to my main background, and I just have wizard quest, not very original, but I'm going to have a background, and then I also have a game over GIF. These are the same size as my window, which is set to 800 by 600. I'm going to go ahead and run my game, and now this is what I have. This is my splash screen. It's going to sit there on the splash until game state changes. That makes sense. We have to put some code in here so we can actually press S to begin. What I have to do is create a function, and I'm going to call it start game. When that happens, we're going to change the game state to, I'm just running, you can call whatever you want. I should just call game, it makes a little more sense, you can call whatever you want. If you haven't seen my local versus global variables video, and you don't understand what that means, watch that now, but since I'm changing game state inside of a function, I need to use global. Again, watch the video, everything is explained very, very clearly. This isn't really good programming practice, but the only alternative is to use classes and again, a lot of people aren't up to speed on classes, so I'm going to skip that for now. What I have to do is create a keyboard binding, so win.listen. This is a particular command of the turtle module. If you're ever curious about the turtle module, there are turtle documents you can use to find these things out. Then what I'm going to do is win.onKeyPress. When I press the key, I'm going to call the function, start game, and start game, and the key is going to be S. Notice that's a lowercase S, not a capital S. Let's go ahead and run that, and we're not going to see too much difference here, I think. I'm going to go ahead and hit S, nothing happened, which is what I expected. That's because I didn't change the background pick. What I'm going to do here is I'm going to say, if game state equals game, so let's say we're playing the game, win.bgpick, what did I call it, main.gif, I think. Let's go ahead and run that, test it, see if it works. I'm going to go ahead and press S, and now we have our game. This is where you would have all, I'm going to put L if, because you can't have them both. This is where you would have all of your game code. This is where you would update the player, this is where you would move enemies, this is where you would shoot missiles, whatever your game is. This is where all of the game code that we've done in other tutorials would go. Let's say at some point your player dies and you want to show the game over screen. What I would do is L if game state equals, whatever you want to call it, it's right up to you, it says a win.bgpick, what do I call it, game over.gif, so we have to figure out how to get that to happen. Let's just go ahead and just say, let's just set the game state to game, test this, let's just test it to game over, let's go ahead and say that, run it and see what the game over screen looks like. Game over, press S, that says press S to begin. What we could do at this point is, let's think about that. In this case, we're starting over. What you might have to do in that case is, in here somewhere, this is where you might say reset the game. This would be, for example, set the score, it says zero, move the player back to the starting position. All those things that are set at the beginning of the game need to be reset. It's probably actually a good idea to do this in here anyway. Again, there are other ways to do it, but this is kind of simple and straightforward to understand. Again, something to think about is, again, if you're not familiar with global and local variables, again, it's not usually a good idea to use global variables, but for beginners, it seems to be a little bit easier for them to understand, so that is a way to do it. Essentially what you're doing is your main game loop has different sections. Let's say, in this case of wizards, let's say I wanted to add a screen where I'm leveling up, I'm buying armor for my character. I could have something like, if game state equals, what would it be, armory. Then you say win.bgpick, I haven't actually made this picture, armory.gif, and then there would be code in here that deals with what happens while you're in the armory, or there could be a screen where you're a map screen or a combat screen, those sorts of things. This way you can more easily divide up your code by keeping track of the game state, or again, you can call whatever you want, but game state pretty covers it pretty well. Just one other thing I wanted to show you is, if you don't want to use an image, a pre-drawn image for whatever reason, you could use the turtle write module and say, so pen dot write, I'll say pen dot go to, I think it's already there, but zero dot zero, pen dot write, and I can never remember the format for this, that's why I pre-loaded this, and I'm just going to go ahead and copy this, and this is the turtle module documentation, so I'm just going to put that into there, and so R exists to be like, you know, you have died, died, whatever you want to put there, put center, and aerial is fine, but I want to make this a really big font, so I'm going to run that, and our game is already set to go to game over, and we had an error, great, pen I have two dots, hopefully you guys caught that before I did, and you have died. Now it's flashing because of, I have this win dot update thing here, so you might have to write some code to get around that, but anyway, that's the general idea of how to do a splash screen, so I'm just going to get that back to where it was. Again, this is a question I get all the time, and I've never really addressed it, so here I am addressing it, hopefully that will help give you an idea of how to divide your code up a little bit better, and how to deal with different stages of your game. So good luck to you, I hope this helps, more than it hurts, so thanks for tuning in, keep on watching, and subscribe for updates, take care.