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

2016/10/25

im trying o make this car constantly move forward

hockeydude1155 hockeydude1155

2016/10/25

#
public class Car extends Actor
{
    boolean gameStarted = false;
    public void act() 
    {
        // Add your action code here.
        if(Greenfoot.isKeyDown("w"))
        {
            gameStarted = true;
        } 
        while (gameStarted == true)
        {
            move (6);
        }
        if (Greenfoot.isKeyDown("a"))turn(-6);
    }    
}
hockeydude1155 hockeydude1155

2016/10/25

#
every time I try to run it Greenfoot stops working
danpost danpost

2016/10/25

#
hockeydude1155 wrote...
every time I try to run it Greenfoot stops working
Once you press the "w" key, the 'while' loop will execute repeatedly -- for ever, as the value of 'gameStarted' remains true. Try 'if' instead of 'while'.
Saladman0 Saladman0

2016/10/25

#
u need to do dank meme
You need to login to post a reply.