The ball mimics physics of the classic Breakout/Arkanoid games. The ball maintains speed and moves in straight lines until it collides with another object. Then it changes direction and velocity. Usually it gains speed to keep things interesting, but it can lose speed too.

Colliders

There are various types of colliders in Frog Ball. The main collider objects are all represented using line segments. The main 3 are: * Wall * Block * Fist

Walls and blocks

Walls and blocks are pretty straightforward. The collision surfaces are just line segments, and all collisions happen in a single 2D plane. When the ball hits one of these line segments, the ball is reflected using the perpendicular, aka normal, of the segment.

libgdx provides a sweet Intersector class which handles a lot of the tedious collision logic.

The collided object and the ball both receive a collision event in case they need to do something special. In the case of the block, the block breaks.

In case there are multiple sides to the object, as with blocks, the object makes multiple line segments, each of which can receive the collision event and forward it to the master object representing the block.

Fist

The players’ fists are very similar to a block, except the fists cause the ball to move forward, from the player’s point of view. The ball is not reflected.

I found a couple helpful links when it came to doing the ball logic.

A huge one was Collision Detection in Breakout by Jake Gordon at codeincomplete.com. He goes in depth into a couple important details of the collision detection, even providing JavaScript code samples.

Another helpful page was this short and sweet Reflecting a Vector at 3dkingdoms.com.



blog comments powered by Disqus

Published

12 November 2012

Tags