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;
}
Not sure I'm going about this the right way but i'm using your map concept and am struggling with adding an actor. I think it has something to do with the constructor i used but i'm not sure how to fix it. I'm pretty sure I need the constructor to re-size my images.Using other things to re-size them always seems to distort the images.
2014/10/10
Shining_Force
2014/10/1
Nightmare: Emergence
2014/10/1
Nightmare: Emergence
2014/10/1
Platformer Tutorial
2014/10/1
Platformer Tutorial
2014/9/27
Car chase
2014/9/27
Car chase
2014/9/27
Shoot!
2014/9/27
Adventure