In this lab, we will practice with events and arrays. The tutorials in the lab will be presented by the TA step-by-step. However, you are free to work at your own pace on the lab. The lab assignment questions will not be presented by the TA.
This part of the lab is a tutorial to cover events: world events, mouse events, keyboard events, and condition events.
Open the Lighthouse world. Play the world. A world event is of two types: when the world starts (run once at the start) and while the world is running (runs continuously as animation is played). We will add the second type so that the lighthouse light is continually turning around. To add a world event, click on the create new event button and select when the world starts. Right click on this event added and change it to while the world is running. The statement that will make the light turn is in the my first method. Move this code to the during section of the new event.
Keyboard events are of three types: when a key is typed, while a key is pressed, and let the arrow keys move an object. We will add two keyboard events. First, we will let the arrow keys move the boat. Add a new event called let the arrow keys move a subject and make the boat the subject. Second, when the j key is pressed, we will make the boat jump 0.5 meters out of the water and then land back in the water again. Create a when a key is typed event and put a "j" and then make boat move up then down 0.5 meters.
Mouse events are of five types: when the mouse is clicked on something, while the mouse is pressed on something, let the mouse move the camera, let the mouse orient the camera, and let the mouse move objects. We will use two of these. First, we will make the light turn on and off when the user clicks the mouse on the lighthouse. Use a when the mouse is clicked on something event and set it up for the lighthouse object. Second, we will let the mouse move objects in our world.
Condition events occur when some state or variable in the world changes. The three types of condition events are: when a variable changes, while something is true, and when something becomes true. We will add a condition event of when something becomes true that detects when the boat hits the rocks. When it hits the rocks, we will make a thud sound and then move the boat back to its starting location. Answer file: Complete lighthouse world
This tutorial will show how to use lists including adding elements, removing elements, and move all together and move all in order.
Open the Fish school. This world has a school of ten fish. The ten fish are stored in a list object. The world already has a loop that runs five times. In each loop iteration, the fish turn a random direction and swim forward a small amount at the same time. We will make each fish swim forward individually in order as well. Add a for all in order loop and copy the four lines of code that picks a random distance and turn amount and then turns and moves forward those amounts.
We will remove one fish from the school (and the list) every loop iteration. To do this we will have the shark pick one of the fish in the list randomly, swim towards it, and eat it. Eating a fish will remove it from the list and make it "disappear" from the world (by setting its opacity to 0).
You can also use methods to add elements to the list during runtime. One issue is that it is not possible to create objects dynamically (at run-time) in Alice. Answer file: Complete fish school world
Create a world with a helicopter. The helicopter blades should always be turning. Allow the user to move the helicopter up and down with the up/down arrow keys and turn left/right with the left/right arrow keys. The helicopter moves forward as long as the user is pressing the space bar. Note that you cannot just use let the arrow keys move the object as the up/down arrow keys are designed to move the object forwards/backwards by default. It should look something like this video.
In the ring catching game, rings fall from the sky and the user tries to catch them by moving a cone beneath them. Allow the user to move the cone with the mouse. There are five levels. In the first level, 1 ring falls from a random place at a random speed. At the second level, two rings fall at the same time. Keep track of the number of rings caught and missed. You will want to use an array to keep track of the rings. It should look something like this video.
For this lab assignment, submit using Connect the two Alice world files for the questions.