Fixed collision with paddle at small ball scale
This commit is contained in:
parent
830e40ca77
commit
7b31604a55
@ -457,11 +457,11 @@ void BALL_MoveAwayFromBoundaries(Ball * obj){
|
|||||||
bool BALL_CollideWithPaddle(Ball * obj, Paddle * paddle){
|
bool BALL_CollideWithPaddle(Ball * obj, Paddle * paddle){
|
||||||
if (RECT_Collide(&(obj->TargetRect), &(paddle->TargetRect))) {
|
if (RECT_Collide(&(obj->TargetRect), &(paddle->TargetRect))) {
|
||||||
Vector ballCenter = BALL_GetCenter(obj);
|
Vector ballCenter = BALL_GetCenter(obj);
|
||||||
if (ballCenter.y > (paddle->TargetRect).y) // if the ball hits the paddle from the sides (or the bottom (?))
|
if ((ballCenter.x) > ((paddle->TargetRect).x) || (ballCenter.x) < ((paddle->TargetRect).x + (paddle->TargetRect).w)) // if the ball hits the paddle from the sides (or the bottom (?))
|
||||||
BALL_CollideWithRect(obj, &(paddle->TargetRect));
|
BALL_SteerMomentum(obj, paddle); // Sets it to unit vector!
|
||||||
else
|
else
|
||||||
BALL_SteerMomentum(obj, paddle); // Sets it to unit vector!
|
BALL_CollideWithRect(obj, &(paddle->TargetRect));
|
||||||
// Following assumes that the paddle position was udated before the ball was updated
|
// Following assumes that the paddle position was udated before the ball was updated
|
||||||
while (RECT_Collide(&(obj->TargetRect), &(paddle->TargetRect))) { // Move away from rect in small steps
|
while (RECT_Collide(&(obj->TargetRect), &(paddle->TargetRect))) { // Move away from rect in small steps
|
||||||
(obj->Location) = VECTOR_Add((obj->Location), (obj->Momentum));
|
(obj->Location) = VECTOR_Add((obj->Location), (obj->Momentum));
|
||||||
BALL_MoveAwayFromBoundaries(obj);
|
BALL_MoveAwayFromBoundaries(obj);
|
||||||
|
Loading…
Reference in New Issue
Block a user