private BubbleObject AcquireBubbleFromPool()
    {
        int bubbleTypeInt = UnityEngine.Random.Range(0, BubbleManager.GeneratePattern.BubbleTypes.Count);

        BubbleObject.BubbleTypes bubbleType = BubbleManager.GeneratePattern.BubbleTypes[bubbleTypeInt];
        var b = BubblePool.Instance.AcquireBubble(bubbleType);

        b.BubbleState = BubbleObject.BubbleStates.State_ReadyForFire;
        return(b);
    }
Example #2
0
    public void GenerateMap()
    {
        for (int r = -1; r < GenerateSize.y; r++)
        {
            int offset = -Mathf.FloorToInt(((float)r) / 2f);
            int gridSizeX = (int)(r % 2 == 0 ? GenerateSize.x : GenerateSize.x - 1);

            for (int q = 0; q < gridSizeX; q++)
            {
                //int bubbleTypeInt = PerlinNoise(q, r, 0,1f, _generatePattern.BubbleTypes.Count, 1);
                int emptyFact = PerlinNoise(q - r, r, q, 0.1f, 100, 1);
                Vector2Int hex = new Vector2Int(q + offset, r);
                if (r < 0)//top compressor
                {
                    var bubble = BubblePool.Instance.AcquireBubble(BubbleObject.BubbleTypes.Bubble_Block);
                    bubble.SetPositionInGrid(hex);
                    bubble.BubbleState = BubbleObject.BubbleStates.State_InMap;

                    Color color = Color.white;
                    color.a = 0;
                    bubble.GetComponent<SpriteRenderer>().color = color;
                    _topBubbleWall.Add(bubble);
                }
                else
                {
                    if (emptyFact >= 60)
                    {
                        var p = Hex2Array(hex);
                        _bubbleMap[p.x, p.y] = null;
                    }
                    else
                    {
                        int bubbleTypeInt = UnityEngine.Random.Range(0, _generatePattern.BubbleTypes.Count);
                        BubbleObject.BubbleTypes bubbleType = _generatePattern.BubbleTypes[bubbleTypeInt];
                        var bubble = BubblePool.Instance.AcquireBubble(bubbleType);
                        if (bubble != null)
                        {
                            AddBubble(bubble, hex);
                        }
                    }
                }

            }
        }

        if (MapGenerated != null)
            MapGenerated(this, null);
    }
Example #3
0
 public BubbleObject AcquireBubble(BubbleObject.BubbleTypes bubbleType)
 {
     if (poolSize > 0)
     {
         var bubble = bubblePool[poolSize - 1];
         bubblePool.Remove(bubble);
         poolSize--;
         bubble.gameObject.SetActive(true);
         bubble.GetComponent <SpriteRenderer>().color = Color.white;
         bubble.BubbleType = bubbleType;
         return(bubble);
     }
     else
     {
         return(null);
     }
 }