From 3a9f4dac2004825ed824b752cc051ceaa9dfecba Mon Sep 17 00:00:00 2001 From: David Vereb Date: Mon, 3 Apr 2023 22:22:59 -0400 Subject: [PATCH] Added positioning. --- main.cpp | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/main.cpp b/main.cpp index c8eb24d..9472991 100644 --- a/main.cpp +++ b/main.cpp @@ -12,6 +12,7 @@ static void finish(int sig); void init_colors(); void PlacePiece(Piece piece, const std::vector &flips, Rotation rotation, int y, int x); +void GetPosition(unsigned long position, int &y, int &x); int main(int argc, char *argv[]) { @@ -44,11 +45,13 @@ int main(int argc, char *argv[]) Flip horizontal = (0b1000 & input_val) ? Flip::FLIP_HORIZONTAL : Flip::FLIP_NONE; Flip vertical = (0b10000 & input_val) ? Flip::FLIP_VERTICAL : Flip::FLIP_NONE; Rotation rotation = static_cast((0b1100000 & input_val) >> 5); + unsigned long position = (0b1111110000000 & input_val) >> 7; + GetPosition(position, y, x); PlacePiece(piece, { horizontal, vertical }, rotation, y, - x); + x * 2); // y += PD_PieceHeight(pieces.at(piece)) + 1; y += 5; } catch(const std::exception &e) { @@ -113,3 +116,57 @@ void PlacePiece(Piece piece, const std::vector &flips, Rotation rotation, PD_DrawPiece(data, y, x, piece); } + +void GetPosition(unsigned long position, int &y, int &x) +{ + if(position < 6) + { + y = 0; + x = position; + return; + } + + if(position < 12) + { + y = 1; + x = position - 6; + return; + } + + if(position < 19) + { + y = 2; + x = position - 12; + return; + } + + if(position < 26) + { + y = 3; + x = position - 19; + return; + } + + if(position < 33) + { + y = 4; + x = position - 26; + return; + } + + if(position < 40) + { + y = 5; + x = position - 33; + return; + } + + if(position < 43) + { + y = 6; + x = position - 40; + } + + x = y = 0; + return; +}