Added positioning.

This commit is contained in:
David Vereb 2023-04-03 22:22:59 -04:00
parent 153a80ddbe
commit 3a9f4dac20

View File

@ -12,6 +12,7 @@ static void finish(int sig);
void init_colors(); void init_colors();
void PlacePiece(Piece piece, const std::vector<Flip> &flips, Rotation rotation, int y, int x); void PlacePiece(Piece piece, const std::vector<Flip> &flips, Rotation rotation, int y, int x);
void GetPosition(unsigned long position, int &y, int &x);
int main(int argc, char *argv[]) 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 horizontal = (0b1000 & input_val) ? Flip::FLIP_HORIZONTAL : Flip::FLIP_NONE;
Flip vertical = (0b10000 & input_val) ? Flip::FLIP_VERTICAL : Flip::FLIP_NONE; Flip vertical = (0b10000 & input_val) ? Flip::FLIP_VERTICAL : Flip::FLIP_NONE;
Rotation rotation = static_cast<Rotation>((0b1100000 & input_val) >> 5); Rotation rotation = static_cast<Rotation>((0b1100000 & input_val) >> 5);
unsigned long position = (0b1111110000000 & input_val) >> 7;
GetPosition(position, y, x);
PlacePiece(piece, PlacePiece(piece,
{ horizontal, vertical }, { horizontal, vertical },
rotation, rotation,
y, y,
x); x * 2);
// y += PD_PieceHeight(pieces.at(piece)) + 1; // y += PD_PieceHeight(pieces.at(piece)) + 1;
y += 5; y += 5;
} catch(const std::exception &e) { } catch(const std::exception &e) {
@ -113,3 +116,57 @@ void PlacePiece(Piece piece, const std::vector<Flip> &flips, Rotation rotation,
PD_DrawPiece(data, y, x, piece); 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;
}