Friday, August 31, 2012

More Code Stuff

As I continued with the crab scenario I had many different goals. One was I was trying to make it bounce of the side instead of just stopping. Another on was instead of making the crab walk in a straight line I was going to try to make the crab walk in a crooked line making to more realistic to an actual crab. I did the first one by typing if ( atWorldEdge() turn(17);. This means when the crab hits the side of the world it will turn around and keep moving instead of just stopping.  To make the random movements I had to type if ( Greenfoot.getRandomNumber(100)>10).  The random number can be anything as long as its true I think (this part was a bit confusing). I experimented with different numbers and they usually work but the smaller the number is, the smaller turn the crab makes. So after typing that my crab was able to move like an actual crab. My next goal is trying to get the crab eat a worm. The picture shows how it all looked when it was written in Greenfoot.

No comments:

Post a Comment