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

2013/9/15

Help

RedFox92 RedFox92

2013/9/15

#
How do i make levels for my game?
In greenfoot, you have subclasses of worlds (hoping you already know that) in which let different actors "live in" and do stuff. To change from one world to the next, you have to use this line of code after you trigger something that will go to the next level:
Greenfoot.setWorld(new MyWorld2); //Replace MyWorld2 with whatever you next level name is.
I hoped that helped!
RedFox92 RedFox92

2013/9/15

#
I created the world and it works ,but i keep getting an error Heres my code could you plz help My worlds name is Two
public void tryToEat()
    {
        if( canSee(Fly.class))
        {
           eat(Fly.class);
           counter.add(50);
           
          
        } 
        
        if( canSee(Coin.class))
        {
           eat(Coin.class);
           counter.add(10);
           
          
        }   
        
        if( canSee(Ant.class))
        {
           eat(Ant.class);
           counter.add(100);
           
          
        }   
        
        if( canSee(Spider.class))
        {
           eat(Spider.class);
           counter.add(200);
           
          
        }   
        
        if (counter.getValue() >= 5000)
        {
            GameOver();
        }
    }
    
    
    public void GameOver()
        {
    
           Greenfoot.stop();
        
        }
        
    public void Game()
    {
      if (GameOver)
        {
            Greenfoot.setWorld(new Two);
        }
    }
Is your error on line 53:
Greenfoot.setWorld(new Two);
it should be instead:
Greenfoot.setWorld(new Two()); //with the parentheses
If that isn't it, please tell me what the error message is.
RedFox92 RedFox92

2013/9/15

#
Thanx that help i did it a little different heres the code
    public void tryToEat()
    {
        if( canSee(Fly.class))
        {
           eat(Fly.class);
           counter.add(50);
           
          
        } 
        
        if( canSee(Coin.class))
        {
           eat(Coin.class);
           counter.add(10);
           
          
        }   
        
        if( canSee(Ant.class))
        {
           eat(Ant.class);
           counter.add(100);
           
          
        }   
        
        if( canSee(Spider.class))
        {
           eat(Spider.class);
           counter.add(200);
           
          
        }   
        
        if (counter.getValue() >= 500)
        {
            GameOver();
        }
    }
    
    
    public void GameOver()
        {
    
           Greenfoot.stop();
         
             Greenfoot.setWorld(new Two());
       
        }
You need to login to post a reply.