Presentation is loading. Please wait.

Presentation is loading. Please wait.

Intro CS – Keyboard and mouse input

Similar presentations


Presentation on theme: "Intro CS – Keyboard and mouse input"— Presentation transcript:

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 Summary
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 What did we learn in the last lecture? Mainly about sprite and how to change their costumes and using variables. What is a costume, what is a variable? What were some interesting, hard, tips for your classmates? Common problems we saw some students encounter. Does anyone know what keyboard and mouse inputs are?

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. Also use for score, movement speed, health level, etc. Do we need to recap? What are some useful things we can use variables for? IE: helping us keep score in games

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) Has everyone gotten a chance to play around with variables? Think of questions one level higher.

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? What do we usually do with keyboard? We press a key and detect that key stroke For games we use arrow keys (left, right, up, down) We can use arrow and space bar to control our Galaga spaceship and fire hits

14 Keyboard Input (part 2) When you use these blocks:
The sprite pauses briefly You can't press 2 keys at the same time (diagonals) Instead, you can do it another way: May need to adjust speed by adding wait, or by moving fewer steps Can also use Change X by and Change Y by to avoid using Point in Direction

15 Mouse Input We’ve already seen this control: What about this one?
What does it do? What about this one? This is how we can have sprites follow the mouse. What does this control block do? Use with Move block to make a sprite chase your mouse pointer, or another sprite 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. What things do you think we can do with mouse input? Some students have already experimented with these controls. Mouse selects/deselects Has movement (with x/y coordinate) Then introduce blocks: point in direction/mouse down?/go to mouse pointer

16 Example Demo Show how to create the CheesePuffGirl Demo
Make sure students know how to pick random x,y start and direction. Make sure they know in order to click the object, it must be in front. 2 conditions in if statement 1. touching 2. mouse clicked.

17 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 Include Points 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 edges 1 Chased sprites have random starting position Chased sprites have random movement direction On mouse-click the chased sprite must hide and reappear later Score is kept correctly

18 Summary Discussion Summary
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


Download ppt "Intro CS – Keyboard and mouse input"

Similar presentations


Ads by Google