In Exercise 9, why is it better to use an event instead of a loop to make the pterodactyl continue flying while the world is running?
In general, when should events be used instead of loops in computer programming?
Exercise 9
The Animals object gallery contains a pterodactyl. The student data files for this book have a world named flapping pterodactyl with a character-level method named flap that will cause the pterodactyl to flap its wings. Do each of the following:
a. Create a method called pterodactyl fly that will make the pterodactyl move forward while flapping its wings, and then create a loop in world.my first method to make the pterodactyl fly away.
b. Add controls to your pterodactyl world so that the user can steer the pterodactyl.
c. Add a user control to point the camera at the pterodactyl when the spacebar is pressed.
d. Modify the world to use an event instead of a loop to make the pterodactyl fly while the world is running. You might need to refer back to Chapter 3, which covers events.