// Create a new map using the Map class // and a map generator. Uses several // parameters to determine geometry private void CreateMap() { _mapTiles = new TileBase[_mapWidth * _mapHeight]; CurrentMap = new Map(_mapWidth, _mapHeight); MapGenerator mapGen = new MapGenerator(); CurrentMap = mapGen.GenerateMap(_mapWidth, _mapHeight, _maxRooms, _minRoomSize, _maxRoomSize); var MapView = new GoRogue.MapViews.LambdaMapView <bool>(_mapWidth, _mapHeight, pos => CurrentMap.Tiles[pos.ToIndex(_mapWidth)].IsTransparent); FOVMap = new GoRogue.FOV(MapView); }
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); } } } } } }
public void CalculateFov(Point dir) { // Use a GoRogue class that creates a map view so that the IsTransparent function is called whenever FOV asks for the value of a position var fovMap = new GoRogue.MapViews.LambdaMapView <bool>(51, 51, CurrentMap.IsTransparent); lastFov = new FOV(fovMap); if (GameLoop.World.players.ContainsKey(GameLoop.NetworkingManager.myUID)) { Point start = GameLoop.World.players[GameLoop.NetworkingManager.myUID].Position + dir; Point playerRel = GameLoop.World.players[GameLoop.NetworkingManager.myUID].CalculatedPosition; playerRel += new Point(6, 6); Point mouseLoc = GameLoop.MouseLoc; double degrees = Math.Atan2((mouseLoc.Y - playerRel.Y), (mouseLoc.X - playerRel.X)) * (180.0 / Math.PI); degrees = (degrees > 0.0 ? degrees : (360.0 + degrees)); lastFov.Calculate(start, 20, Radius.CIRCLE, degrees, 114); foreach (var spot in lastFov.NewlySeen) { TileBase tile = CurrentMap.GetTileAt <TileBase>(spot); tile.IsVisible = true; if (CurrentMap.GetEntitiesAt <Entity>(spot).Count != 0) { for (int j = 0; j < CurrentMap.GetEntitiesAt <Entity>(spot).Count; j++) { CurrentMap.GetEntitiesAt <Entity>(spot)[j].IsVisible = true; } } if (tile is TileDoor door) { door.UpdateGlyph(); } if (!SeenTiles.Contains(spot)) { SeenTiles.Add(new Point(spot.X, spot.Y)); } } foreach (KeyValuePair <long, Player> player in players) { if (!lastFov.BooleanFOV[player.Value.Position.X, player.Value.Position.Y] && player.Key != GameLoop.NetworkingManager.myUID) { player.Value.IsVisible = false; } else if (lastFov.BooleanFOV[player.Value.Position.X, player.Value.Position.Y] || player.Key == GameLoop.NetworkingManager.myUID) { player.Value.IsVisible = true; if (player.Key != GameLoop.NetworkingManager.myUID) { Point myPos = players[GameLoop.NetworkingManager.myUID].Position; Point theirPos = player.Value.Position; int distance = (int)Distance.CHEBYSHEV.Calculate(myPos.X, myPos.Y, theirPos.X, theirPos.Y); player.Value.UpdateStealth((distance / 2) - 5); } } } //foreach (Entity entity in CurrentMap.Entities.Items) { // if (!(entity is Player)) { // if (lastFov.BooleanFOV[entity.Position.X, entity.Position.Y]) { // entity.IsVisible = true; // } // if (!lastFov.BooleanFOV[entity.Position.X, entity.Position.Y]) { // entity.IsVisible = false; // } // } //} for (int i = SeenTiles.Count - 1; i > 0; i--) { var spot = SeenTiles[i]; if (!lastFov.CurrentFOV.Contains(new GoRogue.Coord(spot.X, spot.Y))) { TileBase tile = CurrentMap.GetTileAt <TileBase>(spot.X, spot.Y); tile.Darken(true); SeenTiles.Remove(spot); } else { TileBase tile = CurrentMap.GetTileAt <TileBase>(spot.X, spot.Y); tile.Darken(false); GameLoop.UIManager.MapConsole.ClearDecorators(spot.X, spot.Y, 1); } } GameLoop.UIManager.MapConsole.IsDirty = true; } }