/// <param name="metadata">Metadata for the tile being accessed.</param> /// <param name="environment">The environment the tile is in.</param> /// <returns>The transition texture to use when making a transition with other tiles.</returns> public virtual string TransitionTexture(TileMetadata metadata = null, Map.Environment environment = Map.Environment.Forest) { if (_tTextureFunc != null) { return(_tTextureFunc(TRANSTION_GENERIC, metadata, environment)); } return(TRANSTION_GENERIC); }
/// <param name="metadata">Metadata for the tile being accessed.</param> /// <returns> /// The texture to use when drawing the tile. /// </returns> public virtual string TextureName(TileMetadata metadata = null, Map.Environment environment = Map.Environment.Forest) { if (_tnameFunc != null) { return(_tnameFunc(_textureName, metadata, environment)); } return(_textureName); }
private int GetPopulation(Map.Environment env, Nation nation, int x, int y) { if (env.Map[y][x].OwnedBy.Nation == nation) { return(env.Map[y][x].OwnedBy.Population); } return((-1) * env.Map[y][x].OwnedBy.Population); }
/// <summary> /// Generates a unique identifer for this tile based on the metadata and environment. /// </summary> /// <param name="metadata">Metadata for the tile being accessed.</param> /// <param name="environment">The environment the tile is in.</param> /// <returns>A unique identifier.</returns> public long UniqueIdentity(TileMetadata metadata, Map.Environment environment) { long id = metadata != null?metadata.GetHashCode() & 0xFFFF : 0; id |= (long)ID.GetHashCode() << 16; id |= (long)environment << 48; id |= (long)Layer << 56; return(id); }
public TileMenu(Map.Environment environment, Engine.Game game) { _environment = environment; Game = game; Rectangle = new TweenedRectangle(game, new Rectangle(0, 0, (int)TotalArea.X, 28)); _screenFade = new TweenedDouble(game, 0); Recreate(); }
/// <param name="tile">The tile to get the transition for.</param> /// <param name="metadata">The metadata for the tile.</param> /// <param name="environment">The environment the tile is in.</param> /// <param name="pointOnTexture">The point on the texture the tile is on.</param> /// <returns>The texture for the specified tile.</returns> public Texture2D TextureForTile(Tile tile, TileMetadata metadata, Map.Environment environment, out Point pointOnTexture) { if (!HasTransition(tile, metadata, environment)) { GenerateTileTransition(tile, metadata, environment); } TileTransition transition = _cachedTransitions[tile.UniqueIdentity(metadata, environment)]; pointOnTexture = transition.Point; return(_textures[transition.Texture]); }
/// <summary> /// Finds a tile by name. /// </summary> /// <param name="name">The name of the tile without metadata.</param> /// <param name="layer">The layer the tile belongs to.</param> /// <returns>The tile, or an exception.</returns> public static Tile FindByName(string name, MapLayer layer, Map.Environment environment = Map.Environment.Forest) { foreach (Tile tile in LayerToDictionary(layer).Values) { if (tile.Name(null, environment) == name) { return(tile); } } throw new ArgumentException("Tile with name " + name + " not found."); }
private double[] SimplifyEnvironment(Map.Environment env) { int size = env.Size * 2 + 1; int center = env.Size; double[] sides = new double[4]; Nation nation = env.Map[center][center].OwnedBy.Nation; for (int y = 0; y < size; y++) { for (int x = 0; x < size; x++) { // Tikrinam ar apsimoka ziuret i ta langeli (yra colonija ir ne centrinis langelis) if (env.Map[y][x].IsColonized && (x + y != size - 1)) { // Skaiciavimui virsutines dalies if (y < center && x >= y && x < size - y) { sides[0] += GetPopulation(env, nation, x, y); } // Skaiciavimui desines dalies if (x > center && y > x - center && y <= x) { sides[1] += GetPopulation(env, nation, x, y); } // Skaiciavimui apatines dalies if (y > center && x + y >= size - 1 && x <= y) { sides[2] += GetPopulation(env, nation, x, y); } // Skaiciavimui kaires dalies if (x < center && y >= x && y < size - x) { sides[3] += GetPopulation(env, nation, x, y); } } } } return(sides); }
public override string TextureName(TileMetadata metadata = null, Map.Environment environment = Map.Environment.Forest) { string connection = "normal"; string var = "var" + (_variation + 1); if (_connectedLeft || _connectedRight) { if (_connectedLeft && _connectedRight) { connection = "lr"; } else if (_connectedLeft) { connection = "left"; } else if (_connectedRight) { connection = "right"; } } else if (_connectedUp || _connectedDown) { if (_connectedUp && _connectedDown) { connection = "ud"; } else if (_connectedUp) { connection = "up"; } else if (_connectedDown) { connection = "down"; } } return(base.TextureName(metadata, environment). Replace("{connection}", connection). Replace("{var}", var)); }
public override void Draw(Engine.Game game, Point mapPos, Map map, TileMetadata metadata, Map.Environment environment, Color?color = null) { TileAtlas.Region region = Map.Atlas[TextureName(metadata, environment)]; for (int x = 0; x < 2; x++) { for (int y = 0; y < 2; y++) { if (ScanArea(new Rectangle(mapPos.X - x, mapPos.Y - y, 2, 2), map)) { region = Map.Atlas["tiles/foliage/bigrock.png"]; region.Rectangle = new Rectangle(region.Rectangle.X + x * 16, region.Rectangle.Y + y * 16, 16, 16); } } } game.Batch.Texture( new Vector2(mapPos.X * 16, mapPos.Y * 16), region.Texture, color.HasValue ? color.Value : Color.White, Vector2.One, region.Rectangle); }
public override void DrawAfterTransition(Engine.Game game, Point mapPos, Map map, TileMetadata metadata, Map.Environment environment, Color?color = null) { base.DrawAfterTransition(game, mapPos + Offset, map, metadata, environment, color); }
public override void Draw(Engine.Game game, Point mapPos, Map map, TileMetadata metadata, Map.Environment environment, Color?color = null) { TileAtlas.Region region = Map.Atlas["tiles/foliage/" + (Events as TallGrassEvents).CurrentTextureFor(game, map, mapPos)]; game.Batch.Texture( new Vector2(mapPos.X * 16, mapPos.Y * 16), region.Texture, color.HasValue ? color.Value : Color.White, Vector2.One, region.Rectangle); }
public override string TransitionTexture(TileMetadata metadata = null, Map.Environment environment = Map.Environment.Forest) { return("tiles/transitions/road_color.png"); }
public override void DrawAfterTransition(Engine.Game game, Point mapPos, Map map, TileMetadata metadata, Map.Environment environment, Color?color = null) { TileAtlas.Region region = Map.Atlas["tiles/city/road_corner.png"]; Rectangle mapRect = new Rectangle(0, 0, map.Width, map.Height); if (mapRect.Contains(mapPos - new Point(1, 1)) && map[Layer, mapPos.X - 1, mapPos.Y - 1] != this) { game.Batch.Texture( new Vector2(mapPos.X * 16 - 16, mapPos.Y * 16 - 16), region.Texture, color.HasValue ? color.Value : Color.White, Vector2.One, region.Rectangle, 0, null, SpriteEffects.FlipHorizontally | SpriteEffects.FlipVertically); } if (mapRect.Contains(mapPos + new Point(-1, 1)) && map[Layer, mapPos.X - 1, mapPos.Y + 1] != this) { game.Batch.Texture( new Vector2(mapPos.X * 16 - 16, mapPos.Y * 16 + 16), region.Texture, color.HasValue ? color.Value : Color.White, Vector2.One, region.Rectangle, 0, null, SpriteEffects.FlipHorizontally); } if (mapRect.Contains(mapPos + new Point(1, -1)) && map[Layer, mapPos.X + 1, mapPos.Y - 1] != this) { game.Batch.Texture( new Vector2(mapPos.X * 16 + 16, mapPos.Y * 16 - 16), region.Texture, color.HasValue ? color.Value : Color.White, Vector2.One, region.Rectangle, 0, null, SpriteEffects.FlipVertically); } if (mapRect.Contains(mapPos + new Point(1, 1)) && map[Layer, mapPos.X + 1, mapPos.Y + 1] != this) { game.Batch.Texture( new Vector2(mapPos.X * 16 + 16, mapPos.Y * 16 + 16), region.Texture, color.HasValue ? color.Value : Color.White, Vector2.One, region.Rectangle); } }
public override void Draw(Engine.Game game, Point mapPos, Map map, TileMetadata metadata, Map.Environment environment, Color?color = null) { TileAtlas.Region region = Map.Atlas[TextureName(metadata, environment)]; if (mapPos.X - 1 > 0 && map[Layer, mapPos.X - 1, mapPos.Y].ID == ID) { region = Map.Atlas[TextureName(metadata, environment).Replace("tip.png", "tip_right.png")]; } if (mapPos.X + 1 <= map.Width && map[Layer, mapPos.X + 1, mapPos.Y].ID == ID) { region = Map.Atlas[TextureName(metadata, environment).Replace("tip.png", "tip_left.png")]; } if (mapPos.X - 1 > 0 && map[Layer, mapPos.X - 1, mapPos.Y].ID == ID && mapPos.X + 1 <= map.Width && map[Layer, mapPos.X + 1, mapPos.Y].ID == ID) { region = Map.Atlas[TextureName(metadata, environment).Replace("_tip.png", ".png")]; } game.Batch.Texture( new Vector2(mapPos.X * 16, mapPos.Y * 16), region.Texture, color.HasValue ? color.Value : Color.White, Vector2.One, region.Rectangle); }
/// <summary> /// Draws this tile. /// </summary> /// <param name="batch">The batch to draw with.</param> /// <param name="mapPos">The position this tile is on.</param> /// <param name="map">The map the tile is in.</param> /// <param name="metadata">Metadata associated with this position.</param> /// <param name="environment">The environment the map is in.</param> public virtual void Draw(Engine.Game game, Point mapPos, Map map, TileMetadata metadata, Map.Environment environment, Color?color = null) { TileAtlas.Region region = Map.Atlas[TextureName(metadata, environment)]; SpriteEffects effects = SpriteEffects.None; if (mapPos.X >= 0 && mapPos.X < map.Width && mapPos.Y >= 0 && mapPos.X < map.Height) { bool flipHorizontal = map.HasMetadata(Layer, mapPos.X, mapPos.Y) && map.GetMetadata(Layer, mapPos.X, mapPos.Y).GetOrDefault("flip-h", "false") == "True"; if (flipHorizontal) { effects |= SpriteEffects.FlipHorizontally; } bool flipVertical = map.HasMetadata(Layer, mapPos.X, mapPos.Y) && map.GetMetadata(Layer, mapPos.X, mapPos.Y).GetOrDefault("flip-v", "false") == "True"; if (flipVertical) { effects |= SpriteEffects.FlipVertically; } } game.Batch.Texture( new Vector2(mapPos.X * 16, mapPos.Y * 16), region.Texture, color.HasValue ? color.Value : Color.White, Vector2.One, region.Rectangle, 0, null, effects); }
public override void Draw(Engine.Game game, Point mapPos, Map map, TileMetadata metadata, Map.Environment environment, Color?color = null) { bool faceLeft = mapPos.X - 1 > 0 && map[Layer, mapPos.X - 1, mapPos.Y].ID.StartsWith("city/roof"); TileAtlas.Region region = Map.Atlas[TextureName(metadata, environment)]; game.Batch.Texture( new Vector2(mapPos.X * 16, mapPos.Y * 16), region.Texture, color.HasValue ? color.Value : Color.White, Vector2.One, region.Rectangle, 0, null, faceLeft ? SpriteEffects.FlipHorizontally : SpriteEffects.None); }
public override void Draw(Engine.Game game, Point mapPos, Map map, TileMetadata metadata, Map.Environment environment, Color?color = null) { game.Batch.Texture( new Vector2(mapPos.X * 16, mapPos.Y * 16), Template.TextureForDirection(game, Direction.Down), color.HasValue ? color.Value : Color.White); }
public override void Draw(Engine.Game game, Point mapPos, Map map, TileMetadata metadata, Map.Environment environment, Color?color = null) { if (!_hasValues) { Random random = new Random(); for (int i = 0; i < _randomValues.Length; i++) { _randomValues[i] = random.Next(); } _hasValues = true; } int slot = _randomValues[((Math.Abs(mapPos.Y) * map.Width) + Math.Abs(mapPos.X)) % _randomValues.Length] % 4; _variation = slot == 3 ? 1 : 0; _connectedLeft = mapPos.X - 1 > 0 && map[MapLayer.Decoration, mapPos.X - 1, mapPos.Y] == this; _connectedRight = mapPos.X + 1 < map.Width && map[MapLayer.Decoration, mapPos.X + 1, mapPos.Y] == this; _connectedUp = mapPos.Y - 1 > 0 && map[MapLayer.Decoration, mapPos.X, mapPos.Y - 1] == this; _connectedDown = mapPos.Y + 1 < map.Height && map[MapLayer.Decoration, mapPos.X, mapPos.Y + 1] == this; base.Draw(game, mapPos, map, metadata, environment, color); }
/// <summary> /// A second draw pass. Called after transitions have been drawn. /// </summary> /// <param name="batch">The batch to draw with.</param> /// <param name="mapPos">The position this tile is on.</param> /// <param name="map">The map the tile is in.</param> /// <param name="metadata">Metadata associated with this position.</param> /// <param name="environment">The environment the map is in.</param> public virtual void DrawAfterTransition(Engine.Game game, Point mapPos, Map map, TileMetadata metadata, Map.Environment environment, Color?color = null) { }
public override string TextureName(TileMetadata metadata = null, Map.Environment environment = Map.Environment.Forest) { return(_currentVariation); }
public override void DrawAfterTransition(Engine.Game game, Point mapPos, Map map, TileMetadata metadata, Map.Environment environment, Color?color = null) { if (!_hasValues) { Random random = new Random(); for (int i = 0; i < _randomValues.Length; i++) { _randomValues[i] = random.Next(); } _hasValues = true; } int slot = _randomValues[((Math.Abs(mapPos.Y) * map.Width) + Math.Abs(mapPos.X)) % _randomValues.Length]; _currentVariation = Variations[slot % Variations.Length]; if (_vFunc != null) { _currentVariation = _vFunc(_currentVariation, map, mapPos, slot); } base.DrawAfterTransition(game, mapPos, map, metadata, environment, color); }
public override string TextureName(TileMetadata metadata = null, Map.Environment environment = Map.Environment.Forest) { return(base.TextureName(metadata, environment).Replace("{frame}", _currentSlot.ToString())); }
/// <param name="tile">The tile to get the transition for.</param> /// <param name="metadata">The metadata for the tile.</param> /// <param name="environment">The environment the tile is in.</param> /// <returns>true if the cache has a transition for the specified tile</returns> public bool HasTransition(Tile tile, TileMetadata metadata, Map.Environment environment) { return(_cachedTransitions.ContainsKey(tile.UniqueIdentity(metadata, environment))); }
private void GenerateTileTransition(Tile tile, TileMetadata metadata, Map.Environment environment) { string transitionBase = tile.TransitionTexture(metadata, environment); if (!transitionBase.Contains("_color")) { if (!_masks.ContainsKey(transitionBase)) { _masks.Add(transitionBase, new BitArray(16 * 16)); Color[] data = new Color[16 * 16]; Game.Assets.Get <Texture2D>(transitionBase).GetData(data); if (!_usedAssets.Any(a => a == transitionBase)) { _usedAssets.Add(transitionBase); } for (int i = 0; i < data.Length; i++) { _masks[transitionBase][i] = data[i] == Color.Black; } Game.Assets.UnloadAsset(transitionBase); } } if (_textures.Count == 0 || _currentPointOnTexture.Y >= 16) { _textures.Add(new Texture2D(Game.GraphicsDevice, CACHE_ATLAS_SIZE, CACHE_ATLAS_SIZE)); _currentPointOnTexture = new Point(0, 0); } TileTransition transition = new TileTransition(); transition.Point = _currentPointOnTexture; transition.Texture = _textures.Count - 1; TileAtlas.Region region = Map.Atlas[tile.TextureName(metadata, environment)]; Rectangle textureRectangle = new Rectangle( region.Rectangle.X, region.Rectangle.Y, 16, 16); Color[] tileData = new Color[16 * 16]; region.Texture.GetData(0, textureRectangle, tileData, 0, 16 * 16); Color[] tileTransition = new Color[16 * 16]; if (transitionBase.Contains("_color")) { Game.Assets.Get <Texture2D>(transitionBase).GetData(tileTransition); if (!_usedAssets.Any(a => a == transitionBase)) { _usedAssets.Add(transitionBase); } Game.Assets.UnloadAsset(transitionBase); } else { for (int i = 0; i < tileTransition.Length; i++) { tileTransition[i] = _masks[transitionBase][i] ? tileData[i] : Color.Transparent; } } _textures.Last().SetData(0, new Rectangle(_currentPointOnTexture.X * 16, _currentPointOnTexture.Y * 16, 16, 16), tileTransition, 0, 16 * 16); _currentPointOnTexture.X++; if (_currentPointOnTexture.X >= 16) { _currentPointOnTexture.X = 0; _currentPointOnTexture.Y++; } _cachedTransitions.Add(tile.UniqueIdentity(metadata, environment), transition); }
public override void Draw(Engine.Game game, Point mapPos, Map map, TileMetadata metadata, Map.Environment environment, Color?color = null) { if (mapPos.Y - 1 > 0 && map[Layer, mapPos.X, mapPos.Y - 1] != this) { map[Layer, mapPos.X, mapPos.Y - 1].Draw(game, mapPos, map, map.GetMetadata(Layer, mapPos.X, mapPos.Y - 1), environment); } base.Draw(game, mapPos, map, metadata, environment, color); }
public override void Draw(Engine.Game game, Point mapPos, Map map, TileMetadata metadata, Map.Environment environment, Color?color = null) { TileAtlas.Region region = Map.Atlas.MissingRegion; for (int i = 1; i <= ANIMATION_FRAMES; i++) { // preload all frames region = Map.Atlas["tiles/city/waterwheel/" + i + ".png"]; } region = Map.Atlas.MissingRegion; for (int x = 0; x < 3; x++) { for (int y = 0; y < 4; y++) { if (ScanArea(new Rectangle(mapPos.X - x, mapPos.Y - y, 3, 4), map)) { region = Map.Atlas["tiles/city/waterwheel/" + (((int)(game.Time * 10) % ANIMATION_FRAMES) + 1) + ".png"]; region.Rectangle = new Rectangle(region.Rectangle.X + x * 16, region.Rectangle.Y + y * 16, 16, 16); } } } game.Batch.Texture( new Vector2(mapPos.X * 16, mapPos.Y * 16), region.Texture, color.HasValue ? color.Value : Color.White, Vector2.One, region.Rectangle); }
public override void DrawAfterTransition(Engine.Game game, Point mapPos, Map map, TileMetadata metadata, Map.Environment environment, Color?color = null) { bool faceLeft = mapPos.X - 1 > 0 && map[Layer, mapPos.X - 1, mapPos.Y].ID.StartsWith("city/roof"); if (mapPos.Y + 1 < map.Height && map[Layer, mapPos.X, mapPos.Y + 1] != this) { TileAtlas.Region region = Map.Atlas["tiles/city/beam/top.png"]; game.Batch.Texture( new Vector2(mapPos.X * 16, mapPos.Y * 16 + 16), region.Texture, color.HasValue ? color.Value : Color.White, Vector2.One, region.Rectangle, 0, null, faceLeft ? SpriteEffects.FlipHorizontally : SpriteEffects.None); } }
public override void DrawAfterTransition(Engine.Game game, Point mapPos, Map map, TileMetadata metadata, Map.Environment environment, Color?color = null) { UpdateCurrentFrameWithGame(game, mapPos); base.DrawAfterTransition(game, mapPos, map, metadata, environment, color); }