I want whoever a lobster sees a crab to only get one life ripped off.
The problem is that the crab "crawls" over the lobster and has about 5 times contact = lifetime is deducted.
So a query anzLeben == 0 does not lead to death only if you set anzLeben initially to approx. 10.
I tried to work with a variable hit = true.
Unfortunately I can't get the logic under control. Either the crab is still eaten immediately or not at all :-(
Here's my code try:
I have declared a variable boolean hit = true;
In the method public void lookforcrab()
{
If (canSee (Crab.class) && hits)
{
Crab crab1 = (Crab) getOneObjectAtOffset (0,0,Crab.class);
If (crab1 == null)
{
hit = false;
}
If (hit)
{
krabbe1.lifetime(-1);
}
If (Crab.anzLife == 0)
{
Eat(Crab.class);
Greenfoot.playSound("au.wav")
Greenfoot.stop();
}
}
}