I use getOneIntersectingObject to check any blocked object, once it check a valid object, it get stuck there even other direction cursor key press.
Not understand why?
Thanks!
The Brick object created in the World class
public void act()
{
CheckKeyMove();
}
public boolean CheckCanMove(java.lang.Class blocker)
{
Actor block = getOneIntersectingObject(blocker);
if(block == null)
return true;
else
return false;
}
public void CheckKeyMove()
{
if(Greenfoot.isKeyDown("up"))
{
setRotation(270);
if(CheckCanMove(Brick.class))
setLocation(getX(),getY()-1);
}
else
if(Greenfoot.isKeyDown("right"))
{
setRotation(0);
if(CheckCanMove(Brick.class))
setLocation(getX()+1,getY());
} else
if(Greenfoot.isKeyDown("down"))
{
setRotation(90);
if(CheckCanMove(Brick.class))
setLocation(getX(),getY()+1);
} else
if(Greenfoot.isKeyDown("left"))
{
setRotation(180);
if(CheckCanMove(Brick.class))
setLocation(getX()-1,getY());
}
} for(int i= 0; i< 20; i++)
{
brickA[i] = new Brick();
addObject(brickA[i], locXY[i*2], locXY[i*2+1]);
}
