Exemplo n.º 1
0
        public void AddToPosition(Bubble bubble, Vector position)
        {
            if (grid[position.Y][position.X] != null)
            {
                OutputLog.AddError("[Grid] Target position is not empty. You cannot put anything on this position.");
                return;
            }

            grid[position.Y][position.X] = bubble;

            OutputLog.AddLog("[Grid] Bubble added to position => " + position);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Create rows as much as the given count.
        /// </summary>
        /// <param name="count"></param>
        /// <param name="fillChance">Fill chance should be between 0 and 100. 100 Means always create points inside row.</param>
        public void CreateRows(int count, int fillChance, bool isInstant)
        {
            int mapSizeX = map.Size.X;
            int mapSizeY = map.Size.Y;

            count = Math.Min(count, mapSizeY);

            Bubble[] f_bubbles   = new Bubble[mapSizeX];
            Vector[] f_positions = new Vector[mapSizeX];

            // update bubbles at index 1;
            for (int i = 0; i < count; i++)
            {
                Bubble[] bubbles = new Bubble[mapSizeX];

                for (int x = 0; x < mapSizeX; x++)
                {
                    var randomizer = Random.Range(0, 100);

                    if (randomizer <= fillChance)
                    {
                        bubbles[x] = CreateBubble(ref idCounter);
                        GameEvents.OnBubbleSpawned?.Invoke(bubbles[x], x, 0);
                    }
                }

                map.AddBubbles(bubbles);

                for (int y = 1; y < mapSizeY; y++)
                {
                    int f_count = map.GetBubblesAtRow(y, mapSizeX, ref f_bubbles, ref f_positions);
                    for (int f = 0; f < f_count; f++)
                    {
                        GameEvents.OnBubblePositionUpdate?.Invoke(f_bubbles[f].Id, f_positions[f].X, f_positions[f].Y, isInstant);
                    }
                }
            }
        }
Exemplo n.º 3
0
        public BubbleGrid(Vector GridSize)
        {
            Size = GridSize;

            seekDirections = new Vector[] {
                new Vector(-1, 1),
                new Vector(0, 1),
                new Vector(1, 1),
                new Vector(-1, 0),
                new Vector(1, 0),
                new Vector(-1, -1),
                new Vector(0, -1),
                new Vector(1, -1)
            };

            // define grid.
            grid = new Bubble[Size.Y][];
            for (int y = 0; y < Size.Y; y++)
            {
                grid[y] = new Bubble[Size.X];
            }
            //
        }
Exemplo n.º 4
0
        private Bubble CreateBubble(ref ushort counter)
        {
            var bubble = new Bubble(++counter);

            return(bubble);
        }