The gold coin, feather, and bunny head are some of our game objects. Each of our game objects inherits the AbstractGameObject
class. The AbstractGameObject
holds the attributes and functionalities for physics and collision detection.
First, let's make some preparations in AbstractGameObject
and add a few functionalities for our upcoming physics and collision detection code.
Add the following import to AbstractGameObject
:
import com.badlogic.gdx.math.Rectangle;
Then, add the following member variables and initialization code to the same class:
public Vector2 velocity; public Vector2 terminalVelocity; public Vector2 friction; public Vector2 acceleration; public Rectangle bounds; public AbstractGameObject () { position = new Vector2(); dimension = new Vector2(1, 1); origin = new Vector2(); scale = new Vector2(1, 1); rotation = 0; velocity = new Vector2(); terminalVelocity = new Vector2(1, 1); friction = new Vector2(); acceleration = new Vector2...