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 } }; }
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); }
public void Rotate() { if (IsLastRotationState()) { Rotation = ShapeRotation.Zero; } else { Rotation++; } RotateShape(); }
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()); }
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); }
protected RotatableShape(int xPosition, int yPosition, ShapeColor color, ShapeRotation rotation = ShapeRotation.Zero) : base(xPosition, yPosition, color) { Rotation = rotation; }