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

2013/5/8

New World Help

1
2
3
danpost danpost

2013/5/12

#
It might be best for you to upload your scenario to see what kind of mess you have right now. I can let you know when I have it, so you can delete it back off the site, if you wish.
SWAG SWAG

2013/5/13

#
danpost wrote...
It might be best for you to upload your scenario to see what kind of mess you have right now. I can let you know when I have it, so you can delete it back off the site, if you wish.
I do not feel comfortable putting up my code. Would have any other solutions.?
SWAG SWAG

2013/5/14

#
danpost wrote...
In the 'Level' world class, do the following:
// add the following instance field
private boolean hasStarted;
// in the constructor (after the 'super' statement)
if (!hasStarted)
{
    player = new Player();
    scoreCounter = new ScoreCounter("Score:");
    levelNumber = 0;
    hasStarted = true;
}
Then, you can remove the assignments from the field declaration statements.
// change declarations to
private Player player;
private Counter scoreCounter;
private int levelNumber;
I'm still having trouble with this. When I got to the second level my score is at zero and my player is new and not the one from previous world. Your help would be really appreciated.
danpost danpost

2013/5/14

#
Try this. Change the field declarations to 'public static' in the Level class:
// change declarations to
public static Player player;
public static Counter scoreCounter;
public static int levelNumber;
Then, the first code block you quoted in your last post should go not in the Level class, but in your 'Level0' class.
SWAG SWAG

2013/5/14

#
danpost wrote...
Try this. Change the field declarations to 'public static' in the Level class:
// change declarations to
public static Player player;
public static Counter scoreCounter;
public static int levelNumber;
Then, the first code block you quoted in your last post should go not in the Level class, but in your 'Level0' class.
They are static.
danpost danpost

2013/5/14

#
Yeah. But they were not public.
SWAG SWAG

2013/5/14

#
danpost wrote...
Yeah. But they were not public.
No it still didn't work.
danpost danpost

2013/5/14

#
What do you have for setting up those fields in 'Level1'.
SWAG SWAG

2013/5/14

#
danpost wrote...
What do you have for setting up those fields in 'Level1'.
   public background()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(894, 456, 1); 
        addObject(Levels.getScoreCounter(), 765, 66);

        addObject(Levels.getPlayer(),565, 246);
danpost danpost

2013/5/14

#
And what do you have in the Level class for these fields, now.
SWAG SWAG

2013/5/14

#
danpost wrote...
And what do you have in the Level class for these fields, now.
public class Level extends World
{

    public static PlayerTG player;
    public static Counter scoreCounter;
    public static int levelNumber;
    public boolean hasStarted;
    
    public Levels(int wide, int high, int size)
    {
        super(wide, high, size);
        
        if (!hasStarted)  
            {  
                player = new PlayerTG();  
                scoreCounter = new Counter();  
                levelNumber = 0;  
                hasStarted = true;  
            }  
    }

    public static Counter getScoreCounter()
    {
        return scoreCounter;
    }

    public static PlayerTG getPlayer()
    {
        return player;
    }

    public static int getLevel()
    {
        return levelNumber;
    }

    public static void changeLevel(int difference)
    {
        levelNumber += difference;
        switch (levelNumber)
        {
            case 0:  Greenfoot.setWorld(new easyLevel()); break;
            case 1:  Greenfoot.setWorld(new hardLevel()); break;
        }
    }
}
danpost danpost

2013/5/14

#
Remove lines 7 and 13 through 19 from this class and add them into your first playable world (easyLevel). I am confused. In the 'changeLevel' method, you are showing the first level as 'easyLevel' and the second level as 'hardLevel'; yet you indicated above that your second world was 'background'.
SWAG SWAG

2013/5/14

#
danpost wrote...
Remove lines 7 and 13 through 19 from this class and add them into your first playable world (easyLevel). I am confused. In the 'changeLevel' method, you are showing the first level as 'easyLevel' and the second level as 'hardLevel'; yet you indicated above that your second world was 'background'.
It WORKED thanks.
You need to login to post a reply.
1
2
3