Learning Objectives

We now have a static scene that contains a map. This map has characters on it, one for our hero and a second, a non-player character that so far does nothing. Characters and items on the map have properties and we can output these to the console to give us information about what is happening in a program as it runs. In this lesson, instead of getting properties and outputting them to the screen, use specific keyboard events (e.g., the up or down arrow) to change properties, which will cause things to happen in the game. To do this, we need something new: conditionals.

You will:

  1. Learn about Conditional Statements
  2. Practice using Keyboard Events
  3. Learn how change the x and y position of an item

Conditionals (20 minutes)

As a first step in making our character move, we need to learn about conditionals. These allow the computer to make its own decisions. During the first part of this session, we will discuss this concept and practice using if statements in isolation. In the next activity, we will apply these concepts in Quorum Studio.

Make our Character Move (30 minutes)

To use an if statement for character movement, we need to get some information from a KeyboardEvent every time a key is pressed. As a starting point, we will output this to the screen. Once we can do this, our goal is to learn how to write an if statement that checks whether the key pressed was the up, down, left, or right arrows. If one of these keys are pressed, we should take the following actions:

NOTE: Movement in a 3D space is based on coordinates and will not detect collisions, for movement WITH collisions (like running into a wall or some other item) we need to turn on and use physics.

For 2D Characters

  1. Up arrow: Add to the y coordinate of our character to move 'UP'
  2. Down arrow: Subtract from the y coordinate of our character to move 'DOWN'
  3. Right arrow: Add to the x coordinate of our character to move 'RIGHT'
  4. Left arrow: Subtract from the x coordinate of our character to move 'LEFT'

For 3D Characters WITHOUT physics on

  1. w : Add to the z coordinate of our character to move 'FORWARD'
  2. s : Subtract from the z coordinate of our character to move 'BACKWARD'
  3. d : Add to the x coordinate of our character to move 'RIGHT'
  4. a: Subtract from the x coordinate of our character to move 'LEFT'
  5. SPACE: Add to the y coordinate of our character to move 'UP'
  6. x: Subtract from the y coordinate of our character to move 'DOWN'

For 3D Characters WITH physics on

  1. Up arrow : Add to the z coordinate of our character to move 'FORWARD'
  2. Down arrow : Subtract from the z coordinate of our character to move 'BACKWARD'
  3. Right arrow : Add to the x coordinate of our character to move 'RIGHT'
  4. Left arrow: Subtract from the x coordinate of our character to move 'LEFT'

Wrap-up (10 minutes)

For this wrap-up, we are going to have a discussion in groups. Specifically, if we change the x and y coordinates, we should visibly see a character move, but this leads to questions. One question is about accessibility and the other is about continuous movement. Each group should pick one of these questions and try to answer it:

Question Option 1:

For users that cannot see the screen, moving an object in this way would make no sound, making our game inaccessible. For gaming, what does it mean to be accessible and how might we change our game to make it so?

Question Option 2:

When our keyboard event is fired, we are telling our character to change its x or y coordinate one time. Suppose we wanted the change to be continuous, meaning that when we hold a button down we move and when we let go, we stop. How might we accomplish this?

Next Tutorial

In the next tutorial, we will discuss Placing Objects, which describes placing objects..