ok i have had a look and attempted to impliment it, but no joy so far i'm not sure if its the maths that isn't working or not
Code:
void checkPlayerCollision()
{
int playerradius;
int puckradius;
int playerx;
int playery;
int puckx;
int pucky;
int distancex;
int distancey;
int totaldistancesqd;
int totdistance;
playerradius = player.GetRadius();
puckradius = AIpuck.GetRadius();
playerx = player.GetXLocation();
puckx = AIpuck.GetXLocation();
playery = player.GetYLocation();
pucky = AIpuck.GetYLocation();
distancex = playerx-puckx;
distancey = playery-pucky;
cout << distancex << endl;
cout << distancey << endl;
totaldistancesqd = ((distancex*distancex)+(distancey*distancey));
totdistance = sqrt (totaldistancesqd);
cout << totdistance << endl;
if (totdistance <= 0)
{
AIpuck.setVelocityX(5);
AIpuck.setVelocityY(-5);
}
}
Code:
class CPuck
{
public:
CPuck();
virtual ~CPuck();
SDL_Surface *m_image;
void update();
void passImage(SDL_Surface *img) {m_image = img;};
void drawImage(SDL_Surface*);
void moveLocationX(int a){m_locx += a;};
void moveLocationY(int a){m_locy += a;};
void setVelocityX(int a){m_locx += a;};
void setVelocityY(int a){m_locy += a;};
int GetXLocation(){return m_locx;};
int GetYLocation(){return m_locy;};
int GetHeight(){return height;};
int GetWidth(){return width;};
int GetRadius(){return radius;};
bool collision();
private:
int m_locx, m_locy;
int m_velx, m_vely;
int height;
int width;
int radius;
Code:
class CPaddle
{
public:
CPaddle();
virtual ~CPaddle();
SDL_Surface *m_image;
void update();
void passImage(SDL_Surface *img) {m_image = img;};
void drawImage(SDL_Surface*);
//this has the code in the {} brackets
void moveLocationX(int a){m_locx += a;};
void moveLocationY(int a){m_locy += a;};
void setVelocityX(int a){m_locx += a;};
void setVelocityY(int a){m_locy += a;};
void outofbounds();
int GetXLocation(){return m_locx;};
int GetYLocation(){return m_locy;};
int GetHeight(){return height;};
int GetWidth(){return width;};
int GetRadius(){return radius;};
int ScoreOutput();
private:
int m_locx, m_locy;
int m_velx, m_vely;
int score;
int height;
int width;
int radius;
player is an instance of the paddle class btw