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

2014/12/10

Change level

tabitha0509 tabitha0509

2014/12/10

#
Hey, I am creating a Jump'N'Run Game and i've already managed to make my player change the level. My Player collects Apples. Now I want to program that my player keeps the score of the Apples when he switchs to the next level. Could you help me? (I'm sorry that my english isn't the best haha) Import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) public class Schwein extends Animal { public int gegesseneÄpfel = 0; public void essen() { if (isTouching (Apfel.class)) { removeTouching (Apfel.class); gegesseneÄpfel = gegesseneÄpfel + 1; if (gegesseneÄpfel == 5) { Greenfoot.playSound ("fanfare.wav"); Greenfoot.stop(); } } } public void levelwechseln() { if (isAtEdge()) { if (getWorld() instanceof Level1) { Greenfoot.setWorld(new Level2()); } else if (getWorld() instanceof Level2) { Greenfoot.setWorld(new Level3()); } else if (getWorld() instanceof Level3) { Greenfoot.setWorld(new Level4()); } else if (getWorld() instanceof Level4) { Greenfoot.setWorld(new Level5()); } else if (getWorld() instanceof Level5) { Greenfoot.setWorld(new Level6()); } else if (getWorld() instanceof Level6) { Greenfoot.setWorld(new Level7()); } } } }
danpost danpost

2014/12/10

#
A few questions: (1) what class do your Level1, Level2, etc. classes extend? (2) will the number of apples eaten always be 5 when changing from Level1 to Level2; and will the number always be the same when changing from any level to the next (but not necessarily 5)? (3) is there only one Schwein object added into any world?
You need to login to post a reply.