Ping Pong - Microsoft MakeCode

Use the up and down arrow keys to move your paddle.


arcade-Ping-Pong

4 Likes

Hello, I found your variant of the Pong game. Since I’m currently working with makecode arcade, I took a look at the code. Is there a small explanation of the program steps in the “software update” part with the speeds? I have to admit that I don’t fully understand this part.

Sure thing!

So that part of the code checks if the ball is moving towards the computer paddle or away from it. If the ball vx is greater than 0, it means that it is moving right, towards the computer paddle. In this case, the computer will set its vertical speed (vy) to be positive or negative (down or up) depending on the relative position of the paddle to the ball (I multiplied this difference by 4 so it moves faster and can actually catch the ball). In short, it will try to get to the same point vertically where the ball is at.

If the ball is moving away from the computer, then the computer paddle will try to move to the middle (when y position is 60, since screen is 120 pixels tall). If it is higher than that, it will move down, if it’s there it won’t move and if it is lower, it will move up. This second part of the code doesn’t really add much to gameplay, but it makes it feel more like the computer paddle is alive.

I hope this was useful. Don’t hesitate to ask if you have any other questions!

Best,

Adrian

1 Like