Added positioning.
This commit is contained in:
parent
153a80ddbe
commit
3a9f4dac20
59
main.cpp
59
main.cpp
@ -12,6 +12,7 @@ static void finish(int sig);
|
||||
void init_colors();
|
||||
|
||||
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[])
|
||||
{
|
||||
@ -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<Rotation>((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<Flip> &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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user