Assignment 3.4: Key Press Madness - Visual

A visual approach to the keyboard

Goals

In this assignment, we will practice the following computer science concepts

  • Using conditional statements
  • Managing User Input

Computer Science Principles Curriculum

  • Big Idea: Creativity: EU 1.3, LO 1.3.1, EK 1.3.1D
  • Big Idea: Programming: EU 5.1, LO 5.1.2, EK 5.1.2A, EK 5.1.2B, EU 5.5, LO 5.5.1, EK 5.5.1E, EK 5.5.1F, EK 5.5.1G

Common Core Standards

  • English Language Arts Standards ยป Science & Technical Subjects: CCSS.ELA-Literacy.RST.9-10.3, CCSS.ELA-Literacy.RST.9-10.4, CCSS.ELA-Literacy.RST.9-10.5, CCSS.ELA-Literacy.RST.9-10.7, CCSS.ELA-Literacy.RST.9-10.10, CCSS.ELA-Literacy.RST.11-12.2, CCSS.ELA-Literacy.RST.11-12.3, CCSS.ELA-Literacy.RST.11-12.4, CCSS.ELA-Literacy.RST.11-12.5, CCSS.ELA-Literacy.RST.11-12.10
  • Standards For Mathmatical Practice: CCSS.Math.Practice.MP1, CCSS.Math.Practice.MP2, CCSS.Math.Practice.MP4, CCSS.Math.Practice.MP5, CCSS.Math.Practice.MP6, CCSS.Math.Practice.MP7, CCSS.Math.Practice.MP8

Vocabulary

  • Actions
  • Class
  • Conditional
  • Image Sheet

Overview

This lab demonstrates how to map certain animations to keys on the keyboard to play when that key is pressed. The Quorum Game library will be used, along with the InputMonitor and KeyboardEvent libraries to handle keyboard input during the program. You will write a program that will play certain animations upon a key being pressed. Download Assignment3_4Template for a template to help you get started.

Goal 1: Using Conditional Statements

Open the provided template. In the main.quorum file, code needs to be written in two places. The first place is in an action called CreateGame. In this action, you set up your Sprite object. The second place you write code is in the action called Update(number seconds). In this action, you write the code that plays the animations when keys are pressed. You can easily jump between Actions by using the Navigator window. The key command for the Navigator window is Ctrl+7. A Sprite object has already been declared for you. A file, or class, called Sprite.quorum has been provided to you that includes code that implements the animations. You can look through this file to see what animations are supported, and how they work. The sprite can:

  • Punch
  • Crouch
  • Jump
  • JumpAndPunch
  • ShootPlasma
  • Walk
  • SpecialMove
  • DoNothing

Navigate to the CreateGame action. In this action, we prepare the Sprite to be animated by the game. First, tell the Sprite object which ImageSheet to get animation images from. Do this by calling the SetImageSheet(text sheetName) action on the Sprite. The SetImageSheet action takes a text parameter that represents the name of the ImageSheet. An ImageSheet has already been provided for in the template, located in the resources folder. Once we have told our Sprite where to get its animation images, we setup the Sprite by calling the SetUp action on the Sprite. This action sets the Sprite to its default pose. Next, Add the Sprite to the game. You can look back in previous lesson to remember how to add an object.

Choose the three keys you want to play animations when pressed, and choose which animations to play when that key is pressed. You will write a conditional statement in the Update(number seconds) action to check for these keys being pressed. If they are, play the animation for that key.

Example: Jump when a key is pressed.

// this line checks if the "A" key is pressed.
if inputMonitor:IsKeyPressed(keys:A)
   // this line makes the sprite jump when we press the A key
   fighter:Jump()
end

Activity: Add three more conditions.

Because the Sprite can only do one animation at a time, it makes sense to use the if... elseif structure in this situation. This ensures that only one animation will play. Add the conditions for two more keys, and the condition for when no keys are pressed. If no keys are pressed, the Sprite's idle animation should play, by calling the DoNothing action.

When you run your program and press those keys, the animations you associated with those keys will play. You can keep a key pressed down to play a animation for a longer period of time or just tap the key to play the animation for a short period of time.

To expand your game, choose more keys to associate animations with, check for those keys being pressed, and play more animations!

Sample Output

The program should play at least 3 different animations upon three different key presses. The Sprite should display its idle animation when no keys are pressed down.

Next Tutorial

In the next tutorial, we will discuss Assignment 3.5, which describes how Robots work in Quorum..