No categories assigned

Exercise: A Platformer Game

music-design-platformer.png

Let's consider a simple platformer game with 5 level with the following contexts: Menu, Level 1, Level 2, ..., Advance, Win, and Game Over. (See the image.)

  • Menu will be a music loop which will play while the user is in the main menu of the game.
  • Level 1, "Level 2", ..., "Level 5" will be music loops, one for each level of the game.
  • Advance, Win and Game Over are likely to be one-shot music tracks, i.e. short pieces of non-looping music.
  • "Advance" would play upon a successful completion of Level 1 through Level 4. The same music for all four situations.
  • "Win" would play upon a successful completion of Level 5.
  • "Game Over" would play when the player loses the game.

Menu and Level music contexts can utilize the Duration Retargeting technique as it is not clear how long that context would last. (Most of our assets support duration retargeting.) Advance, Win, and Game Over should be limited in time, play their contents and then stop. For that we could use the one-shot modules.

Create pages

Based on this design, let's create the following pages, one for each unique context. Please note the priority level 20 for the loops and 30 for the one-shots.

Page Priority Music format
MENU 10 Duration retargeting
LEVEL_1 20 Duration retargeting
LEVEL_2 20 Duration retargeting
LEVEL_3 20 Duration retargeting
LEVEL_4 20 Duration retargeting
LEVEL_5 20 Duration retargeting
ADVANCE 30 One-shot
WIN 30 One-shot
GAME_OVER 30 One-shot

The music can be then used as follows:

When this happens Make this WLA API Call Explanation
Program starts Activate page MENU Leave it activated as long as the program is running. Menu has a priority 10, the lowest of all pages. This will ensure that if no other music page is active, the MENU page will serve as a fallback, yet at the same time, once any other page is activated, the music immediately starts its transition to it.
Level 1 starts Activate page LEVEL_1 The level pages have a higher priority than MENU and so a Module-to-module Transition will be triggered once any of the LEVEL page is activated
Level 1 completed Simultaneously:
* Activate page ADVANCE
* Activate page LEVEL_2
The Page Priority Level hierarchy will ensure the music is played in the correct order. ADVANCE page has a higher priority than the LEVEL, and so it will play first. Since it has a one-shot music associated to it, its duration is finite. At the end of the ADVANCE music, a transition to LEVEL_2 is triggered automatically. LEVEL_1 page is deactivated automatically when LEVEL_2 is activated because they share the same priority level. The programmer doesn't need to do anything at the end of ADVANCE music.
Level 2 has failed and game is over Simultaneously:
* Activate page GAME_OVER
* Deactivate page LEVEL_2
After GAME_OVER playback is finished, the music automatically returns to MENU.
Level 5 is completed Simultaneously:
* Activate page WIN
* Deactivate page LEVEL_5
After WIN playback is finished, the music automatically returns to MENU.

Code snippets

In code, this is how you activate a page:

// Find the instance of WeloveAudioPlayuer
var player = (WeloveAudioPlayer)FindObjectOfType(typeof(WeloveAudioPlayer));
// Check if it exists
if (player != null) {
  // Call the "activate page" method
  player.WlaActivatePage("LEVEL_1");
}

And this is how you deactivate a page:

player.WlaDeactivatePage("LEVEL_1");

Choosing the assets in our catalog

In BASIC tier you are welcome to use our welove.audio Catalog to populate the pages with music. In ADVANCED tiers, you will be able to utilize our assets too in addition to your own music. (This tier is currently in development. Please stay tuned.)

To continue our example: For MENU page we can choose "Sci-fi Category" and "Cinematic Flavor" (see picture). The asset BSAS07x Juno will work for this page.

platformer-game-menu-music.png

LEVEL_1 through LEVEL_5 could be populated for example using these five assets from the Nebulae chapter:

platformer-game-level-music.png

To choose one-shots for ADVANCE, WIN, and GAME_OVER, we can utilize the "One-shot Structure" checkbox in the filter on the left.

platformer-game-one-shot-music.png

Overall, this is how the populated project might look like:

platformer-game-populated-project.png