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

2017/4/23

Help Me Please :(

iban iban

2017/4/23

#
i want make game stage :(
Yehuda Yehuda

2017/4/23

#
iban wrote...
i want make game stage :(
It's not so clear what your question is. Can you elaborate on it.
danpost danpost

2017/4/23

#
First thing you need is a field to hold the current stage, so that you have something to check before allowing a world level to be entered into. An int field is sufficient where its value would be the highest level that can currently be run. Because the levels are each separate worlds, the field will need to be made static -- a class field instead of an object field. However, as a class field, it will need to be programmatically reset for each running of the scenario (it will not be reset when resetting the scenario -- only by recompiling it). In order to reset it each time the scenario is started anew, we need a new starting point for the scenario, one that will not be returned to later during run-time (all the worlds you currently have will probably have objects created from them during runtime). Create a new subclass of World and call it InitialWorld. Its size is of little importance. What is important is that its constructor can reset any static fields that need to be reset before setting a new MyWorld object active. Let us say you added a static field called 'stage' in the 'MyWorld' class; then your new subclass could be:
public class InitialWorld extends greenfoot.World
{
    public InitialWorld()
    {
        super(600, 400, 1);
        MyWorld.stage = 1;
        Greenfoot.setWorld(new MyWorld());
    }
}
Close the editor and right click on the InitialWorld class and select 'new InitialWorld'. This sets the InitialWorld class as the starting World subclass for your scenario. It may look like it starts with the MyWorld class, but if you inspect it, you will see that the value of 'stage' is set to one already. With the 'stage' field in place, you can now use its value to determine which picture to give to the stage buttons as well as adding the extra condition on button clicking (the level must be open AND the button must be clicked to proceed to that level). So, for example, the 'if' statement in your Stage_2 class act method could be:
if (MyWorld.stage >= 2 && Greenfoot.mousePressed(this))
iban iban

2017/4/24

#
oh very difficult. my project already post you can see that. i want open stage 2 if score stage 1 >= 200 and same for next stage. my logic if stage 2 >= 200 than image stage 3 in World is changed to new image :(
You need to login to post a reply.