 Hello, everybody. Welcome back. This is, like, the 14th time I've tried to record the beginning of this video, and you will probably see me fail multiple times in a blooper video that it might be coming up soon, or something. Anyway, in this video we're going to continue with the drawing functions that we learned in the last video, and we're going to try and make a little world, a kind of editor thing for the small little game engine that we've been building. This is going to be very, very primitive. In fact, there are going to be no controls other than just drawing boxes. Super duper tiny, super duper small, and super duper easy. That's all it does. It just draws your platforms for you and keeps track of where they will all be. So, I'm going to actually make this pretty freaking huge. In fact, it's going to be 1200x700, so I can at least fit it on my computer monitor. Actually, I can fit it on a little bit bigger than that, and I can probably go 1900. Anyway, that's just fine for us. I'm actually going to implement a clock this time, piegame.time.clock, and let's actually add frames per second. I'll just call it FPS rather than typing all that out, because I'm feeling lazy today. Let's import the colors so I don't have to grab any of that stuff from colors, import all that, and I don't need this white and red garbage window.fill white. That's just fine, and we don't need any of this garbage here either. Okay, once we actually add all that, we do want a few variables to keep track of what it is we should display on the screen. Let's actually maintain all of this by a list. It actually knows what have we drawn and what have we already drawn and what should we keep. So, I'm going to call that variable to draw, and right now, at the beginning of the program, it's just going to be an empty list. And we're going to want to have some variables that are keeping track of whether or not we are actually drawing right now. If we have the mouse button pressed down, then we're still drawing. If we have the mouse button released, then okay, we must have finished drawing. So, I'll call that variable something stupid like draw, start, box. And right now, that's going to be false, because obviously we're not drawing anything. Okay, so then we have our event loop. We're actually testing if we've quit the program or not yet. Otherwise, let's look for some events that determine whether we've actually pressed the button down or not. So, if the event.type is equal to mouse button down, I'm sure you guys know this from some other videos and earlier videos. I just kind of choked on my words there and made a zombie sound that was probably not very pleasant to hear, sorry. We'll keep track of the mouse coordinates. That's all that we're doing with this line of code, pygame.mouse. The function to retrieve those is getPOS, getPoss, getMyPossy, that sort of thing. If the event is actually being pressed down, if that's when we're actually still like, you know, the moment that we've pressed the button, mouse button down, okay. So, this one up here, I'm actually, I'm actually repeating my ideas, sorry. Mouse button down is when we're actually pressing the button, we want the mouse position all the time, whenever we move the mouse. So, this event should actually not be mouse button down, but instead mouse motion. I was getting ahead of myself there, I'm sorry. In the case though that this is the mouse button down, position is equal to mouse position. And you're saying WTF, John, why did you do that? Why are you keeping track of the variable that is already a variable? Well, position is going to stay the same while mouse position is going to change, because we've moved the mouse in some cases. So, we're just doing that so we can keep track of one instance. And that's when we actually start to draw. And the way we know that we're drawing is by saying, drawStartBox is going to be true. Cool. Now let's test for the other events, if the event.type should go to pygame.mouseButtonDown, but no, it should be mouse button up, and that sort of thing. That's when we can say, okay, the final position is now the mouse position that we're at, because we've stopped and all that. And we can say that the drawStartBox is now going to be false because we are all done drawing. You'll see this in motion. You'll see this actually make a bit more sense while we're programming and while the code is actually being run. So, this is when we add because we've finally finished drawing once we've released the mouse button. That's when we add something to repeatedly draw on the screen that we'll actually keep. That's when we can add, okay, a new object of the rect. And that's going to be to draw add new list elements, which is the rect pygame.rect at its current position, or at least at the position that we started with, and then final position zero minus position zero. Now, you might be wondering why we're actually subtracting and doing all this rather than just passing in final position as the other one. Well, keep in mind that the rect variable, or the rect object, is actually initialized with the arguments that determine its top left, that it's topped coordinate, and it's left coordinate, and the width and height. So, when we subtract the final position by the reverse position, that's how we find the width and height. Simple, simple stuff. And actually, let's just have it display some information about these plot about these objects and things that we've drawn. Sorry. Once we hit the enter key, and we can test that if event.type is equal to pygame.keydown. Now, let's do, let's test if the event.type is equal to pygame.keyreturn. And that's the constant for the enter key. And this way, we'll actually check, okay, for each plot, sorry, platform that we're drawing in our to draw variable or list, then we can go ahead and print out. I'll put this in array syntax, so it's a bit more evident. Platform.string.platform.split. Because remember, split is going, this string of this platform is going to return it to us as a tuple or as a tuple. However, you want to say it, people yell at me for saying tuple. And let's actually go from the first coordinate of that. I should be using regular expressions or something to actually match this, but just for easeability, I'm going to go ahead and keep using the split command, split function. So we actually just get what's inside the tuple. But it would probably be much better to use the, it would be much better to use regular expressions to process all that. I'll add a comma. Okay. And then we're done with the print statement. Cool. So now we're done testing for event handling. And now we want to actually want to get back to our while loop in this, this indentation. We'll fill the window with white, keep the background just fine in the same. If we are drawing, if the draw start box is true, we don't need to have that because that's the way the Python works if we just test for if. That's when we'll start to draw. Wrecked window. Let's draw it red. Pygame dot. Wrecked position. Mouse position zero. And mouse position one. Now we do this because, okay, we're drawing the wrecked from the start. And then up until where we were keeping moving the mouse. So we keep having that one be variable. That sort of thing. In fact, let's do mouse position minus position one because remember we want the width and the height. And do the same for the other variable. Okay. That's good. And now we can test, okay, what about the things that we've actually released and the things that we've actually kept? If we do that with a for loop, for item in to draw, we will go ahead and draw pygame.draw.wrecked. I'll scroll down here so you can see this a little bit better. Window, let's actually keep this black instead. And then we'll draw that item because we're adding that wrecked to the thing. Okay, that's pretty simple. Actually, let's add another button that will allow us to remove things from to draw. If event, this should be event.key, sorry. It's a good thing. If event.key is equal to pygame return. Otherwise, if event.key is equal to pygame.key backspace to draw. I think pop will work. I think. That might need an argument. Okay, otherwise it's just fine. So I've got a huge window here. It's all white. I'm moving it around. You still can't really see too much of a change. But now if I draw, okay, nothing's gonna happen. Never mind. I forgot to update the screen. I'm an idiot. This is when we update. And we'll actually tick so we can stop my processor from freaking out. Now when we run the program. Sorry about that, guys. Now when we're in the program, we've got this big white mass. And if I draw, okay, a red block, I can keep moving. I'm still holding the mouse button down. Once I release it, it turns black because now we've got that platform there. And I can keep drawing other things like, okay, let's draw a block here. Let's draw a block here. Maybe one down here. Keep moving the screen here. Let's draw one that looks like it's coming from the top here. Right over here. We can make it look like we've got some stairs or something. Right now this is a lot of different blocks. And that's probably pretty bad. It's not gonna look all that good. Or at least we know that it's not very efficient. Like we know that, okay, this is made up. This is pretty choppy. Like it's made up of other things that are not really real blocks or whatever. And then I'll put something way down at the bottom that we can just jump to. Okay. So now we've got all that. If I hit the backspace button, that might hopefully, okay, good, that does remove itself. The pop function in Python will just remove the last item from a list and return it, I believe. But now we've got this big, big level, right? And if I hit enter, it releases all of the information about this block or all of the blocks that we've created. So what if we copy and paste that into our other code that we have? The one that we were actually, okay, making levels with. What if we had level one be filled with this stuff? Bam, copy and paste that right in here. And okay, hopefully the player will be at a good position when we run this code. Let's let's check it out. Let's try it. If I run the program, okay, no, invalid, invalid thing. Right, right, right. This is where we have to get into normalizing our objects or our platforms. Because what if the width is less than the X value or some absurd strange thing? We'll have to test for that in the upcoming tutorial. See this negative value? WTF is that? We can have a negative width. For now, I'll show you that, okay, we've got all this that we can use. And this very primitive world editor that we just created all of this code with. Okay, good. I closed it. I copied and paste all of these dimensions. And I'm sure you did the same on your end. Now, let's see if we can actually get these to work in our game engine and code that we initially wrote. I'll do that in the next tutorial. But for now, we've got this funky little world editor that we can use somewhat. It's not as it's not as pristine, it's not as elegant as we would like. But we'll keep modifying it as we go along. For now, thank you for watching. I hope you enjoy this. Hope you understood everything that we kind of did. And I'm sure you see the code in motion when it's actually running the program. Thanks again. Talk to you later.