private PossibleDirection GetIntendedDirection(Monster monster) { TilePos tp = monster.TilePosition; TilePos playerPosition = GlobalServices.GameState.Player.TilePosition; int yDiff = tp.Y - playerPosition.Y; // +ve and the monster is below, -ve and the monster is above int xDiff = tp.X - playerPosition.X; // +ve and the monster is to the right, -ve and the monster is to the left var orientation = this.CurrentDirection.Orientation(); if (orientation == Orientation.Horizontal) { if (yDiff > 0) { return(PossibleDirection.Up); } if (yDiff < 0) { return(PossibleDirection.Down); } } else if (orientation == Orientation.Vertical) { if (xDiff > 0) { return(PossibleDirection.Left); } if (xDiff < 0) { return(PossibleDirection.Right); } } return(MonsterMovement.RandomDirection()); }
protected IDirectionChosen GetDesiredDirection() { if (this.CurrentDirection == Direction.None) { return(ShouldMonsterFollowPlayerIntoAnotherRoom() ? this.Monster.DetermineDirectionTowardsPlayer() : MonsterMovement.RandomDirection()); } bool shouldChangeDirection = GlobalServices.Randomness.Test(7); if (shouldChangeDirection) { return(ShouldMonsterFollowPlayerIntoAnotherRoom() ? this.Monster.DetermineDirectionTowardsPlayer() : MonsterMovement.AlterDirectionByVeeringAway(this.CurrentDirection)); } if (this.Monster.CanMoveInDirection(this.CurrentDirection)) { return(new ConfirmedDirection(this.CurrentDirection)); } var reversed = this.CurrentDirection.Reversed(); return(new PossibleDirection(reversed)); }
public override ConfirmedDirection GetDirection() { var result = ShouldMakeAnAggressiveMove(this.Monster) ? this.Monster.DetermineDirectionTowardsPlayer() : MonsterMovement.RandomDirection(); return(base.GetConfirmedDirection(result)); }
public static IDirectionChosen MoveTowardsPlayer(Monster monster) { bool shouldMoveRandomly = GlobalServices.Randomness.Test(7); IDirectionChosen result = shouldMoveRandomly ? MonsterMovement.RandomDirection() : monster.DetermineDirectionTowardsPlayer(); return(result); }
private IDirectionChosen GetDesiredDirection() { if (this.Monster.ChangeRooms == ChangeRooms.FollowsPlayer && !this.Monster.IsPlayerInSameRoom() && this.Monster.IsPlayerNearby()) { var pursuitResult = CautiousPursuit.MoveTowardsPlayer(this.Monster); return(pursuitResult); } var result = MonsterMovement.RandomDirection(); return(result); }
private static PossibleDirection GetRandomPerpendicularDirection(Direction currentDirection) { if (currentDirection == Direction.None) { return(MonsterMovement.RandomDirection()); } bool whichWay = GlobalServices.Randomness.Next(2) == 0; var orientation = currentDirection.Orientation(); switch (orientation) { case Orientation.Horizontal: return(whichWay ? PossibleDirection.Up : PossibleDirection.Down); case Orientation.Vertical: return(whichWay ? PossibleDirection.Left : PossibleDirection.Right); } throw new InvalidOperationException(); }