Fly Actor and For Loops
Fly Actor
- Added a
Flyactor as a subclass. - The
Flyclass includes:- A speed variable (integer) set to 2.
- A constructor that sets a random rotation using
setRotationandgetRandomNumber(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
addObjectmethod withnew Fly()to create a new fly in a random location usinggetRandomNumber(getWidth())andgetRandomNumber(getHeight()).
- Use the