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

2015/12/14

help pls when score hit 500 add boss.

ggtamilggt ggtamilggt

2015/12/14

#
so this is my 1st time to try greenfoot how can i add boss when i score like 500 this is my counter class
public class Counter  extends Actor
{
    public int totalCount = 0;

    public Counter()
    {
        setImage(new GreenfootImage("SCORE  :", 20, Color.WHITE, Color.BLACK));
    }

    /**
     * Increase the total amount displayed on the counter, by a given amount.
     */
    public void bumpCount(int amount)
    {
        totalCount += amount;
        setImage(new GreenfootImage("SCORE : " + totalCount, 20, Color.WHITE, Color.BLACK));
        
    }
and this is my world class
public class ScrollingWorld extends World
{
    public Player thePlayer;
    public Erm theErm;
    public Counter theCounter;
    private HP theHP;
    
    public ScrollingWorld()
    {    
        super(800, 600, 1, false); //The extra 'false' parameter means that the world is unbounded.
   
        
        thePlayer = new Player();
        addObject(thePlayer, 300, 354); //Creates the player.
        theErm = new Erm();
        addObject(theErm, 0, -10);
        theCounter = new Counter();
        addObject(theCounter, 40, 340);
        theHP = new HP();
        addObject(theHP, 40, 200);
        
    }
   
     public void act()
     {
         String key = Greenfoot.getKey();
            
                
                if (Greenfoot.isKeyDown("space"))
                {
                    thePlayer.shoot();
                }
                
           if (Greenfoot.isKeyDown("left"))
        {
           thePlayer.moveLeft();
        }
        
         if (Greenfoot.isKeyDown("right"))
        {
            thePlayer.moveRight();
        }
        
              if (Greenfoot.isKeyDown("up"))
            {
                thePlayer.moveUp();
            }
           
          else  if (Greenfoot.isKeyDown("down"))
            {
                thePlayer.moveDown();
                
            }
      
           }
        

    
    
    
    
    public Player getPlayer()
    {
        return thePlayer;
    }
    
    public Erm getErm()
    {
        return theErm;
    }
    
    public Counter getCounter()
    {
        return theCounter;
    
    }
    
    
    public HP getHP()
    {
        return theHP;
    }
   
    
    /**
     * Prepare the world for the start of the pPlayergram. That is: create the initial
     * objects and add them to the world.
     */
    private void prepare()
    {
       
        addObject(new Enemy(), getWidth() + 20 , Greenfoot.getRandomNumber(400));
        addObject(new Enemy(), getWidth() + 20 , Greenfoot.getRandomNumber(400));
        addObject(new Enemy(), getWidth() + 20 , Greenfoot.getRandomNumber(400));
    }
   
}
fejfo fejfo

2015/12/14

#
public void bumpCount(int amount)
    {
        totalCount += amount;
        setImage(new GreenfootImage("SCORE : " + totalCount, 20, Color.WHITE, Color.BLACK));
         if(totalCount > 500 && totalCount-amount < 500) getWorld().addObject(new Boss(),<x>,<y>);
    }
so just check if it went over 500 by adding and then spawn a boss
You need to login to post a reply.