コード例 #1
0
        protected sealed override GameObject[,] CreatePixels(PixelDescription[,] pixelsDescription)
        {
            var pixels = new GameObject[(int)PixelsCount.X, (int)PixelsCount.Y];

            for (int x = 0; x < PixelsCount.X; x++)
            {
                for (int y = 0; y < PixelsCount.Y; y++)
                {
                    var pixelDescribtion = pixelsDescription[x, y];

                    if (pixelDescribtion == null)
                    {
                        continue;
                    }

                    var            pixelIndex = new Vector2(x, y);
                    CollisionPixel pixel;
                    pixels[x, y] = pixel = new CollisionPixel(Level, _world,
                                                              PixelMath.PixelToGamePosition(pixelIndex, PixelsCount), PixelOptions.PixelSize);
                    PixelCreated(pixel);
                    // Change pixels color according to description.
                    pixel.ColorChanger.ResetColor(pixelDescribtion.Color);

                    ConnectNeighbours(pixels, pixel, x, y);
                    SetNeighbourBorders(pixel, x, y);
                }
            }

            return(pixels);
        }
コード例 #2
0
        private void ConnectPixels(CollisionPixel pixelA, CollisionPixel pixelB)
        {
            if (pixelA == null || pixelB == null)
            {
                return;
            }

            pixelA.AddNeighbour(pixelB);
            pixelB.AddNeighbour(pixelA);
        }
コード例 #3
0
        public void AddNeighbour(CollisionPixel collisionPixel)
        {
            _neighboursCount++;
            collisionPixel.OnKilled  += CollisionPixel_OnKilled;
            collisionPixel.OnRevived += CollisionPixel_OnRevived;

            if (!ShouldBeEnabled())
            {
                DisableBody();
            }
        }
コード例 #4
0
        private void ConnectNeighbours(GameObject[,] pixels, CollisionPixel pixel, int indexX, int indexY)
        {
            // Left pixel
            if (indexX > 0)
            {
                ConnectPixels(pixel, (CollisionPixel)pixels[indexX - 1, indexY]);
            }

            // Top pixel
            if (indexY > 0)
            {
                ConnectPixels(pixel, (CollisionPixel)pixels[indexX, indexY - 1]);
            }

            // No more are needed because the pixels are being created from left top corner.
        }
コード例 #5
0
        /// <summary>
        /// Checks if the pixel is at the game border and if so then tells it to the pixel.
        /// </summary>
        /// <param name="pixel">The specific pixel which is being checked.</param>
        /// <param name="indexX">X index in the pixel array</param>
        /// <param name="indexY">Y index in the pixel array</param>
        private void SetNeighbourBorders(CollisionPixel pixel, int indexX, int indexY)
        {
            if (indexX == 0)
            {
                pixel.AddNeighbourBorder();
            }

            if (indexX == PixelsCount.X - 1)
            {
                pixel.AddNeighbourBorder();
            }

            if (indexY == 0)
            {
                pixel.AddNeighbourBorder();
            }

            if (indexY == PixelsCount.Y - 1)
            {
                pixel.AddNeighbourBorder();
            }
        }
コード例 #6
0
 protected virtual void PixelCreated(CollisionPixel pixel)
 {
 }