 Okay, welcome to space arena the ultimate Python turtle graphics game tutorial part seven in this part We're going to be creating the borders of our game. So to do this. Well, actually first Let me show you what I have real quick and in case you come back from before so in the last video We added health bars and health meters to the objects Now there was a little bit of an extra gray area and you can see I've gotten rid of that and the actual code to Do that is down here and what what I found was that even when the pen is going forward by zero Pixels it still draws a little bit of color there like a little dot So to get rid of that I said if the health equals the Mac if it's health doesn't equal the max health Then we need a gray bar if they are equal that means you have max health and there would be no grace That fixes that little problem. So what we're gonna do is you want to add some borders to our screen Now you can see here to our game they can see here We've got a screen width and a screen height already But if you recall from the introduction video the borders are actually going to be end up being bigger than what we can see Okay, so we're gonna get that started today But we won't do the big part just just yet. So what I want to do is I want to create a new class and I'm gonna call this game now. I could have done this with I Could have made a border class or whatever But I decided just to put it into a game class because it's part of the game. So when I initialize my game You know I was gonna do self I got to give it a width and a height Okay, and again this width and this height are going to be different to this because the game arena is Larger or right now. We're actually make it smaller. So what we'll do is we'll say self dot width equals width self dot height Equals height. So we're just creating the object and using it to contain or to keep track of the width and height of the game area now to Actually draw it. We're gonna go ahead and make a render method Okay, and I'm gonna say deaf render border And self Okay, so What we're gonna do is well, we're gonna go ahead and use the pen. Sorry, I should have done that So I'll say pen dot color and I just made the border white You can make it a different color if you like, of course pen dot Width is gonna be three and you can make it bigger smaller again pen dot pen up You'll see what I'm gonna do here in a second. So what I'm about to do is I'm just gonna break it down into Pieces, but I could have done it all in basically one line But I'm gonna make it in pieces just so it's easy to understand what's going on So left equals self dot width Divided by 2.0 right equals self dot width Divided by 2.0 and actually left should be negative. Sorry about that so for example if our Screen or if our game is the same size as the screen and it was 800 wide So the left X over here on the left side would be negative 400 and the right side would be positive 400 So I'm gonna do top equals self dot height Divide by 2.0 and bottom equals equals negative self that height divided by 2.0 So this gives us the left Most Export the right most ex-cordant the top most wide-cordant and the bottom most wide-cordant So now what we're gonna do it's gonna be very very simple. We're gonna say pen dot go to left top Pen dot pen down. We're gonna put the pen down so we can actually draw. I'm gonna say pen dot go to Right Top again, so I'm just gonna go up to the top left corner across the top right corner down to the bottom right corner Over to the bottom left corner back up to the top left corner I'm just gonna draw a big square and I'm gonna get fancy you can make it an octagon or something like that But that would make the collisions a little bit difficult to calculate Right top and I'm gonna say pen dot go to right bottom Penn dot go to let's see left comma bottom and Penn dot go to Left top again. I'm gonna say pen dot pen up So the pen is no longer drawing So that's the class again the class defines how the object works So later in my game before I actually you know do this whole thing down here. So here I created the sprites I'm gonna go ahead and Gonna say create the border I'll say create the game object So I'm gonna say game equals game. I need to tell it the width So what I'm gonna do here is I'm gonna make it's 600 by 300 just so it's on the screen and we can see what's happening and Then in my main loop, I'm gonna go ahead and I'm gonna render that so I could do it down here Doesn't really matter what order so I'm gonna game render border So in the main loop, it's gonna go ahead and do that. So let's go ahead and run that see what happens We got an error Okay, so render border is missing one required positional argument pen Okay, so I forgot to put past pen as an argument tell what pen we're using. I got another error It's about height wrong. You guys probably saw that a while ago line 42 Where's that? H E I G th Th T It's right again There we go. So now we've got a border And of course everybody goes outside of the border, but that's a different problem Yeah, so basically we've drawn a border now that border could be any size But for now, we're gonna keep it really small just to cut for testing purposes So next thing I want to do or the next thing I want to do is to have it bounce off of the border Okay, now this is gonna go in our sprite class because this is gonna apply to every object in the game Basically every sprite at least so I'm gonna go ahead and make a method And I'm gonna call it deaf border check self So this is gonna check if the sprite has Hit the border So basically what we're gonna do is if Self dot X is greater than game dot width Divided by down there 2.0 Then we set self dot X equal to game dot with Divide by 2.2 point O and then we say self dot DX times equals negative one So that will bounce it off of in this case the right wall. So let's go ahead just test test that Well, it's not gonna work. We don't we don't call it. Okay, so we got to do so what we do is in my update I'm gonna call self dot border Check I don't need to put self So the sprite is going to do the border check now For the player since it has its own it doesn't have its own update method yet. Okay, well it will eventually But okay, so we'll do it like that So function f5 you see how it's getting a little bit long now. I'm gonna see what happens when I hit the right border Okay, so that's pretty cool. Now Now one thing what do you notice that's kind of a little bit weird? So you can see how the player is Actually going a little bit over the border Now one way the easiest way to fix that since it's we know the size is about 20 by 20 is in the border check On a left side or on the right side we put minus 10 So that so what's happening here is the X is the middle But a plus 10 is the right side of it. So let's go ahead and test that and see how the bouncing goes this time Okay, so you see how it bounces a little bit more naturally I mean won't notice it too much once the game's going but it does help. I think a little bit. So I'm gonna go ahead and Copy that and now we're gonna do the other side and watch carefully. It's less than negative game with Plus 10 Because we're on the left side of it now the self times DX times negative one still works and here I want to do L if because if we're on the right side of the screen It's not possible to be on the left side of the screen. So I'm gonna go ahead and test it Okay So you see I can bounce basically forever boom boom boom and now let's go ahead and do the top and You either type it from scratch or do what I do just I have some working code So I just need to change why why why and this is gonna be game height instead And it's gonna be do why and say anything here. Why? Why oops and why and game height Okay, so I'm just gonna go ahead and test it at five and That is working and you notice how now these guys are also bouncing off of The walls and this is what we want. This is this is exactly what we were looking for So that is basically that so now we have a game arena. Let me just show you something real quick What's nice about this now that we have it coded is now I can make this game arena Much larger. I'm gonna keep it 300, but then I'm gonna make this 1,000 Okay, so let's watch that see what happens So you see now that the game arena if I make this bigger You see the game arena is still being drawn, but it's outside the size of our window But still there it's still working so I can still bounce off of it And that's gonna be really what we want to happen because what we want in this game is for the game arena to be bigger Than this 800 by 600 area and that everything else is gonna move relative to the player And that'll be coming up in a future video. Let's just review that real quick In this video we created a game class again, it could have been a border class But I just used game for this one. I'm gonna use it for some other things We initialize it with a width and height of what we want our arena to be and it can be smaller than the Screen width it can be larger than the screen width, you know the the window width that we've used in our case We're gonna want it to be bigger, but right now we're keeping it smaller just for testing purposes Then we need a render method and basically we're just drawing a square We go up the top left corner put the mouse pen down down over or over down over up done we created our Game object right here and then in our rendering we did game.render border We sent the pen as an argument and we also added a Where's that here? Border check method inside of our sprite class As we want all the objects in the game these all the sprites to bounce off of the border for us and that my friends is That stay tuned for more subscribe for updates