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

2015/6/18

Increasing speed per click?

lamboa lamboa

2015/6/18

#
I'm trying to make a game that every time you click the criminal, its speed gets higher and higher but am unsure how to do this? This is what I have so far:
    public void criminalMovement()
    {
        if(Greenfoot.getRandomNumber(100) < 10)
        {
            turn(Greenfoot.getRandomNumber(90) - 45);
        }
        if (getX() <= 5 || getX() >= getWorld().getWidth() - 5)
        {
            turn(180);
        }
        if(getY() <= 5 || getY() >= getWorld().getHeight() - 5)
        {
            turn(180);
        }
    }
    public criminalSpeed()
    {
    }
miningmanna miningmanna

2015/6/18

#
The speed of what?
lamboa lamboa

2015/6/18

#
Sorry, I meant the speed that the criminal moves.
wabuilderman wabuilderman

2015/6/18

#
you would have a variable, "speed", and you would increase it by a certain amount whenever the mouse is clicked. If you don't know how to code that, try looking at the API. Here. It would look something like this:
public int speed = 0;
public int speedIncrease = 1;
public void act()
{
     move(speed);
     if(Greenfoot.mouseClicked(this))
     {
          speed += speedIncrease;
     }
}
You need to login to post a reply.