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

2017/3/19

Multiple Levels with subworlds

Dylex Dylex

2017/3/19

#
Hi, i'm creating a game with multiple levels, but i want these levels to all be under one world, so that data can transfer between them. I'm not seeing any simple ways to do this and i'm wondering if there is a simple way of going about this. Here's what my world classes look like at the moment I want to keep the gameworld going for the whole time, but i simply want to switch between subworlds, such as floorone and later on floortwo.
Super_Hippo Super_Hippo

2017/3/19

#
If the floors are similar (like only different objects are created, but the world does (almost) the same), then you don't need separate classes for it.
I want to keep the gameworld going for the whole time
Only one world can be active at a time. So if GameWorld is active, FloorOne is not. (Not active does not mean that you can not switch back and forth.) To make subclassing worlds work, you have to make sure that the first line in each constructor of the World's subclasses will still call the constructor of the World class.
danpost danpost

2017/3/19

#
If you want all your subworlds to share a single field whose value is retained from world to world, then make it a 'static' field. For example:
// instead of
public int score;
public int lives;
// use
public static int score;
public static int lives;
Just make sure to explicity reset the value of these fields in your initial world object. Refer to my Super Level Support Class scenario as an example of what I mean.
You need to login to post a reply.