Note: This is an automatic translation from Russian. It looks good enough, but there may be inaccuracies. We are sorry for the inconvenience.

Adding sound to the game

If you want to add audio to your game, the Audio property of the Game class, represented by the IAudio type, is used to control the audio. All methods and properties of the IAudio interface are described in the API documentation .

Sound in TeravQuest can be of three types: effects, music and ambiance.

Effects are short sounds like banging, opening a door, shooting, etc. Once you start playing this sound, you cannot stop it. Several effect sounds may sound at one time.

Music can be started and stopped. Only one song can sound at a time. The music is looped, so the running track will constantly repeat itself, and to stop it, you need to call the appropriate method.

Ambiance sounds serve to add additional mood to the location. It can be the sound of the wind in the desert, birdsong in the forest, etc. Technical features are the same as for music: the track is looped and only one file can sound. However, music and atmospheric sound can be played at the same time.

Let's add the sound of the door opening when the main character leaves his house by adding the following to ToForest method of the Home class:

private void ToForest(Game game)

The @ before the line with the path to the file is used so that you do not need to escape the backslash.

Let's add ambiance to the Forest location:

public override void OnVisit(Game game)

Accordingly, to prevent the birds from singing in the room or cave, you will need to call the StopAmbiance method somewhere, for example, in the OnLeave method of the same location, or play another file in a different location.

Let's add some anxious music when the hero of the game enters the battle in the cave:

        public override void OnVisit(Game game)
            if ((game as MyGame).QuestStage < 2)
                Content = "As soon as you entered the cave, something incomprehensible and aggressive pounced on you from the darkness ...";
                AddOption(new Option("Fight", Fight));

And after the hero wins, because he will certainly win, you will need to call the StopMusic method.