예제 #1
0
 public bool CheckGhostBorderCollision(ServerGhost ghost)
 {
     if (rightBorder < ghost.Position.X || ghost.Position.X < leftBorder || lowerBorder < ghost.Position.Y ||
         ghost.Position.Y < topBorder)
     {
         return(true);
     }
     return(false);
 }
예제 #2
0
 public bool CheckGhostWallCollision(ServerGhost ghost)
 {
     foreach (var wall in walls)
     {
         if (wall.Position.X - wall.Width <= ghost.Position.X &&
             ghost.Position.X - ghostSize <= wall.Position.X &&
             wall.Position.Y <= ghost.Position.Y + ghostSize &&
             ghost.Position.Y <= wall.Position.Y + wall.Length)
         {
             return(true);
         }
     }
     return(false);
 }
예제 #3
0
 public List <ServerGhost> GhostMovement(List <ServerGhost> ghosts)
 {
     return(ghosts.Select(ghost => {
         ServerGhost newGhost = ghost.Copy();
         newGhost.Position.X += newGhost.Speed.X;
         if (CheckGhostWallCollision(newGhost) || CheckGhostBorderCollision(newGhost))
         {
             newGhost.Position.X -= newGhost.Speed.X;
             newGhost.Speed.X = -newGhost.Speed.X;
         }
         newGhost.Position.Y += newGhost.Speed.Y;
         if (CheckGhostWallCollision(newGhost) || CheckGhostBorderCollision(newGhost))
         {
             newGhost.Position.Y -= newGhost.Speed.Y;
             newGhost.Speed.Y = -newGhost.Speed.Y;
         }
         return newGhost;
     }).ToList());
 }