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

2014/10/2

i'm trying to make something move back and forth but its not working

DragonGirl DragonGirl

2014/10/2

#
this is my code but like i said it's not working
    public void moveAround() 
    {
        move(4);
        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);
    }
danpost danpost

2014/10/2

#
From what I can tell, your actor will move around and 'bounce' off the edges of the world with the code given.
Super_Hippo Super_Hippo

2014/10/2

#
Do you call the moveAround method from the act method? Saying "it's not working" is not precise at all...
DragonGirl DragonGirl

2014/10/4

#
I think i've figured it out but thanx anyway guys:) i do however have a different question How do i make a character shoot a bullet
danpost danpost

2014/10/5

#
You really need to give more background to your questions. Also, you should at least try something on your own and then, if you come across problems that seem to overwhelm you, post the code you tried with a brief description of what you were trying to do. Asking "How do I make a character shoot a bullet" leaves way to much to guesswork:
You need to login to post a reply.