TopNested LoopsTalking to animated objects

Talking to animated objects

We looked at a version of the basketball program in which the ball bounces to see how the main program could interact with an animated object. In Frogger, the vehicles and frog will also interact.

The dribbler class has a method stopDribbling which simply sets the variable moving equal to false which in turn quickly causes the loops to terminate.

One interesting thing that becomes obvious in the while loops of the bouncing ball start method is a feature of many loops -- they tend to be preceded by one or more statements that "initialize" the variables that are changed within the loop. That is, we have described the general structure of most loops as:

  while ( some condition ) {
     do something depending on some variables
     change the variables used
  }

a more complete template would be:

  set initial values of variables used in loop.
  while ( some condition ) {
     do something depending on some variables
     change the variables used
  }

Yet another example using animations: DrawBanner


TopNested LoopsTalking to animated objects