so i’ve got this ball that i’d like to bounce off a paddle however the ball isnt effected at all by the paddle upon collision, I think it may have to do with pointers but i could be something else
ball class:
bool CBall::mCollision(CPaddle* other)
{
if((mY >= other->mGetY() +other->mGetH()) && (mX >= other->mGetX() + other->mGetW()) &&
(mY + mH <= other->mGetY()) && (mX + mW <= other->mGetX()))
return true;
}
void CBall::mBounce(CPaddle* other)
{
if(CBall::mCollision(other))
{
if(mDirection>=0 && mDirection<90)
{
if(mY + mH <= other->mGetY())
mDirection = 270 + ((270 - mDirection) * 2);
if(mX + mW <= other->mGetX())
mDirection = 180 - ((0 + mDirection) * 2);
}
if(mDirection>=90 && mDirection<180)
{
if(mY + mH <= other->mGetY())
mDirection = 270 + ((270 - mDirection) * 2);
if(mX >= other->mGetX() + other->mGetW())
mDirection = 0 - ((0 + mDirection) * 2);
}
if(mDirection>=180 && mDirection<270)
{
if(mY >= other->mGetY() + other->mGetH())
mDirection = 90 + ((270 - mDirection)*2);
if(mX >= other->mGetX() + other->mGetW())
mDirection = 0 - ((mDirection - 180)*2);
}
if(mDirection>=270 && mDirection<360)
{
if(mY >= other->mGetY() + other->mGetH())
mDirection = 90 - ((mDirection - 270)*2);
if(mX + mW <= other->mGetX())
mDirection = 180 + ((360 - mDirection)*2);
}
}
}
paddle class:
int CPaddle::mGetX()
{
return mX;
}
int CPaddle::mGetY()
{
return mY;
}
int CPaddle::mGetW()
{
return mW;
}
int CPaddle::mGetH()
{
return mH;
}
main:
// instantiate objects
CPaddle mPlayer(10, (SCREEN_HEIGHT/2) - 30, 20, 60, 0xff, 0xff, 0xff, 5);
CBall mBall;
// logic
mBall.mBounce(&mPlayer);
this is all the code related to the bounce function i believe, everything else works besides this bounce function(IDK why?), I’m able to get the ball to bounce off the screen borders so I know the bounce math is good just getting the ball to react to a collision with an object with changable x and y seems to be the problem