 Okay, this is part two in a series on 2d game design using phaser 2d if you didn't watch the last video in the series I definitely recommend watching it go ahead and check out the playlist. Hopefully there's a link in the description to the full playlist Now last video was kind of long. Hopefully this video will be a little bit shorter, but we're gonna do some fun things We're gonna add physics to our players so far. We have two players here One there and one there using our players function here Let's go ahead and add physics to our game. So we're gonna come in here and Under our create function so while the game is being created what we're gonna do is we're gonna say okay Find our game and we're gonna add in some physics So games are game physics dot Start the system now phaser has different types of Physics systems at least three different types. We're doing the most basic here Which is the least system hungry when it comes to resources and that would be arcade physics So basically each character is going to have a an invisible square around them that indicates their boundaries So our tux isn't going to have you know Boundary that matches around the image like this It basically has an image of visible square that is the boundary of the image Which is good enough for the game that we're creating here So again, we're saying here take the game that we are that we created using our phaser library up here So that game that object we're gonna call the physics function and start the physics system And we're gonna say use the physics system of arcade Okay, so now we have physics in our game, but we need to tell The game that our players All of our players need to have those physics applied to them because not everything in your game is gonna have physics So I'm gonna come down here to again to our create function and after we've created our players group we're gonna say take our players group and dot enable Body remember, this is case sensitive. So write it like I'm writing it And we're gonna say set it to true So now any player that we add to the players group will have physics But you can have different physics for different players because there's different parameters for each player so let's come down to our create function here art now create function bar create player function and We're gonna say in here take the player not players But player that we created on the line above right here And we're gonna say look at its body which which created with the physics that we've added to it And we're gonna say that we want it to bounce So bounce on the y-axis. So that's up and down x is left and right y is up and down And how much we want to bounce we'll say zero point two so a little bit of a bounce and That's not gonna do anything at this point because The player isn't falling, you know, the player isn't moving. So let's go ahead and add player dot body So we're gonna add to the player's body Dot gravity on the y-axis. So we're gonna say ready. I'm gonna put in just from my notes I have 300 so obviously if you want them to fall faster make that number bigger. So first let's go ahead and actually Comment out our bounce line. We should have done the gravity line first just as an example. So now I can restart this and you can see our player falls and keeps falling So it didn't stop and it didn't bounce well For it to bounce it needs something bounce off of and we're gonna add a ground plane later on but for right now We're gonna say player dot body dot collide world Bounds equals true. So our world is a certain size and So our player without this the player will go off screen left right up down the world's not gonna stop it But with this set to true We'll save that and now our player will fall both our players will fall and stop when I get the bomb But they just it's very they just kind of stop Yeah, so now we'll uncomment our Bounce property here. So we're saying that it has a property of bouncing which by default is set to zero But we're gonna turn up a little bit to two point one or I'm sorry zero point two and now they bounce a little bit Now obviously if we were to turn this number up Instead of zero point two, we'll just make it two. Let's save that and refresh Okay, let's do point No, let's just do one. Let's see how much that is Falling falling falling Okay They almost hit the top again, but they didn't and they're gonna bounce and bounce And they're gonna see they're gonna bounce so Let's change this to point five Just zero point five you can take zero point five or just point five. It doesn't care There we go You can see it bounce bounce bounce till they come to a stop But I like point two in my notes. That's what I found to work the best and there we go We have players that bounce with a little bit of physics so let's go ahead and Make this full screen so you can see String things down this a little bit so you can see all the code So just to quickly review we create our game with some parameters up here We preload right now. We're preloading one image just means that we're putting that image in making sure it's downloaded in Ram So it's ready to load Saying the background color here using hex code Then we're setting that our game has physics. You gotta say the game is gonna have physics So it enables that physics engine. We're creating a group for our players and then we're saying that any player in the in the Players group has a body enabled set to true So this is saying physics has bodies so you can add physics but also collision which we're gonna get to right now It's colliding with the world. We're gonna collide with ground planes and other Objects and stuff in the near future there. We're here. We're creating two players Setting different coordinates for each of them, which is all done here We haven't done anything in our update function because all the updates We've had right now are handled by the physics engine, but we'll get into more of that later So anyway, I thank you for watching again. This is part of a series Now someone's gonna ask because they always do I can't find the next video in this series Well, there's a link to a playlist in the description of this video and if you can't access that because it's marked as private that's because It's not gonna be released until next week. I'm putting out one video each week. Now if you are a patreon supporter You can get videos early So think about becoming a supporter over at patreon.com forward slash metal x1000 and there for You can support me minimal financially a dollar a month Is is much appreciated if you can't support me financially, but you like my videos Be sure to like subscribe subscribe share and comment that way you don't miss any videos But it also helps boost the popularity of my videos a little bit As always, please visit my website films by Chris calm That's Chris the case should be a link to that in the description as well And as always, I hope that you have a great day