So my lab in my computer science class is to write code that will make a circle take 10 steps (5 pixels a step) then change direction randomly from the four cardinal directions (Up, Left, Right, Down) and go 10 steps etc. This is how far I am now. Please Please help!
int myX = 300; int myY = 300; int myXSpeed = 5; int myYSpeed = 5; int choice = 10;
in each of the "if" statements with rand. I put myX = rand * myXSpeed, which didn't work. I'm not entirely clear what belongs there. does it have something to do with the println figures. I'm sorry for my naivety I'm very new at this.
The code above have to be fixed: rand values go from 0 to 3, not 1 to 4. It can also use a switch () statement instead of the ifs, or at least use else between the statements... The println() just shows the current value of rand (on each frame). Depending on rand (the cardinal direction), you have to change myX or myY, with opposite speeds (ie. -mySpeed vs. mySpeed on left vs. right).
Leave a comment on PhiLho's reply
Change topic type
Link this topic
Provide the permalink of a topic that is related to this topic