collision detection

hello i seem to get a error when trying to do collision detection with my pacman and ghost. here is the two methods from my main code:
void Pacman::CheckGhostCollisions()
{
//Implement collision detection between the ghosts and pacman
for (int i = 0; i < GHOSTCOUNT; i++)
{
if (CollisionCheck(_pacman->x, _pacman->y, _pacman->width, _pacman->height, _ghosts[i]->x, _ghosts[i]->y, _ghosts[i]->width, _ghosts[i]->height))
_pacman->Dead = true;// Collision occurred

}

}
bool CollisionCheck(int x1, int y1, int width1, int height1, int x2, int y2, int width2, int height2)
{
int left1 = x1;
int left2 = x2;
int right1 = x1 + width1;
int right2 = x2 + width2;
int top1 = y1;
int top2 = y2;
int bottom1 = y2 + height1;
int bottom2 = y2 + height2;
if (bottom1 < top2)
return false;
if (top1 > bottom2)
return false;
if (right1 < left2)
return false;
if (left1 > right2)
return false;

return true;
}

here is the code from my header structures
struct Player
{
Vector2* Position;
Rect* SourceRect;
Texture2D* Texture;
int Direction;
int Frame;
int CurrentFrameTime;
bool Dead;
int x;
int y;
int width;
int height;

};

struct MovingEnemy
{
Rect* Position;
Rect* sourceRect;
Texture2D* texture;
int direction;
float speed;
int x;
int y;
int width;
int height;
};
Please edit your post and use code tags - http://www.cplusplus.com/articles/jEywvCM9/

Also we cant read minds, please copy paste your errors.
Last edited on
Your problem is here:
int bottom1 = y2 + height1;
Topic archived. No new replies allowed.