DiMastero, our recently discovered ROBOTC master, has done it again. He has re-created the classic game Pong on the NXT.
See it in action:
How it works:
It uses my previous bouncing ball program, combined with a player-controlled bat, different levels, random difficulty increase and point display. The ball starts off at a random position within the playing field, to avoid patterns, after which it bounces off every wall (or bat) it meets, at a 90° angle. The bat is controlled by turning the wheel connected to motor A, and its stopped whenever it tries to exit the allowed area. Once the ball gets one pixel away from the bat, it compares its own position to the bat’s, and bounces away when it’s acceptable, increasing your point-count with one for each hit. In case it’s not, the game freezes and the famous “you lose” appears on the display, after which the program is aborted.
The game has different levels, too; the level you’re playing at is increased by one whenever your points are above 150% of the last level you passed (if the last level was ten, you’d need to get above 15, then 23, then 35, etc.), so it takes longer as you get better. Each time the level increases, the NXT randomly picks one of the following to make your life more difficult:
- Increasing the ball’s speed, by decreasing the waiting time at the end of the main loop
- Decreasing the bat’s speed, by increasing the amount of encoder ticks it takes to move one pixel
- Making the bat smaller, by four pixels