EDIT - Never mind, figured it out. It feels so good to solve a problem on your own
I am trying to bounce an enemy across walls. However, my code is working as planned.
Here it is -
if (x >= 750)
{
x = 749;
newDirection = true;
}
if (x <= 10)
{
x = 11;
newDirection = true;
}
if (y == 480)
{
y = 479;
newDirection = true;
}
if (y == 10)
{
y = 11;
newDirection = true;
}
if (newDirection)
{
if ((dx == 1) && (dy == 1))
{
if (y == 479) dx = -1;
if (x == 749) dy = -1;
}
if ((dx == 1) && (dy == -1))
{
if (y == 479) dx = -1;
if (x == 11) dy = 1;
}
if ((dx == -1) && (dy == 1))
{
if (y == 11) dx = 1;
if (x == 749) dy = -1;
}
if ((dx == -1) && (dy == -1))
{
if (y == 11) dx = 1;
if (x == 11) dy = 1;
}
newDirection = false;
}
x = x + dx;
y = y + dy;
Any help would be appreciated.