Fly Actor and For Loops

Fly Actor

  • Added a Fly actor as a subclass.
  • The Fly class includes:
    • A speed variable (integer) set to 2.
    • A constructor that sets a random rotation using setRotation and getRandomNumber (between 0 and 360).
    • An act method that makes the fly move at its defined speed.

For Loops

  • Used to repeat a block of code a certain number of times.
  • Syntax:
    • for (int counter = 0; counter < 50; counter = counter + 1) { // Code to be repeated }
      • int counter = 0: Initializes a loop counter.
      • counter < 50: Condition to keep the loop running.
      • counter = counter + 1: Increments the counter each time the loop runs.
  • Adding flies inside a loop:
    • Use the addObject method with new Fly() to create a new fly in a random location using getRandomNumber(getWidth()) and getRandomNumber(getHeight()).