Exemple #1
0
        /// <summary>
        /// Updates nearby pixels so they are no longer inactive
        /// </summary>
        /// <param name="body"></param>
        public void UpdateNearbyPixels(PixelBody2D body)
        {
            //  if (inactivePixels.Contains(body)) return;
            //Get Surrounding Positions
            Vector2Int        position             = body.GetPosition();
            List <Vector2Int> surroundingPositions = new List <Vector2Int>();

            surroundingPositions.Add(new Vector2Int(position.x, position.y + 1)); //Up
            surroundingPositions.Add(new Vector2Int(position.x, position.y - 1)); //Down
            surroundingPositions.Add(new Vector2Int(position.x - 1, position.y)); //Left
            surroundingPositions.Add(new Vector2Int(position.x + 1, position.y)); //Right

            /* surroundingPositions.Add(new Vector2Int(position.x - 1, position.y + 1)); //Up Left
             * surroundingPositions.Add(new Vector2Int(position.x - 1, position.y - 1)); //Down Left
             * surroundingPositions.Add(new Vector2Int(position.x + 1, position.y + 1)); //Up Right
             * surroundingPositions.Add(new Vector2Int(position.x + 1, position.y - 1)); //Down Right */

            //For each surrounding position, if we have that key, make sure that that key is active.
            //This might cause problems
            foreach (var pos in surroundingPositions)
            {
                if (pixels.ContainsKey(pos) && inactivePixels.Contains(pixels[pos]))
                {
                    AddActivePixel(pixels[pos]);
                    UpdateNearbyPixels(pixels[pos]);
                }
            }
        }
Exemple #2
0
 /// <summary>
 /// Destroys a pixel
 /// </summary>
 /// <param name="position"></param>
 public void DestroyPixel(Vector2Int position)
 {
     if (pixels.ContainsKey(position))
     {
         PixelBody2D body = pixels[position];
         pixels.Remove(position);
         activePixels.Remove(body);
         inactivePixels.Remove(body);
         body.Destroy();
     }
 }
Exemple #3
0
 /// <summary>
 /// Sets the state of a particular position
 /// </summary>
 /// <param name="position"></param>
 /// <param name="body"></param>
 public void SetPixel(Vector2Int position, PixelBody2D body)
 {
     if (pixels.ContainsKey(position))
     {
         pixels[position] = body;
     }
     else
     {
         pixels.Add(position, body);
     }
 }
Exemple #4
0
 /// <summary>
 /// Removes an active pixel.
 /// </summary>
 /// <param name="body"></param>
 public void RemoveActivePixel(PixelBody2D body)
 {
     body.transform.SetParent(inactivePixelsParent.transform);
     if (activePixels.Contains(body))
     {
         activePixels.Remove(body);
     }
     if (!inactivePixels.Contains(body))
     {
         inactivePixels.Add(body);
     }
 }