Пример #1
0
        //TODO
        private void moveGhost(Ghost ghost, Pathfinder.Direction dir)
        {
            bool moved = false;

            switch (dir)
            {
            case Pathfinder.Direction.Left:
                if (!hasSomeone(ghost.pos - Map.unitx))
                {
                    ghost.pos.x--;
                    moved = true;
                }
                break;

            case Pathfinder.Direction.Right:
                if (!hasSomeone(ghost.pos + Map.unitx))
                {
                    ghost.pos.x++;
                    moved = true;
                }
                break;

            case Pathfinder.Direction.Up:
                if (!hasSomeone(ghost.pos - Map.unity))
                {
                    ghost.pos.y--;
                    moved = true;
                }
                break;

            case Pathfinder.Direction.Down:
                if (!hasSomeone(ghost.pos + Map.unity))
                {
                    ghost.pos.y++;
                    moved = true;
                }
                break;

            default:
                break;
            }

            if (moved)
            {
                ghost.lastMove = dir;
            }
        }
Пример #2
0
        /// <summary>
        /// Updates all of the ghost's positions in the current scene, using
        /// their own A* pathfinder.
        /// </summary>
        public void updateGhosts()
        {
            foreach (Ghost ghost in currentScene.ghosts)
            {
                // Got that bastard!!!
                if (pacmanReached(ghost))
                {
                    // set on future respawn position
                }
                // Move torward pacman, almost there!!!
                else if (ghost.getPathToPac() != null)
                {
                    ghost.state = Ghost.GhostState.OK;
                    Pathfinder.Direction dir = ghost.getPathToPac().Pop();
                    ghost.lastMove = dir;

                    switch (dir)
                    {
                    case Pathfinder.Direction.Left:
                        moveGhost(ghost, Pathfinder.Direction.Left);
                        break;

                    case Pathfinder.Direction.Right:
                        moveGhost(ghost, Pathfinder.Direction.Right);
                        break;

                    case Pathfinder.Direction.Up:
                        moveGhost(ghost, Pathfinder.Direction.Up);
                        break;

                    case Pathfinder.Direction.Down:
                        moveGhost(ghost, Pathfinder.Direction.Down);
                        break;

                    default:
                        break;
                    }
                }
                // F**k..., no way to pacman
                else
                {
                    ghost.state = Ghost.GhostState.Pissed;
                }
            }
        }