Example #1
0
        private void Initialize(Map map, uint[] data, List <Material> materials)
        {
            Tiles         = new TileGrid(Width, Height);
            BaseMap       = map;
            BaseMaterials = materials;
            LayerTileSets = new List <TileSet>();
            // data is left-to-right, top-to-bottom
            for (int x = 0; x < Width; x++)
            {
                for (int y = 0; y < Height; y++)
                {
                    uint id = data[y * Width + x];

                    // compute the SpriteEffects to apply to this tile
                    SpriteEffects spriteEffects = new SpriteEffects();

                    // MARIO: new method to verify flipped tiles
                    spriteEffects.flippedHorizontally   = (id & FlippedHorizontallyFlag) == FlippedHorizontallyFlag;
                    spriteEffects.flippedVertically     = (id & FlippedVerticallyFlag) == FlippedVerticallyFlag;
                    spriteEffects.flippedAntiDiagonally = (id & FlippedAntiDiagonallyFlag) == FlippedAntiDiagonallyFlag;

                    // MARIO: new strip out the flip flags to get the real ID
                    // Fixed for AntiDiagonallyFlgs
                    id &= ~(FlippedHorizontallyFlag |
                            FlippedVerticallyFlag |
                            FlippedAntiDiagonallyFlag);

                    // get the tile
                    Tile t = null;
                    BaseMap.Tiles.TryGetValue((int)id, out t);

                    // if the tile is non-null...
                    if (t != null)
                    {
                        // if we want unique instances, clone it
                        if (MakeUniqueTiles)
                        {
                            t = t.Clone();
                            t.SpriteEffects = spriteEffects;
                        }

                        // otherwise we may need to clone if the tile doesn't have the correct effects
                        // in this world a flipped tile is different than a non-flipped one; just because
                        // they have the same source rect doesn't mean they're equal.
                        else if (t.SpriteEffects != spriteEffects)
                        {
                            t = t.Clone();
                            t.SpriteEffects = spriteEffects;
                        }

                        // Add this Tile's TileSet to LayerTileSets list, if it is not there yet
                        if (!LayerTileSets.Contains(t.TileSet))
                        {
                            LayerTileSets.Add(t.TileSet);
                        }
                    }

                    // put that tile in our grid
                    Tiles[x, y] = t;
                }
            }

            GenerateLayer();
        }
Example #2
0
        private void Initialize(Map map, uint[] data, bool makeUnique, List<Material> materials)
        {
            Tiles = new TileGrid(Width, Height);

            // data is left-to-right, top-to-bottom
            for (int x = 0; x < Width; x++)
            {
                for (int y = 0; y < Height; y++)
                {
                    uint index = data[y * Width + x];

                    // compute the SpriteEffects to apply to this tile
                    SpriteEffects spriteEffects = SpriteEffects.None;
                    if ((index & FlippedHorizontallyFlag) != 0)
                        spriteEffects |= SpriteEffects.FlipHorizontally;
                    if ((index & FlippedVerticallyFlag) != 0)
                        spriteEffects |= SpriteEffects.FlipVertically;

                    // strip out the flip flags to get the real ID
                    int id = (int)(index & ~(FlippedVerticallyFlag | FlippedHorizontallyFlag));
                    //Debug.Log("Tile ID: " + id + " (index : " + index + ")");
                    // get the tile
                    Tile t = null;
                    map.Tiles.TryGetValue(id, out t);

                    // if the tile is non-null...
                    if (t != null)
                    {
                        // if we want unique instances, clone it
                        if (makeUnique)
                        {
                            t = t.Clone();
                            t.SpriteEffects = spriteEffects;
                        }

                        // otherwise we may need to clone if the tile doesn't have the correct effects
                        // in this world a flipped tile is different than a non-flipped one; just because
                        // they have the same source rect doesn't mean they're equal.
                        else if (t.SpriteEffects != spriteEffects)
                        {
                            t = t.Clone();
                            t.SpriteEffects = spriteEffects;
                        }
                    }

                    // put that tile in our grid
                    Tiles[x, y] = t;
                }
            }

            GenerateLayer(map, materials);
        }
Example #3
0
        private void Initialize(Map map, uint[] data, List<Material> materials)
        {
            Tiles = new TileGrid(Width, Height);
            BaseMap = map;
            BaseMaterials = materials;
            LayerTileSets = new List<TileSet>();
            // data is left-to-right, top-to-bottom
            for (int x = 0; x < Width; x++)
            {
                for (int y = 0; y < Height; y++)
                {
                    uint id = data[y * Width + x];

                    // compute the SpriteEffects to apply to this tile
                    SpriteEffects spriteEffects = new SpriteEffects();

                    // MARIO: new method to verify flipped tiles
                    spriteEffects.flippedHorizontally = (id & FlippedHorizontallyFlag) == FlippedHorizontallyFlag;
                    spriteEffects.flippedVertically = (id & FlippedVerticallyFlag) == FlippedVerticallyFlag;
                    spriteEffects.flippedAntiDiagonally = (id & FlippedAntiDiagonallyFlag) == FlippedAntiDiagonallyFlag;

                    // MARIO: new strip out the flip flags to get the real ID
                    // Fixed for AntiDiagonallyFlgs
                    id &= ~(FlippedHorizontallyFlag |
                            FlippedVerticallyFlag |
                            FlippedAntiDiagonallyFlag);

                    // get the tile
                    Tile t = null;
                    BaseMap.Tiles.TryGetValue((int)id, out t);

                    // if the tile is non-null...
                    if (t != null)
                    {
                        // if we want unique instances, clone it
                        if (MakeUniqueTiles)
                        {
                            t = t.Clone();
                            t.SpriteEffects = spriteEffects;
                        }

                        // otherwise we may need to clone if the tile doesn't have the correct effects
                        // in this world a flipped tile is different than a non-flipped one; just because
                        // they have the same source rect doesn't mean they're equal.
                        else if (t.SpriteEffects != spriteEffects)
                        {
                            t = t.Clone();
                            t.SpriteEffects = spriteEffects;
                        }

                        // Add this Tile's TileSet to LayerTileSets list, if it is not there yet
                        if (!LayerTileSets.Contains(t.TileSet))
                            LayerTileSets.Add(t.TileSet);
                    }

                    // put that tile in our grid
                    Tiles[x, y] = t;
                }
            }

            GenerateLayer();
        }
Example #4
0
        private void Initialize(Map map, uint[] data, bool makeUnique, List <Material> materials)
        {
            Tiles = new TileGrid(Width, Height);

            // data is left-to-right, top-to-bottom
            for (int x = 0; x < Width; x++)
            {
                for (int y = 0; y < Height; y++)
                {
                    uint index = data[y * Width + x];

                    // compute the SpriteEffects to apply to this tile
                    SpriteEffects spriteEffects = SpriteEffects.None;
                    if ((index & FlippedHorizontallyFlag) != 0)
                    {
                        spriteEffects |= SpriteEffects.FlipHorizontally;
                    }
                    if ((index & FlippedVerticallyFlag) != 0)
                    {
                        spriteEffects |= SpriteEffects.FlipVertically;
                    }

                    // strip out the flip flags to get the real ID
                    int id = (int)(index & ~(FlippedVerticallyFlag | FlippedHorizontallyFlag));

                    //Debug.Log("Tile ID: " + id + " (index : " + index + ")");
                    // get the tile
                    Tile t = null;
                    map.Tiles.TryGetValue(id, out t);

                    // if the tile is non-null...
                    if (t != null)
                    {
                        // if we want unique instances, clone it
                        if (makeUnique)
                        {
                            t = t.Clone();
                            t.SpriteEffects = spriteEffects;
                        }

                        // otherwise we may need to clone if the tile doesn't have the correct effects
                        // in this world a flipped tile is different than a non-flipped one; just because
                        // they have the same source rect doesn't mean they're equal.
                        else if (t.SpriteEffects != spriteEffects)
                        {
                            t = t.Clone();
                            t.SpriteEffects = spriteEffects;
                        }
                    }

                    // put that tile in our grid
                    Tiles[x, y] = t;
                    // TODO: The location should be set in the constructor
                    // or just somewhere better IMO
                    t.x = x;
                    t.y = y;
                }
            }

            GenerateLayer(map, materials);
        }