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

2014/12/3

How to make different enemy spawn if enemy is killed

cloud41910 cloud41910

2014/12/3

#
I'm trying to make that if my first enemy is killed then a new one will show up i find it hard to make a new level so i decided to make it continuous and here's my code although i'm getting a syntax error
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Heartless here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
    /**
     * Act - do whatever the Heartless wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
public class Heartless extends Actor
{
    HeartlessBlast heartlessblast = new HeartlessBlast();
    private int shotDelay = 0;
    private int JumpChance = 0;
    private int vspeed = 0;
    private int acceleration = 1;
    boolean CanJump;
    private Bar healthBar;
  
    public void act() 
    {
        fall();
        healthBar.setLocation(getX(), getY());  
        randomjump();
        fap();
        shoot();
        hit();
       
        
    }

    public Heartless()
     {  
             
     
        healthBar = new Bar("", "", 100, 100);  
        healthBar.setShowTextualUnits(false);  
        healthBar.setBarWidth(30);  
        healthBar.setBarHeight(3);  
        healthBar.setMaximumValue(70);
        healthBar.setValue(70);
        healthBar.setBreakValue(10); 
    }  
      
      public void fap()
    {
         getWorld().addObject(heartlessblast, getX(), getY());  
    }
    
    public void shoot()
    {
        if(shotDelay >= 100)
        {
            getWorld().addObject(new HeartlessBlast(), getX(), getY());
            shotDelay = 0;
        }
        shotDelay++;
    }
   public boolean isOnGround()
    {
        Clone Window = (Clone) getWorld();
        if(getY() + (getImage().getHeight() / 2) >= (Window.getHeight() -1)) {
             vspeed = 0; return true;
        }
        return false;
    }
   public void randomjump()
   {
       if( isOnGround() && Greenfoot.getRandomNumber(100) ==3)
       {
           jump();
        }
    }
    public void jump()  
   {  
     vspeed = -10;  
     fall();  
   }  
   public void fall()  
   {  
     setLocation ( getX(), getY() + vspeed);  
     vspeed = vspeed + acceleration;  
   }  
      protected void addedToWorld(World world)  
    {  
        world.addObject(healthBar, getX()-0, getY()-0);  
    }  
   public void hit()
   {
         Actor kiblast = getOneIntersectingObject(KiBlast.class);  
        if(kiblast != null)  
        {  
            healthBar.subtract(10);  
            getWorld().removeObject(kiblast);
        }  
           if(healthBar.getValue() == 0)  
        {    
        World world = getWorld();
            Clone clone = (Clone)world;
        ScoringPoints scoringpoints = clone.getScoringPoints();
        scoringpoints.addScore();
        getWorld().addObject(LastHeartless.class);
        getWorld().removeObject(healthBar);  
        getWorld().removeObject(this);
        }  
    }
}
danpost danpost

2014/12/3

#
You say you are getting a syntax error ... what is it ????
cloud41910 cloud41910

2014/12/3

#
method addObject in class greenfoot.World cannot be applied to given types; required: greenfoot.Actor,int,int found: java.lang.Class<LastHeartless> reason: actual and formal argument lists differ in length
cloud41910 cloud41910

2014/12/3

#
That's what i'm getting
danpost danpost

2014/12/3

#
In line 105 above, you are calling the 'addObject' method of the World class. It requires an Actor object and two location coordinates to place that actor at. You are only giving a Class, 'LastHeartless.class'. The method is not going to create the actor for you and place it randomly in the world because you did not specify where.
cloud41910 cloud41910

2014/12/3

#
I got it now thanks for helping me out
You need to login to post a reply.