First, let us make some preparations by extending the
AbstractGameObject
class with some additional attributes and general 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(); bounds = new Rectangle(); }
The following list contains a brief description of the purpose of each variable:
velocity
: This is the object's current speed in m/s.terminalVelocity...