Home Assignment 2: Multiplayer Pong
In this task, we will create a 2-player Pong game. The game is displayed on the Android device screen, player controls 1 their paddle with the smartphone sensors, while player 2 controls their paddle from ESP32.
Game UI & Physics (5 pts)
- Draw the game UI: the ball and two players.
- Use a custom view and canvas drawing to display the game UI and create game physics
- See Lab 11 for more about custom views
- The ball should collide with the player paddles and top,bottom screen edges.
- The ball should be reset to the center of the screen if it runs out of bounds (left or right edge).
- The intersects() method is helpful to check for collisions in some of the cases.
Accelerometer control for player 1 (3 pt)
- Use accelerometer input to control the player one (left) paddle
- For this task, you can only account for 1 accelerometer axis.
MQTT + ESP32 control for player 2 (7 pts)
- Host a MQTT broker on your development machine (1 pt)
- Use a MQTT client on Android that accepts messages on a topic and translates them to movements for the 2nd players (right) paddle (3 pt)
- Create a Arduino/ESP32 MQTT Client that sends messages to the broker based on ESP32 touch pins (3 pt)
- The ESP32 has capacitive Touch Sensor pins, which can sense variations in electrical charge - including when touched by human skin. Not all pins can be used as touch sensor. On ESP32, pins 32 and 33 can be used for this task. See here for more info.
Both players should be able to move up, down, or stand still.
Other requirements
- Lock the screen orientation to landscape mode for this assignment.
- Remove the action bar of the app
- Closing the application / re-opening it should not cause any unexpected crashes
General tips:
You can base the refreshing of the game UI, physics & state on the accelerometer update events - they happen frequently enough & at a constant rate to make the game feel responsive.
From a game development perspective, the usual approach (not needed for this task), would be to implement a game loop.
Submission
In your submission, submit both Arduino and Android code.