Download presentation
Presentation is loading. Please wait.
Published byEdwin Eaton Modified over 8 years ago
1
Intro CS – Keyboard and mouse input Lesson Plan 7
2
Goals Understanding Keyboard and Mouse Input Single key press, and held down state Mouse position and mouse click Controlling sprites using the keyboard or mouse
3
Objectives Students are introduced to the topic and given examples of keyboard and mouse input Students are given real problems to code and solve using the keyboard and mouse Results are demonstrated through demos of running code and displayed results
4
Pre Requisites Understanding of Scratch, Sprites, Animation, IF, hit detection, looping
5
Materials Slides with examples (or present on whiteboard) PCs with development environments installed
6
Lesson Description Introduce Scratch blocks for Key N pressed, MouseX, MouseY, Mouse down Give examples/demo of handling key presses, and key held down Give examples/demo of handling mouse movement and click Give sample problems to solve in class Students practice and extend examples 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
7
Lesson Procedure Review previous lessons: Animation, x position, y position of sprites Give exercises for in class practice (move a sprite based on keyboard input) Direct movement on key press, key held, OR, constant movement with key input to change direction Direct movement of sprite to current mouse position Chase movement of sprite to follow (move towards) mouse position Walk the room answering questions, looking over the shoulder, asking questions, etc.
8
Closure/Conclusion Discussion How do you apply this to your Galaga project ship? What other kinds of games can you make with keyboard and mouse input? Summary Key press and key down handling Mouse input Ask questions on what is confusing or needs more time/practice
9
Keyboard and Mouse Input Lesson 7
10
Example Demo Today we’re going to learn more about keyboard and mouse inputs (how to get your sprite to move on command). We’re also going to revisit the concept of variable and see how we can keep score. Demo CheesePuffGirl mini-game
11
Variables What is a variable? Stores a value that can be reused in code. Pros: if you want to change a number, you will only have to change it in one place. Example how to create a variable and use it.
12
Variables Continued… How do you create a variable? How do you deleted a variable? How do you show a variable on the screen? How do you set the value of the variable? How can you increment/decrement the value of a variable? What do these two variable blocks do? (Same as the third bullet)
13
Keyboard Input We’ve already seen: What does this do? What if we wanted to move a sprite to the left with our left arrow key? Right arrow? Up/Down arrow?
14
Mouse Input We’ve already seen this control: What does it do? What about this one? This is how we can have sprites follow the mouse. What does this control block do? What about these blocks? Show the x-coordinate of the mouse Show the y-coordinate of the mouse Condition statement to check if the mouse was clicked.
15
Example Demo Show how to create the CheesePuffGirl Demo
16
Daily project By the end of class create a mini-game where a sprite chases other sprites (either by using keyboard or mouse inputs) and on clicking the chased sprites, the score is increased by 1 point. Worth 10 points total. Save your project: File format: LP7-YourLastName_YourFirstName.sb Grade Breakdown – Must IncludePoints Sprite movement on either keyboard or mouse input (must move correctly in all 4 directions) 2 (1/2 for each direction) Contains at least two other moving sprite (besides the one being controlled by keyboard/mouse input) 2 Chased sprites must bounce off screen edges1 Chased sprites have random starting position1 Chased sprites have random movement direction1 On mouse-click the chased sprite must hide and reappear later1 Score is kept correctly2
17
Summary Discussion How do you apply this to your Galaga project ship? What other kinds of games can you make with keyboard and mouse input? Summary Key press and key down handling Mouse input Ask questions on what is confusing or needs more time/practice
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.