Hi there,
I currently have a game where the player moves into new areas, but I am unsure of how to keep the same player object, and amount of lives in each new area. My level transition is inside my player object
And my objects are inside my initial world class
Could someone please provide help as to how I would be able to keep my player and lives when moving through to different rooms.
Thanks
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 | public void level_right() { if (getX() == 959 ) { level = level + 1 ; } if (getY() == 639 ) { level = level + 2 ; } } public void new_level() { if (level == 2 ) { Second_world second = new Second_world(); //Create the end game scenario Greenfoot.setWorld(second); //Set the world for the End Game World setImage (sr); } if (level == 3 ) { Third_World third = new Third_World(); //Create the end game scenario Greenfoot.setWorld(third); //Set the world for the End Game World } } |
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 | */ public class world extends World { /** * Constructor for objects of class world. * */ public world() { // Create a new world with 600x400 cells with a cell size of 1x1 pixels. super ( 960 , 640 , 1 ); prepare(); } /** * Prepare the world for the start of the program. That is: create the initial * objects and add them to the world. */ private void prepare() { Player player = new Player(); addObject(player, 130 , 262 ); Lives lives = new Lives(); addObject(lives, 61 , 40 ); lives.setLocation( 87 , 34 ); Enemy enemy = new Enemy(); addObject(enemy, 406 , 198 ); PowerUp powerup = new PowerUp(); addObject(powerup, 400 , 303 ); Earth_Boss earth_boss = new Earth_Boss(); addObject(earth_boss, 575 , 420 ); } public Lives lives = new Lives(); } |