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

2012/12/21

In my scenario people are able to make "childs". But instead of making one child, they're making 5-10.

kaatja kaatja

2012/12/21

#
We're in Homer, one of the "Parents"
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Homer here.
* 
* @author (your name) 
* @version (a version number or a date)
*/
public class Homer extends Opfer
{
private static final double WALKING_SPEED = 5.0;
/**
* Act - do whatever the Homer wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act() 
{
{
[b]if (canSee(Marge.class))
{
getWorld().addObject( new Maggie(), 150, 100 );
}[/b]
if ( atWorldEdge() )
{
turn(7);
}
if ( Greenfoot.getRandomNumber(100) <10 )
{
turn(23);
}
heal();
move();
meetMikrobe();
if(meetMikrobe())
{
if (Greenfoot.getRandomNumber(100)<50)
{
getsick();
}
}
}
} 

public boolean meetMikrobe()
{
Actor Mikrobe = getOneObjectAtOffset(0, 0, Mikrobe.class) ;
if(Mikrobe != null)
{ 
return true;
}
else
{
return false;
}
}
public void getsick()
{
setImage("ORIGINAL HOMER KRANK.gif");

}

public void heal()
{ if (canSee(Retter.class))
{
setImage("ORIGINAL HOMER.gif");
}
}
}
kaatja kaatja

2012/12/21

#
How do I can change the code, that theres only appearing one new object?
tylers tylers

2012/12/21

#
whats <span class="bb_bold"> for -- thats html
danpost danpost

2012/12/21

#
Change
if (canSee(Marge.class))
to
if (canSee(Marge.class) && getWorld().getObjects(Maggie.class).isEmpty())
You need to login to post a reply.