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

2015/5/4

make enemy accelerate when level increase [HELP]

pandu4431 pandu4431

2015/5/4

#
i think i want make my enemy / Asteroid accelerate when level increase can you help me?? i tried some method to add the speed, such like i put "int m=5;" in asteroid
 Level lvl = new Level();
    int m =5;
public boolean AtWorldEdge()  
{  
    double w=getImage().getWidth(),h=getImage().getHeight();  
    return getX()==w || getY()==h || getX()==getWorld().getWidth()/-(w+2) || getY()==getWorld().getHeight()-(h+2);  
}  

    /**
     * Act - do whatever the rock wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        
        setLocation(getX(), getY()+6);
        
        if (AtWorldEdge()) {
            int ran = Greenfoot.getRandomNumber ( 500 );
            getWorld().addObject( new Asteroid(), ran, 0);
            getWorld().removeObject(this);
           
        }
}
and then i add in the level method
public void addLevel(){
        level++;
        World myWorld = getWorld();
           Asteroid as = new Asteroid();
           as.m+=6;
      
    }
pandu4431 pandu4431

2015/5/4

#
ups, in Asteroid in act() should "setLocation(getX(), getY()+m);"
You need to login to post a reply.