public override ValueTask <MovementResult> Update(CanvasTimingInformation context)
        {
            if (!_readyToExit && _door.CanGhostLeave(Ghost))
            {
                _readyToExit = true;
                return(new ValueTask <MovementResult>(MovementResult.NotFinished));
            }

            if (_finished)
            {
                Ghost.Direction = new DirectionInfo(Directions.Left, Directions.Left);
                Ghost.SetMovementMode(GhostMovementMode.Undecided);
                return(new ValueTask <MovementResult>(MovementResult.Finished));
            }

            Vector2 diff = _cellToMoveTo - _cellToMoveFrom;

            if (diff != Vector2.Zero)
            {
                diff = diff.Normalize();

                Ghost.Position = Ghost.Position + diff / Vector2s.Two;

                var dir = DirectionToIndexLookup.GetDirectionFromVector(diff);

                Ghost.Direction = new DirectionInfo(dir, dir);
            }

            if (Ghost.Position.Floor() == _cellToMoveTo.Floor())
            {
                Ghost.Position = _cellToMoveTo;
                whenAtTargetCell();
            }

            return(new ValueTask <MovementResult>(MovementResult.NotFinished));
        }
        public GhostInsideHouseMover(
            Ghost ghost,
            IMaze maze,
            GhostHouseDoor ghostHouseDoor) :
            base(ghost, GhostMovementMode.InHouse, maze, () => new ValueTask <CellIndex>(CellIndex.Zero))
        {
            _door = ghostHouseDoor;

            Vector2 center = Maze.PixelCenterOfHouse;

            float x = center.X + ghost.OffsetInHouse * 16;

            _topPos    = new Vector2(x, (float)(13.5 * 8 + 4));
            _bottomPos = new Vector2(x, (float)(15.5 * 8 - 4));

            var centerOfUpDown = new Vector2(_topPos.X, Maze.PixelCenterOfHouse.Y);

            ghost.Position = _topPos + new Vector2(0, (_bottomPos.Y - _topPos.Y) / 2);

            _cellToMoveFrom = ghost.Position;

            if (ghost.Direction.Current == Directions.Down)
            {
                _cellToMoveTo = _bottomPos;
            }
            else if (ghost.Direction.Current == Directions.Up)
            {
                _cellToMoveTo = _topPos;
            }
            else
            {
                throw new InvalidOperationException("Ghost must be pointing up or down at start.");
            }

            _routeOut = new[] { centerOfUpDown, Maze.PixelCenterOfHouse, Maze.PixelHouseEntrancePoint };
        }
Esempio n. 3
0
 public GhostLogic(IMaze maze, Ghost ghost)
 {
     _maze  = maze;
     _ghost = ghost;
     _lastDecisionMadeAt = CellIndex.Zero;
 }
Esempio n. 4
0
 public GhostFrightenedMover(Ghost ghost, IMaze maze) : base(ghost, GhostMovementMode.Frightened, maze, _getChaseTargetCell)
 {
 }