 Okay, welcome to game coding pie game platformer basics by Tokyo EdTech. That's me This is probably one of the most requested things I get on my channel And I finally had some time to work on it yesterday And so I'm gonna go ahead and try and walk you through what I did and how I did it and why so first Let me give a quick shout out to my channel members. You can see Mod and Kim Sheung have made it to their second month of membership. So thank you so much And thank you to everyone who has paid to be a member. I just sincerely appreciate it So let's take a look at what we're doing and what we have So this is what I've already done and I'm gonna walk you through this in this particular lesson But this is what we should have by the end of this So you can see we've got some kind of platform stuff And then we got a player and I'm using the arrow keys to move left and right. So each time I push it Player moves a little bit You can see how the player slows down because we are I added friction and then player will fall If I push the space bar, the player will jump and it jumps pretty realistically. I mean it jumps really high We probably won't want that in a real game, but for a test, you know, it's okay And then if it falls off it comes back to the top. So that's what I want to get Started with today. So that'll that'll teach you basically how a platformer works. So let's get started Now here is the platformer base code that we're going to start with and It's it's just a very simple kind of skeleton code that has two things basically it has a pi game window and It has a sprite class that I created Okay, so you can see here Class sprite now pi game does have its own built-in sprite class. I haven't really done much with it So I can't really say, you know, how to use it or how not to use it but the sprite class that I'm using What's nice about it is that it has just what we need and it also would make this program easier to You know change so that for example, you want to do it with a turtle You could probably switch it over to a turtle very easy rather than using the pi game Sprite class. Okay, so just walk you through it real quick I'm using the following modules pi game sis math and random in pi game You have to initialize The game you have to initialize pi game I should say and then you need to you don't have to do this But you can set your display caption now there should be an underscore here, but sometimes it doesn't show up So let's see I'll make this text a little bit bigger So we do see the underscore and I just gave it a name and then we need a clock and the clock helps us keep The game speed consistent Between systems so notice how this C is Capitalized everything else is lower case and I decided to make the game 1200 by 800 pixels Notice how width and height are capitalized. I did that because these are constant values They do not change and then here I just defined a few colors that I might want to use and as you can see from the demo I'm using basically green white and black for the background So we need to create a screen for pi game and we use pi game dot display dot set mode And notice there's an extra set of parentheses here Width comma height. Okay, so that's a topple and as I mentioned earlier I made my own sprite class and when we initialize it it has an x-coordinate a y-coordinate a width and a height and So then we just set self x to x self y to y We also are using dx and dy which will control the x movement and we'll control the y movement If you don't know what those are You know I've done this in several other tutorials So I want to check some of those other things out and of course width and height are also added No, this is the width and height of each particular sprite and by default I've made each sprite white the background is going to be black and I've added a value called friction and Friction should be between zero which is no friction and one which is you can't move anywhere It's like you're stuck in quicksand. Okay, so I just played around the number zero point eight seemed good You can make it whatever you want. I also made a little function for each sprite called go to and so I could say you know Sprite dot go to X watch some x y coordinate and it will go to that x y coordinate and This is where we actually render is where we draw what we're what our sprite looks like We use the pie game dot draw dot wrecked method and we're using screening which comes from here We have a color and again. We give the color initially We gave basic sprites are all white and then we use pie game dot wrecked and then We draw it at the x minus self width divided by two Self y minus self height divided by two the reason is That in pie game the x y coordinates are the top left corner Of that object. I personally don't like that. I find it a little confusing so what I did was I I have kind of like my own way of rendering so From the center x and y Subtract half the width. That's this top left and then draw from oops and then draw from the width Over so you draw the width and the height and this will just draw a Rectangle or square or whatever shape we give it now later. We could add you know images and all that sort of thing This is a very special method This is called access align bounding box collision And this is what we're going to use to see if one sprite is Colliding with another sprite now. I got this from stack overflow. I think some website somewhere I mentioned this in another video. I did I had a link there, so I'm sorry I forgot what it was and then here's just some You know comments that I may not necessarily use for this particular game tonight We won't do font or sounds, but we'll do game objects We have our main game loop and this is just kind of standard Pi game stuff, you know for event and pie game dot event get get If the event type is pie game quit then we exit the game and I'm looking for basically Keydown so we push a key down and I'm looking for key left key right These are the arrow keys and the space and we'll be filling that in later Then we got to move our objects check for collisions We have to do something if the player falls off the screen Render the background render the objects again and then flip which actually puts it on to the screen And then I set it to 30 frames per second for this particular game You could set it to whatever you want, but 30 works well with the numbers that I'm going to be using So if I run this I have the following so this is so far what I've got So let's go ahead and start filling in the missing code okay, so We have some code to make a sprite so What I want to do is I want to start with the player Okay, so I'm going to make a new class called player And it is a child of the sprite class what that means that the player is also a sprite So it inherits all of these different things from it so when I Instantiate my sprite my player class. I need the init method. Yeah, if you know what this stuff means watch my Class and object-oriented program tutorial explains it. I think pretty well so self we need x y width and height and Now because it's a child class. We also have to initialize the parent class. Now you can also use Was it Super or something like that, but I like to do it pretty explicitly So width comma height. I know somebody's going to ask me why I didn't do that I prefer to do it this way so our player is a sprite and what I want to do is I'm just going to go ahead and create the player So this is the player object and I know this one of the reasons I know this is because this is lowercase This is uppercase class names are uppercase So I want the player And self is actually from here. That's a little confusing. So I need to x y and the width Now I've already gone through and calculated all these things. That's why I know what I'm about to write is correct But it took me quite a lot of experimentation To get these things right so 20 and 40 So let's go ahead and see what that does Nothing. Okay, which is about what we expected So I've created a player I've put it at 600 zero now in pi game This is zero zero in the turtle Zero zero is at the center. So from zero over to 600 because remember the width is 1200 so 600 would be the center And it's at zero. So it should be kind of like half on the screen half off Now we don't see it because we haven't rendered it So what I need to do is down here where it says render objects I'm going to do player render And again this render Comes from the sprite class And you can see this is that pi game dot draw dot rect thing I talked about earlier Let's go ahead and run that And you can see there is the player now the player is actually Off the screen a little bit. So that's not the full player I'm going to go ahead also and make the player green because I like that. So self Dot color green again this green comes from Here I define the colors here. Let's go ahead and f5 Oops And we got an error which was Double object is not callable self dot color. Okay, it's not a function. It is self dot color equals Green my bad. Sorry about that And now you can see it is green So this is The part where we got to start thinking about how does a platformer work versus say like pacman Or space invaders or pung So what we're trying to do in this particular case Is to simulate gravity So we need to Do the physics of this So what I want to do Is I'm going to up here with width and height. I'm going to define gravity because gravity is going to be the same for every object And Basically I've through experimentation. I found that one works really well now again keep in mind Pi game is a little different to the turtle if you're used to my turtle Tutorials. So this is zero zero Y is positive Going down instead of negative, which is probably what you're used to or for math class X is positive to the right negative to the left Y is positive going down and negative going up So that's why gravity equals one Now gravity Affects The change in Y Okay, so if you're falling gravity keeps you know adding speed adding speed adding speed adding speed So what I'm going to do Is I want to make a new method here in my sprite class called move Again, if you're not familiar with Classes and object-oriented programming watch my tutorial and come back to this. I'll I'll try to remember to put a link there So self x equals so plus equals self dot dx And self dot y plus equals self dot dy And self dot dy plus equals Gravity So what that means Is dx and dy So if dx is positive, it's going to move to the right if dx is negative It's going to move to the left If dy is negative it would move up as we said, you know, that's the way the y-cord it works in Pi game if it's positive it will move down So we're going to add gravity to that each time through because gravity is always acting on objects So what I need to do is I've created this method, but I haven't called it So series says move and update objects And actually with this type of game the order of the code is super duper duper important Um, if you put things in a slightly different order collisions won't work correctly and it it gets very confused That's one of the challenges of a platformer. So what I'm going to do here is I'm going to say player dot move And then That should do it. Let's try it Okay, you can see the player just dropped right like a rock off the screen Which is what we wanted Okay, and so the other thing I want to do is I'm going to border check the player So if the player dot x Um, sorry y is greater than 600. So it's it's fallen off the screen Then we'll say player dot go to We'll go back to the start 600 zero Okay, so I'm going to hit f5 and we should just have an infinite falling loop Falling falling falling. You can see how it's falling faster and faster and faster Uh, because gravity keeps working on it at high speeds Okay, and we'll go ahead and stop that. So it's getting a little crazy now All right, so We've got a player the player falls And so what we can do here is we could either do the left and right thing or we could do the Colliding with something thing. Let's go ahead and maybe just start with the collisions It doesn't really matter what order we do this in So let's go ahead and add a block And what I'm going to do is I'm going to make a list of blocks. We're going to have more than one Okay, and I'm going to go ahead and say blocks Dot append And again, this is something I've already calculated. So I know You know, this is correct. So the block is just going to be a sprite I'll probably create a block class later. But for now, this will do what we want it to do 600 and I'm going to make it at 600 200 It's going to be 400 wide And 20 pixels tall I could have made it taller. I could have made a shorter doesn't really matter Okay, so what I've done is I've created a block. It's a Sprite at this x and y location this width and this height So then down here Says move and update objects now sprites blocks don't move. They're going to be stationary. So I don't need to move them But I do need to check for collisions. But let's first let's see if it's on the screen Not on the screen because I forgot to render So for block in blocks A block dot render again right now. We only have one block, but we'll add some more Okay, so what's supposed to happen is it's supposed to stop there So Collisions It's very very interesting So what I need to do Is I need to check for the player colliding with all of the With the block So all the blocks are safe. So for block in blocks Now this is actually the hardest part at least in my mind of the Uh platform. This is what makes platformers difficult Is the math involved in the collisions now, I've already told you about this Collision method that I got off the internet. I don't quite understand it a hundred percent I know an access line bounding box is but I haven't like really sat down and done done the actual math on this I do have a video about collision detection And if you watch that explains this a little bit better than I'm doing now Um, I don't want to repeat myself because I already have a video about this Um, so anyway, so for block in blocks If player dot is a a bb collision with the block So if the player collides with the block, I'm just gonna go ahead for now and print collision Because and the reason I'm doing this is I want to know is this collision working. Is it registering? So I should see collision down here. So I'm going to go ahead and run it Oops, and it's in the way, but you do see where it says collision. So that tells me probably it's working the way I want it to Okay, so this is where you need to start thinking about How the collision is going to work so If the block collides with the platform in this case or the block What do we want it to do And then this is this again, this is the process I went through and it took me quite some time to figure out All the exact math and the coordinates and how to do this But uh, it's it's a good exercise and I'll walk you through some of it at least So it's falling it hits a platform. We want it to stop falling. So let me go ahead and code that So we'll say player dot dy equals zero So that should stop the player. So let's see if see if it does it Okay, here we go. It is stuck on the platform So, yeah, that's working. I'm amazingly enough. Um I didn't think it worked that well, but it did. There's there's some other code. I have written here, but you'll see So see here All right, let's look at that. So why don't we go ahead and do jumping now so we can see if it will jump So again, we didn't have to do it in this order, but I think walking it through this step You'll see how okay you fix this thing and then it causes a problem over here with that thing That's part of the challenge of coding We're also part of the fun. Okay, so let's go ahead and do jump So here we've got keyboard events and if we put the game over press a key And the key is a space we want to jump So what I did was I just made it a player dot Move uh jump method. I haven't made it yet, but I'm going to in a second So in my player class I'm gonna say def jump Self Now think about this if we jump What are we affecting? Okay, all right. We are affecting the rate at which the player is Falling or moving or going up. Okay, so what I did is I said self dot dy Minus equals 24 and again, I just played around with the numbers 24 seem to work So I'm gonna go ahead and try this Again, it's minus because in pi game minus moves you up Okay, now I'm gonna go ahead and press the space bar And now we've got a jumping character Pretty cool That's pretty cool. Uh, it just looks cool. I really enjoyed just doing this over over again Okay, so we got we got a jumping character now. I can tell you from experience. This is not quite done yet But it looks good. So let's just move on to The next thing which is left and right Okay, and then once we do that we'll add another platform and then you'll start to see okay Well, this isn't doing what I thought it should do Okay, and this is this like said, this is I think pretty educational for this type of game I think it's good to see this because a lot of like game engines you just type some code like okay platformer player You know, it has it built in all these types of things and it's cool It's great if you want to make a game, but if you want to learn how to code Yeah, it's not so helpful because they do so many things for you So let's go ahead and do left and right okay, so Just like jump we're going to be Making some methods so death left Just left self And instead of working on self dot dy we're going to be self dot dx And remember left is also negative And so i'm going to do negative equals six and again, this is a number I found worked pretty well And so then that tells us right is going to be self dot dx plus equals six Okay, so Go ahead and hit f5 Now i'm going to hit the left arrow Oh, I know what I didn't do I didn't put that here so player dot left So when I push the left arrow I call the player left method And this is going to be player dot right Okay, so there's left And there's right And the more I push it the faster it falls now you can see right now how it's falling through The platform so you can see there's there's a little bit of a problem there already Okay Okay, so let's go ahead and fix that Now what's happening Is that You know the player is falling faster and faster So each time through the loop instead of moving one pixel at a time It's moving six pixels. It's moving 12 pixels. It's moving 20 pixels Whatever that speed is So it jumps into the middle of the object So to fix that what we got to do Is when there's a collision, where is that? So When there's a collision We need to do something like the following we need to set the dy to zero But we also need to put That object Up a little bit And so what we got to do is say player dot y Equals So we're looking at the block the block dot y Minus because we're going up Block dot height divided by 2.0 Minus the player dot height Divide by 2.0. Okay, so we want so This Is from the center of the block to the top of the block And then this is from the center of the player Uh to the middle like basically to half the height of the player and what that does you'll see here if I fall off It puts it back up You know so from here it adds to here and then it adds this distance So half the height and half the height so it puts it back to that particular spot Okay, and you can see how it is Working kind of kind of like we expect I think Um now the only thing is like you got to keep hitting the left and right key Um, maybe fix that in a future video, but for now it's it's fine Okay, so jumping works. So what I'm gonna do is I'm gonna go ahead and just it's looking good like so far I'm not seeing any problems Um, it's kind of doing what I want it to do So I'm gonna go ahead and add another block And so I'm just gonna go ahead and copy this And I'm not sure what I used last time because I that that's the one part. I didn't uh save well Um, so this one this one is also 600. Oops It's also 600, but it's going to be a little bit lower 400 And it's going to be 600 wide By 20 tall Let me go ahead and run that and see what we got Okay, so we got another And okay, so it's working pretty well. Okay. I'm pretty happy with that. Let's let it fall off. Okay So everything's still working now. Let's see. I'm gonna try and jump Okay, good and when you notice now like, um, it It's going really really fast. It's like it's like skating on ice, which is fine if you like that um, that's what I do. That's what I use the friction for and uh So what we could do and this is how I did it actually Is if there's a collision with a box So player dot dx Times equals block dot friction And I like I said, I set friction to zero pointy and I kind of played around with it Let me change that to point six for now. Just see what happens Okay, so you can see how it's Going and slowing down. So maybe point six is a little too high. Oh, actually it should be higher. Sorry higher's Like lower is Slower there's more friction. Yeah, sorry. I got that backwards One would be zero friction zero would be total friction. Sorry. I got that backwards. So I'm gonna try zero point nine Okay, I like that a little bit better Okay All right now watch what happens if I jump So you can see it goes right through the platform Now you may like that if that is how you want the game to play Then by all means leave it that way um So you saw how it kind of works there. Um, I personally don't like that Okay, so we have to deal with this particular situation And the way we're going to do that Um, is we're going to do some else else else statements So think about this we've got two cases one where the player is falling from above And one where the player is jumping From below Okay, so here's how I dealt with this. I think there's other ways to do this, but I'm going to do it this way um So if there's a collision Okay, so I'm going to put here Player is below. That's what we've already done. So if player dot y Is less than block dot y Okay, because that's again That's the way the coordinate system works Okay, it will do that So let's go ahead and try that and see what happens Okay, so that's still working Okay, it's still doing that which is not what we wanted, but that's okay Because we haven't dealt with The other situation l if Player dot y is greater than block dot y So in this case, oops So in this case we are jumping up from below So we're going to do the same thing player dot dy equals zero And I'm going to go ahead and just basically Copy this Because we want to do the exact same thing Except in the opposite direction because we're below. Okay, so now if I hit F5 I'm using genie. Okay. Now we got it doing exactly what we wanted to do. Isn't that cool? So we got a little platformer already. This is this is very much fun Okay, I'm good with this. I'm really happy with where we're going. Okay, so the next step I think is to add some more Blocks and you'll see once we do this, you'll see that there's going to be some errors popping up With the way it behaves now. I'm just going to go ahead and copy it from over here because I forgot to write it down and So these are the rest of the sprites That we I did Now what I can do is I could I could just copy it the way it is But I'll I'll stick with what I did in the other video. So I'm going to copy that And again, you know, feel free to to make your own So I'm going to go ahead blocks dot append Okay, don't forget that second thing blocks dot and it doesn't matter what order you append these It's going to work just fine. You can put whatever order And blocks that oops, I forgot the blocks dot append Okay, so I'm going to run this and there's there's what you saw earlier Now watch you're going to start to see some weird little things happening. Okay, that's still working That's fine Okay, that's working now watch what happens when I hit from the left here Did you did you see what happened there? Okay, now let me let me show you what's happening. I'll have to change something I'm going to make this 800 so that's off the screen So player y is greater than 800 So you can see actually what happens It fell right through Okay, now you notice there it went up Okay, I don't want that to happen either. I want it to bounce off and I want I don't want it to like automatically shoot up Okay, so what's happening is there's a collision and we only have two cases so far We have if y is if it's above the halfway point or below the halfway point if it's above puts it up here If it's below it puts it down here, which is now below the platform Okay, so that's why we're seeing that weird error So we got to deal with that and that's pretty straightforward to deal with it's not too too hard But we got to add another Thing another condition so player is above So what we're going to do is Before these it has to be before So if player dot x Is less than block Block dot x Minus block dot width divided by 2.0. Again, it took me a while to figure this out And okay, well, I'll do it that I'll leave that one. There's an and Let me say player dot dx equals zero Because we want it to stop moving left and right say player dot x equals uh block dot x minus block dot width width divided by 2.0 minus player dot width divided by 2.0 And again, this is just the left the x-quartered version of what we did here Okay, so if it collides we want it to move Just outside of where the box is so we make that a zero So i'm going to test this so this is a case where The player is to the left player is to the left Okay, so am I gonna go ahead and run it? So the player is to the left. I'm going to go to the right Okay Something went wrong there Uh, let's see what I did Ah, this should be an l if Because we can only do one of these collisions at a time Okay, so i'm going to go to the right. Oh, it still did it. Now. Why is that? Player dot dx block 2.0 block x 2.0 It's moving to the right. Let me just run that again. See what's going on here. Okay work there So that's doing what I want it to do, but if i'm down here Oh, okay now it's not doing it. Okay, great All right, maybe uh, yeah, okay. Well, I'll talk that up as a win for now. Um, so it's working fine Um, but it might not be there's there's something I got to fix. I'll show that to you in a second Um, so I'm going to go ahead and do the exact opposite thing for moving to the right or moving is to the right So copy So there's basically four cases. So the player is above players to the right and player is to the left Um, unless I miss one of those so we're going to be greater than Block x plus block width And then same thing we want to add Just like we did with the y. Okay, so I'm going to go ahead and Oh, that was weird Oh, okay. I know what's happened now. I remember how to fix that now. You see how it's like doing that weird thing like that Um, so there's still a little like a couple little weird. You saw you saw what happened there, right? Um, oh, there's another weird thing we got to fix So you see there's just kind of some weird artifacts Um, okay, so I know I know what's going on and I'll I'll I'll fix it here Again, I figured this all out yesterday when I was experimenting um One of the problems that we're having and it's it's it's a real this was a really really really subtle thing um Is that we When the player is above And then we I'm going to put it and then we Because down here then we do the movement. We do all the physics Um, there's still actually a collision registered And so what we got to do what fixes it is to add one here or is it subtract one? Yeah, it's adds one Uh, sorry plus one And again, it just took me a really long time to Do The player is above. Sorry Sorry, it's going to be this one plus let's see here So I was checking what I wrote before Player is above we add one Player is above. Yeah, so we add one plus one So I think that fixes it. Okay, that didn't fix it. Um, I think the other thing I had to do was For this thing There's an extra and condition. So and player dot dx is greater than zero So if it's to the left and it's moving right and then And player dot dx is less than zero Okay, so Okay Okay, so you see how it's Yeah, it's still messing up over there, which is kind of annoying but other one doesn't do that Um, why is that? Okay, that's working and again, this is this is the process. I you know, I did this yesterday And it worked didn't have this problem yesterday. I gotta figure out why Um, probably I have a little error. So let's take a look at the code real quick Um, I'm just going to compare it to what I wrote yesterday and I have it on a different screen here So you guys can't see it player x is less than So players to the left block x less block Player dx greater than zero. Yep player dx equals zero Okay, good player is to the right player. Ah You guys probably saw this a while ago. Um, okay, that's to be a plus not a greater than So I guess I didn't need all those things that was doing but um, these things do fix Uh All the different problems that you have with this type of game except for that one. What did I do wrong? There Ah, again, I need another l if again, you guys probably saw that. Um, I think I did that yesterday too Okay, there we go Okay, it's off the screen and you notice how it's slowing down when it cool. It's it's the friction thing and Now the other thing is like, you notice how it's up in the air, which is not what we want to happen So, uh, the way I fix this one And there's got to be a better way to do it, but uh, I'll I'll do what I just did last time is Before I jump I'm only going to jump Uh, if there's a collision Because you only want to jump if you're touching something So you shouldn't be able to jump in the mid in the middle of the air. So So if the player Is touching one of the blocks, then it can jump And then at that point we can say break because we only need to we can stop searching So we search through all the blocks. Is there a collision with the block? If so, then we let the player jump So I can That's what I did. Okay So that's okay. That's why I screwed that thing up earlier. Okay, that makes sense all right, so if you remember earlier, I was talking about this plus one thing and That should fix that. I'm not sure why it's not, but that's the reason I added that plus one. Um, let me check the code here and That's players above Player dy equals zero player y equals block y Okay, I think This is above that's why I labeled it incorrectly. This is below Sorry about that. Um, so this should be here Because what yeah, let me just make sure that works and you know, I'll stop talking I don't know what I'm talking about. Um Now you notice how I do let it kind of move in the air a little bit I don't know if that's the way you want it, but I I kind of like that I like that effect so you can jump in the air. Um, okay, so basically what's happening Is before what I was doing is I was putting the player Up just above the platform. So in that case, there was no collision But because of that the jumping thing didn't work, right? So what I did was I put the player up above the platform But plus one pixel. So there is a collision registering right now Um, so that that fixes that problem. Uh, it works pretty pretty well actually. Um, Yeah, I think that's I think that's it. I think that's uh, that's what I wanted to do in the game today. Um So that's your platformer. Yeah, um I don't think I'm missing anything Okay, that works I can go back and forth. Um, now I did See how it goes a little too fast. I did add a little code to limit the speed Um, so in the player thing so You know if self dot Dx I think is less than I think I did negative 12 Self dot dx equals negative 12 So I kind of limit the the maximum left and right speed Um if self dot dx Is greater than 12 Again, I just played around with numbers until I got what I liked You can do whatever numbers you like as well and maybe make it Okay, so you can see that that's the maximum speed it will go And then you can see the the friction is slowing it down And Yeah, that's it. So there is your platform game. Uh, let me just go over that real real quick again Just uh kind of review some of the main points We're using gravity and gravity is positive in this game because of the way pi games coordinate system works Then we got some colors we defined Just, you know basic pi game type stuff. We have a sprite class Which I explained earlier in the video and then the player is where we added a bunch of stuff Okay, so we set the player's color to green We initialize its parent class And when the player moves, we add dx to its x dy to its y and gravity to the dy So keep that's just physics. That's just the way physics works When we jump we change the dy to negative 24 or we subtract 24 from the dy so it will go up and Then we for left same thing we go left minus six from wherever it's going Uh, right is plus six on the dx and then we we limited that speed We just added some we added the player. We added some blocks and you can kind of you know just design your own You know kind of thing at this point Maybe in a future video we can add some you know images so it looks like an actual platformer Um, we'll talk about you know how to move the camera around a little bit Then this is just the standard pi game You know event loop and and how we do things in pi game So we're looking for a key press and if it's left arrow move the player left right arrow move the player right Space, uh, we said should only work if the player is basically landed on a block and so Um, here's all the code. So we we move the player and then for every block We check for a collision and then if there's a collision to the left um We set the player dx to zero and we move it to the left of the block It's to the right. Um Again, say then we check if there's a collision We move it to the left or to the right of a block And then the same thing with y where the player is above the block Um, if it's falling we set the dy to zero and we set the height to just above the block But one pixel in so we have a little bit of an extra collision going on And then if it's also if it's above we activate friction I didn't activate it here if the player is below I didn't think it was really necessary because there should only be a momentary contact But uh above we want the friction to work and remember, um, I said it wrong initially in the video But the higher the friction number the less friction there is the lower the friction number the the More friction there is and I could have reversed that but uh, since I I'll leave it the way it is And then uh, yeah, so there's four cases where the player is coming from the left Players coming from the right the player is falling and the player is Moving up from below and they have if you notice how they have to be exclusive So if an ellipse you see a couple times in the video I had if and you can see it had those weird, uh Artifacts that we didn't want to happen and then when the player, you know falls off the bottom of the screen We just want to move the player back up to the beginning now We could also do something like, you know player dot d x equals zero So and player dot dy equals zero So when it falls off the screen It falls straight down that you might prefer that you might not um, I kind of like it that way myself And then we just fill the background of the screen We render the player render the blocks We do the pie game flip method And then we again as I said in this particular game I set the clock to 30 frames per second if it was 60 frames per second you'd probably have to Reduce these numbers to to match that but these numbers work pretty well For the current size of things So that is it. Um, I will put this code Oh, I should have saved the base version. Okay, I'll make a base version for you guys So you can kind of follow along and I'll I'll erase everything that I I did here And then I'll also put this in there For you in case you just want to download it and play around with it. Okay So, uh, yeah, like I said again, uh, just quick thanks to my members for supporting the channel And uh, encouraging me to produce more content. It really does make a difference So if you can click the join button below everybody else. Have a great day and keep on coding