This site requires JavaScript, please enable it in your browser!
Greenfoot back
arthurmadson
arthurmadson wrote ...

2018/3/14

How to make turnTowards inversion

arthurmadson arthurmadson

2018/3/14

#
Hello everybody i'm here to discuss one issue that i'm stuck with, the problem is i've created two classes one called boy and other it called sawdich. i want to do the reverse of this function turnTowards(x,y); where instead of the sawdich chase the boy it run away from him. in Sawdich class { act{ move(1); boardSawdich(); } public void boardSawdich(){; if(isAtEdge()){ int grausSawdich=Greenfoot.getRandomNumber(100); turn(grausSawdich); } } } makes the sawdich move until reach the board then turn in some random direction and it keep moving what i want is one function where i can use turnTowards(); to make the sawdich run away from the boy when a especific range will reached.
danpost danpost

2018/3/14

#
arthurmadson wrote...
i want to do the reverse of this function turnTowards(x,y); where instead of the sawdich chase the boy it run away from him.
The following would be like the reverse method ("function"):
public void turnAway(int x, int y)
{
    turnTowards(x, y);
    turn(180);
}
Pretty simple -- probably not worth creating a seperate method for.
You need to login to post a reply.