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

Computer Science Principles Curriculum

Common Core Standards



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:

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
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..