Astronomy Hour of Code
Activity 16: Using the Game EngineInstructions:
(Advanced Lesson)
Our overall goal in this Hour of Code is to create a virtual telescope in our browser that we can control like a real robotic telescope. Now that we've learned some of the basics of computer programming we are going to start putting the pieces together. In order to have a virtual world environment we are going to use the Quorum Game Engine. The first thing we will do is to create our Audio object inside a program that runs the Game Engine.
We don't need to get into all the details of how the Game Engine works in order to take this first step, so we will use the "skeleton" of a Game Engine to allow us to play our sound file. The starting code in the code window marks two places where we need to insert code to make our sound play. At the top, we'll put in our library reference:
use Libraries.Sound.Audio
The CreateGame action in the starting code is automatically called by the Game Engine when the program runs, so any code we put in that section is run one time when the program starts. This is the section where we will create our Audio object and play it. We can use the code that we wrote in the previous section:
Audio clickSound
clickSound:Load("media/astro/click.wav")
clickSound:Play()
When you finish and click the Run Program button, you should hear the click sound play once automatically.
Exploration Challenge (Optional):
There is another different click sound on the server at: media/astro/click2.wav. Create another Audio object with a different name and play that sound also. Then write the code to ask the user which sound they want to hear (1 or 2) and play the correct one by using an if/else statement. If you want to go further, use an if/elseif/else statement to either play a sound or display an error if the user did not type a 1 or 2 when you asked for input.
Next Tutorial
In the next tutorial, we will discuss Astronomy Hour of Code | Activity 0, which describes Accessible astronomy themed Hour of Code.