Download presentation
Presentation is loading. Please wait.
1
Intro CS – Screens and Variables
Lesson Plan 9
2
Goals Using sprites as full screens (Start screen, Game over)
Using layering to control ordering of screens Using full screen sprites to create moving backgrounds Using global and sprite level variables – when and why for each
3
Objectives Students are introduced to the topic and given examples of full screen sprites for start/end screens, and for animated backgrounds; also examples of global and sprite level variables Students are given real problems to code and solve for practice Results are demonstrated through demos of running code and displayed results
4
Pre Requisites Basic Understanding of Scratch, Sprites, Animation, Costumes, and Variables
5
Materials Slides with examples (or present on whiteboard)
PCs with development environments installed (this includes moving backgrounds that are pre-installed)
6
Lesson Description Introduce full screen sprites, positioning, animating them Review variables – used to track information that may change due to user input, hit detection, time, etc. Discusses when to use variables, how to use them, and what are their benefits and drawbacks (variables at sprite and global level) Examples/demos – get scrolling background working in class Students practice and extend problem to their own wishes Students present their solutions, typically F2F with the instructor(s) at their desk Students analyze their and others’ solutions for bugs Won’t do Breakout game, instead give them time to work on their Galaga Projects.
7
Lesson Procedure Review previous lessons: Repeat loops, Animation, Costumes, Hit Detection In class examples: Full screen sprite with layered button (click button to start) Full screen sprites to animate background horizontally/vertically Examples of global and local variables Give exercises for in class practice Walk the room answering questions, looking over the shoulder, asking questions, etc. Won’t do Breakout game, instead give them time to work on their Galaga Projects.
8
Closure/Conclusion Discussion Summary
How do you add Start and Game over screens to your Galaga game? What kind of scrolling background will you use? How would you use global and local variables in your Galaga game? Summary Using variables to track app state and animation of backgrounds Sprite vs. global variables Ask questions on what is confusing or needs more time/practice
9
Animated Backgrounds and Scoped Variables
Lesson Plan 9 Today we’re going to talk about start, end, scrolling screens, and variables that help manage state that will help you guys in your Galaga project. But first off, discuss the quiz (too hard, too easy? Everyone had enough time? Was everyone prepared?) Secondly discuss what we learned last lesson – hit detection and broadcasting. Did anyone have trouble? What did a lot of you notice? Some people had trouble with the Done (variable) equals True statement, what do you guys think we had that for – to check for the state of the program (if the AngryShark had hit something).
10
3 Concepts Today Needed for your Galaga projects Moving Backgrounds
Screens and Broadcasting Variable Scoping
11
Backgrounds What have we done so far with backgrounds?
Backgrounds are static (can’t move) in BYOB We can change them whenever we want using the two following blocks : What else might we want to do? What if we wanted a scrolling background in our Galaga game? What if we wanted to create a Start or Game over screen? Make sure everyone understands how to import and change a background, should be review. How could we create a scrolling background in our game? Paper demo: one piece of paper with a design how can we make it seem like it’s scrolling forever. Hints: what does a treadmill do? So how can we translate this to Scratch?
12
Moving Backgrounds?
13
Background in Galaga
14
Paper Prototype Partner up Get out some paper
Try to recreate either Fred’s or Galaga’s background as a quick mockup / prototype How would you solve this in Snap?
15
Full Screen Sprites Background images can also be used as regular Sprites - these are known as full screen sprites. By using backgrounds as Sprites we can control: Position Animation/movement (tip: glide block will allow for smooth background movement) Layering (tip: be careful of layering, make sure what you want to show is layered on top at the correct time; layering can be used to control ordering of screens) Demo scrolling background Full screen sprites will allow you to create moving backgrounds, think about Mario and Galaga space bgs.
16
The Pseudo code & Math Start BG1 fully on screen (at 0,0)
Start BG2 fully on screen (above at 0,360) Move both down at same time When BG1 goes off the bottom of the screen (0,-360), move it back to the middle When BG2 goes to the center of the screen (0,0), move it back to the top
17
UPDATE In the gear menu in Snap, turn on the Prefer smooth animations checkbox Also, if you get a gap, create 2 variables and try this: On each sprite Stage
18
Screens and Broadcasting
19
Start Screen State
20
Play Button Similar to everything else in Scratch, the Play Button will also be a Sprite, however it’s more of an object than a character. Demo Play Button Next thing we want to discuss is how to start your game by pressing a Play Button. How do we think this might be accomplished?
21
Variable Scoping
22
Global vs. Sprite Variables
What is a Global variable? Variable for all sprites Example: In our past projects we have used a single variable for speed or step size. What is a Sprite variable (also known as local variable)? Variable for a single sprite Example: If you want to make the dive directions for your enemy ships in Galaga different or anything else that is specific to a single sprite. What else could we use global and sprite variables for?
23
Global vs. Sprite Variables – Used in Broadcasting
Scratch cannot limit where a Broadcast can go Work around for this is to use a global variable and private/local/sprite variable for each sprite: We discussed Global and Sprite Variables in the last Broadcasting lecture and it was also the Bonus question for your quizzes, does anyone remember what the difference between a Global and Sprite Variable are? How did it help Broadcasting?
24
Daily project By the end of class: Add a scrolling background to your project Extra: add a Start screen and button to your project Show me "for this sprite only" variables and how they work
25
Summary Discussion Summary
How do you add Start and Game over screens to your Galaga game? What kind of scrolling background will you use? How would you use global and local variables in your Galaga game? Summary Using variables to track app state and animation of backgrounds Sprite vs. global variables
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.