Hey People,
i am doing a Game with a Rabbit trying to eat Mushrooms. He is chased by a Dog trying to eat him.
I want to do 2 Levels, the first should end if the Rabbit has eaten 10 (or so) Mushrooms or is eaten by the Dog.
I have got the Code for the end if he is eaten by the Dog but I cant get it to work if the Rabbit has eaten 10 Mushrooms.
+ i would like to let the Mushrooms disappear after 10 or 20 seconds, to make it harder.
+ i would like to let the Background change color for like 2-3 seconds if the Rabbit eats a Mushroom.
Thanks already for the help! ;)
And here the codes:
Rabitt:
World (Mushroom spawn inside it):
public class hase extends Actor
{
/**
* Act - do whatever the hase wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
{if(Greenfoot.isKeyDown("up"))
{move(3);}}
{if(Greenfoot.isKeyDown("down"))
{move(-3);}}
{if(Greenfoot.isKeyDown("left"))
{turn(-3);}}
{if(Greenfoot.isKeyDown("right"))
{turn(3);}}
eat();
}
public void eat()
{Actor pilz;
pilz = getOneObjectAtOffset(0,0,pilz.class);
if(pilz !=null){getWorld().removeObject(pilz);
Greenfoot.playSound("burp.mp3");
((world) getWorld()).counteat();
}
}
}
public class world extends World
{
Counter counter = new Counter("Score: ");
public world()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(900, 600, 1);
setPaintOrder(ScoreBoard.class, hase.class, pilz.class, dog.class, Counter.class);
prepare();
}
private int counterspawn;
private int counterremove;
private void prepare()
{
hase hase = new hase();
addObject(hase, 275, 250);
dog dog = new dog();
addObject(dog, 603,365);
dog.setLocation(823,515);
hase.setLocation(252,222);
addObject(counter, 100, 560);
}
public void act()
{
runcounterspawn();
}
public void counteat()
{
counter.add(10);
}
private void runcounterspawn()
{
counterspawn = (counterspawn+1)%300;
if (counterspawn == 0) spawnPilz();
}
private void spawnPilz()
{
int x = Greenfoot.getRandomNumber(getWidth());
int y = Greenfoot.getRandomNumber(getHeight());
addObject(new pilz(), x, y);
}
public void gameOver()
{
addObject(new ScoreBoard(counter.getValue()), getWidth()/2, getHeight()/2);
Greenfoot.playSound("zonk.mp3");
Greenfoot.stop();
}
}


