Skip to content
This repository has been archived by the owner on Jul 11, 2024. It is now read-only.

Sense HAT(2)

alienzhangyw edited this page Apr 25, 2020 · 3 revisions

Pong game

Run the classic Pong game on Sense HAT, here's the video:

https://video.zhihu.com/video/1221850509822537728

First of all, create a draw_bat function to draw the bat on the LED matrix, bat_Y is the middle of the bat.

Use the joystick on Sense HAT to move the bat up and down. The main program keeps refreshing the bat's position:

Create a draw_ball function to draw the ball, posX and posY are coordinates of the ball, and Vx and Vy are the velocities of the ball at two directions. When the ball touches the top or bottom edge, Vy reverses. When the ball touches the right edge or the bat, Vx reverses.

If the ball gets to left edge, the game fails and shows “You lose!”, then restarts. Create an initialize function to initialize the variables.

The main program with the ball added:

The whole program:

Try it yourself! You can add more features like points, levels...

The save file is here(right-click then save-as).