示例#1
0
        void BuildChunk()
        {
            cd = cRender.mm.map.chunks[position.x, position.y];
            int        hei = cRender.mm.chunkHeight;
            MapManager mm  = MapManager.instance;

            for (int i = 0; i < cRender.mm.chunkWidth; i++)
            {
                for (int j = 0; j < hei; j++)
                {
                    TileString tl = cd.GetTile(i, j, layer);
                    if (!ReferenceEquals(tl, null))
                    {
                        TileBase tb = mm.GetTileFromCollection(tl);
                        AddTile(i, j, tb);
                        if (tb.gameObject)
                        {
                            if (gameObjects[i, j] == null)
                            {
                                gameObjects[i, j] = GameObject.Instantiate(tb.gameObject, transform, false);
                                gameObjects[i, j].transform.localPosition = new Vector3(i, j) * scale;
                            }
                        }
                    }
                    else
                    {
                        if (gameObjects[i, j] != null)
                        {
                            Destroy(gameObjects[i, j]);
                        }
                    }
                }
            }
        }
示例#2
0
        private void SmoothMooreCellularAutomata(int index, MapManager gen)
        {
            TileString rID = null;

            for (int i = 0; i < cellPasses[index].smoothPasses; i++)
            {
                for (int x = 0; x < gen.mapWidth; x++)
                {
                    for (int y = cellPasses[index].cellMinHeight; y < cellPasses[index].cellMaxHeight; y++)
                    {
                        int surroundingTiles = GetMooreSurroundingTiles(x, y, gen, ref rID);

                        //The default moore rule requires more than 4 neighbours
                        if (surroundingTiles > 4)
                        {
                            gen.temporaryMap[MapLayers.FG][x, y] = rID;
                        }
                        else if (surroundingTiles < 4)
                        {
                            gen.temporaryMap[MapLayers.FG][x, y] = null;
                        }
                    }
                }
            }
        }
        // Update is called once per frame
        void Update()
        {
            if (Input.GetKeyDown(KeyCode.Alpha1))
            {
                ml = MapLayers.FG;
            }
            if (Input.GetKeyDown(KeyCode.Alpha2))
            {
                ml = MapLayers.BG;
            }
            if (Input.GetKeyDown(KeyCode.M))
            {
                minimap.SetActive(!minimap.activeSelf);
            }
            curspeed = Input.GetKey(KeyCode.LeftShift) ? fastSpeed : moveSpeed;
            Vector2 moveVec = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"));

            moveVelo = moveVec * curspeed;

            if (Input.GetKeyDown(KeyCode.Z))
            {
                Vector2Int po = MapManager.instance.WorldToBlock(cam.ScreenToWorldPoint(Input.mousePosition));
                TileString s  = MapManager.instance.GetTile(po.x, po.y, MapLayers.FG);
                blockName.text    = s != null ? $"{s.nspace}:{s.tile}" : "";
                blockBitmask.text = MapManager.instance.GetBitmask(po.x, po.y, MapLayers.FG).ToString();
            }


            Vector2    pos;
            Vector2Int blockPos;

            if (Input.GetMouseButton(0))
            {
                pos      = cam.ScreenToWorldPoint(Input.mousePosition);
                blockPos = mm.WorldToBlock(pos);
                for (int i = -destroyRadius; i < destroyRadius; i++)
                {
                    for (int j = -destroyRadius; j < destroyRadius; j++)
                    {
                        mm.SetTile(blockPos.x + i, blockPos.y + j, blockToPlace, ml);
                    }
                }
            }

            if (Input.GetMouseButton(1))
            {
                pos      = cam.ScreenToWorldPoint(Input.mousePosition);
                blockPos = mm.WorldToBlock(pos);
                for (int i = -destroyRadius; i < destroyRadius; i++)
                {
                    for (int j = -destroyRadius; j < destroyRadius; j++)
                    {
                        mm.SetTile(blockPos.x + i, blockPos.y + j, null, ml, true, true, true);
                    }
                }
            }
        }
示例#4
0
        private int GetMooreSurroundingTiles(int x, int y, MapManager gen, ref TileString rID)
        {
            int tileCount = 0;

            for (int neighbourX = x - 1; neighbourX <= x + 1; neighbourX++)
            {
                for (int neighbourY = y - 1; neighbourY <= y + 1; neighbourY++)
                {
                    if (neighbourX >= 0 && neighbourX < gen.mapWidth && neighbourY >= 0 && neighbourY < gen.mapHeight)
                    {
                        //We don't want to count the tile we are checking the surroundings of
                        if (neighbourX != x || neighbourY != y)
                        {
                            tileCount += gen.temporaryMap[MapLayers.FG][neighbourX, neighbourY] == null ? 0 : 1;
                            if (!ReferenceEquals(gen.temporaryMap[MapLayers.FG][neighbourX, neighbourY], null))
                            {
                                rID = gen.temporaryMap[MapLayers.FG][neighbourX, neighbourY];
                            }
                        }
                    }
                }
            }
            return(tileCount);
        }