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

2012/5/3

hey how can you an actor walk automatic with this code

martijn13039 martijn13039

2012/5/3

#
hey all, I have make this code so I can drive an actor but what need I change in this code so that another actor (who i can't drive) would walk as the same as this code (but than automatic)
public void processKeys()
    {

        if(Greenfoot.isKeyDown ("left")) {
            setLocation(getX() - 2, getY());
        } 
        else {
            setLocation(getX(),getY());
        }

        if(Greenfoot.isKeyDown ("down")) {
            setLocation(getX(),getY() + 2);
        }
        else {
            setLocation(getX(),getY());
        }

        if(Greenfoot.isKeyDown ("right")) {
            setLocation(getX() + 2,getY());
        }
        else {
            setLocation(getX(),getY());
        }

        if(Greenfoot.isKeyDown ("up")) {
            setLocation(getX(),getY() - 2);
        }
        else {
            setLocation(getX(),getY());
        }
    }
andrewsadik andrewsadik

2012/5/3

#
if your actors move on the world as birds eye view that would work move(); move(); move(); if(atWorldEdge()) turn(79); if(Greenfoot.getRandomNumber(180)<40) { if(Greenfoot.getRandomNumber(2)<1) { turn(5); } else { turn(-5); } }
andrewsadik andrewsadik

2012/5/3

#
0
martijn13039 martijn13039

2012/5/3

#
but andrewsadik this don´t work because an actor can now walk on his had but I want the actor walk as the code I make but than randomly withoud if(Greenfoot.isKewDown(right)); maby now you understand what I mean
martijn13039 martijn13039

2012/5/3

#
I hope you guy understand what I mean if you don´t ask me what you not understand in my question
You need to login to post a reply.