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

2021/6/11

random direction

How do i make it so when there is an intersection, there is a randomisation of which direction to take? if(earthFront()) { if(!earthToLeft()) setDirection(LEFT); move(5); } //Other directions for above, right and below apply too (there are four options for direction)
danpost danpost

2021/6/11

#
First list the possible directions available at the moment. Then randomly choose an index from the size of the list. Or: Use a boolean array of size 4. Index times 90 degrees is direction. Mark all valid directions true, else false. Count true values. Get random number on that count. Count true values to that random number. Use index of where you end up to set direction.
Thanks bro. One more thing how would you code for when two characters intersect, the ghost must kill the player? Available commands: intersects(Character), getClara(), makeClaraDead()
danpost danpost

2021/6/11

#
Maybe:
if (intersects(getClara())) makeClaraDead();
You need to login to post a reply.