20 Movement With Keyboard

How can we integrate keyboard interactivity into our programs?

Vocabulary

|| OR, && AND, keyIsPressed, keyPressed, ==, ===, keyCode, MVP

Study Questions

  1. What might be a reason to provide multiple input methods for the user? (example mouse/ keyboard/ gamepad)
  2. What is the difference between keyIsPressed and keyPressed() function?
  3. Should we worry about making every variable global?
  4. What is a local variable and when might you want to use a local variable?

Activity

  • Watch Video #1 (below)
  • Create one canvas RPG GAME. You are creating a scenic canvas of interactive elements. Think of old style 2-d game world. Your canvas will have your imagination.

2D Game Example - Pokemon on Nintendo DS

  • Use graphing paper to plan your elements (attached under lesson 03).
  • Minimum Viable Product (MVP) will have the following in addition to the basic rubric:
  • At least 5 interactions.
  • Use if_else if wherever appropriate.
  • Movement with keyboard arrow keys.
  • Use text() to relay story about interactions. Think about a text-box at the bottom of the canvas.
  • Use functions to chunk your code into re-usable blocks. All code should not be in the draw function.
  • Scenic background.
  • Implement score keeping and a way for the game to finish - Completion Criteria.
  • Present a game completion screen.
  • Well commented code. Also, explain the details about the game in a comment at the top of code.
  • A nice extension of your ideas would create a canvas where the interactions teach about the environment, sustainability…a real world issue. (Run the idea by me before you implement it.)
    • Name your sketch and comment your code.
    • Use camelCase for variable, function names, or where ever appropriate.
    • Use variables for modifiable colors and other elements that the user could set at the top of the program.
    • Use functions for blocks of reusable code.
    • Discuss the answers to study questions.

Resources

  1. Video: 18 Collision Detection and Importing a library
  2. Link: Find keyCodes