integer a = 0
integer b = 1
integer c = 2

//versus

Array array
array:Add(0)
array:Add(1)
array:Add(2)

Learning Objectives

To make our game both more fun and accessible, we are now going to add more sound to our game. In the first part of this lesson, we are going to be looking online for sound effects. Once complete, we are going to download an effect and hook it into our game.

You will:

  1. Learn about hooking in sound effects
  2. Learn how to remove items from a game after a collision
  3. Learn about arrays

Find Sound Effects and Hook them In (10 minutes)

For sound effects, any source is fine, but one that can be used for simple sound effects is https://freesound.org/. This site allows us to create and download a variety of effects in different styles, like coins, explosions, lasers, or other audio. Again like before, we will use Audacity to convert the files to Ogg format for use. We need a free account to use the site.

Play Sounds on Collision and Remove Potions (20 minutes)

Instead of outputting text to the console when we collide with an item, we will now convert our output statement to an audio object we will tell to play. We will use the sound tutorial to learn how to do that. Finding the objects still may be difficult from an accessibility perspective and we encourage thinking about how we might fix that for users of our game. Finally, when a player collides with a potion, we will remove it from the game.

Introduction to Arrays (20 minutes)

While so far we have used variables whenever we had multiple items, like potions or something else, this can be tedious when we have many items. To fix this in a future tutorial, we first need to learn about arrays. In this part of the session, we will go over the arrays tutorial and practice with the concept.

Wrap-up (10 minutes)

The concept of arrays can be confusing to people, so in a classroom it makes sense to spend a reasonable amount of time on it. It is also a very important concept in computer science, because storing data is a commonplace thing we want to do. In groups, discuss the difference between the following two ways of writing variables:

Here are two questions each group should consider: 1) the second program is storing the same information as the first, so why even bother to use an array?, 2) What do the funny greater and less than symbols mean? Once your group has answered these two questions, there is one final activity. The Array class has many actions available. Choose two actions from the documentation and put what those actions do in your own words.

Next Tutorial

In the next tutorial, we will discuss Spatial Sounds, which describes spatial sound in a running game..