Institute of Computer Science
  1. Courses
  2. 2020/21 fall
  3. Mobile Computing and Internet of Things (LTAT.06.009)
ET
Log in

Mobile Computing and Internet of Things 2020/21 fall

  • Main
  • Lectures
  • Labs
  • Homeworks & Home Assignments
  • Quizes
  • Task submission
  • Extra Materials
  • Projects
    • Teams & Topics
    • Presentations & Report
    • Grading & Submission

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 1 controls 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 (canvas) 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.
  • Players should not be able to move outside of the screen bounds.

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/7 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/7 pts)
  • Create a Arduino/ESP32 MQTT Client that sends messages to the broker based on ESP32 push button usage - 1 button corresponds to "up" movement, while the other button for "down" movement. (3/7 pts)
    • Your ESP32 kit included 2 push buttons. They can be connected to most of the digital GPIO pins (for example- 33, 32). One of the button legs should be connected to GND, while the other to the GPIO pin.
    • You should also activate the GPIO pins PULL UP resistor (in-built to ESP32) when using the buttons. The pull up resistor makes the "default" state of the pin to be "High", otherwise when the button is not pressed and the pin is not connected to GND (or anything), the state of the pin would be "hovering", picking up noise and you would see it jump between different values, even though the button is not being pressed
    • To activate the pull up resistor for an input pin, use this code: pinMode(somePin, INPUT_PULLUP); Note: it doesn't work with all pins ( https://github.com/espressif/arduino-esp32/issues/316)

Other requirements

  • Both players should be able to move up, down, or stand still.
  • 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
    • It's OK if it causes the game (Score) to be reset

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.

  • Institute of Computer Science
  • Faculty of Science and Technology
  • University of Tartu
In case of technical problems or questions write to:

Contact the course organizers with the organizational and course content questions.
The proprietary copyrights of educational materials belong to the University of Tartu. The use of educational materials is permitted for the purposes and under the conditions provided for in the copyright law for the free use of a work. When using educational materials, the user is obligated to give credit to the author of the educational materials.
The use of educational materials for other purposes is allowed only with the prior written consent of the University of Tartu.
Terms of use for the Courses environment