public static ColliderList GenerateSemiEfficientColliderGrid(VirtualMap <char> tileMap, int cellWidth, int cellHeight)
        {
            ColliderList colliders = new ColliderList();

            for (int x = 0; x < tileMap.Columns; x++)
            {
                for (int y = 0; y < tileMap.Rows; y++)
                {
                    if (tileMap.AnyInSegmentAtTile(x, y) && tileMap[x, y] != '0')
                    {
                        int    width  = 1;
                        int    height = 1;
                        Hitbox h      = new Hitbox(cellWidth, cellHeight, x, y);
                        while (tileMap.AnyInSegmentAtTile(x, y) && tileMap[x, y] != '0')
                        {
                            width++;
                            height++;
                            x++;
                            y++;
                        }
                        h.Width  *= width;
                        h.Height *= height;
                        colliders.Add(h);
                    }
                }
            }
            return(colliders.colliders.Length > 0 ? colliders : null);
        }
        public FancySolidTiles(EntityData data, Vector2 offset, EntityID id)
            : base(data.Position + offset, GenerateTileMap(data.Attr("tileData", "")))
        {
            blendEdges = data.Bool("blendEdges");

            seed = data.Int("randomSeed");

            if (data.Bool("loadGlobally"))
            {
                loadGlobally = true;
            }
            else
            {
                RemoveTag(Tags.Global);
            }
            this.id = id;

            Remove(Tiles);
            Remove(AnimatedTiles);

            VirtualMap <char> tileMap = f_SolidTiles_tileTypes[this];

            for (int x = 0; x < tileMap.Columns; x++)
            {
                for (int y = 0; y < tileMap.Rows; y++)
                {
                    if (tileMap.AnyInSegmentAtTile(x, y) && tileMap[x, y] != '0')
                    {
                        Add(new LightOcclude(new Rectangle(x * 8, y * 8, 8, 8)));
                    }
                }
            }
        }
        public static ColliderList GenerateBetterColliderGrid(VirtualMap <char> tileMap, int cellWidth, int cellHeight)
        {
            ColliderList  colliders        = new ColliderList();
            List <Hitbox> prevCollidersOnX = new List <Hitbox>();
            Hitbox        prevCollider     = null;

            void ExtendOrAdd()
            {
                bool extendedOnX = false;

                foreach (Hitbox hitbox in prevCollidersOnX)
                {
                    if (hitbox.Position.X + hitbox.Width == prevCollider.Position.X &&
                        hitbox.Position.Y == prevCollider.Position.Y &&
                        hitbox.Height == prevCollider.Height)
                    {
                        // Weird check, but hey.
                        extendedOnX   = true;
                        hitbox.Width += cellWidth;
                        prevCollider  = null;
                        break;
                    }
                }
                if (!extendedOnX)
                {
                    colliders.Add(prevCollider);
                    prevCollidersOnX.Add(prevCollider);
                    prevCollider = null;
                }
            }

            for (int x = 0; x < tileMap.Columns; x++)
            {
                for (int y = 0; y < tileMap.Rows; y++)
                {
                    if (tileMap.AnyInSegmentAtTile(x, y) && tileMap[x, y] != '0')
                    {
                        if (prevCollider == null)
                        {
                            prevCollider = new Hitbox(cellWidth, cellHeight, x * cellWidth, y * cellHeight);
                        }
                        else
                        {
                            prevCollider.Height += cellHeight;
                        }
                    }
                    else if (prevCollider != null)
                    {
                        ExtendOrAdd();
                    }
                }

                if (prevCollider != null)
                {
                    ExtendOrAdd();
                }
            }
            return(colliders.colliders.Length > 0 ? colliders : null);
        }
示例#4
0
        void Start()
        {
            Debug.Log("==读取GamePlay的Texture");
            Gfx.Game        = Atlas.FromAtlas(Path.Combine("Graphics", "Atlases", "Gameplay"), Atlas.AtlasDataFormat.Packer);
            foregroundTiles = new Tiles(Path.Combine(Util.GAME_PATH_CONTENT, Path.Combine("Graphics", "ForegroundTiles.xml")));
            backgroundTiles = new Tiles(Path.Combine(Util.GAME_PATH_CONTENT, Path.Combine("Graphics", "BackgroundTiles.xml")));
            AreaData.Load();
            Stage stage = new Stage(0, AreaMode.Normal);

            stage.Load();

            //生成地图数据
            Autotiler.Behaviour fgBehaviour = new Autotiler.Behaviour()
            {
                EdgesExtend             = true,
                EdgesIgnoreOutOfLevel   = false,
                PaddingIgnoreOutOfLevel = true
            };
            Autotiler.Behaviour bgBehaviour = new Autotiler.Behaviour()
            {
                EdgesExtend             = true,
                EdgesIgnoreOutOfLevel   = false,
                PaddingIgnoreOutOfLevel = false
            };
            VirtualMap <char> foregroundData = stage.ForegroundData;

            this.colliderGrid = new ColliderGrid(foregroundData.Columns, foregroundData.Rows, 8f, 8f);
            for (int x = 0; x < foregroundData.Columns; x += 50)
            {
                for (int y = 0; y < foregroundData.Rows; y += 50)
                {
                    if (foregroundData.AnyInSegmentAtTile(x, y))
                    {
                        int index1 = x;
                        for (int index2 = Math.Min(index1 + 50, foregroundData.Columns); index1 < index2; ++index1)
                        {
                            int index3 = y;
                            for (int index4 = Math.Min(index3 + 50, foregroundData.Rows); index3 < index4; ++index3)
                            {
                                if (foregroundData[index1, index3] != '0')
                                {
                                    this.colliderGrid[index1, index3] = true;
                                }
                                else
                                {
                                    this.colliderGrid[index1, index3] = false;
                                }
                            }
                        }
                    }
                }
            }
            //VirtualMap<char> backgroundData = stage.BackgroundData;
            foregroundTiles.GenerateTiles(this.fgTilemap, foregroundData, 0, 0, foregroundData.Columns, foregroundData.Rows, false, '0', fgBehaviour, colliderGrid);
            //bgTileDictionary.GenerateTiles(this.bgTilemap, backgroundData, 0, 0, backgroundData.Columns, backgroundData.Rows, false, '0', bgBehaviour);
        }
        private static Autotiler.Generated Generate(this Autotiler tiler, VirtualMap <char> mapData, int startX, int startY, VirtualMap <char> forceData, Autotiler.Behaviour behaviour)
        {
            usingCustomAutotiler       = true;
            forceData_CustomAutotiler  = forceData;
            startPoint_CustomAutotiler = new Point(startX, startY);

            TileGrid      tileGrid      = new TileGrid(8, 8, forceData.Columns, forceData.Rows);
            AnimatedTiles animatedTiles = new AnimatedTiles(forceData.Columns, forceData.Rows, GFX.AnimatedTilesBank);
            Rectangle     empty         = new Rectangle(startX, startY, forceData.Columns, forceData.Rows);

            for (int i = startX; i < startX + forceData.Columns; i += 50)
            {
                for (int j = startY; j < startY + forceData.Rows; j += 50)
                {
                    if (!mapData.AnyInSegmentAtTile(i, j))
                    {
                        j = j / 50 * 50;
                    }
                    else
                    {
                        int k   = i;
                        int num = Math.Min(i + 50, startX + forceData.Columns);
                        while (k < num)
                        {
                            int l    = j;
                            int num2 = Math.Min(j + 50, startY + forceData.Rows);
                            while (l < num2)
                            {
                                object tiles = m_TileHandler.Invoke(tiler, new object[] { mapData, k, l, empty, forceData[k - startX, l - startY], behaviour });
                                if (tiles != null)
                                {
                                    (Calc.Random as PositionRandom)?.SetPosition(k - startX, l - startY); // Positional Randomization for TileSeedController
                                    tileGrid.Tiles[k - startX, l - startY] = Calc.Random.Choose(f_Tiles_Textures.GetValue(tiles));
                                    if (f_Tiles_HasOverlays.GetValue(tiles))
                                    {
                                        animatedTiles.Set(k - startX, l - startY, Calc.Random.Choose(f_Tiles_OverlapSprites.GetValue(tiles)), 1f, 1f);
                                    }
                                }
                                l++;
                            }
                            k++;
                        }
                    }
                }
            }
            usingCustomAutotiler = false;
            return(new Autotiler.Generated {
                TileGrid = tileGrid,
                SpriteOverlay = animatedTiles
            });
        }
        public static ColliderList GenerateInefficientColliderGrid(VirtualMap <char> tileMap, int cellWidth, int cellHeight)
        {
            ColliderList colliders = new ColliderList();

            for (int x = 0; x < tileMap.Columns; x++)
            {
                for (int y = 0; y < tileMap.Rows; y++)
                {
                    if (tileMap.AnyInSegmentAtTile(x, y) && tileMap[x, y] != '0')
                    {
                        colliders.Add(new Hitbox(cellWidth, cellHeight, x * cellWidth, y * cellHeight));
                    }
                }
            }
            return(colliders.colliders.Length > 0 ? colliders : null);
        }
示例#7
0
        public new Generated GenerateOverlay(char id, int x, int y, int tilesX, int tilesY, VirtualMap <char> mapData)
        {
            // be sure our overlay doesn't cross null segments, because they might just not get rendered there.
            for (int i = x; i < x + tilesX; i = (i / 50 + 1) * 50)
            {
                for (int j = y; j < y + tilesY; j = (j / 50 + 1) * 50)
                {
                    if (!mapData.AnyInSegmentAtTile(i, j))
                    {
                        mapData[i, j] = mapData.EmptyValue;
                    }
                }
            }

            return(orig_GenerateOverlay(id, x, y, tilesX, tilesY, mapData));
        }
示例#8
0
        public override void Awake(Scene scene)
        {
            base_Awake(scene);

            TileGrid tileGrid;

            if (!f_DashBlock_blendIn[this])
            {
                tileGrid = GFX.FGAutotiler.GenerateMap(tileMap, default(Autotiler.Behaviour)).TileGrid;
                for (int x = 0; x < tileMap.Columns; x++)
                {
                    for (int y = 0; y < tileMap.Rows; y++)
                    {
                        if (tileMap.AnyInSegmentAtTile(x, y) && tileMap[x, y] != '0')
                        {
                            Add(new LightOcclude(new Rectangle(x * 8, y * 8, 8, 8)));
                        }
                    }
                }
            }
            else
            {
                Level             level      = SceneAs <Level>();
                Rectangle         tileBounds = level.Session.MapData.TileBounds;
                VirtualMap <char> solidsData = level.SolidsData;
                int x = (int)(X / 8f) - tileBounds.Left;
                int y = (int)(Y / 8f) - tileBounds.Top;
                tileGrid = GFX.FGAutotiler.GenerateOverlay(tileMap, x, y, solidsData).TileGrid;
                Add(new EffectCutout());
                Depth = -10501;
            }
            Add(tileGrid);
            Add(new TileInterceptor(tileGrid, true));
            if (CollideCheck <Player>())
            {
                RemoveSelf();
            }
        }
示例#9
0
        public void GenerateTiles(Tilemap tilemap, VirtualMap <char> foregroundData, int startX, int startY, int tilesX, int tilesY, bool forceSolid, char forceID, Autotiler.Behaviour behaviour, ColliderGrid colliderGrid)
        {
            Rectangle forceFill = Rectangle.Empty;

            if (forceSolid)
            {
                forceFill = new Rectangle(startX, startY, tilesX, tilesY);
            }
            if (foregroundData != null)
            {
                for (int x1 = startX; x1 < startX + tilesX; x1 += 50)
                {
                    for (int y1 = startY; y1 < startY + tilesY; y1 += 50)
                    {
                        if (!foregroundData.AnyInSegmentAtTile(x1, y1))
                        {
                            y1 = y1 / 50 * 50;
                        }
                        else
                        {
                            int x2 = x1;
                            for (int index1 = Math.Min(x1 + 50, startX + tilesX); x2 < index1; ++x2)
                            {
                                int y2 = y1;
                                for (int index2 = Math.Min(y1 + 50, startY + tilesY); y2 < index2; ++y2)
                                {
                                    Autotiler.Tiles tiles = this.TileHandler(foregroundData, x2, y2, forceFill, forceID, behaviour);
                                    if (tiles != null)
                                    {
                                        SolidTile tile = ScriptableObject.CreateInstance <SolidTile>();
                                        tile.SetTile(tiles);
                                        tile.colliderType = colliderGrid[x2 - startX, y2 - startY]? Tile.ColliderType.Grid:Tile.ColliderType.None;
                                        tilemap.SetTile(new Vector3Int(x2 - startX, -(y2 - startY), 0), tile);
                                        //this.tilemap.SetTile(new Vector3Int(0, 0, 0), tile);
                                        //return;
                                    }
                                    //if (tiles != null)
                                    //{
                                    //    tileGrid.Tiles[x2 - startX, y2 - startY] = RandomUtil.Random.Choose<MTexture>(tiles.Textures);
                                    //    //if (tiles.HasOverlays)
                                    //    //    animatedTiles.Set(x2 - startX, y2 - startY, RandomUtil.Random.Choose<string>(tiles.OverlapSprites), 1f, 1f);
                                    //}
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                for (int x = startX; x < startX + tilesX; ++x)
                {
                    for (int y = startY; y < startY + tilesY; ++y)
                    {
                        Autotiler.Tiles tiles = this.TileHandler((VirtualMap <char>)null, x, y, forceFill, forceID, behaviour);
                        if (tiles != null)
                        {
                            SolidTile tile = ScriptableObject.CreateInstance <SolidTile>();
                            tile.SetTile(tiles);
                            tile.colliderType = colliderGrid[x - startX, y - startY] ? Tile.ColliderType.Grid : Tile.ColliderType.None;
                            tilemap.SetTile(new Vector3Int(x - startX, -(y - startY), 0), tile);
                            //this.tilemap.SetTile(new Vector3Int(0, 0, 0), tile);
                            //return;
                        }
                        //if (tiles != null)
                        //{
                        //    tileGrid.Tiles[x - startX, y - startY] = RandomUtil.Random.Choose<MTexture>(tiles.Textures);
                        //    if (tiles.HasOverlays)
                        //        animatedTiles.Set(x - startX, y - startY, RandomUtil.Random.Choose<string>(tiles.OverlapSprites), 1f, 1f);
                        //}
                    }
                }
            }
        }
示例#10
0
    private Autotiler.Generated Generate(
        VirtualMap <char> mapData,
        int startX,
        int startY,
        int tilesX,
        int tilesY,
        bool forceSolid,
        char forceID,
        Autotiler.Behaviour behaviour)
    {
        TileGrid      tileGrid      = new TileGrid(8, 8, tilesX, tilesY);
        AnimatedTiles animatedTiles = new AnimatedTiles(tilesX, tilesY, Gfx.AnimatedTilesBank);
        Rectangle     forceFill     = Rectangle.Empty;

        if (forceSolid)
        {
            forceFill = new Rectangle(startX, startY, tilesX, tilesY);
        }
        if (mapData != null)
        {
            for (int x1 = startX; x1 < startX + tilesX; x1 += 50)
            {
                for (int y1 = startY; y1 < startY + tilesY; y1 += 50)
                {
                    if (!mapData.AnyInSegmentAtTile(x1, y1))
                    {
                        y1 = y1 / 50 * 50;
                    }
                    else
                    {
                        int x2 = x1;
                        for (int index1 = Math.Min(x1 + 50, startX + tilesX); x2 < index1; ++x2)
                        {
                            int y2 = y1;
                            for (int index2 = Math.Min(y1 + 50, startY + tilesY); y2 < index2; ++y2)
                            {
                                Autotiler.Tiles tiles = this.TileHandler(mapData, x2, y2, forceFill, forceID, behaviour);
                                if (tiles != null)
                                {
                                    tileGrid.Tiles[x2 - startX, y2 - startY] = RandomUtil.Random.Choose <MTexture>(tiles.Textures);
                                    if (tiles.HasOverlays)
                                    {
                                        animatedTiles.Set(x2 - startX, y2 - startY, RandomUtil.Random.Choose <string>(tiles.OverlapSprites), 1f, 1f);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        else
        {
            for (int x = startX; x < startX + tilesX; ++x)
            {
                for (int y = startY; y < startY + tilesY; ++y)
                {
                    Autotiler.Tiles tiles = this.TileHandler((VirtualMap <char>)null, x, y, forceFill, forceID, behaviour);
                    if (tiles != null)
                    {
                        tileGrid.Tiles[x - startX, y - startY] = RandomUtil.Random.Choose <MTexture>(tiles.Textures);
                        if (tiles.HasOverlays)
                        {
                            animatedTiles.Set(x - startX, y - startY, RandomUtil.Random.Choose <string>(tiles.OverlapSprites), 1f, 1f);
                        }
                    }
                }
            }
        }
        return(new Autotiler.Generated()
        {
            TileGrid = tileGrid,
            SpriteOverlay = animatedTiles
        });
    }