I am wondering if there is anyone who can explain to me what the "for" loop below is doing because am confused.
public void act()
{
move(4);
}
public void move(int moveAmt)
{
// determine direction by keypress checking
int dx = 0, dy = 0;
if (Greenfoot.isKeyDown("d"))
{dx += 1;}
if (Greenfoot.isKeyDown("a"))
{dx -= 1;}
if (Greenfoot.isKeyDown("s"))
{dy += 1;}
if (Greenfoot.isKeyDown("w"))
{dy -= 1;}
// check for wall on each step of move in both vertical and horizontal directions
for (int i = 0; i < moveAmt; i++)
{
setLocation(getX() + dx, getY());
if (getOneIntersectingObject(Wall.class) != null) setLocation(getX() - dx, getY());
setLocation(getX(), getY() + dy);
if (getOneIntersectingObject(Wall.class) != null) setLocation(getX(), getY() - dy);
}
}
