My First Game – Part 6: Pong – Second Paddle

So far we have a paddle on the left, that can be moved with the UP and DOWN keys.

What if we want to add a second player? We can just make a quick modification to the MenuState.hx :

Oops, for the left paddle, we’re controlling it using UP and DOWN keys. What about the right paddle? Let’s modify the code a little…

Now we have two paddles on the screen! Note that the code is not optimised — it’s not adhering to the DRY (Don’t Repeat Yourself) methodology, but for now it’s excusable because we’re still learning.

Now if you test the game, you will see two paddles which can be moved by the W/S and UP/DOWN keys.

ss5

Now that we have two paddles, we will need the ball. In our next post, we shall create the Pong ball, inclusive of the logic to keep the ball within the screen boundaries and for the ball to bounce off the Paddles.

Leave a Reply

Your email address will not be published. Required fields are marked *