Alice Lab 4 (Methods, If/Else, Events, and While Loops)



Download 242.91 Kb.
Page1/4
Date26.03.2021
Size242.91 Kb.
#124696
  1   2   3   4

Alice Lab 4
(Methods, If/Else, Events, and While Loops)

Part 1:


We’ll start with a simple loop. First, create a scene with a horse (from the animals gallery), a fence (from the building gallery), and Kelly (from the people gallery. Position them as follows:

This actually looks easier than it is. The fence and the horse should be fairly easy to position using the positioning buttons below the scene and in the upper right corner



Getting Kelly to appear as though she is sitting on the horse, however, takes a bit more work. To do this, I selected Kelly from the objects in my world (on the left side). I then selected lower body. On the right side, under the buttons, I chose affect subparts:



Now very carefully select Kelly’s right thigh and position it. Then select her right calf and position it. Finally, if necessary, click on and position her foot.



For Kelly’s left leg, select leftLeg under the Kelly object on the upper left side. Then Choose properties, and next to isShowing, choose false:

Finally, since Kelly is sitting on the horse, we want to make sure that if the horse moves, Kelly moves as well. To do this, select Kelly from the objects on the left side. Then select properties, and then select horse-> the entire horse:



So far so good.

Now write a method that makes the horse do one gallop: I turned both front legs back .125, and both back legs forward .125, then turned both front legs backward .25 and both back legs forward .25, then both front legs frontward and both back legs frontward .125. Feel free to play with the upper and lower legs as well to make it more realistic.

Test by making an event ( in the upper right side of window) such that when the world starts, do the horse.gallop method. Now hit play and see if this does what you want. If it doesn’t, play with it until it does.

Next write a jump method for the horse that makes the horse spread his legs straight out, go up 1 meter, and go forward 1.5 meters, then land with its legs down again.

Test this as you did your horse.gallop method.

Now we’ll put it all together. Create a brand new method under horse called gallopandjump. In this method you want to select do in order. First have the horse orient to the fence’s top Crossbar 2 (using the orient to method under horse methods). Now drag in the do together control statement. The first thing you want to do inside do together is use the move toward method to move the horse toward the fence’s top crossbar 2 until you are within .5 meters of the fence’s top crossbar2 (you will use the technique for calculating distance you used in Alice lab 2.) At the end of this command, select more, then duration, then make the duration really long (like 6 or 7 seconds using the other option at the bottom of the drop-down menu).

Next we will add a loop. We could just drag the horse.gallop method under the horse.move method above, but the horse’s legs would only gallop once, then the horse would continue to move forward, but its legs would be still. That’s not what we want. We want the horse to do the gallop method again and again until the horse is within .5 meters of the fence (which is where he’ll jump over the fence using your jump method). To make the horse do the gallop method over and over again until he’s within a certain distance of the fence, we’ll use a while loop.

1. Drag While (From the bottom menu) right under the horse.move toward method inside the do together statement. Select True

2. Select the World object (top left), then functions (bottom left) to get math.

3. Drag a over True. Select 1, < 0.5.

4. Now select the horse object (from above, left).

5. Under functions, select horse distance to. Drag that over the 1, then pick fence, then top crossbar 2



Download 242.91 Kb.

Share with your friends:
  1   2   3   4




The database is protected by copyright ©www.essaydocs.org 2023
send message

    Main page