previous
contents
next

The Model: Code

  void makeOneStep() {
     xPosition += xDelta;
     if(xPosition < 0 || xPosition >= xLimit) {
        xDelta = -xDelta;
        xPosition += xDelta;
     }
     yPosition += yDelta;
     if(yPosition < 0 || yPosition >= yLimit) {
        yDelta = -yDelta;
        yPosition += yDelta;
     }
  }