Lesson: Fish Tank
Time: 45+ mins
IntroductionIn this lesson, campers will learn how to use code blocks to program Actors to detect distance from other Actors as they create fish-themed projects and solve a puzzle module. Additionally, campers will be introduced to functions. Coding concepts include distance, comparison operators (like ">"), and calling functions.
- Computer, laptop, or tablets (1 per camper)
New Code Blocks
: Start the program when the play button is selected. : Move the Actor to the specified x- and y-coordinates on the Stage. : Keep repeating the blocks inside this loop forever. : If the condition is true, then run the code inside the block. : Make the Actor repeat this loop until a true or false (boolean value) determines when the block should stop repeating the code inside it. : Move the Actor a specified number of units. : Rotate the Actor to the right (clockwise) by a specified amount. : Rotate the Actor to the left (counter-clockwise) by a specified amount. : Pause the program for a specific number of seconds. : Make the Actor disappear from the screen. : React when the specified parameter is detected. : Stop running the current script. : Point the Actor towards the specified parameter. : This is a comparison operator that returns true if the first value is greater than the second value, and returns false otherwise. "<" returns true if the first value is less than the second value. : This is a math operator that returns a random number between the two parameters.
- Code: The language that tells a computer what to do
- Sequence: The order in which steps or events happen
- Command: A specific action or instruction that tells the computer to do something
- Actor: A Tynker character or object that can talk and interact with others
- Stage: The background of the project where the Actors are placed
- Loop: An action that repeats one or more commands over and over
- Counting loop: A loop that repeats one or more commands a specific number of times
- Infinite loop: A loop that repeats forever and does not end until the program stops
- Function: A sequence of commands that can be run together as if it were a single command
- Condition: A logical expression that evaluates to true or false
- Conditional statement: A type of statement that executes different parts of the code based on whether a logical expression evaluates to true or false
- Use code blocks to program Actors to detect distance from other Actors
- Use functions to reuse groups of code blocks
- Apply coding concepts to solve a puzzle
- Create a Get the Treasure game
Getting Started (5 minutes)
- Ask campers, "How do you think Actors know where other Actors are located in video games?" Explain that characters are programmed to track each other and gauge distances from one another. Also explain that we'll learn that creating a function is an easy way to reuse a set of code blocks. Point out that we'll explore these concepts in today's lesson.
Coding Activities (40+ minutes)The lessons are intended for self-directed learning. Your role will be to facilitate as campers complete the Fish Tank modules on their own:
1. Concepts (Video)
- A friendly pirate introduces three coding concepts:
- Distance- Campers will observe how the "distance to" code blocks affects two Actors. Make sure campers are analyzing the given code.
- Stop All- Campers are instructed to click (for web)/tap (for mobile) the "stop all" code block to make the robot and Codey stop moving.
- ">" Operator- Campers are asked to provide a number between 1-100 and see how it affects Codey. Make sure that campers understand that they ">" symbol means "greater than."
- Calling Functions- Campers learn that functions can be used to save time because they don't have to rewrite code for multiple Actors--they can use functions instead.
- In this tutorial, campers will learn how to make schools of fish follow each other.
- Coding activities include adding an undersea background and school of fish Actors to the Stage; setting the starting point for the school of fish 1 Actor; programming the arrow keys (for web) or tilt controls (for mobile); making the school of fish 1 move; programming the game to end when the school of fish 1 Actor touches the edge of the screen; making the school of fish 2 Actor point towards the school of fish 1 Actor and check the distance; and programming the school of fish 3 Actor check the distance and point towards the school of fish 2 Actor.
- Make sure campers are reading the instructions carefully. Were they able to program the school of fish Actors to follow each other? Did the game end when the school of fish 1 Actor touched the edge of the screen?
- In this tutorial, campers will expand on the previous tutorial and learn how to program the school of fish to collect treasure.
- Activities include adding an underwater background and school of fish Actors; programming a function to make the treasure respawn and hide; making the treasure appear in random locations; broadcasting messages; calling the "respawn" function; programming the school of fish 2 Actor to appear after the school of fish 1 Actor collects treasure; and programming the game to end when the school of fish 2 Actor touches the school of fish 1 Actor.
- After campers finish programming their project, ask them to test it out. Did the treasure appear in random locations after the fish ran into it? Did the functions work as expected?
- To solve this puzzle module, campers need to program the treasure to respawn when the fish collect it. Can they navigate the fish and collect four treasure chests without running into the other fish?
- Give a hint: Ask campers…
- What needs to happen when the distance to fishies1 is greater than 300? (Answer: The treasure needs to go to a random screen location.)
- What are some screen location code blocks that we can use for the x-location? (Answer: "Screen left" and "screen right.")
- What are some screen location code blocks that we can use for the y-location? (Answer: "Screen top" and "screen bottom.")
- The treasure needs to become visible after it respawns, so what code block should we use? (Answer: "Show.")
- In this DIY (do-it-yourself) project, campers will follow step-by-step directions and apply what they've learned so far to create their own Get the Treasure game! The goal of the game is to get the treasure while avoiding colliding with the other fish.
- Step 1 of the tutorial includes a completed example. How to play: The fish always swims forward, control where the fish swims using the arrow keys (for web) or tilt controls (for mobile).
- Activities include changing the background, adding two more school of fish Actors, modifying the code, and adding background music.
- Step 6 of the tutorial includes a bonus activity that encourages campers to add a predator Actor that moves around the screen randomly. Campers can try changing the "wait" and movement blocks to adjust the difficulty of their game.
Wrap UpUnplugged Activity: Discussion
- Who can think of another game or project idea that uses Actors detecting distances from other Actors?
- What is something you learned today using Tynker? (Example: We learned how to program Actors to detect distances. We also learned that creating a function allows us to reuse a set of code blocks.)
These student-facing slide presentations help educators seamlessly run Tynker lessons in a virtual or physical classroom setting. Each lesson has its own set of slides that introduce the big ideas, suggest unplugged activities, and include a section for each activity module. While running lesson slides, you can switch back and forth between the activity, the slides, answer keys and other lesson materials.
A sample slide presentation is available for your review. Please log in to view all the class presentations available with your plan..
Lights, Music, Action
Make Games - Animated Greeting Card
Make Games - Music Video
Make Games - Maze Game
Make Games - 2-Player Battle Game
Make Games - Animated Story