Pong Game

Play the classic pong game with your friends!


You'll need

  • 1 x micro:bit
  • 1 x breakout board
  • 2 x ADKeyboards

Step 1

Instructions

Connect the micro:bit to the breakout board.

Attach 1 ADKeyboard to Pin 0, and 1 ADKeyboard to Pin 1.
Connect your micro:bit using a Micro USB Cable to your computer.




Materials

1x micro:bit
1x breakout board
2x ADKeyboards


Step 2

Instructions

We will first start off by defining the variables as well as the start screen of the pong game.

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.

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


Step 3

Instructions

Now, we will define the 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

Instructions

Now, we will define the functions for the movement of the pong ball.

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


Step 5

Instructions

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


Step 6

Instructions

Now, we will define the function game_over(). This function shows a string "A loses!" or "B loses!" depending on which player lost, and then resets the game.


Step 7

Instructions

Now, we will put 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

Instructions

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


Code and References

Completed this tutorial?

Spread the word! Let's get this trending on social media with #letsgethacking #PongGame