80 likes | 219 Vues
This tutorial for CPSC 203 explores key programming concepts through animation exercises. Students will learn how to implement conditional expressions using Boolean values and relational operators, along with randomness to set object sizes. Practical exercises include animating skaters' movements and incorporating a bunny's behavior based on positional changes. Additionally, students will utilize while loops to control the flow of a program, ensuring the robot and fighter interact dynamically within the scene. Clear steps are provided for revision to enhance their programming skills.
E N D
CPSC 203 Tutorial Xin November 22, 2010
Exercise start Skater turns towards skater2 Skater2 turns towards skater Skater moves to pose 2 Skater2 moves to pose 2 Bunny move up by 0.5m Bunny turns legs Skater moves to pose 3 Skater2 moves to pose 3 Bunny move down Bunny turns legs back end
Conditional expression • The condition must be a Boolean value, i.e., True or False. • Use lab3If1.a2w for practice
Using relational operators • ==, !=, >, >=, <, <= Hare’s height <= 2 True False Husky scratch ears Husky barks 2 seconds Husky walks circles equal to hare’s height
randomness • Set the hare’s size to a random size at the beginning • Set the random value between .1 and 1.5
Repeatation • Use lab3Rep.a2w Kick left leg Point Cannon forward Resize by 0.9
While loops • Terminate the loop when certain condition is satisfied
Exercise • Revise the program so that the robot stops when its height > 1 • Add a fighter to your world • Revise your program, so that the fighter is enlarged by 1.2 while the robot is moving, until the fighter is larger than the robot. • The fighter move downwards by half its distance above the robot.