Пример #1
0
        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);
        }
Пример #2
0
        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);
        }
Пример #3
0
        /// <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);
        }
Пример #4
0
        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);
        }
Пример #5
0
        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);
            }
        }
Пример #6
0
        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);
        }
Пример #7
0
        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);
            }
        }
Пример #8
0
        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);
        }
Пример #9
0
        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);
        }