Dynamic Ball Bouncing Technical - nmerris/Mini-Arknoid-libgdx-game GitHub Wiki
I wanted to make this game as fun as possible. I quickly realized that just allowing the ball to bounce off of objects without altering it's trajectory was no fun, and the ball would end up getting stuck going perfectly horizontal at times.
To correct this, I did 3 things
- Added dynamic 'bouncing' logic when the ball hits your character
- Added pinball style flippers to your character, so you can whack the ball OR just let it bounce off
- never allow the ball to travel perfectly horizontally or vertically
Dynamic bouncing
The trajectory of the ball bounce depends on how far from the center line the ball hits your character. I used right triangle geometry to change the outgoing angle: the farther from the center line, the more extreme the change in angle. I was trying to emulate the behavior of the old school Arkanoid game.
Below: some of the code I wrote to manipulate the ball bounce back angles