Ejemplo n.º 1
0
        public void Initialize(GroundLayer layer, int minimumLayerDepth, int width)
        {
            _layer = layer;
            BoxCollider2D collider = GetComponent <BoxCollider2D>();

            collider.size = new Vector2(width, layer.Depth);
            collider.transform.position = new Vector2(collider.size.x / 2f, -collider.size.y / 2f + minimumLayerDepth + 1);
        }
Ejemplo n.º 2
0
        private void GenerateLayer(TilemapData tilemapData, GroundLayer groundLayer, int leftBorder, int rightBorder, int minimumDepth, int maximumDepth)
        {
            List <float> resourceProbabilities = groundLayer.GetResourceProbabilitiesForGeneration();
            bool         tileSet;
            float        prob;


            for (int x = leftBorder; x < rightBorder; ++x)
            {
                for (int y = minimumDepth; y > maximumDepth; --y)
                {
                    tileSet = false;
                    prob    = Random.Range(0f, 1f);
                    for (int j = 0; j < groundLayer.Resources.Count; ++j)
                    {
                        if (prob <= resourceProbabilities[j])
                        {
                            tilemapData.SetTileId(x, y, groundLayer.Resources[j].Type.Id);
                            tileSet = true;
                            break;
                        }
                    }

                    if (!tileSet)
                    {
                        tilemapData.SetTileId(x, y, groundLayer.DefaultTile.Id);
                    }
                }
            }

            for (int y = minimumDepth; y > (maximumDepth + 1); --y)
            {
                for (int x = leftBorder; x < rightBorder; ++x)
                {
                    prob = Random.Range(0f, 1f);
                    if (prob <= groundLayer.ProbabilityOfEmptySpaces)
                    {
                        tilemapData.SetTileId(x, y, -1);
                    }
                }
            }
        }
Ejemplo n.º 3
0
 public void Initialize(GroundLayer layer)
 {
     _layer = layer;
 }