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

2013/4/16

Stopping the scenario.....

1
2
JetLennit JetLennit

2013/4/16

#
and remove all my additions but the act method
jennnnay24 jennnnay24

2013/4/16

#
thank you all!
isaunders7289 isaunders7289

2013/4/17

#
How do you make the wombats face random directions when compiled in the world
JetLennit JetLennit

2013/4/17

#
Could you show the wombat code?
isaunders7289 isaunders7289

2013/4/17

#
/** * Sets the direction we're facing. The 'direction' parameter must * be in the range . */ public void setDirection(int direction) { if ((direction >= 0) && (direction <= 3)) { this.direction = direction; } switch(direction) { case SOUTH : setRotation(90); break; case EAST : setRotation(0); break; case NORTH : setRotation(270); break; case WEST : setRotation(180); break; default : break; } }
danpost danpost

2013/4/17

#
isaunders7289 wrote...
How do you make the wombats face random directions when compiled in the world
First, simplify your 'setDirection' method to the following:
private void setDirection(int direction)
{
    if (direction < 0 || direction > 3) return;
    this.direction = direction;
    setRotation(90 * direction);
}
Then, if you do not already have Wombat constructor in your code, add the following to the Wombat class:
public Wombat()
{
    setDirection(Greenfoot.getRandomNumber(4));
}
If you already had a Wombat constuctor, just append the 'setDirection' line to it.
You need to login to post a reply.
1
2