Representation of the player of the Pong game. More...
This class stores the position and velocty of the ball, updates and draws it.
Constructor.
Constructor that sets the ball's position and velocity to the given values.
pos | The ball's initial position. Defaults to (0, 0). | |
vel | The ball's initial velocity. Defaults to (0, 0). |
Ball::Ball | ( | float | x, | |
float | y, | |||
float | velX = 0 , |
|||
float | velY = 0 | |||
) |
Constructor.
Constructor that sets the ball's position and velocity to the given values.
x | The ball's initial x-coordinate. | |
y | The ball's initial y-coordinate. | |
velX | The x-coordinate of the ball's initial velocity. Defaults to 0. | |
velY | The y-coordinate of the ball's initial velocity. Defaults to 0. |
Ball::~Ball | ( | void | ) |
Default destructor.
float Ball::x | ( | ) |
Returns the ball's current x-coordinate.
float Ball::y | ( | ) |
Returns the ball's current y-coordinate.
void Ball::setPos | ( | vec3 | pos | ) |
Sets the ball's current position.
pos | The ball's new position. |
void Ball::setPos | ( | float | x, | |
float | y | |||
) |
Sets the ball's current position.
x | The ball's new x-coordinate. | |
y | The ball's new y-coordinate. |
Sets the ball's current velocity.
vel | The ball's new velocity. Defaults to (0, 0). |
void Ball::update | ( | ) |
Updates the ball's current position using only its own velocity.
Calls proposeMove() to simply move one step ahead according to the ball's current velocity.
Updates the ball's current position and velocity using external forces.
First updates the ball's current velocity by taking an average of it's own velocity and the velocity of the flow data at its position. Then, if the player is currently in attraction or repulsion mode, the ball's velocity is further adjusted using an appropriate attraction or repulsion force, inversely strong to the distance between ball and player. Finally calls proposeMove() to move one step ahead according to the ball's updated velocity.