diff --git a/Pieces.cpp b/Pieces.cpp index 606c5bd..e9ea342 100644 --- a/Pieces.cpp +++ b/Pieces.cpp @@ -3,34 +3,127 @@ #include #include // exit() -unsigned PieceHeight(const Piece &piece) +unsigned PieceHeight(const Piece &piece, Rotation rotation) { switch(piece) { case PIECE_ONE: - return 2; + switch(rotation) + { + default: + case ROTATION_NONE: + case ROTATION_180: + return 2; + case ROTATION_90: + case ROTATION_270: + return 3; + }; break; case PIECE_TWO: - return 4; - break; case PIECE_THREE: - return 4; + switch(rotation) + { + default: + case ROTATION_NONE: + case ROTATION_180: + return 4; + case ROTATION_90: + case ROTATION_270: + return 2; + }; break; case PIECE_FOUR: - return 3; + case PIECE_SEVEN: + switch(rotation) + { + default: + case ROTATION_NONE: + case ROTATION_180: + return 3; + case ROTATION_90: + case ROTATION_270: + return 2; + }; break; case PIECE_FIVE: + case PIECE_EIGHT: return 3; break; case PIECE_SIX: - return 2; + switch(rotation) + { + default: + case ROTATION_NONE: + case ROTATION_180: + return 2; + case ROTATION_90: + case ROTATION_270: + return 4; + }; break; + } + + std::exit(-1); +} + +unsigned PieceWidth(const Piece &piece, Rotation rotation) +{ + switch(piece) + { + case PIECE_ONE: + switch(rotation) + { + default: + case ROTATION_NONE: + case ROTATION_180: + return 3; + case ROTATION_90: + case ROTATION_270: + return 2; + }; + break; + case PIECE_TWO: + case PIECE_THREE: + switch(rotation) + { + default: + case ROTATION_NONE: + case ROTATION_180: + return 2; + case ROTATION_90: + case ROTATION_270: + return 4; + }; + break; + case PIECE_FOUR: case PIECE_SEVEN: - return 3; + switch(rotation) + { + default: + case ROTATION_NONE: + case ROTATION_180: + return 2; + case ROTATION_90: + case ROTATION_270: + return 3; + }; break; + case PIECE_FIVE: case PIECE_EIGHT: return 3; break; + case PIECE_SIX: + switch(rotation) + { + default: + case ROTATION_NONE: + case ROTATION_180: + return 4; + case ROTATION_90: + case ROTATION_270: + return 2; + }; + break; } std::exit(-1); diff --git a/Pieces.h b/Pieces.h index 82424e4..971739f 100644 --- a/Pieces.h +++ b/Pieces.h @@ -69,7 +69,10 @@ typedef uint8_t Piece; // only need literally 8, not 8 bits, but hey. * [][][] */ -unsigned PieceHeight(const Piece &piece); +unsigned PieceHeight(const Piece &piece, + Rotation rotation = Rotation::ROTATION_NONE); +unsigned PieceWidth(const Piece &piece, + Rotation rotation = Rotation::ROTATION_NONE); void DrawPiece(const Piece &piece, int y, int x, Rotation rotation = Rotation::ROTATION_NONE); diff --git a/main.cpp b/main.cpp index b48c8b1..6a86e18 100644 --- a/main.cpp +++ b/main.cpp @@ -96,13 +96,38 @@ void DemoPieces() for(auto rotation : rotations) { clear(); - int x = 1; + + int x, y; + + // Always same distance apart: + x = 10; + y = 2; for(auto i = 0; i < 8; ++i) { Piece piece = static_cast(i); - DrawPiece(piece, 2, x, rotation); + DrawPiece(piece, y, x, rotation); x += 12; } + + // Always same width apart: + x = 2; + y = 10; + for(auto i = 0; i < 8; ++i) + { + Piece piece = static_cast(i); + DrawPiece(piece, y, x, rotation); + x += PieceWidth(piece, rotation) * 2 + 2; + } + // Always same height apart, sharing first piece with same-width row: + x = 2; + y = 10 + PieceHeight(0, rotation) + 1; + for(auto i = 1; i < 8; ++i) // skip first + { + Piece piece = static_cast(i); + DrawPiece(piece, y, x, rotation); + y += PieceHeight(piece, rotation) + 1; + } + getch(); } move(8, 2);