Beispiel #1
0
        /// <summary>
        /// Check collisions with monsters
        /// </summary>
        /// <param name="GameObject">Pacman or monster</param>
        /// <param name="Monsters">Monsters list</param>
        /// <param name="DimFlag">WHere you what to go</param>
        /// <param name="except">Number of monster in List of monsters (if pacman use -1)</param>
        /// <returns></returns>
        private bool CheckPacmanMonsterCollision(List <Monster> Monsters, MoveIntensions DimFlag, int except)
        {
            int  pacmanX  = Pacman.CurrentPositionX;
            int  pacmanY  = Pacman.CurrentPositionY;
            bool moveFlag = true;

            for (int i = 0; i < Monsters.Count; i++)
            {
                if (i == except)
                {
                    continue;
                }

                int monsterX = Monsters[i].CurrentPositionX;
                int monsterY = Monsters[i].CurrentPositionY;

                if ((pacmanY == monsterY) && (pacmanX == monsterX))
                {
                    moveFlag = false;
                    break;
                }
            }

            return(moveFlag);
        }
Beispiel #2
0
        /// <summary>
        /// Check collision for walls
        /// </summary>
        /// <param name="GameObject">Pacman or monster</param>
        /// <param name="Walls">List of walls</param>
        /// <param name="DimFlag">Where you want to move</param>
        /// <returns>Can you move or not</returns>
        private bool CheckWallCollision(MovableGameObject GameObject, List <Wall> Walls, MoveIntensions DimFlag)
        {
            int  pacmanX  = GameObject.CurrentPositionX;
            int  pacmanY  = GameObject.CurrentPositionY;
            bool moveFlag = true;

            if (DimFlag == MoveIntensions.UP)
            {
                pacmanY -= 1;
            }
            else if (DimFlag == MoveIntensions.DOWN)
            {
                pacmanY += 1;
            }
            else if (DimFlag == MoveIntensions.RIGHT)
            {
                pacmanX += 1;
            }
            else
            {
                pacmanX -= 1;
            }

            foreach (Wall wall in Walls)
            {
                int wallX = wall.CurrentPositionX;
                int wallY = wall.CurrentPositionY;

                if ((pacmanY == wallY) &&
                    (pacmanX == wallX))
                {
                    moveFlag = false;
                    break;
                }
            }

            return(moveFlag);
        }