This is my collision detection function in the maze game im working at. I never made a game before and I dont have that much programming experience.
The question I keep asking me continously is why this isn't working. The Solids are instances of the class Solids with rectangular shape(X(Top-left-corner),Y(Top-left-corner),width,height) which are stored in a List< T >. The function below iterates through the List and calls the second function below. checkForCollision is called every FrameUpdate.
Can somebody please help me. I'm becoming desperate :)
private void checkForCollision()
{
foreach (Solids wall in level1.WallObjects)
{
if (IsCollidedSolids(ref Pl1, wall))
{
Pl1.OnCollision();
break;
}
}
}
public bool IsCollidedSolids(ref Player Pl ,Solids act)
{
if (Pl.X+Pl.width >= act.X && Pl.Y >= act.Y - act.height)
return true;
if (Pl.X + Pl.width >= act.X && Pl.Y -Pl.height <= act.Y)
return true;
if (Pl.X <= act.X + act.width && Pl.Y - Pl.height <= act.Y)
return true;
if (Pl.X <= act.X + act.width && Pl.Y >= act.Y - act.height)
return true;
else
return false;
}