This site requires JavaScript, please enable it in your browser!
Greenfoot back
Kirito101

Kirito101

Welcome to my page

Kirito101's scenarios

play Shining_Force play Car chase

Kirito101's collections

This user has no collections

Recent Comments | Show All

Kirito101

2014/10/10

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; }
nvm im just silly