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

2013/5/21

Moving help please

Miikku Miikku

2013/5/21

#
How to do turning as standart snake game. Turn always when you press arrow key 90 degrees.
Miikku Miikku

2013/5/21

#
Help?
bourne bourne

2013/5/21

#
Something like:
private boolean pressingLeft = false;
private boolean pressingRight = false;

public void act()
{
    if (Greenfoot.isKeyDown("left"))
    {
        if (!pressingLeft)
        {
            pressingLeft = true;
            setRotation(getRotation() - 90);
        }
    }
    else
        pressingLeft = false;

    if (Greenfoot.isKeyDown("right"))
    {
        if (!pressingRight)
        {
            pressingRight = true;
            setRotation(getRotation() + 90);
        }
    }
    else
        pressingRight = false;
}
Miikku Miikku

2013/5/21

#
Thx
You need to login to post a reply.