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

2013/6/1

Predator/Prey Scenario-Need Help With Clock

Awesomefly890 Awesomefly890

2013/6/1

#
Hi everyone. I was making an underwater predator/prey scenario, where a dolphin eats fish and gains points, and lobsters have to catch the dolphin. Anyways, I would like to create a clock, so if the fish don't eat the seaweed(it spawns naturally) in a designated period of time they will de-spawn. Can anyone help me out with this? And ahead of time, thanks. I appreciate any suggestions that could possibly help me solve this or make my game better. Awesomefly890
erdelf erdelf

2013/6/1

#
create a double called lastWeed in the fish class, and then the following in the act method. change the 10000 to any time you like
if(System.currentTimeMillis() > lastWeed + 10000)
{
    getWorld().removeObject(this)
}
that should do it
Awesomefly890 Awesomefly890

2013/6/1

#
Thanks erdelf. I'll try this out.
Awesomefly890 Awesomefly890

2013/6/1

#
I can't get it to work. It claims 'cannot find symbol-variable lastWeed'. Perhaps I didn't create a double right? public void act() { moveAndTurn(); eat(); lastWeed(); } That's the act. The lastWeed act is... public void lastWeed() { if(System.currentTimeMillis() > lastWeed + 10000) { getWorld().removeObject(this); } } Any ideas?
erdelf erdelf

2013/6/1

#
lastWeed wasnt supposed to be a method, change line
 if(System.currentTimeMillis() > lastWeed + 10000)
to
 if(System.currentTimeMillis() > lastSeaWeed + 10000)
and create a double in the class
Awesomefly890 Awesomefly890

2013/6/1

#
Ok, I'll change it now. Thanks.
You need to login to post a reply.