//Update the FOV of the player public void UpdateFOV(Point location) { //Compute FOV at the player's location FOVMap.Calculate(location, 10, Radius.CIRCLE); //Hide the unseen tiles foreach (Coord unseen in FOVMap.NewlyUnseen) { CurrentMap.Tiles[unseen.ToIndex(CurrentMap.Width)].IsVisible = false; foreach (Entity entity in CurrentMap.Entities.Items) { if ((entity.Position.X == unseen.X) && (entity.Position.Y == unseen.Y)) { entity.Animation.IsVisible = false; } } } //Draw the tiles that are in the FOV foreach (Coord seen in FOVMap.NewlySeen) { CurrentMap.Tiles[seen.ToIndex(CurrentMap.Width)].IsVisible = true; foreach (Entity entity in CurrentMap.Entities.Items) { if ((entity.Position.X == seen.X) && (entity.Position.Y == seen.Y)) { entity.Animation.IsVisible = true; } } } //Make sure the console will update the screen GameLoop.UIManager.MapConsole.IsDirty = true; ColoredString message = new ColoredString("Seen " + Convert.ToString(GameLoop.World.FOVMap.NewlySeen.Count())); GameLoop.UIManager.MessageLog.Add(message); }
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; } }
public void RefreshVisibilityTiles() { // Check to see if have left a room if (currentRegion != null && !currentRegion.InnerPoints.Contains(Position)) { // If player, handle room lighting if (this == CurrentMap.ControlledGameObject) { foreach (Coord point in currentRegion.InnerPoints) { CurrentMap.GetTerrain <Tile>(point).UnsetFlag(TileFlags.Lighted, TileFlags.InLOS); } foreach (Coord point in currentRegion.OuterPoints) { CurrentMap.GetTerrain <Tile>(point).UnsetFlag(TileFlags.Lighted, TileFlags.InLOS); } foreach (Coord tile in FOVSight.CurrentFOV) { CurrentMap.GetTerrain <Tile>(tile).SetFlag(TileFlags.InLOS); } foreach (Coord tile in FOVLighted.CurrentFOV) { CurrentMap.GetTerrain <Tile>(tile).SetFlag(TileFlags.Lighted); } } // We're not in this region anymore currentRegion = null; } // Not in a region, so find one. if (currentRegion == null) { // See if we're in a different region foreach (Region region in CurrentMap.Regions) { if (region.InnerPoints.Contains(Position)) { currentRegion = region; break; } } } // TODO: This code was placed here, got working, but the region code and // newly unused variables have not been scrubbed. // BUG: If I exit a region and stand on the doorway, the tiles in the room // that should be visible are not. // Visibility FOVSight.Calculate(Position, VisibilityDistance); // If player, handle LOS flags for tiles. if (this == CurrentMap.ControlledGameObject) { foreach (Coord tile in FOVSight.NewlyUnseen) { CurrentMap.GetTerrain <Tile>(tile).UnsetFlag(TileFlags.InLOS); } foreach (Coord tile in FOVSight.NewlySeen) { CurrentMap.GetTerrain <Tile>(tile).SetFlag(TileFlags.InLOS); } } // Lighting FOVLighted.Calculate(Position, LightSourceDistance); if (this == CurrentMap.ControlledGameObject) { foreach (Coord tile in FOVLighted.NewlyUnseen) { CurrentMap.GetTerrain <Tile>(tile).UnsetFlag(TileFlags.Lighted); } foreach (Coord tile in FOVLighted.NewlySeen) { CurrentMap.GetTerrain <Tile>(tile).SetFlag(TileFlags.Lighted, TileFlags.Seen); } } // Check and see if we're in a region, ensure these tiles are always visible and lighted. if (currentRegion != null) { Tile tile; // Make sure these are lit foreach (Coord point in currentRegion.InnerPoints) { tile = CurrentMap.GetTerrain <Tile>(point); // If player, handle room lighting if (this == CurrentMap.ControlledGameObject) { tile.SetFlag(TileFlags.Lighted, TileFlags.InLOS, TileFlags.Seen); } // Add tile to visible list, for calculating if the player can see. VisibleTiles.Add(tile); } foreach (Coord point in currentRegion.OuterPoints) { tile = CurrentMap.GetTerrain <Tile>(point); // If player, handle room lighting if (this == CurrentMap.ControlledGameObject) { tile.SetFlag(TileFlags.Lighted, TileFlags.InLOS, TileFlags.Seen); } // Add tile to visible list, for calculating if the player can see. VisibleTiles.Add(tile); } } }