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

2022/12/12

How to set a score that keeps the same in new worlds?

LR6549 LR6549

2022/12/12

#
I tried to make a game where the world (Level) changes depending on the amount of items collected. But every time a new world is generated, the amount of items gets set to 0. To fix this I tried to call the class with the amount of items (public Player(int items){}) but this completly removes the act funktion even though you use the run option. how can I fix it?
Jestry Jestry

2022/12/12

#
code please. I don't know how exactly you are trying to access your variable, but if your "itemscollect" Variable is bound to your player, than simply give the Next World you open a pointer of your player. For that u have to modify the constructor of your World class, to give it the player.
danpost danpost

2022/12/13

#
LR6549 wrote...
I tried to make a game where the world (Level) changes depending on the amount of items collected. But every time a new world is generated, the amount of items gets set to 0. To fix this I tried to call the class with the amount of items (public Player(int items){}) but this completly removes the act funktion even though you use the run option. how can I fix it?
Try putting the same Player object in the new world. That is, for example, something like this:
public Level extends World
{
    private Player player;
    
    public Level()
    {
        this(new Player());
    }
    
    public Level(Player plyr)
    {
        super(600, 400, 1)
        player = plyr;
        // etc.
    }

    // etc.
}
That should get you going.
You need to login to post a reply.