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

2012/5/2

How do i take score to multiple levels?

chilvenl01 chilvenl01

2012/5/2

#
I am creating a game for ICT and i need to know if it is posssible to carry the score over multiple worlds? the score is saved in the World file where it is accessed when the bullet hits the enemy. what i am trying to get is when the character touches the house door actor then it will change the world so that the player is then in the house. when they then intersept with another object they will be put back onto the main world but will maintain there score throughout each level. Is this possible? If so can you make it as simple as possible. Thank you.
PStigerID PStigerID

2012/5/2

#
You can look at my programm and do it like I did - http://www.greenfoot.org/scenarios/4984. Basicly in a world which is active write "public static int X = 0;" Then if you want to change it write "NameOfWorld.X += 200;" or "NameOfWorld.X -= 200;" Hope this helps!
erdelf erdelf

2012/5/2

#
Nice idea PStigerID, here is an another Make a masterworld and all playable worlds a subclass of the masterworld. Now create an it in the masterworld and change the score like PStigerID told you
chilvenl01 chilvenl01

2012/5/3

#
That worked perfectly, thanks guys,
chilvenl01 chilvenl01

2012/5/3

#
Using the static methods doesnt reset the score when the game is reset, how can i make it do this? Thanks
davmac davmac

2012/5/3

#
Don't use static. Pass the value between your worlds instead. Either add a parameter to the world constructor, or add a 'setScore' method and call it just after you create the world.
davmac davmac

2012/5/3

#
Example:
  public MyWord(int score)
  {
     this.score = score;
  }
You can keep the original constructor as well, so that you can still create the first world without supplying a score.
You need to login to post a reply.