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

4 days ago

How would i go about making an upgrade that is continuous?

Just_a_person847 Just_a_person847

4 days ago

#
I am trying to make a roguelike in greenfoot, but I need to be able to make upgrades last between stages. Whenever the world changes, how do i make the upgrade *not* reset?
danpost danpost

3 days ago

#
Just_a_person847 wrote...
Whenever the world changes, how do i make the upgrade *not* reset?
My suggestion is to use static fields for the upgrades. They must be initialized during your initial world constructor only. Static fields are "class fields" which do not reset when a new world is created, nor when the scenario is reset. This is why they need initialized in the initial world constructor. The keyword "static" is added to the field declaration line. For example:
public static java.util.List<Upgrade> upgrades;

public MyWorld() {
    super(600, 400, 1);
    upgrades = new java.util.ArrayList<Upgrade>();
    // etc.
}
You need to login to post a reply.