예제 #1
0
 public ShapeJ(int xPosition, int yPosition, ShapeRotation rotation = ShapeRotation.Zero) : base(xPosition, yPosition, _color, rotation)
 {
     _shape = new[, ]
     {
         { true, false, false },
         { true, true, true },
         { false, false, false }
     };
 }
예제 #2
0
        public bool[,] GetShapeRotated(ShapeRotation rotation)
        {
            var rotatedWidth  = Height;
            var rotatedHeight = Width;

            bool[,] result;

            switch (rotation)
            {
            case ShapeRotation.Zero:
                return((bool[, ])Shape.Clone());

            case ShapeRotation.OneEighty:
                result = new bool[Height, Width];
                for (var y = 0; y < Height; y++)
                {
                    for (var x = 0; x < Width; x++)
                    {
                        var resultX = Width - x - 1;
                        var resultY = Height - y - 1;
                        result[resultY, resultX] = Shape[y, x];
                    }
                }
                return(result);

            case ShapeRotation.TwoSeventy:
                result = new bool[rotatedHeight, rotatedWidth];
                for (var y = 0; y < Height; y++)
                {
                    for (var x = 0; x < Width; x++)
                    {
                        var resultX = y;
                        var resultY = Width - x - 1;
                        result[resultY, resultX] = Shape[y, x];
                    }
                }
                return(result);

            case ShapeRotation.Ninety:
                result = new bool[rotatedHeight, rotatedWidth];
                for (var y = 0; y < Height; y++)
                {
                    for (var x = 0; x < Width; x++)
                    {
                        var resultX = Height - y - 1;
                        var resultY = x;
                        result[resultY, resultX] = Shape[y, x];
                    }
                }
                return(result);
            }
            // unreachable
            return(null);
        }
예제 #3
0
        public void Rotate()
        {
            if (IsLastRotationState())
            {
                Rotation = ShapeRotation.Zero;
            }
            else
            {
                Rotation++;
            }

            RotateShape();
        }
예제 #4
0
        public Vector2 GetPivotRotated(ShapeRotation rotation)
        {
            switch (rotation)
            {
            case ShapeRotation.Zero:
            case ShapeRotation.OneEighty:
                return(new Vector2(PivotX, PivotY));

            case ShapeRotation.Ninety:
            case ShapeRotation.TwoSeventy:
                var rotatedPivotX = (Height - 1) / 2;
                var rotatedPivotY = (Width - 1) / 2;
                return(new Vector2(rotatedPivotX, rotatedPivotY));
            }
            // unreachable
            return(new Vector2());
        }
예제 #5
0
        private MoveCollisionResponse TryUpdate(Stage stage, Vector2 moveDirection, ShapeRotation newRotation)
        {
            ApplyStage(stage, BlockColor.None, Position);

            var oldRotation = Rotation;

            Rotation = newRotation;

            var collisionResponse = CanMove(stage, moveDirection);

            if (collisionResponse == MoveCollisionResponse.None)
            {
                Position += moveDirection;
            }
            else
            {
                Rotation = oldRotation;
            }

            ApplyStage(stage, Shape.Color, Position);

            return(collisionResponse);
        }
예제 #6
0
 protected RotatableShape(int xPosition, int yPosition, ShapeColor color, ShapeRotation rotation = ShapeRotation.Zero) : base(xPosition, yPosition, color)
 {
     Rotation = rotation;
 }