Hey guys :)
I'm a beginner when it comes to Greenfoot and I really need help with my game.
I have to make one for school and it's due to wednesday :/
So here is my problem:
The actor (boy) needs to collect lifepoints while not getting caught by the randomly moving rocks.
A collision with those leads to him being 'eaten up', so he dissapears and a game over screen appears. However if he gets to collect all lifepoints without getting hit, he wins and gets to enter the second level.
I managed to program the boys movements and the randomly moving rocks, however how do I program that the boy dissapears and the game over screen?
And how can I make him move from level to the other?
Please help me, it's very urgent!
Thank you all already :)
Code for the boy:
public class boy extends Mover
{
/**
* Act - do whatever the boy wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act() {
if (Greenfoot.isKeyDown("left") )
{
moveLeft();
}
if (Greenfoot.isKeyDown("right") )
{
moveRight();
}
if (Greenfoot.isKeyDown("up") )
{
moveUp();
}
if (Greenfoot.isKeyDown("down") )
{
moveDown();
}
}
}
Code for the rocks:
public class rock extends Mover
{
public void act()
{
move(4);
if(Greenfoot.getRandomNumber(100) <10)
{
turn(Greenfoot.getRandomNumber(40)-20 );
}
if (atWorldEdge())
{
turn(12);
}
}
public boolean atWorldEdge()
{
if(getX() < 10 || getX() > getWorld().getWidth() - 10)
return true;
if(getY() < 10 || getY() > getWorld().getHeight() - 10)
return true;
else
return false;
}
}
Code for the world:
public class world1 extends World
{
/**
* Constructor for objects of class world1.
*
*/
public world1()
{
super(750, 450, 1);
addObjects();
}
public void addObjects(){
addObject(new rock(), 1, 50);
addObject(new rock(), 152, 282);
addObject(new rock(), 75 , 110 );
addObject(new rock(), 176, 59);
addObject(new rock(), 311, 170);
addObject(new rock(), 403, 44);
addObject(new rock(), 495, 230);
addObject(new rock(), 496, 362);
addObject(new rock(), 668, 295);
addObject(new rock(), 572, 127);
addObject(new boy(), 34, 406);
addObject(new lifepoints(), 245, 315);
addObject(new lifepoints(), 603, 369);
addObject(new lifepoints(), 682, 44);
addObject(new lifepoints(), 88, 22);
}
}

