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

2014/11/14

i successed greeps to deop paint, but i can't make them to follow the paint

songgh1999 songgh1999

2014/11/14

#
what should i do? i should use paint method?
danpost danpost

2014/11/14

#
You should use 'seePaint(String)' method where the string is either "red", "orange", or "purple". The method returns a boolean (true/false) value indicating whether the greep currently sees paint of that color (the method is found in and inherited to the Greep class from the Creature class). Use it as an 'if' condition to do whatever you might do to attempt to follow the trail (I used the word 'attempt' because greeps are fairly limited in what they are capable of).
songgh1999 songgh1999

2014/11/15

#
oh i wrote deop instead of spit XD i should use like this? public boolean seePaint(String "color") { List paintDrops = getIntersectingObjects(Paint.class); for(Object obj : paintDrops) { if ( ((Paint)obj).getColor().equals(color)) { return true; } } return false; }
danpost danpost

2014/11/15

#
That looks very similar to the method that is already in the Creature class that you can use directly in the Greep class. The only difference is that there are no double quotes around 'color' in the first line. You do not need to re-write the method in the Greep class -- as I said, because Greeps extends the Creature class, the method is inherited (becomes part of the Greep class). You only need to create an 'if' block within the act method of your Greep class using the method in its conditional expression. For example:
1
2
3
4
if (seePaint("red"))
{
    // what to do if sees red paint
}
songgh1999 songgh1999

2014/11/16

#
oh yeeeaaahhhhhhhhhh i got it thx thx :) p.s. what can i use 'follow' instead?
You need to login to post a reply.