Lesson 27: Virtual Pet with Sprite Lab
Overview
In this lesson, students will create an interactive Virtual Pet that looks and behaves how they wish. Students will use Sprite Lab's "Costumes" tool to customize their pet's appearance. They will then use events, behaviors, and other concepts they have learned to give their pet a life of its own!
Purpose
This lesson allows students to apply programming concepts from prior lessons in a more creative context. For example, students will use a variable to store their pet's "happiness" as an integer, which should help them understand how variables can be used in other applications. Last, completing this lesson should prepare students to engage with the open-ended final project.
Agenda
Warm Up (15 min)
Main Activity (30 min)
Wrap Up (15 min)
View on Code Studio
Objectives
Students will be able to:
- Create an interactive virtual pet using events, behaviors, variables, and custom art.
- Program solutions to problems that arise when designing a virtual pet, like feeding it or monitoring its happiness.
Preparation
- Play through the puzzles to find any potential problem areas for your class.
- Make sure every student has a journal.
Links
Heads Up! Please make a copy of any documents you plan to share with students.
For the Students
- Think Spot Journal - Reflection Journal
Support
Report a Bug
Teaching Guide
Warm Up (15 min)
Introduction
Revisit events and behaviors in programming. Additionally, introduce the Sprite Lab "Costumes" tool that allows students to draw their own costumes.
Review: Ask students questions about events and behaviors. Show them the Alien Dance Party mini-project (from the Events with Sprite Lab lesson) as an example.
- Do you remember what an event is?
- Can you name any of the events that you used to make the aliens dance? What do they do?
when clicked
when blue alien touches pink alien
when arrow pressed
- Do you remember what a behavior is?
- Can you remember some of the behaviors you used to make the aliens dance? What do they do?
patrolling
jittering
spinning right/left
Display: Begin by showing Puzzle 1 of today's lesson to your students.
Think/Pair: Ask students to predict what will happen when the code is run, and to discuss with their neighbors. Run the code, and discuss the outcome.
Display: Show Puzzle 2. Briefly demonstrate how to do the following:
- Navigate between the Code and Costumes tabs.
- Draw a costume.
- Choose a costume from the costume library.
- Change the virtual pet's sprite's costume to a custom one.
Main Activity (30 min)
Goal: Today, students will be creating their own virtual pet! They will begin by drawing or selecting a new costume for a sprite. Then they will create events that cause actions and behaviors upon interaction.
Teaching Tip
Encourage students with questions/challenges to start by asking their partner. Unanswered questions can be escalated to a nearby group, who might already know the solution. Have students describe the problem that they’re seeing:
- What is it supposed to do?
- What does it do?
- What does that tell you?
Online Puzzles
Transition: Move students to their machines. Encourage students to follow the instructions for each puzzle. Help them realize that this is a creative activity, intended to help them learn Sprite Lab. It is not an assessment activity of any sort.
Reminder: If puzzles are sharable, remind the students to only share their work with their close friends or family. For more information watch or show the class Pause and Think Online - Video.
Wrap Up (15 min)
Journaling
Having students write about what they learned, why it’s useful, and how they feel about it can help solidify any knowledge they obtained today and build a review sheet for them to look to in the future.
Journal Prompts:
- What was today's lesson about?
- How do you feel about today's lesson?
- What other options would you like to be able to have your pet do?
Student Instructions
Free Play: Whoa! Check out this cool pet!
While reading the code below, ask yourself:
- How do you command the pet to move?
- What happens when the pet touches the ice cream cone? How about the pepper?
- How is the
energy
variable used? How can you check the pet's currentenergy
value?
Run the code and play with the pet! When you are done, click Finish.
Teaching Tip
This lesson contains a mini-project called Virtual Pet. This progression may feel very different from what has come earlier in the course for you as well as your students. These levels have some new characteristics you may want to explore before starting.
- The code your students write in one level will automatically transfer over to the other levels. This allows them to build gradually and iterate on their ideas as they learn.
- These levels allow for more open-ended creativity. Empower your students to determine for themselves when they have completed each task. There is no one right answer!
- Example solutions are available for this step of the progression which can be viewed by opening the teacher panel to the right.
Student Instructions
Now it's your turn to create your own virtual pet! Start by giving it a look you like.
- Click the Costumes tab at the top-left of your screen (next to Code).
- Edit the starting costume, or add a new one that you like.
- Change the sprite's costume to your own in the code below.
- Click Run to see your pet's new look!
Teaching Tip
This lesson contains a mini-project called Virtual Pet. This progression may feel very different from what has come earlier in the course for you as well as your students. These levels have some new characteristics you may want to explore before starting.
- The code your students write in one level will automatically transfer over to the other levels. This allows them to build gradually and iterate on their ideas as they learn.
- These levels allow for more open-ended creativity. Empower your students to determine for themselves when they have completed each task. There is no one right answer!
- Example solutions are available for this step of the progression which can be viewed by opening the teacher panel to the right.
Student Instructions
Create events to make your pet move on command!
Start by using the while up key pressed event block along with the move in direction action block to make your pet move North while the up arrow is pressed.
Repeat the above for the other three directions (South, West, East) and arrow keys (down, left, right)!
Teaching Tip
This lesson contains a mini-project called *Virtual Pet. This progression may feel very different from what has come earlier in the course for you as well as your students. These levels have some new characteristics you may want to explore before starting.
- The code your students write in one level will automatically transfer over to the other levels. This allows them to build gradually and iterate on their ideas as they learn.
- These levels allow for more open-ended creativity. Empower your students to determine for themselves when they have completed each task. There is no one right answer!
- Example solutions are available for this step of the progression which can be viewed by opening the teacher panel to the right.
This level will validate a student’s code by checking that the following conditions have been met: * Students must have at least three sprites.
Student Instructions
Let's make some wandering food!
- Add two sprites to your world.
- Make one sprite look like what your pet likes to eat, and the other look like what it doesn't like to eat.
- Make each food sprite begin the wandering behavior immediately after it appears.
Teaching Tip
This lesson contains a mini-project called Virtual Pet. This progression may feel very different from what has come earlier in the course for you as well as your students. These levels have some new characteristics you may want to explore before starting.
- The code your students write in one level will automatically transfer over to the other levels. This allows them to build gradually and iterate on their ideas as they learn.
- These levels allow for more open-ended creativity. Empower your students to determine for themselves when they have completed each task. There is no one right answer!
- Example solutions are available for this step of the progression which can be viewed by opening the teacher panel to the right.
Student Instructions
Use the when touching block with the jump to location block to simulate "eating" in your virtual world!
- Create an event that makes one of your food sprites jump to a random location when your pet touches it.
- Repeat the above for the other food sprite.
Teaching Tip
This lesson contains a mini-project called Virtual Pet. This progression may feel very different from what has come earlier in the course for you as well as your students. These levels have some new characteristics you may want to explore before starting.
- The code your students write in one level will automatically transfer over to the other levels. This allows them to build gradually and iterate on their ideas as they learn.
- These levels allow for more open-ended creativity. Empower your students to determine for themselves when they have completed each task. There is no one right answer!
- Example solutions are available for this step of the progression which can be viewed by opening the teacher panel to the right.
Student Instructions
Use the set variable block along with the change variable block to make eating food affect your pet's energy! The more energy it has, the faster it moves!
- Set the variable
energy
to 5 when the program starts. - When your pet eats food it likes, add 1 to
energy
. - When your pet eats food it doesn't like, set
energy
back to 5. - Change each arrow key event so that your pet now moves
energy
pixels instead of a specific number.
Teaching Tip
This lesson contains a mini-project called Virtual Pet. This progression may feel very different from what has come earlier in the course for you as well as your students. These levels have some new characteristics you may want to explore before starting.
- The code your students write in one level will automatically transfer over to the other levels. This allows them to build gradually and iterate on their ideas as they learn.
- These levels allow for more open-ended creativity. Empower your students to determine for themselves when they have completed each task. There is no one right answer!
- Example solutions are available for this step of the progression which can be viewed by opening the teacher panel to the right.
Student Instructions
You can check your pet's energy
value with the print block, a new block found in the World
category!
Create an event that makes the value of energy
be printed when the pet sprite is clicked.
Teaching Tip
This lesson contains a mini-project called Virtual Pet. This progression may feel very different from what has come earlier in the course for you as well as your students. These levels have some new characteristics you may want to explore before starting.
- The code your students write in one level will automatically transfer over to the other levels. This allows them to build gradually and iterate on their ideas as they learn.
- These levels allow for more open-ended creativity. Empower your students to determine for themselves when they have completed each task. There is no one right answer!
- Example solutions are available for this step of the progression which can be viewed by opening the teacher panel to the right.
Student Instructions
Free Play: Your virtual pet is VIRTUALLY AWESOME!
What more can you do? Try these ideas:
Change the background to a color or an image.
Print more! Try printing "Yum! Energy increased!" when the pet eats food it likes, or "Yuck! Energy reset!" when it eats food it doesn't like.
Add another sprite that interacts with your pet in a different way. How about a toy sprite?
Add another variable that can affect your pet or the world. What might happiness
or age
do?
* Experiment with behaviors! Try editing the wandering behavior to slow down or speed up the food sprites (hint: their "speed" is currently 5...).
Standards Alignment
View full course alignment
CSTA K-12 Computer Science Standards (2017)
AP - Algorithms & Programming
- 1B-AP-10 - Create programs that include sequences, events, loops, and conditionals.
- 1B-AP-12 - Modify, remix or incorporate portions of an existing program into one's own work, to develop something new or add more advanced features.