Here is my code:
Code: Select all
if ((int)player2Pos.x > (int)gemPos.x)
{
player2Direction = UP;
player2Animating = true;
player2.Move(0, -2);
}
else if ((int)player2Pos.x < (int)gemPos.x)
{
player2Direction = DOWN;
player2Animating = true;
player2.Move(0, 2);
}
else if ((int)player2Pos.y > (int)gemPos.y)
{
player2Direction = LEFT;
player2Animating = true;
player2.Move(-2, 0);
}
else if ((int)player2Pos.y < (int)gemPos.y)
{
player2Direction = RIGHT;
player2Animating = true;
player2.Move(2, 0);
}