???

imageUnit 5
Game Animation

Unit Overview

Students define functions that map position n to position n+1, allowing them to move their dangers, targets, and projectiles.

State Standards

See our Standards Document provided as part of the Bootstrap curriculum.

Types

Functions

Number

+ - * / sq sqrt expt

String

string-append string-length

Image

rectangle circle triangle ellipse star text scale rotate put-image

Bug Hunting

Overview

Learning Objectives

    Product Outcomes

      Standards

        Materials

        • Pens/pencils for the students, fresh whiteboard markers for teachers

        • Class poster (List of rules, language table, course calendar)

        • Language Table (see below)

        • Bug Hunting [Bugs.rkt from source-files.zip | WeScheme] file preloaded on students’ machines, in front

        Preparation

          Bug Hunting (Time 20 minutes)

          • Debugging is an important part of programming, so it’s a good idea to practice finding bugs in code.

            Open the Bug Hunting program in a new window, and see if you can find the bug in each expression. Click "Run" and read the error message carefully! After you fix each one, clicking Run will show you the error message for the next bug.

            Make sure students understand that the goal is not to FIX the bugs, but rather just to find them.

          Danger Movement

          Overview

          Students model animation in the coordinate plane, and write a simple linear function that animates their Danger.

          Learning Objectives

            Product Outcomes

              Standards

                Materials

                • Pens/pencils for the students, fresh whiteboard markers for teachers

                • Class poster (List of rules, language table, course calendar)

                • Language Table (see below)

                Preparation

                  Danger Movement (Time 30 minutes)

                  • imageThe dimensions of your videogame are 640x480, and each character is placed on the screen at a set of (x,y) coordinates. Your Target (T), Player (P) and Danger (D) each move along the x- or y-axis, having their x- or y-coordinate changed according to an animation function. These animation functions will start off simple: they take in the current x- or y-coordinate, and produce the next x- or y-coordinate. Later on you’ll be able to adapt them to create more sophisticated motion, using both the x- and y-coordinates.

                  • Turn to Page 15 for update-danger.
                    • Read the word problem carefully, and what the function takes in.

                    • Fill out the Contract and Purpose Statement for the function, using what you circled to help you choose the Domain.

                    • Write two Examples for the function.

                    • Circle and label what varies between those examples, and label it with a variable name.

                    • Define the function.

                    If students are working on their own, check their work to make sure every last step is being executed correctly. If the class is working through it together, be sure to ask students to justify each steps in terms of a prior step.

                  • Putting all of these together, update-danger is defined by: (Note: you may have slightly different Examples or variable names.)

                  • Now it’s time to animate the Target, which moves in the opposite direction.

                    Turn to Page 16 for update-target.
                    • Read the word problem carefully, and what the function takes in.

                    • Fill out the Contract and Purpose Statement for the function, using what you circled to help you choose the Domain.

                    • Write two Examples for the function.

                    • Circle and label what varies between those examples, and label it with a variable name.

                    • Define the function.

                    For students who finish these quickly, have them experiment with making the Target and Danger move faster or slower, or change direction altogether. Be sure that they are typing in Examples, and updating those examples to keep up with any changes to their definition.

                  Projectile Movement

                  Overview

                  OPTIONAL: students discover that the "mystery" definitions in the game are actually used to add projetiles, and adapt these definitions to add a custom projectile and projectile animation to their game.

                  Learning Objectives

                    Product Outcomes

                      Standards

                        Materials

                          Preparation

                            Projectile Movement (Time 15 minutes)

                            • This game template also has a mystery object, which is defined at the very bottom of the screen. The "mystery" is actually a projectile, which will be set to the Player’s position whenever the spacebar is pressed. As you can see, mystery is defined to be a small gray star, but you can change that to be any image you like. If you have a game in which the player is a monkey, you could change the definition of mystery to be a bitmap of a banana, so that the monkey will throw bananas every time you hit the spacebar. A game that takes place in space could have an alien throwing crystals, or a sports game might involve an athlete thowing a ball.
                              • Change the definition for mystery, so that your projectile looks the way you want it to. Don’t forget to use scale and rotate if you need to change the image slightly.

                              • Use the Design Recipe to write update-mystery, so that the projectile moves to the left or right. Hint: this will be very similar to your solutions for update-danger and update-target!

                            Closing

                            Overview

                            Learning Objectives

                              Product Outcomes

                                Standards

                                  Materials

                                    Preparation

                                      Closing (Time 5 minutes)

                                      • Congratulations - you’ve got the beginnings of a working game! However, several things remain unfinished:

                                        • The Player doesn’t move

                                        • When the Target and Danger move offscreen, they never come back

                                        • Nothing happens when the Player collides with the Danger or Target

                                        The next few lessons will extend what you know about functions, so that you can define functions to implement each of these features.

                                      imageBootstrap by Emmanuel Schanzer is licensed under a Creative Commons 3.0 Unported License. Based on a work at www.BootstrapWorld.org. Permissions beyond the scope of this license may be available at schanzer@BootstrapWorld.org.