Hi there I am new to Greenfoot but I am really struggling with a piece of code I am trying to create a second level to my dungeon game but when I do its carrying all my enemy actors and barrel actors over to my next level which I do not want. How do i stop this? Someone please help me the code below is of my first level which i have called Desert
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Desert here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Desert extends World
{
private Hero player;
//Class level variables
/**
* Constructor for objects of class Desert.
*
*/
public Desert()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(600, 400, 1);
populateWorld();
}
public void act()
{
if(player.getLives()==0)
{
removeObject(player);
Greenfoot.stop();
}
}
private void populateWorld()
{
int blockX = 100;
addObject(new Enemy(), 50, 50);
addObject(new Enemy(), 50, 150);
addObject(new Enemy(), 50, 255);
addObject(new Enemy(), 500, 150);
player = new Hero();
addObject(player, 550, 350);
addObject(new Exit(), 30, 30);
addObject(new Block(), 300, 150);
for(int count=0; count<5; count++)
{
addObject(new Block() ,blockX, 340);
blockX+=100;
}//ENDFOR
}//End populateWorld method
{
setPaintOrder(Hero.class,Enemy.class,Exit.class);
}
}
