Esempio n. 1
0
        public static void ResizeArray <T>(ref T[,] array, int width, int height, Direction8 dir, bool initialize) where T : new()
        {
            Direction4 vert  = Direction4.None;
            Direction4 horiz = Direction4.None;

            DecomposeDiagonal(dir, ref horiz, ref vert);

            Loc2D offset = new Loc2D();

            if (horiz == Direction4.None)
            {
                offset.X = (width - array.GetLength(0)) / 2;
            }
            else if (horiz == Direction4.Left)
            {
                offset.X = (width - array.GetLength(0));
            }

            if (vert == Direction4.None)
            {
                offset.Y = (height - array.GetLength(1)) / 2;
            }
            else if (vert == Direction4.Up)
            {
                offset.Y = (height - array.GetLength(1));
            }


            T[,] returnArray = new T[width, height];
            if (initialize)
            {
                for (int x = 0; x < width; x++)
                {
                    for (int y = 0; y < height; y++)
                    {
                        if (x >= offset.X && x < offset.X + array.GetLength(0) &&
                            y >= offset.Y && y < offset.Y + array.GetLength(1))
                        {
                            returnArray[x, y] = array[x - offset.X, y - offset.Y];
                        }
                        else
                        {
                            returnArray[x, y] = new T();
                        }
                    }
                }
            }
            else
            {
                for (int x = Math.Max(-offset.X, 0); x < array.GetLength(0) && x + offset.X < returnArray.GetLength(0); x++)
                {
                    for (int y = Math.Max(-offset.Y, 0); y < array.GetLength(1) && y + offset.Y < returnArray.GetLength(1); y++)
                    {
                        returnArray[x + offset.X, y + offset.Y] = array[x, y];
                    }
                }
            }

            array = returnArray;
        }
Esempio n. 2
0
        public float TryToMove(float distance, Direction4 direction, Vector2 deltaPosition = default)
        {
            float allowedMove   = GetAllowedMovement(distance, direction, deltaPosition);
            float effectiveMove = ForceMove(allowedMove, direction);

            return(effectiveMove);
        }
Esempio n. 3
0
        public static void Draw(Bounds bounds, Direction4 direction, float length = 1f)
        {
            if (direction.IsHorizontal())
            {
                Vector2 originTop = (Vector2)bounds.center + new Vector2(bounds.extents.x * direction.Sign(), bounds.extents.y);
                Debug.DrawLine(originTop, originTop + direction.ToVector2(length), Color.magenta);

                Vector2 originCenter = (Vector2)bounds.center + new Vector2(bounds.extents.x * direction.Sign(), 0);
                Debug.DrawLine(originCenter, originCenter + direction.ToVector2(length), Color.magenta);

                Vector2 originBottom = (Vector2)bounds.center + new Vector2(bounds.extents.x * direction.Sign(), -bounds.extents.y);
                Debug.DrawLine(originBottom, originBottom + direction.ToVector2(length), Color.magenta);
            }
            else
            {
                Vector2 originLeft = (Vector2)bounds.center + new Vector2(-bounds.extents.x, bounds.extents.y * direction.Sign());
                Debug.DrawLine(originLeft, originLeft + direction.ToVector2(length), Color.magenta);

                Vector2 originCenter = (Vector2)bounds.center + new Vector2(0, bounds.extents.y * direction.Sign());
                Debug.DrawLine(originCenter, originCenter + direction.ToVector2(length), Color.magenta);

                Vector2 originRight = (Vector2)bounds.center + new Vector2(bounds.extents.x, bounds.extents.y * direction.Sign());
                Debug.DrawLine(originRight, originRight + direction.ToVector2(length), Color.magenta);
            }
        }
Esempio n. 4
0
        public static int DistanceInFront(int x1, int y1, int x2, int y2, Direction4 dir)
        {
            switch (dir)
            {
            case Direction4.Down:
            {
                return(y2 - y1);
            }

            case Direction4.Left:
            {
                return(x1 - x2);
            }

            case Direction4.Up:
            {
                return(y1 - y2);
            }

            case Direction4.Right:
            {
                return(x2 - x1);
            }

            default: return(0);
            }
        }
Esempio n. 5
0
        public static Loc2D GetResizeOffset(int oldWidth, int oldHeight, int width, int height, Direction8 dir)
        {
            Direction4 vert  = Direction4.None;
            Direction4 horiz = Direction4.None;

            DecomposeDiagonal(dir, ref horiz, ref vert);

            Loc2D center = new Loc2D();

            if (horiz == Direction4.None)
            {
                center.X += (width - oldWidth) / 2;
            }
            else if (horiz == Direction4.Left)
            {
                center.X += (width - oldWidth);
            }

            if (vert == Direction4.None)
            {
                center.Y += (height - oldHeight) / 2;
            }
            else if (vert == Direction4.Up)
            {
                center.Y += (height - oldHeight);
            }

            return(center);
        }
Esempio n. 6
0
    public static Direction4 ToDirection4(Vector2 velocity)
    {
        Direction4 dir = Direction4.EAST;

        if (Mathf.Abs(velocity.x) >= Mathf.Abs(velocity.y))
        {
            if (velocity.x > 0)
            {
                dir = Direction4.EAST;
            }
            else
            {
                dir = Direction4.WEST;
            }
        }
        else
        {
            if (velocity.y > 0)
            {
                dir = Direction4.NORTH;
            }
            else
            {
                dir = Direction4.SOUTH;
            }
        }
        return(dir);
    }
Esempio n. 7
0
 public static Direction2V ToDirection2V(this Direction4 direction)
 {
     if (direction.IsHorizontal())
     {
         throw new Exception("Passed horizontal direction4 in place of vertical");
     }
     return(direction == Direction4.Up ? Direction2V.Up : Direction2V.Down);
 }
Esempio n. 8
0
 public static Direction2H ToDirection2H(this Direction4 direction)
 {
     if (direction.IsVertical())
     {
         throw new Exception("Passed vertical direction4 in place of horizontal");
     }
     return(direction == Direction4.Left ? Direction2H.Left : Direction2H.Right);
 }
Esempio n. 9
0
 public static Direction4 ReverseDir(Direction4 dir)
 {
     if ((int)dir <= (int)Direction4.None)
     {
         return(dir);
     }
     return((Direction4)(((int)dir + 2) % 4));
 }
Esempio n. 10
0
 public static Direction4 Rotate(this Direction4 dir, int quaterClockwise)
 {
     while (quaterClockwise < 0)
     {
         quaterClockwise += 4;
     }
     return((Direction4)(((int)dir + quaterClockwise) % 4));
 }
Esempio n. 11
0
 public CollisionMoveHit(Transform transform, Vector2 point, Vector2 normal, Direction4 rayDirection, float distanceToHit)
 {
     this.transform     = transform;
     this.point         = point;
     this.distanceToHit = distanceToHit;
     this.rayDirection  = rayDirection;
     this.normal        = normal;
     isTilemap          = transform.CompareTag("Tilemap");
 }
Esempio n. 12
0
    /// <summary>
    /// Rotates the direction a set amount of times
    /// </summary>
    /// <param name="dir4"></param>
    public static Direction4 Rotate(this Direction4 dir4, int times = 1)
    {
        if (times >= 0)
        {
            return((Direction4)(((int)dir4 + times * 2) % 8));
        }

        throw new ArgumentException("Argument must be greater than or equal to zero");
    }
Esempio n. 13
0
 private ColorPairPuyo CreateColorPuyo(PuyoType satellite, PuyoType pivot, Direction4 dir, int pos)
 {
     return(new ColorPairPuyo()
     {
         Pivot = pivot,
         Satellite = satellite,
         Dir = dir,
         Pos = pos,
     });
 }
Esempio n. 14
0
        private IEnumerable <CollisionMoveHit> GetCollisionMoveHitsBelow()
        {
            float      distance  = RaycastHelpers.skinWidth;
            Direction4 direction = Direction4.Down;

            (RaycastHit2D[] hits, int count) = movement.raycaster.GetHits(distance, direction);
            IEnumerable <CollisionMoveHit> collisionMoveHits = movement.collisionMoveHitsFactory.GetUniqueRaycasterHits(hits, count, direction);

            return(collisionMoveHits);
        }
Esempio n. 15
0
        private float NoDistanceForceMove(Direction4 direction)
        {
            float distance = RaycastHelpers.skinWidth;
            IEnumerable <CollisionMoveHit> raycasterHits = GetCollisionMoveHits(distance, direction);

            foreach (CollisionMoveHit raycasterHit in raycasterHits)
            {
                collisionMoveController.ForceMoveInto(raycasterHit, 0);
            }
            return(0);
        }
Esempio n. 16
0
 public CollisionMoveHit(RaycastHit2D hit, Direction4 rayDirection) :
     this(
         transform : hit.transform,
         point : hit.point,
         normal : hit.normal,
         rayDirection : rayDirection,
         distanceToHit : hit.distance
         //distanceToHit: Mathf.Max(hit.distance - RaycastHelpers.skinWidth, 0)
         )
 {
 }
Esempio n. 17
0
 public static void AssignDirDim(int x, int y, int p, Direction4 dir)
 {
     if (dir == Direction4.Down || dir == Direction4.Up)
     {
         y = p;
     }
     else
     {
         x = p;
     }
 }
		public BackgroundParticle(int ox, int oy, Fraction f, float px, float py, Direction4 dir)
		{
			OriginX = ox;
			OriginY = oy;

			X = px;
			Y = py;

			Fraction = f;
			RemainingPower = INITIAL_POWER;
			Direction = dir;
		}
Esempio n. 19
0
 public static Direction4 AddDir(Direction4 dir1, Direction4 dir2)
 {
     if ((int)dir1 <= (int)Direction4.None)
     {
         return(dir2);
     }
     if ((int)dir2 <= (int)Direction4.None)
     {
         return(dir1);
     }
     return((Direction4)(((int)dir1 + (int)dir2) % 4));
 }
        static public int X(this Direction4 direction4)
        {
            switch (direction4)
            {
            case Direction4.Left:
                return(-1);

            case Direction4.Right:
                return(1);
            }
            return(0);
        }
		public BackgroundParticle(BackgroundParticle source, float px, float py, Direction4 dir)
		{
			OriginX = source.OriginX;
			OriginY = source.OriginY;

			X = px;
			Y = py;

			Fraction = source.Fraction;
			RemainingPower = source.RemainingPower - 1;
			Direction = dir;
		}
        static public int Y(this Direction4 direction4)
        {
            switch (direction4)
            {
            case Direction4.Up:
                return(1);

            case Direction4.Down:
                return(-1);
            }
            return(0);
        }
Esempio n. 23
0
    public void Inject(SnailController controller)
    {
        rigidbody = controller.di.physics.movement.rigidbody;

        if (forward)
        {
            dir4 = initialSurfaceNormal.RotateClockwise();
        }
        else
        {
            dir4 = initialSurfaceNormal.RotateCounterClockwise();
        }
    }
Esempio n. 24
0
        void MakeWall(Mass m, Direction4 d)
        {
            int newI = m.I, newJ = m.J;
            switch (d)
            {
                case Direction4.Up: newI = m.I - 1; break;
                case Direction4.Right: newJ = m.J + 1; break;
                case Direction4.Down: newI = m.I + 1; break;
                case Direction4.Left: newJ = m.J - 1; break;
            }

            maze[newI, newJ].MassState = State.Wall;
        }
Esempio n. 25
0
        public static void FillArray(int arrayWidth, int arrayHeight, TileCheck checkOp, TileOperation fillOp, Loc2D loc)
        {
            var stack = new Stack <StackItem>();

            stack.Push(new StackItem(loc.X, loc.X, loc.Y, Direction4.None, true, true));
            fillOp(loc.X, loc.Y);

            while (stack.Count > 0)
            {
                var        item    = stack.Pop();
                int        minX    = item.MinX;
                int        maxX    = item.MaxX;
                int        y       = item.Y;
                Direction4 dir     = item.Direction;
                bool       goLeft  = item.GoLeft;
                bool       goRight = item.GoRight;

                int newMinX = minX;
                if (goLeft)
                {
                    while (newMinX - 1 >= 0 && checkOp(newMinX - 1, y))
                    {
                        newMinX--;
                        fillOp(newMinX, y);
                    }
                }

                int newMaxX = maxX;
                if (goRight)
                {
                    while (newMaxX + 1 < arrayWidth && checkOp(newMaxX + 1, y))
                    {
                        newMaxX++;
                        fillOp(newMaxX, y);
                    }
                }

                minX--;
                maxX++;

                if (y < arrayHeight - 1)
                {
                    AddNextScanLine(checkOp, fillOp, minX, maxX, newMinX, newMaxX, y + 1, dir != Direction4.Up, Direction4.Down, stack);
                }

                if (y > 0)
                {
                    AddNextScanLine(checkOp, fillOp, minX, maxX, newMinX, newMaxX, y - 1, dir != Direction4.Down, Direction4.Up, stack);
                }
            }
        }
Esempio n. 26
0
        public static void FillArray(int arrayWidth, int arrayHeight, TileCheck checkOp, TileOperation fillOp, Loc2D loc)
        {
            Stack <Tuple <int, int, int, Direction4, bool, bool> > stack = new Stack <Tuple <int, int, int, Direction4, bool, bool> >();

            stack.Push(new Tuple <int, int, int, Direction4, bool, bool>(loc.X, loc.X, loc.Y, Direction4.None, true, true));
            fillOp(loc.X, loc.Y);

            while (stack.Count > 0)
            {
                Tuple <int, int, int, Direction4, bool, bool> this_should_really_be_a_class = stack.Pop();
                Direction4 dir     = this_should_really_be_a_class.Item4;
                int        minX    = this_should_really_be_a_class.Item1;
                int        maxX    = this_should_really_be_a_class.Item2;
                int        y       = this_should_really_be_a_class.Item3;
                bool       goLeft  = this_should_really_be_a_class.Item5;
                bool       goRight = this_should_really_be_a_class.Item6;

                int newMinX = minX;
                if (goLeft)
                {
                    while (newMinX - 1 >= 0 && checkOp(newMinX - 1, y))
                    {
                        newMinX--;
                        fillOp(newMinX, y);
                    }
                }

                int newMaxX = maxX;
                if (goRight)
                {
                    while (newMaxX + 1 < arrayWidth && checkOp(newMaxX + 1, y))
                    {
                        newMaxX++;
                        fillOp(newMaxX, y);
                    }
                }

                minX--;
                maxX++;

                if (y < arrayHeight - 1)
                {
                    AddNextScanLine(checkOp, fillOp, minX, maxX, newMinX, newMaxX, y + 1, dir != Direction4.Up, Direction4.Down, stack);
                }

                if (y > 0)
                {
                    AddNextScanLine(checkOp, fillOp, minX, maxX, newMinX, newMaxX, y - 1, dir != Direction4.Down, Direction4.Up, stack);
                }
            }
        }
Esempio n. 27
0
        public void DrawStraightPassage(Loc2D loc1, Loc2D loc2)
        {
            Loc2D      diff   = loc2 - loc1;
            Direction4 dir    = (Math.Abs(diff.Y) > Math.Abs(diff.X)) ? Direction4.Down : Direction4.Right;
            Direction4 subDir = (dir == Direction4.Down) ? Direction4.Right : Direction4.Down;

            if (Operations.DimOfDir(diff.X, diff.Y, dir) < 0)
            {
                dir = Operations.ReverseDir(dir);
            }
            if (Operations.DimOfDir(diff.X, diff.Y, subDir) < 0)
            {
                subDir = Operations.ReverseDir(subDir);
            }
            Loc2D increment    = new Loc2D();
            Loc2D subIncrement = new Loc2D();

            Operations.MoveInDirection4(ref increment, dir, 1);
            Operations.MoveInDirection4(ref subIncrement, subDir, 1);

            int change    = Math.Abs(Operations.DimOfDir(diff.X, diff.Y, dir));
            int subChange = Math.Abs(Operations.DimOfDir(diff.X, diff.Y, subDir));

            int err = change / 2;


            Loc2D curLoc     = loc1;
            int   tileSize   = rand.Next(minPassageSize, maxPassageSize + 1);
            int   tileLimit  = rand.Next(minSizeChangePeriod, maxSizeChangePeriod + 1);
            int   tilesMoved = 0;

            while (Operations.DimOfDir(curLoc.X, curLoc.Y, dir) != Operations.DimOfDir(loc2.X, loc2.Y, dir))
            {
                DrawPath(curLoc, tileSize);
                curLoc += increment;
                err    -= subChange;
                if (err < 0)
                {
                    curLoc += subIncrement;
                    err    += change;
                }
                tilesMoved++;
                if (tilesMoved >= tileLimit)
                {
                    tileSize   = rand.Next(minPassageSize, maxPassageSize + 1);
                    tileLimit  = rand.Next(minSizeChangePeriod, maxSizeChangePeriod + 1);
                    tilesMoved = 0;
                }
            }
            DrawPath(loc2, tileSize);
        }
Esempio n. 28
0
    internal void Rotate90()
    {
        if (forward)
        {
            dir4 = dir4.RotateClockwise();
        }
        else
        {
            dir4 = dir4.RotateCounterClockwise();
        }

        transform.Rotate(new Vector3(0, 0, -90));
        Physics2D.SyncTransforms();
    }
Esempio n. 29
0
        public static Orientation4 GetOrientation4(Direction4 dir)
        {
            switch (dir)
            {
            case Direction4.Down:
            case Direction4.Up:
                return(Orientation4.Vert);

            case Direction4.Left:
            case Direction4.Right:
                return(Orientation4.Horiz);

            default:
                return(Orientation4.None);
            }
        }
Esempio n. 30
0
 public StackItem(
     int minX,
     int maxX,
     int y,
     Direction4 dir,
     bool goLeft,
     bool goRight
     )
 {
     MinX      = minX;
     MaxX      = maxX;
     Y         = y;
     Direction = dir;
     GoLeft    = goLeft;
     GoRight   = goRight;
 }
Esempio n. 31
0
        private float GetAllowedMovementAt_Obsolete(float distance, Direction4 direction, Vector2 deltaPosition = default)
        {
            if (!RaycastHelpers.IsValidDistance(distance))
            {
                return(0);
            }

            IEnumerable <CollisionMoveHit> raycasterHits = GetCollisionMoveHits(distance, direction, deltaPosition);
            float allowedDistance = distance;

            foreach (CollisionMoveHit raycasterHit in raycasterHits)
            {
                allowedDistance = collisionMoveController.GetAllowedMoveInto(raycasterHit, allowedDistance);
            }
            return(allowedDistance);
        }
Esempio n. 32
0
        Mass MakeNewRoad(Mass m, Direction4 d)
        {
            int i = m.I, j = m.J;
            int newI = i, newJ = j;
            switch (d)
            {
                case Direction4.Up: newI = i - 2; break;
                case Direction4.Right: newJ = j + 2; break;
                case Direction4.Down: newI = i + 2; break;
                case Direction4.Left: newJ = j - 2; break;
            }

            maze[newI, newJ].MassState = State.Empty;

            return maze[newI, newJ];
        }
Esempio n. 33
0
        public static float Sign(this Direction4 direction)
        {
            switch (direction)
            {
            case Direction4.Down:
            case Direction4.Left:
                return(-1f);

            case Direction4.Right:
            case Direction4.Up:
                return(1f);

            default:
                Debug.LogError($"Unhandled enum value: {direction}");
                return(0f);
            }
        }
        static public Vector2Int ToVector2Int(this Direction4 direction4)
        {
            switch (direction4)
            {
            case Direction4.Up:
                return(new Vector2Int(0, 1));

            case Direction4.Down:
                return(new Vector2Int(0, -1));

            case Direction4.Left:
                return(new Vector2Int(-1, 0));

            case Direction4.Right:
                return(new Vector2Int(1, 0));
            }
            return(new Vector2Int());
        }
Esempio n. 35
0
        int BreakWall(Mass m, Direction4 d, Dictionary<int, List<Mass>> clustering)
        {
            int i = m.I, j = m.J;
            int newI = i, newJ = j;
            Mass newMass = null;
            switch (d)
            {
                case Direction4.Up: newI = i - 1; newMass = maze[i - 2, j]; break;
                case Direction4.Right: newJ = j + 1; newMass = maze[i, j + 2]; break;
                case Direction4.Down: newI = i + 1; newMass = maze[i + 2, j]; break;
                case Direction4.Left: newJ = j - 1; newMass = maze[i, j - 2]; break;
            }

            int minLabel = Math.Min(m.Label, newMass.Label),
                maxLabel = Math.Max(m.Label, newMass.Label);

            maze[newI, newJ].MassState = State.Empty;

            if (clustering.ContainsKey(maxLabel))
                clustering[maxLabel].ForEach(c => c.Label = minLabel);

            return maxLabel;
        }
Esempio n. 36
0
 public static VehicleDirection12 ToVehicleDirection12(Direction4 direction)
 {
     switch (direction)
     {
         case Direction4.Up:
             return VehicleDirection12.VerticalUp;
         case Direction4.Down:
             return VehicleDirection12.VerticalDown;
         case Direction4.Left:
             return VehicleDirection12.HorizontalLeft;
         case Direction4.Right:
             return VehicleDirection12.HorizontalRight;
         default:
             throw new ArgumentOutOfRangeException("direction");
     }
 }
Esempio n. 37
0
 void InventorySelectionMove(Direction4 dir)
 {
     if (dir == Direction4.Left) { inventoryselectedx--; }
     if (dir == Direction4.Right) { inventoryselectedx++; }
     if (dir == Direction4.Up) { inventoryselectedy--; }
     if (dir == Direction4.Down) { inventoryselectedy++; }
     inventoryselectedx = MyMath.Clamp(inventoryselectedx, 0, inventorysize - 1);
     inventoryselectedy = MyMath.Clamp(inventoryselectedy, 0, inventorysize - 1);
 }
Esempio n. 38
0
        Mass MakeNewWall(Mass m, Direction4 direction)
        {
            int i = m.I, j = m.J;
            int newI = i, newJ = j;
            switch (direction)
            {
                case Direction4.Up: newI = i - 2; break;
                case Direction4.Right: newJ = j + 2; break;
                case Direction4.Down: newI = i + 2; break;
                case Direction4.Left: newJ = j - 2; break;
            }

            if (maze[newI, newJ].MassState != State.Wall)
                maze[newI, newJ].MassState = State.NewWall;

            return maze[newI, newJ];
        }