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

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?
  • Free Play
  • 1
  • (click tabs to see student view)
View on Code Studio

Student Instructions

Free Play: Whoa, check out this cool pet! But wait, this isn't an ordinary pet. It's a...

VIRTUAL PET

  • Unlike regular pets, virtual pets live inside computers, so they only listen to code!
  • A virtual pet can be a dog, a guinea pig, a dinosaur, a robot, a rock, an alien... anything!

Read and run the code below, then observe what the pet does. Try changing some of the code to produce different results!

When you're done, click Finish.

View on Code Studio

Student Instructions

Now it's your turn to create your own virtual pet! Let's start by giving it a look you like.

  1. Click the Costumes tab.
  2. Draw your own costume, or choose one from the library.
  3. In the code below, change the pet sprite's costume to your own.
View on Code Studio

Student Instructions

Your pet looks hungry. Let's prepare it some food!

  1. Add a new sprite to the screen at a random location.
  2. Create or select a costume that looks like food your pet enjoys eating.
  3. Assign your new sprite the food costume.
View on Code Studio

Student Instructions

Let's make it so your pet can "eat" its food. Add an event that makes the food jump to a random location when your pet touches it.

View on Code Studio

Student Instructions

What does your pet not like to eat?

  1. Add a new sprite at a random location. Make its costume be food your pet doesn't like to eat.
  2. Make an event that causes the disliked food to jump to a random location when your pet touches it.
View on Code Studio

Student Instructions

When your pet eats food it likes, it should become happier. When your pet eats food it doesn't like, it should become less happy.

  1. Set the variable happiness to 0 when the program starts.
  2. When your pet eats food it likes, change happiness by 1.
  3. When your pet eats food it doesn't like, change happiness by -1.

We'll learn about how we can "see" your pet's happiness in the next step!

View on Code Studio

Student Instructions

How happy is your pet? Let it speak for itself!

Print your pet's happiness level each time it eats food. Use this block, found in the "World" toolbox category: print text block

View on Code Studio

Student Instructions

What more can you make your pet do? Try these ideas: Change the background to something more habitable for your pet. Add another food sprite, and modify happiness by any value you want when your pet eats it. Edit the wandering behavior so that your pet moves slower or faster (hint: distance). Make your pet perform a different behavior at the start, or change behaviors when certain foods are eaten. * Make one of your food sprites controllable by adding keypress events (example: press up to go up, down to go down).

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.

Cross-curricular Opportunities

This list represents opportunities in this lesson to support standards in other content areas.

Common Core English Language Arts Standards

SL - Speaking & Listening
  • 4.SL.1 - Engage effectively in a range of collaborative discussions (one-on-one, in groups, and teacher-led) with diverse partners on grade 4 topics and texts, building on others’ ideas and expressing their own clearly.
  • 4.SL.6 - Differentiate between contexts that call for formal English (e.g., presenting ideas) and situations where informal discourse is appropriate (e.g., small-group discussion); use formal English when appropriate to task and situation.
W - Writing
  • 4.W.6 - With some guidance and support from adults, use technology, including the Internet, to produce and publish writing as well as to interact and collaborate with others; demonstrate sufficient command of keyboarding skills to type a minimum of one page in a

Common Core Math Standards

MP - Math Practices
  • MP.1 - Make sense of problems and persevere in solving them
  • MP.2 - Reason abstractly and quantitatively
  • MP.5 - Use appropriate tools strategically
  • MP.6 - Attend to precision
  • MP.7 - Look for and make use of structure
  • MP.8 - Look for and express regularity in repeated reasoning

Next Generation Science Standards

ETS - Engineering in the Sciences
ETS1 - Engineering Design
  • 3-5-ETS1-1 - Define a simple design problem reflecting a need or a want that includes specified criteria for success and constraints on materials, time, or cost.
  • 3-5-ETS1-2 - Generate and compare multiple possible solutions to a problem based on how well each is likely to meet the criteria and constraints of the problem.