Hi,
My brother has university project to create a Pacman game and is currently stuck on the bounding box collision. What happens when you debug the game in visual studio is all of the munchies disappear as if they are all being collided with and hes spent sometime trying to figure it out but hes reached a point where nothing works as he thinks its something to do with how he is using the sprites.
This is the check collision:
boolean Pacman::CheckCollision(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 = y1 + height1;
int bottom2 = y2 + height2;
if (bottom1 < top2 && top1 > bottom2 && right1 < left2 && left1 > right2)
{
return true;
}
}
This is the Munchie collision, the pacman pellets:
void Pacman::MunchieCollision()
{
for (int i = 0; i < MUNCHIECOUNT; i++)
{
if(CheckCollision(_pacman->Position->X, _pacman->Position->Y, _pacman->Position->Width,
_pacman->Position->Height, _munchies[i]->MunchieRect->X, _munchies[i]->MunchieRect->Y, _munchies[i]->MunchieRect->Width, _munchies[i]->MunchieRect->Height) )
{
_munchies[i]->MunchieRect->X = 1300;
_munchies[i]->MunchieRect->Y = 1300;
}
}
}
This is where the rectangle is located:
// Load Pacman
_pacman->Texture = new Texture2D();
_pacman->Texture->Load("Textures/Pacman.tga", false);
_pacman->Position = new Rect(350.0f, 350.0f, 32, 32);
_pacman->SourceRect = new Rect(0.0f, 0.0f, 15, 15);
//Load ghost
_ghosts[0]->texture = new Texture2D();
_ghosts[0]->texture->Load("Textures/GhostBlue.tga", true);
_ghosts[0]->posRect = new Rect(rand() % Graphics::GetViewportWidth(), rand() % Graphics::GetViewportHeight(), 28, 28);
_ghosts[0]->sourceRect = new Rect(0.0f, 0.0f, 16, 16);
// Load Munchie
Texture2D* munchieTexture = new Texture2D();
munchieTexture->Load("Textures/MunchieText.png", true);
for (int i = 0; i < MUNCHIECOUNT; i++)
{
_munchies[i]->MunchieTexture = munchieTexture;
_munchies[i]->MunchieRect = new Rect(rand() % Graphics::GetViewportWidth(), rand() % Graphics::GetViewportHeight(), 20, 20);
_munchies[i]->munchieSourceRect = new Rect(0.0f, 0.0f, 7, 7);
}
he also wanted me to attach the game incase anyone wants to take a look
Thanks for your help
Pacman.rar