Hello everyone, I am trying to create a bounding box around a Sprite in my simple Pong game. The bounding box needs to be a simple rectangle around the sprite so that it can act as a collision detector between the ball and paddle.
I have already tried to create the bounding box but it's not quite working as expected.
float current_x = paddle_right->xPos();
float current_y = paddle_right->yPos();
float current_x2 = paddle_left->xPos();
float current_y2 = paddle_left->yPos();
float width_x = current_x + 16;
float width_y = current_y + 150;
float width_x2 = current_x2 + 16;
float width_y2 = current_y2 + 150;
if((x_pos > current_x && x_pos < width_x && y_pos > current_y && y_pos < width_y)||
(x_pos > current_x2 && x_pos < width_x2 && y_pos > current_y2 && y_pos < width_y2))
{
dir_vector.setX(dir_vector.getX() * -1);
}
The above code is the code I have used to create said bounding box, but like I said, it's simply not working correctly (As in the ball will sometimes go through the Sprite or have an abnormal reaction to it such as bouncing the wrong way).
I hope I have explained this well, if not please ask me which part to explain again. Basically, I just want do create a bounding box around a Sprite (in this case, the Paddle) to which then the ball can collide from.
For reference I am using the AwesomeSauce Game Engine.