protected void DrawObjects() { var player = GlobalConstants.GameManager.Player; var playerVision = player.VisionProvider; for (int i = 0; i < this.FogHolder.GetChildCount(); i++) { PositionableSprite fog = this.FogHolder.GetChild <PositionableSprite>(i); ShaderMaterial shaderMaterial = fog?.Material as ShaderMaterial; bool canSee = playerVision.HasVisibility(player, player.MyWorld, fog.WorldPosition); int lightLevel = this.m_ActiveWorld.LightCalculator.Light.GetLight(fog.WorldPosition); shaderMaterial?.SetShaderParam("canSee", canSee); shaderMaterial?.SetShaderParam("lightLevel", lightLevel); } for (int i = 0; i < this.GameManager.EntityHolder.GetChildCount(); i++) { var node = this.GameManager.EntityHolder.GetChild <JoyObjectNode>(i); bool canSee = playerVision.HasVisibility(player, player.MyWorld, node.WorldPosition); if (canSee != node.Visible) { node.Visible = canSee; } } for (int i = 0; i < this.GameManager.ItemHolder.GetChildCount(); i++) { var node = this.GameManager.ItemHolder.GetChild <JoyObjectNode>(i); if (node.MyJoyObject is IItemInstance item) { if (item.InWorld == false) { continue; } bool canSee = playerVision.HasVisibility(player, player.MyWorld, node.WorldPosition) & item.InWorld; if (canSee != node.Visible) { node.Visible = canSee; } } } }
public WorldState(IWorldInstance overworldRef, IWorldInstance activeWorldRef) : base() { this.m_ActiveWorld = activeWorldRef; this.m_Overworld = overworldRef; this.GameManager = GlobalConstants.GameManager; this.PhysicsManager = this.GameManager.PhysicsManager; this.RelationshipHandler = this.GameManager.RelationshipHandler; this.ConversationEngine = this.GameManager.ConversationEngine; this.GUIManager = this.GameManager.GUIManager; this.m_Camera = new Camera2D { AnchorMode = Camera2D.AnchorModeEnum.DragCenter, ProcessMode = Camera2D.Camera2DProcessMode.Physics, Current = true, ZIndex = 100, ZAsRelative = false }; this.FogHolder = this.GameManager.FogHolder; GlobalConstants.GameManager?.Player.MyNode?.AddChild(this.m_Camera); GlobalConstants.GameManager.Player.AliveChange -= this.OnPlayerDeath; GlobalConstants.GameManager.Player.AliveChange += this.OnPlayerDeath; GlobalConstants.GameManager.Player.ConsciousnessChange -= this.OnPlayerConsciousChange; GlobalConstants.GameManager.Player.ConsciousnessChange += this.OnPlayerConsciousChange; var player = GlobalConstants.GameManager.Player; for (int i = 0; i < this.FogHolder.GetChildCount(); i++) { PositionableSprite fog = this.FogHolder.GetChild(i) as PositionableSprite; ShaderMaterial shaderMaterial = fog?.Material as ShaderMaterial; shaderMaterial?.SetShaderParam("darkColour", player.VisionProvider.DarkColour); shaderMaterial?.SetShaderParam("lightColour", player.VisionProvider.LightColour); shaderMaterial?.SetShaderParam("minimumLight", player.VisionProvider.MinimumLightLevel); shaderMaterial?.SetShaderParam("minimumComfort", player.VisionProvider.MinimumComfortLevel); shaderMaterial?.SetShaderParam("maximumComfort", player.VisionProvider.MaximumComfortLevel); shaderMaterial?.SetShaderParam("maximumLight", player.VisionProvider.MaximumLightLevel); } this.Tick(); }
protected void InstantiateWorld() { IGameManager gameManager = GlobalConstants.GameManager; List <IBasicValue <float> > values = new List <IBasicValue <float> > { new ConcreteBasicFloatValue("weight", 1), new ConcreteBasicFloatValue("bonus", 1), new ConcreteBasicFloatValue("size", 1), new ConcreteBasicFloatValue("hardness", 1), new ConcreteBasicFloatValue("density", 1) }; this.m_ActiveWorld.Initialise(); ISpriteState state = null; float scale = (float)GlobalConstants.SPRITE_WORLD_SIZE / GlobalConstants.SPRITE_TEXTURE_SIZE; var floorTileMap = gameManager.FloorTileMap; floorTileMap.TileSet = this.m_ObjectIcons.GetStaticTileSet(this.m_ActiveWorld.Tiles[0, 0].TileSet, true); int surroundFloorIndex = floorTileMap.TileSet.FindTileByName("SurroundFloor"); var wallTileMap = gameManager.WallTileMap; wallTileMap.TileSet = this.m_ObjectIcons.GetStaticTileSet(this.m_ActiveWorld.Tiles[0, 0].TileSet); int surroundWallIndex = wallTileMap.TileSet.FindTileByName("SurroundWall"); for (int i = 0; i < this.m_ActiveWorld.Tiles.GetLength(0); i++) { for (int j = 0; j < this.m_ActiveWorld.Tiles.GetLength(1); j++) { Vector2Int intPos = new Vector2Int(i, j); //Make the fog of war PositionableSprite fog = gameManager.FogPool.Get(); fog.Name = "Fog of War " + intPos; fog.Show(); fog.Scale = new Vector2(scale, scale); fog.Move(intPos); //Make the floor floorTileMap.SetCell(i, j, surroundFloorIndex); } } //Make the upstairs if (this.m_ActiveWorld.Guid != this.m_Overworld.Guid) { floorTileMap.SetCellv( this.m_ActiveWorld.SpawnPoint.ToVec2(), floorTileMap.TileSet.FindTileByName("upstairs")); } //Make each downstairs foreach (KeyValuePair <Vector2Int, IWorldInstance> pair in this.m_ActiveWorld.Areas) { floorTileMap.SetCellv( pair.Key.ToVec2(), floorTileMap.TileSet.FindTileByName("downstairs")); } //Create the walls foreach (Vector2Int position in this.m_ActiveWorld.Walls) { wallTileMap.SetCellv( position.ToVec2(), surroundWallIndex); } int index = 0; index = this.CreateItems(index, this.m_ActiveWorld.Items); GlobalConstants.GameManager.EntityHolder.ZIndex = index + 10; //Create the entities int innerIndex = 0; int itemIndex = 0; foreach (IEntity entity in this.m_ActiveWorld.Entities) { JoyObjectNode gameObject = gameManager.EntityPool.Get(); gameObject.Show(); gameObject.AttachJoyObject(entity); gameObject.ZIndex = index; innerIndex += gameObject.CurrentSpriteState.SpriteData.Parts.Max(part => part.m_SortingOrder) + 1; itemIndex = this.CreateItems(itemIndex, entity.Contents, false); itemIndex = this.CreateItems(itemIndex, entity.Equipment.Contents, false); } GlobalConstants.GameManager.FogHolder.ZIndex = index + innerIndex + 10; this.Done = true; }