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

2016/10/26

how to reset car back when it hits the border

hockeydude1155 hockeydude1155

2016/10/26

#
public class Car extends Actor
{
    boolean gameStarted = false;
    public void act() 
    {

        if(Greenfoot.isKeyDown("w"))
        {
            gameStarted = true;
        } 
        if (gameStarted == true)
        {
            move (6);
        }
        if (Greenfoot.isKeyDown("a") && gameStarted == true)turn(-6);
        Actor a = getOneIntersectingObject(tire.class);
        if(a != null) {
            setLocation(202,521);
            setRotation(0);
            gameStarted = false;
            return;
        }    
}
}
I haven't tried any code yet idk what to do
danpost danpost

2016/10/26

#
The code from line 18 to 21 resets the car. Add the condition to line 17:
if (a != null || isAtEdge())
You need to login to post a reply.