This senses if the character is within 24 pixels of the center of river when facing a direction. If facing to the right it will only block going right. RiverA is my image.Hope this makes sense. There is no doubt a better way of doing this though.
I used:
public int Direction()
{
Actor RiverR=getOneObjectAtOffset(24,0,RiverA.class);
Actor RiverL=getOneObjectAtOffset(-24,0,RiverA.class);
Actor RiverT=getOneObjectAtOffset(0,-25,RiverA.class);
Actor RiverB=getOneObjectAtOffset(0,25,RiverA.class);
if(Greenfoot.isKeyDown("Up"))
{
Direction=3;
if(RiverT == null)
if(speed<=3)
speed++;
else{
speed=0;setLocation(getX(), getY()-1);}
}
else if(Greenfoot.isKeyDown("Right"))
{
Direction=4;//facing right
//loop to move 1 square
if(RiverR == null)
if(speed<=3)
speed++;
else{
speed=0;move(1);}
}
else if(Greenfoot.isKeyDown("Left"))
{
Direction=2;
if(RiverL == null)
if(speed<=3)
speed++;
else{
speed=0;move(-1);}
}
else if(Greenfoot.isKeyDown("Down"))
{
Direction=1;
if(RiverB == null)
if(speed<=3)
speed++;
else{
speed=0;setLocation(getX(), getY()+1);}
}
return Direction;
}
Recent Comments | Show All
2014/10/10
Shining_Force
2014/10/1
Nightmare: Emergence