Pong Game

Play the classic pong game with your friends!


YOU WILL NEED

  • 1 x Micro:bit
  • 1 x Tinkercademy Breakout Board
  • 2 x ADKeypad

Looking for parts to make this?


STEP 1

(a) Connect the micro:bit to the breakout board.
(b) Attach the first ADKeypad to Pin 0, and a second ADKeypad to Pin 1.
(c) Connect your micro:bit using a Micro USB cable to your computer.




Materials

  • 1 x Micro:bit
  • 1 x Tinkercademy breakout board
  • 2 x ADKeypad


STEP 2

Defining variables and start screen

(a) bottom_position_of_A and bottom_position_of_B refers to the Y-coordinate of the position of the bottom half of the 2 pong boards.

(b) ball_horizontal and ball_vertical refers to the direction of which the ball goes.



STEP 3

Functions for moving of the pong boards
We can't have our pong boards moving off-screen, so we have set a boundary for the movements of the pong board.



STEP 4

Functions for the movement of the pong ball
(a) ball_bounce() refers to the ball bouncing off the pong boards.
(b) ball_bounce_top_bottom() refers to the ball bouncing off the top and bottom boundaries of the screen.
(c) ball_move() refers to the ball moving in the direction dictated by ball_vertical and ball_horizontal.



STEP 5

Now, we will combine all ball movements into one big function. This function will be called main_game.



STEP 6

Define game over
This function shows a string "A loses!" or "B loses!" depending on which player lost, and then resets the game.



STEP 7

Combine main_game and game_over together to form the game itself. Pong board movements are also mapped to their respective buttons on the ADKeyboards.



STEP 8

After all that, download the code into your micro:bit and it's done. Find a friend to play the pong game with you!


Made this activity? Good Job! Now spread the word. Share a photo of your creation on social media with #letsgethacking #PongGame