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

2017/12/15

how to fix this code for class moves very choppy need help quick

roonie01 roonie01

2017/12/15

#
public class forerunner extends Actor
{
    int shoot=0;
    public void forerunner()
    {
        
       
    }
    /**
     * Act - do whatever the forerunner wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        if(isAtEdge())
        {
          turn(180);
        }
         movement();
         shoot();
    }    
    public void shoot()
    {
        shoot++;
        if(shoot==100)
        {
           getWorld().addObject(new Bullet2(),getX(),getY());
        }
    }
    public void movement()
    {
        move(Greenfoot.getRandomNumber(5));
    }
}
Super_Hippo Super_Hippo

2017/12/15

#
Why do you use the random number in line 32? What are you trying to do? If you want a random speed which stays the same, you have to save one random number in a variable and use this variable as the speed. Right now, it will create a new random number each time the method is executed.
roonie01 roonie01

2017/12/15

#
oh thanks so much man your a life saver that's exactly what I was trying to do
You need to login to post a reply.