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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | 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 ); } } |