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); }
/// <summary> /// Sets the metadata for a certain tile. An empty string or null = remove metadata. /// </summary> /// <param name="layer">The layer the tile is on.</param> /// <param name="x">The X position of the tile.</param> /// <param name="y">The Y position of the tile.</param> /// <param name="metadata">The metadata string, or null.</param> public void SetMetadata(Tile.MapLayer layer, int x, int y, TileMetadata metadata) { if (HasMetadata(layer, x, y)) { ushort slot = GetMetadataSlot(layer, x, y); LayerToMetadataArray(layer).RemoveAt(slot - 1); LayerToTileArray(layer)[(y * Width) + x] = LayerToTileArray(layer)[(y * Width) + x] & 0xff; for (int i = 0; i < Width * Height; i++) { if ((LayerToTileArray(layer)[i] & 0xFFFF0000) >> 16 >= slot) { ushort lastMetadataAttr = (ushort)((LayerToTileArray(layer)[i] & 0xFFFF0000) >> 16); lastMetadataAttr--; LayerToTileArray(layer)[i] = (uint)((LayerToTileArray(layer)[i] & 0xFFFF) | (lastMetadataAttr << 16)); } } } if (metadata != null && metadata.HasValuesSet) { LayerToMetadataArray(layer).Add(metadata); LayerToTileArray(layer)[(y * Width) + x] = (uint)((LayerToTileArray(layer)[(y * Width) + x] & 0xFFFF) | ((LayerToMetadataArray(layer).Count) << 16)); } }
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); }
public override void OnInteract(TileMetadata metadata, WorldState world, Point mapPos) { if (metadata == null || !metadata.IsKeySet("needs-user-interaction") || metadata["needs-user-interaction"] == "True") { DoTextBox(metadata, world, mapPos); } }
public override void OnWalkLeave(TileMetadata metadata, WorldState world, Point mapPos) { if (_walkedOn == mapPos) { _walkedOn = new Point(-1, -1); } }
public override void OnWalkEnter(TileMetadata metadata, WorldState world, Point mapPos) { if (metadata != null && metadata["needs-user-interaction"] == "False") { DoTextBox(metadata, world, mapPos); } }
/// <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); }
/// <param name="from">The point the transition is coming from.</param> /// <param name="to">The point the transition is going to.</param> /// <param name="map">The map.</param> /// <param name="other">The tile to transition with.</param> /// <param name="metadata">Metadata for the tile being accessed.</param> /// <param name="otherMetadata">Metadata for the other tile being accessed.</param> /// <returns> /// If this tile should create a transition to the other tile. /// By default this will happen if: /// * The tile is on the terrain layer /// * The tile ID hash has a higher int value than the other tile /// * The tile doesn't have the same ID as the other tile /// OR /// * The tile is on the terrain layer and has a higher transition priority (and the other tile doesn't have -1). /// </returns> public virtual bool UseTransition(Point from, Point to, Map map, Tile other, TileMetadata metadata = null, TileMetadata otherMetadata = null) { bool result = false; if (_useTransitionFunc != null) { return(_useTransitionFunc(result, from, to, map, other, metadata)); } if (map.Info.Environment == Map.Environment.Inside) { return(false); } if (Layer == MapLayer.Terrain && TransitionPriority() != -1 && other.TransitionPriority(otherMetadata) != -1) { if (other.TransitionPriority(otherMetadata) < TransitionPriority(metadata)) { result = true; } else if (other.TransitionPriority(otherMetadata) == TransitionPriority(metadata)) { result = other.ID.GetHashCode() > ID.GetHashCode(); } } return(result); }
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); }
private void DoTeleport(TileMetadata metadata, WorldState world, Point mapPos) { if (!metadata.IsKeySet("map-file")) { return; } WorldState.SpawnArgs args = new WorldState.SpawnArgs(new Point(-1, -1), Gameplay.Direction.Down, world.Player); if (metadata.IsKeySet("custom-spawn-position")) { string[] vec = metadata["custom-spawn-position"].Split(','); for (int i = 0; i < vec.Length; i++) { vec[i] = vec[i].Trim(); } int x = int.Parse(vec[0]); int y = int.Parse(vec[1]); args.Position = new Point(x, y); } if (metadata.IsKeySet("spawn-direction")) { Enum.TryParse <Direction>(metadata["spawn-direction"], out args.Direction); } world.TransitionToMap("data/maps/" + metadata["map-file"], metadata["transition"] != "False", args); }
/// <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 transition priority for the tile. Higher = will get transition. /// -1 = never use transition with this tile. /// </returns> public virtual int TransitionPriority(TileMetadata metadata = null) { if (_tpriorityFunc != null) { return(_tpriorityFunc(_transitionPriority, metadata)); } return(_transitionPriority); }
/// <param name="metadata">Metadata for the tile being accessed.</param> /// <returns> /// If this tile is solid or not (if the player can walk through it). /// </returns> public virtual bool Solid(TileMetadata metadata = null) { if (_sFunc != null) { return(_sFunc(_solid, metadata)); } return(_solid); }
/// <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); }
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); }
/// <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); }
private void DoTextBox(TileMetadata metadata, WorldState world, Point mapPos) { string text = metadata != null && metadata.IsKeySet("value") ? metadata["value"] : "ERROR!!! VA FAN DET �R ERROR!!! F�R HELVETE ERROR!!!\n(du m�ste s�tta v�rdet av textboxen i map editorn)"; TextBox.Show(world, new TextBoxContent { Speaker = metadata != null && metadata.IsKeySet("speaker") ? metadata["speaker"] : "Unknown", Text = text }); }
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 void OnWalkEnter(TileMetadata metadata, WorldState world, Point mapPos) { if (metadata == null) { return; } if (metadata["needs-user-interaction"] == "False") { DoTeleport(metadata, world, mapPos); } }
/// <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]); }
public override void OnWalkEnter(TileMetadata metadata, WorldState world, Point mapPos) { _latestMap = world.Map; _walkedOn = mapPos; _walkedOnTick = world.Game.TotalFixedUpdates; // if this map is a combat area we should just encounter enemies on every single tile if (!world.Map.Info.CombatArea) { RandomEncounter.TryRandomEncounter(world); } }
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 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)); }
private static void ReadJSONComplexTileObject(JsonReader reader, Map map, Tile.MapLayer layer, int x, int y) { string id = ""; TileMetadata metadata = new TileMetadata(); while (reader.Read()) { if (reader.TokenType == JsonToken.PropertyName) { switch (reader.Value) { case "id": id = reader.ReadAsString(); break; case "metadata": while (reader.Read()) { if (reader.TokenType == JsonToken.PropertyName) { metadata[(string)reader.Value] = reader.ReadAsString(); } else if (reader.TokenType == JsonToken.EndObject) { break; } } break; } } else if (reader.TokenType == JsonToken.EndObject) { break; } } map[layer, x, y] = Tile.Find(id, layer); map.SetMetadata(layer, x, y, metadata); }
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 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]; _currentVariation = Variations[slot % Variations.Length]; if (_vFunc != null) { _currentVariation = _vFunc(_currentVariation, map, mapPos, slot); } base.Draw(game, mapPos, map, metadata, environment, color); }
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 string TextureName(TileMetadata metadata = null, Map.Environment environment = Map.Environment.Forest) { return(_currentVariation); }
public override void OnWalkLeave(TileMetadata metadata, WorldState world, Point mapPos) { }
public override void OnStandingOn(TileMetadata metadata, WorldState world, Point mapPos, long tickCount) { }