Add variables for the second ball (example: x2, y2, vx2, vy2). Here's how we would do one step better than this: Use the key variable to allow a player to use the AWSD keys to control the ball. Perhaps the most important one is that bonk.io is not a single player game! When you're done your code should behave like this!Ĭomments on further improvements to the gameĮven if you have completed both challenges, you may notice some things that we are still missing. Replace it with your modified version of the horizontal force code above.Īdvice #2: Add force arrows for the vertical forces with this code: This is all that was meant by "why the extra step?" We were just pointing out that, in general, one can have multiple forces in the x & y directions. So when you write down Fnety you'll want to put down something like this: Both of these forces contribute to the net force. In this case ( Fnety) we will have a vertical force ( Fy) and the weight ( -mass*g). So why bother with Fnetx? Answer: when there is more than one force, it is only the "net" force that matters. You could just skip it and use ax = Fx/mass instead of ax = Fnetx/mass and everything would still work fine. The reason we highlighted this is that we don't absolutely need this line for the force in the x direction. In the above we've highlighted this line of code: The idea is that you will modify this code so that the up and down arrows create a vertical force ( Fy) and this factors into the change in velocity in the y direction ( deltaVy) In fact, most bonk.io levels start with the ball on the ground at rest and you use the up and down arrows to start bouncing.Īdd vertical forces to the code by adapting adapt this code from earlier to the y direction: Specifically, the real bonk.io game has vertical forces controlled by the up and down arrows that are very important to the game. If you've gotten to this point and done everything so far correctly, there is still an important element that is missing from our bonk.io clone. There is more than one right way to do it. You need to modify the if statements so that the bounce only happens if 0 < x < widthĪdvice #1: Review the if statements in the Pong gameĪdvice #2: You can use multiple or/and symbols in one if statement or you can make two or even three if statements inside of each other to get it to work. Try to get the behavior in the example you just played with by modifying this code: Notice that the game over happens not when the blob reaches the edge of the screen, but after it passes the edge and then drops down to y < 0! If you've never played bonk.io before, here is a demo of how the "game" over behaves. If (y - blob_radius width) it won't bounce when it gets close to y = 0, and instead it will trigger a game over. Check out this modified version of the pong gameĬlick here to look at this modified version of the pong game! (3) Optional Challenge #1: Add a game over, (4) Optional challenge #2: Add vertical forces (besides gravity) that are controlled by the up and down arrow keys. (2) Add horizontal forces that are controlled by the left and right arrow keys. Here is the (video) game plan: (1) Add gravity to the pong game. It's a little bit like sumo wrestling that way. You have some ability to affect your motion, but if you get bounced by some object or some other player so that you fly off the board you lose the game. You're a little ball and you bounce off the ground and various objects. io games out there right now is bonk.io If you've not played it you should definitely check it out. One of the most popular and entertaining.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |