Lesson: Detecting Screen Bounds
Time: 60+ mins
IntroductionIn this lesson, students will create a space shooter game! Additionally, students will learn how to move Actors to different screen locations using random number generators and will learn how to detect screen boundaries.
: React when the specified condition is happening. : If the condition is true, then run the code inside the block. : Move the Actor to the specified location. : Move the Actor to the specified x- and y-coordinates on the Stage. : Point the Actor at the specified degree. : Return a random number between two parameters. : Detect if one Actor is touching a specified Actor, or the edge of the Stage. : Make the Actor repeat this loop until a true or false (boolean) value determines when the block should stop repeating the code inside it. : Make the Actor appear on the screen. : Make the Actor disappear from the screen.
- Use code blocks to move Actors to different screen locations using random number generators
- Use code blocks to make Actors appear and disappear from the Stage
- Computers, laptops, or mobile devices (1 per student) with student account access to Tynker.com
Warm-Up (15 minutes)Lead a mini-discussion with your students:
- Tell students that they are going to create a space shooter game using Tynker!
- Ask students to raise their hand if they’re familiar with space shooter games (e.g., Space Invaders).
- Discuss common features of most space shooter games. (There is an enemy that needs to be destroyed, the spaceship typically shoots out a laser to destroy the enemy, the user needs to navigate the spaceship)
- Ask, "What do you think makes a good space shooter game? Is it the sound effects? Navigating a cool spaceship? Level of difficulty? Having different levels?"
Activities (45 minutes)Facilitate as students complete all Detecting Screen Bounds modules on their own:
1. Asteroid Shooter Example (Example)
- Students will preview a completed game, where they will need to pilot a spaceship!
- Tell students to move the spaceship with the left and right arrow keys (web) or tilt their screen left and right (mobile). Students can shoot the aliens with the spacebar (web) or by tapping the spaceship (mobile).
- In this DIY (do-it-yourself) project, students will follow step-by-step directions to program a spaceship to destroy the evil alien spaceship!
- Students will learn how to make a projectile glide smoothly across the Stage using a "repeat" loop, along with a "move pixels" block, and a "wait" block.
- Students will also use a "hide" code block along with a "touching?" condition to create the illusion of an Actor being destroyed--the alien spaceship will be hidden from view as soon as it is touched by the laser.
- Did students finish early? Direct their attention to the bonus section in the last page of the tutorial, which encourages students to add a sound effect or animation when the alien spaceship is touched by the laser.
- This DIY project showcases a common technique used in video games, which is moving objects from one edge of the screen to the opposite edge to create a seamless looping effect.
- In Tynker, this effect can be created using a "when occurs" event code block to detect when the Actor reaches the bottom edge of the screen. The vertical positioning of the Actor is reset to the top using the "go to" code block, which also randomizes the horizontal positioning using "pick random" with the "screen left" and "screen right" parameters.
- In this puzzle module, student will need to program the spaceship controls so the spaceship can avoid the asteroid and reach the power cell.
- Give a hint: Tell students to set each key to move the spaceship 30 pixels rather than 20.
- Bonus: Ask your students if they can figure out a way to "cheat" in this puzzle. (One possible solution is programming the spaceship to jump 850 units to the right, which will result in an immediate win--no asteroid dodging needed!)
- This asteroid shooter game is partially completed for your students. Tell them to look over the existing code and explore what each section does.
- The instructions direct users to add movement controls, program the laser to fire, and make the aliens fall and disappear.
- On Web: Your students will use the left and right arrow keys to move the spaceship left and right.
- On Mobile: Your students will tilt their mobile devices to move the spaceship left and right.
- Did students finish early? Direct their attention to the bonus section in the last page of the tutorial, which encourages students to make some of the aliens zoom randomly across the screen.
Extended Activities (10 minutes)Discuss the following with students:
- What are some ways we can improve our asteroid shooter game? Who can list which code blocks we might use and describe how we could apply it to our game?
- Who can describe how we moved Actors to different screen locations? (used random number generators with screen bound parameters)
- Who can describe how to make Actors appear and disappear from the Stage? (used "hide" and "show" code blocks)
- CCSS-Math: MP.1
- CCSS-ELA: RF.1.1, RF.2.4, RF.2.4.A, RF.3.4.A, RF.4.4.A, RI.2.6
- CSTA: 1B-AP-10, 1B-AP-11, 1B-AP-15
- CS CA: 3-5.AP.12, 3-5.AP.13, 3-5.AP.17
- ISTE: 1.c, 1.d, 4.d, 5.c, 5.d, 6.b
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..
Loops and Animation
Creating a Scene
Jumping over Obstacles
Music and Animation
Instruments and Tempo
Message Driven Programming
Pop the Balloon
Animation with Movement