This site requires JavaScript, please enable it in your browser!
Greenfoot back

Report as inappropriate.

patpal
patpal presents ...

2014/2/10

Tara-Lara

No description.

1726 views / 302 in the last 7 days

1 vote | 0 in the last 7 days

Tags: with-source

open in greenfoot
Your browser does not support the canvas tag.
patpalpatpal

2014/2/11

Hi please help me. How do i make Lara (person), go to a new level (world) with a different background and a different image for lara. This is her code as of now public int counter = 0; public void act() { if (canSee(Monuments.class)) { eat(Monuments.class); Greenfoot.playSound("slurp.wav"); counter++; if(counter == 3 ) { newLevel(); } } if (Greenfoot.isKeyDown("right")) { move (4); } if (Greenfoot.isKeyDown("left")) { move (-4); } if (canSee(Bomb.class)) { eat(Bomb.class); Greenfoot.playSound("au.wav"); } } public void newLevel() { World world; world = getWorld(); int x = (int)(100+Math.random()*350); int y = 80; world.addObject(new Monuments(x,y) , x,y); x = (int)(100+Math.random()*350); world.addObject(new Monuments(x,y) , x,y); x = (int)(100+Math.random()*350); world.addObject(new Monuments(x,y) , x,y); }
danpostdanpost

2014/2/11

If you are only going to have two levels, you can just put the code in the 'newLevel' method using the 'world.setBackground(String imageFilename)' and 'setImage(String imageFilename)' methods to make the changes. If you are adding additional levels, best would be to put the filenames in arrays and add an instance int field to track the level number and determine what index in the arrays to get the names from (still, the code for incrementing the level number and setting the images would go in the 'newLevel' method).
patpalpatpal

2014/2/11

I have three levels. I used this code for Lara and Iv'e managed to make her go to the next level but i cant make her move to the third. public int counter = 0; public void act() { if (canSee(Monuments.class)) { eat(Monuments.class); Greenfoot.playSound("slurp.wav"); counter++; if(counter == 3 ) { newLevel(); } } if (Greenfoot.isKeyDown("right")) { move (4); } if (Greenfoot.isKeyDown("left")) { move (-4); } if (canSee(Bomb.class)) { eat(Bomb.class); Greenfoot.playSound("au.wav"); } } public void newLevel() { World world; world = getWorld(); Greenfoot.setWorld(new Asia()); } public void newLeve2() { World world; world = getWorld(); Greenfoot.setWorld(new Europe()); }
patpalpatpal

2014/2/11

BTW, thank you danpost for replying so quickly!
danpostdanpost

2014/2/11

Changing thing up, eh? Before, it appeared all levels would be using the same world instance; now, it appears you are using different worlds (there were no 'setWorld' methods used in your first post). This changes things drastically. Your 'newLevel' method will need to determine what world is currently active to know which world to proceed to. This is done by using the 'instanceof' operator on the world object. For example: if (getworld() instanceof Asia) Greenfoot.setWorld(new Europe()); You will need a similar line for each possible level change.
patpalpatpal

2014/2/12

Thank you so much!

Want to leave a comment? You must first log in.

Who likes this?

herusaputra