Demo 'Pong' Game
Play the classic arcade game "Pong" with a friend using two ZentriOS devices
- SDK directory:
API Features Demonstrated
- Network Interface API
- TCP/TLS Client/Server API
- Event Handler API
- RTOS API
- Custom Commands API
- Button Utility API
- LED Matrix 8x8 Library
This app works on:
- AMW004 - Zentri Mackerel evaluation board - See Connecting a Zentri AMW004 to a Zentri ASG001 Backpack.
- AMW106 - Zentri Moray evaluation board fitted with a Zentri ASG001 Backpack
Requirements and Prerequisites
This app requires two ZentriOS devices, such as AMW106-E03 (Moray) evaluation boards. Each device requires two buttons, two LEDs and an 8x8 LED matrix display, such as provided with the Zentri ASG001 Monitor Backpack.
This app uses two ZentriOS devices to implement the classic arcade video game 'Pong' to simulate a game of table tennis (aka Ping-pong).
The following instructions assume the ZentriOS device is an AMW106-E03 evaluation board connected to the LED matrix via an I2C interface. For information about using and connecting I2C peripherals to ZentriOS, see ZentriOS Peripherals
- Two boards are required to play the game. Each board needs to be fitted with the Moray 'Monitor' backpack which contains a LED Matrix display
- Using the ZentriOS SDK, build and download the Pong app into each board
- When the app runs, the text "Pong! BTN1=P1 BTN2=P2" starts scrolling across the LED display
- Two opponents play against one other.
- The eval boards connect to each other as a (softAP+TCP) server and (WLAN+TCP) client.
- The server (Player 1) is selected by pressing Button 1 on the eval board.
- When the server starts, the RED LED on the Moray eval board begins blinking, which indicates a softAP is active.
- The client (Player 2) is selected by pressing Button 2 on the eval board. Note that Player 2 should wait until Player 1 has started the server before
- pressing Button2.
- Each board scrolls the text "Connecting" while the boards are attempting to connect
- Once connected, the boards display the text "Hold buttons". At this point, the game is ready to begin.
- To begin the game, both players simultaneously hold down Button1 & Button2.
- Use Button1/Button2 to move the paddle left/right to bounce the ball back to your opponent. If you miss the ball, your opponent gains a point.
The first player to reach 5 points WINS the game!
Several game variables may be changed using a ZentriOS terminal connected to either evaluation board while the game is running. These variables may be configured the same way any other ZentriOS variable is configured. The variables are:
> set pong.max_score 5 <= Max score to win a game > set pong.pad.sensitivity 55 <= Limits speed at which the paddle can move > set pong.pad.size 3 <= Width of the paddle in pixels > set pong.update.increment 600 <= How fast to increase the ball speed on each increment > set pong.update.min_interval 200 <= Minimum ball update interval (lower = faster)
A custom command is also available to restart the game at any point. The command is: