public void GlobalSetup() { var map = new Generator(PathDistance + 5, PathDistance + 5) .ConfigAndGenerateSafe(gen => gen.AddSteps(DefaultAlgorithms.RectangleMapSteps())) .Context.GetFirst <IGridView <bool> >("WallFloor"); // A couple points exactly PathDistance apart. We keep the paths on the same y-line so that they are // PathDistance apart regardless of the DistanceCalc. // Path performance checks will independently path both from p1 to p2 and from p2 to p1, in order to // account for one direction likely being faster (first direction checked in the neighbors loop) _p1 = (1, 5); _p2 = (PathDistance + 1, 5); // An AStar instance to use for pathing _aStar = new GoRogue.Pathing.AStar(map, DistanceCalc); // Equivalent FastAStar instance _fastAStar = new FastAStar(map, DistanceCalc); }
private void CheckKeyboard() { var mapView = new GoRogue.MapViews.LambdaMapView <bool>(GameLoop.World.CurrentMap.Width, GameLoop.World.CurrentMap.Height, pos => GameLoop.World.CurrentMap.IsTileWalkable(new Point(pos.X, pos.Y))); var AStar = new GoRogue.Pathing.AStar(mapView, Distance.CHEBYSHEV); if (SadConsole.Global.KeyboardState.IsKeyReleased(Microsoft.Xna.Framework.Input.Keys.F5)) { SadConsole.Settings.ToggleFullScreen(); } if (SadConsole.Global.KeyboardState.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.Up)) { GameLoop.CommandManager.MoveActorBy(GameLoop.World.Player, new Point(0, -1)); CenterOnActor(GameLoop.World.Player); } if (SadConsole.Global.KeyboardState.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.Down)) { GameLoop.CommandManager.MoveActorBy(GameLoop.World.Player, new Point(0, 1)); CenterOnActor(GameLoop.World.Player); } if (SadConsole.Global.KeyboardState.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.Left)) { GameLoop.CommandManager.MoveActorBy(GameLoop.World.Player, new Point(-1, 0)); CenterOnActor(GameLoop.World.Player); } if (SadConsole.Global.KeyboardState.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.Right)) { GameLoop.CommandManager.MoveActorBy(GameLoop.World.Player, new Point(1, 0)); CenterOnActor(GameLoop.World.Player); } if (SadConsole.Global.KeyboardState.IsKeyReleased(Microsoft.Xna.Framework.Input.Keys.Z)) { GameLoop.CommandManager.UndoMoveActorBy(); CenterOnActor(GameLoop.World.Player); } if (SadConsole.Global.KeyboardState.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.X)) { GameLoop.CommandManager.RedoMoveActorBy(); CenterOnActor(GameLoop.World.Player); } //If the player moved, move the enemy if (SadConsole.Global.KeyboardState.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.Up) || SadConsole.Global.KeyboardState.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.Down) || SadConsole.Global.KeyboardState.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.Left) || SadConsole.Global.KeyboardState.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.Right)) { foreach (Entity monster in GameLoop.World.CurrentMap.Entities.Items) { if (monster is Monster) { Path path = AStar.ShortestPath(monster.Position, GameLoop.World.Player.Position); if (path.Length < monster.VisibleRange && GameLoop.World.CurrentMap.GetEntityAt <Monster>(path.GetStep(0)) == null) { int diceOutcome = Dice.Roll("1d100"); if (diceOutcome >= 100 - monster.MoveChance && path.GetStep(0) != GameLoop.World.Player.Position) { GameLoop.CommandManager.MoveMonster((Actor)monster, path.GetStep(0)); } if (path.GetStep(0) == GameLoop.World.Player.Position && !(GameLoop.World.Player.Attacked) && diceOutcome >= 50) { GameLoop.CommandManager.MoveMonster((Actor)monster, path.GetStep(0), true); } } } } } }