Game Development Community

dev|Pro Game Development Curriculum

Torque Minimal Template -- Part 5. Levels, sound and ML text

by Pedro Vicente · 08/07/2011 (12:49 pm) · 8 comments

This is Part 5 of the Minimal Template series. In this resource we will be adding the ability to change levels and adding sound.

Previous resources


The other resources regarding this series are:

Torque Minimal Template -- Part 4. Retina Display
Torque Minimal Template -- Part 3. Adding objects
Torque Minimal Template -- Part 2. A C++ start function
Torque Minimal Template -- Part 1

Levels


The default template provided with Torque uses a series of script files to load and terminate levels. It all starts in this function of game.cs

function startGame(%level)
sceneWindow2D.loadLevel(%level);

Where %level is the name of a file (that is read from a XML file). In this resource an alternative way to change levels is presented.

What are Levels


For the Torque engine, levels are basically instances of t2dSceneGraph where all torque t2dSceneObject objects are managed. To avoid the unnecessary complexity to manage these instances in several script files, following is a simple function that initiates a t2dSceneGraph instance with a t2dSceneGraph class name, and automatically sets everything needed (like camera size). It can be used to load other levels. In this resource a complete project is shown.

The loadSceneGraph function


function loadSceneGraph( %scenegraph_name )
{
   //delete the previous scenegraph
   deleteSceneGraph();

   if ( $pref::iDevice::ScreenOrientation  == $iDevice::constant::Landscape )
   {
      if( $platform $= "ipad" ||  ( $platform $= "windows" && $platform_simul $= "ipad") )
      {

         %scenegraph = new t2dSceneGraph( %scenegraph_name ) 
         {
            cameraPosition = "0 0";    
            cameraSize = "1024 768";    
         };
      }
      else
      {
         %scenegraph = new t2dSceneGraph( %scenegraph_name ) 
         {
            cameraPosition = "0 0";    
            cameraSize = "480 320";    
         };          
      } 
   }
   else if ( $pref::iDevice::ScreenOrientation  == $iDevice::constant::Portrait )
   {
      if( $platform $= "ipad" ||  ( $platform $= "windows" && $platform_simul $= "ipad") )
      {

         %scenegraph = new t2dSceneGraph( %scenegraph_name ) 
         {
            cameraPosition = "0 0";    
            cameraSize = "768 1024";    
         };
      }
      else
      {
         %scenegraph = new t2dSceneGraph( %scenegraph_name ) 
         {
            cameraPosition = "0 0";    
            cameraSize = "320 480";    
         };          
      } 
      
      
   }


   sceneWindow2D.setSceneGraph(%scenegraph);
   %scenegraph.performPostInit();
   %cameraPosition = sceneWindow2D.getCurrentCameraPosition();
   %cameraSize = t2dVectorSub(getWords(sceneWindow2D.getCurrentCameraArea(), 2, 3),
                              getWords(sceneWindow2D.getCurrentCameraArea(), 0, 1));
                              
   if (%scenegraph.cameraPosition !$= "")
      %cameraPosition = %scenegraph.cameraPosition;
   if (%scenegraph.cameraSize !$= "")
      %cameraSize = %scenegraph.cameraSize;
      
   sceneWindow2D.setCurrentCameraPosition(%cameraPosition, %cameraSize);

}

The deleteSceneGraph function


This function deletes the previous scene graph; it is called by loadSceneGraph. All objects from the scene are iterated and deleted.
function deleteSceneGraph()
{
   
   %scenegraph = sceneWindow2D.getSceneGraph();
   
   if (isObject(%scenegraph))
   {
      %sceneObjectList = %sceneGraph.getSceneObjectList();
      // And finally, notify all the objects that they were loaded.
      for (%i = 0; %i < getWordCount(%sceneObjectList); %i++)
      {
         %sceneObject = getWord(%sceneObjectList, %i);
         if( %sceneObject.isMethod( "onLevelEnded" ) )
            %sceneObject.onLevelEnded(%sceneGraph);
      }
      
      // Notify the scenegraph that the level ended.
      if( %sceneGraph.isMethod( "onLevelEnded" ) )
         %sceneGraph.onLevelEnded(); 
         
      %scenegraph.clearScene(true);
   }
   
   
   if (isObject(%scenegraph))
   {
      if( isObject( %scenegraph.getGlobalTileMap() ) )
         %scenegraph.getGlobalTileMap().delete();
         
      %scenegraph.delete();
   }
   
}


The Home application


Following is presented a sample application that loads 3 levels using this function. The application shows a main menu where a button is pressed that optionally loads 2 other levels. These 2 levels also have a button to return to the main menu.

Three classes are defined:

MainMenuSceneGraph


function MainMenuSceneGraph::OnAdd(%this)
{
   CreateBackground( %this );
   CreateButton( %this, "Level_01_Button",  "ButtonLevelImageMap",  0, -100,  128, 128);
   CreateButton( %this, "Level_02_Button",  "ButtonLevelImageMap", 0,  100,  128, 128);
   makeTextObject( %this, "I am in the Main menu");
}

The resources of every scene graph must be explicitly deleted as called by deleteSceneGraph

function MainMenuSceneGraph::onLevelEnded(%this)
{
   %this.clearScene();
}

SceneGraphLevel_01


function SceneGraphLevel_01::OnAdd(%this)
{
   CreateBackground( %this );
   CreateButton( %this, "ButtonHome", "ButtonHomeImageMap", 0,  170, 128, 128);
   makeTextObject( %this, "I am in Level 1");
}


SceneGraphLevel_02


function SceneGraphLevel_02::OnAdd(%this)
{
   CreateBackground( %this );
   CreateButton( %this, "ButtonHome", "ButtonHomeImageMap", 0, 170, 128, 128);
   %this.CreateGuiText();
   
}

The name of these classes are passed as parameters to the function loadSceneGraph above, like in this call made from main.cs

loadSceneGraph( MainMenuSceneGraph );

To load the other level, the mouse up function for a t2dStaticSprite instance was subclassed:

function ButtonHome::onMouseUp( %this, %modifier, %worldPosition, %clicks )
{
   %this.schedule(0, "changeLevel" );
   alxPlay("beepSound"); 
}

function ButtonHome::changeLevel(%this)
{
	loadSceneGraph( MainMenuSceneGraph );
}

So, pressing the mouse loads the other level. An utility function that defines this button was also defined, that accepts the t2dSceneGraph object (not name) as parameter.

createButton function


function createButton( %scenegraph_obj, %class, %image_map, %xpos, %ypos, %xsize, %ysize )
{
    %obj = new t2dStaticSprite() 
    { 
        scenegraph = %scenegraph_obj; 
        class = %class;
        useMouseEvents = "1";
    };
    %obj.setVisible( true );
    %obj.setImageMap( %image_map );
    %obj.setPosition( %xpos, %ypos );	
    %obj.setSize( %xsize, %ysize );
}



Loading the application, this is the result

www.space-research.org/games/garage_games/21169_1.png

Pressing the upper button, this level is loaded; pressing the button, the previous level is loaded

www.space-research.org/games/garage_games/21169_2.png


Following are the complete source files for the project. The folder structure and files are:

main.cs
scripts/menu.cs
scripts/menu.cs
scripts/level_01.cs
scripts/level_02.cs
scripts/datablocks.cs
data/images
data/audio
data/fonts

Complete project


Can be downloaded from here

#1
08/07/2011 (1:14 pm)

main.cs Part 1


// main.cs
// (c) Pedro Vicente
// iTorque2D, Torque2D minimal template
// Notes: folders are 
// /data/images -- where we store images
// /data/fonts  -- store fonts
// /scripts     -- game script code

function initCanvas(%name)
{
   if (!createCanvas(%name)) 
   {
      quit();
      return;
   }

}

function resetCanvas()
{
   if (isObject(Canvas))
   {
      Canvas.repaint(); 
   }
}

dbgSetParameters( 6060, "password", false );
setRandomSeed();

$pref::Video::displayDevice        = "OpenGL";
$Gui::fontCacheDirectory           = expandFilename("data/fonts");
$iDevice::constant::iPhone         = 0;
$iDevice::constant::iPad           = 1;
$iDevice::constant::iPhone4        = 2;
$iDevice::constant::Landscape      = 0;
$iDevice::constant::Portrait       = 1;
$pref::iDevice::iAdOnTop           = 1;
$pref::iDevice::ScreenOrientation  = $iDevice::constant::Portrait;
$platform_simul                    = "iphone";
$musicStreamHandle                 = 0;
$Game::UsesAudio                   = 1;
$is_iDevice                        = false;
$debug_mode                        = true;

///
/// Audio
///

$pref::Audio::driver = "OpenAL";
$pref::Audio::forceMaxDistanceUpdate = 0;
$pref::Audio::environmentEnabled = 0;
$pref::Audio::masterVolume   = 0.8;

exec("scripts/audio.cs");
exec("scripts/utils.cs");


if( $platform $= "iphone" )
{
   $pref::iDevice::DeviceType          = $iDevice::constant::iPhone;
}
else if( $platform $= "iphone4" )
{
   $pref::iDevice::DeviceType          = $iDevice::constant::iPhone4;
}
else if( $platform $= "ipad" )
{
   $pref::iDevice::DeviceType          = $iDevice::constant::iPad;
}


new GuiCursor(DefaultCursor)
{
   hotSpot = "4 4";
   renderOffset = "0 0";
   bitmapName = "data/images/cursor";
};

initCanvas("Game");

// Start up the audio system.
if( $Game::UsesAudio )
   initializeOpenAL();

// Set a default cursor.
Canvas.setCursor(DefaultCursor);
Canvas.showCursor();

//---------------------------------------------------------------------------------------------
// GuiDefaultProfile is a special profile that all other profiles inherit defaults from. It
// must exist.
//---------------------------------------------------------------------------------------------
new GuiControlProfile (GuiDefaultProfile)
{
   tab = false;
   canKeyFocus = false;
   hasBitmapArray = false;
   mouseOverSelected = false;

   // fill color
   opaque = true;
   fillColor = "0 0 0";
   fillColorHL = "244 244 244";
   fillColorNA = "244 244 244";

   // border color
   border = 1;
   borderColor   = "40 40 40 100";
   borderColorHL = "128 128 128";
   borderColorNA = "64 64 64";

   // font
   fontType = "Arial";
   fontSize = 14;

   fontColor = "0 0 0";
   fontColorHL = "32 100 100";
   fontColorNA = "0 0 0";
   fontColorSEL= "80 80 80";

   // bitmap information
   bitmap = "";
   bitmapBase = "";
   textOffset = "0 0";

   // used by guiTextControl
   modal = true;
   justify = "left";
   autoSizeWidth = false;
   autoSizeHeight = false;
   returnTab = false;
   numbersOnly = false;
   cursorColor = "0 0 0 255";

   // sounds
   soundButtonDown = "";
   soundButtonOver = "";

};

new GuiControl(mainScreenGui) 
{
   canSaveDynamicFields = "0";
   isContainer = "1";
   Profile = "GuiDefaultProfile";
   HorizSizing = "width";
   VertSizing = "height";
   Position = "0 0";
   canSave = "1";
   Visible = "1";
   hovertime = "1000";

   new t2dSceneWindow(sceneWindow2D) 
   {
      canSaveDynamicFields = "0";
      isContainer = "0";
      Profile = "GuiDefaultProfile";
      HorizSizing = "width";
      VertSizing = "height";
      Position = "0 0";
      canSave = "1";
      Visible = "1";
      tooltipprofile = "GuiDefaultProfile";
      hovertime = "1000";
      lockMouse = "0";
      useWindowMouseEvents = "1";
      useObjectMouseEvents = "1";
   };

};
#2
08/07/2011 (1:16 pm)

main.cs -- Part 2


//landscape
if ( $pref::iDevice::ScreenOrientation  == $iDevice::constant::Landscape )
{
   if( $platform $= "iphone" ||  ( $platform $= "windows" && $platform_simul $= "iphone") )
   {
      mainScreenGui.Extent = "480 320";
      sceneWindow2D.Extent = "480 320";
   }
   
   else if( $platform $= "ipad" ||  ( $platform $= "windows" && $platform_simul $= "ipad") )
   {
      mainScreenGui.Extent = "1024 768";
      sceneWindow2D.Extent = "1024 768";
   }
   else if( $platform $= "iphone4" ||  ( $platform $= "windows" && $platform_simul $= "iphone4") )
   {
      mainScreenGui.Extent = "480 320";
      sceneWindow2D.Extent = "480 320";
   }
}
//portrait
else if ( $pref::iDevice::ScreenOrientation  == $iDevice::constant::Portrait )
{
   if( $platform $= "iphone" ||  ( $platform $= "windows" && $platform_simul $= "iphone") ) 
   {
      mainScreenGui.Extent = "320 480";
      sceneWindow2D.Extent = "320 480";
   }
   
   if( $platform $= "ipad" || ( $platform $= "windows" && $platform_simul $= "ipad") ) 
   {
      mainScreenGui.Extent = "768 1024";
      sceneWindow2D.Extent = "768 1024";
   }
   else if( $platform $= "iphone4" ||  ( $platform $= "windows" && $platform_simul $= "iphone4") )
   {
      mainScreenGui.Extent = "320 480";
      sceneWindow2D.Extent = "320 480";
   }
}



Canvas.setContent(mainScreenGui);
setScreenModeWindows();

exec("scripts/datablocks.cs");
exec("scripts/level_01.cs");
exec("scripts/level_02.cs");
exec("scripts/menu.cs");


//load the first "level"
loadSceneGraph( MainMenuSceneGraph );

   
//---------------------------------------------------------------------------------------------
// onExit
// Called when the engine is shutting down. 
//---------------------------------------------------------------------------------------------
function onExit()
{  
   //delete the current scenegraph
   deleteSceneGraph();
   
}
#3
08/07/2011 (1:19 pm)

utils.cs Part 1


//---------------------------------------------------------------------------------------------
// utils.cs
//---------------------------------------------------------------------------------------------

// .....................................................................................
function deleteSceneGraph()
{
   
   %scenegraph = sceneWindow2D.getSceneGraph();
   
   if (isObject(%scenegraph))
   {
      %sceneObjectList = %sceneGraph.getSceneObjectList();
      // And finally, notify all the objects that they were loaded.
      for (%i = 0; %i < getWordCount(%sceneObjectList); %i++)
      {
         %sceneObject = getWord(%sceneObjectList, %i);
         if( %sceneObject.isMethod( "onLevelEnded" ) )
            %sceneObject.onLevelEnded(%sceneGraph);
      }
      
      // Notify the scenegraph that the level ended.
      if( %sceneGraph.isMethod( "onLevelEnded" ) )
         %sceneGraph.onLevelEnded(); 
         
      %scenegraph.clearScene(true);
   }
   
   
   if (isObject(%scenegraph))
   {
      if( isObject( %scenegraph.getGlobalTileMap() ) )
         %scenegraph.getGlobalTileMap().delete();
         
      %scenegraph.delete();
   }
   
}

// .....................................................................................
function loadSceneGraph( %scenegraph_name )
{
   //delete the previous scenegraph
   deleteSceneGraph();

   if ( $pref::iDevice::ScreenOrientation  == $iDevice::constant::Landscape )
   {
      if( $platform $= "ipad" ||  ( $platform $= "windows" && $platform_simul $= "ipad") )
      {

         %scenegraph = new t2dSceneGraph( %scenegraph_name ) 
         {
            cameraPosition = "0 0";    
            cameraSize = "1024 768";    
         };
      }
      else
      {
         %scenegraph = new t2dSceneGraph( %scenegraph_name ) 
         {
            cameraPosition = "0 0";    
            cameraSize = "480 320";    
         };          
      } 
   }
   else if ( $pref::iDevice::ScreenOrientation  == $iDevice::constant::Portrait )
   {
      if( $platform $= "ipad" ||  ( $platform $= "windows" && $platform_simul $= "ipad") )
      {

         %scenegraph = new t2dSceneGraph( %scenegraph_name ) 
         {
            cameraPosition = "0 0";    
            cameraSize = "768 1024";    
         };
      }
      else
      {
         %scenegraph = new t2dSceneGraph( %scenegraph_name ) 
         {
            cameraPosition = "0 0";    
            cameraSize = "320 480";    
         };          
      } 
      
      
   }


   sceneWindow2D.setSceneGraph(%scenegraph);
   %scenegraph.performPostInit();
   %cameraPosition = sceneWindow2D.getCurrentCameraPosition();
   %cameraSize = t2dVectorSub(getWords(sceneWindow2D.getCurrentCameraArea(), 2, 3),
                              getWords(sceneWindow2D.getCurrentCameraArea(), 0, 1));
                              
   if (%scenegraph.cameraPosition !$= "")
      %cameraPosition = %scenegraph.cameraPosition;
   if (%scenegraph.cameraSize !$= "")
      %cameraSize = %scenegraph.cameraSize;
      
   sceneWindow2D.setCurrentCameraPosition(%cameraPosition, %cameraSize);

}

// .....................................................................................
function setScreenModeWindows()
{
   if( $platform $= "windows" ) 
   {
      if ( $pref::iDevice::ScreenOrientation  == $iDevice::constant::Landscape )
      {
         if( $platform_simul $= "ipad" ) 
         setScreenMode( 1024, 768, 32, false );
         else
         setScreenMode( 480, 320, 32, false );
      }
      if ( $pref::iDevice::ScreenOrientation  == $iDevice::constant::Portrait )
      {
         if( $platform_simul $= "ipad" ) 
         setScreenMode( 768, 1024, 32, false );
         else
         setScreenMode( 320, 480, 32, false );
      }
   }
}
#4
08/07/2011 (1:23 pm)

utils.cs Part 2


// .....................................................................................
function CreateButton( %scenegraph_obj, %class, %image_map, %xpos, %ypos, %xsize, %ysize )
{
    %obj = new t2dStaticSprite() 
    { 
        scenegraph = %scenegraph_obj; 
        class = %class;
        useMouseEvents = "1";
    };
    %obj.setVisible( true );
    %obj.setImageMap( %image_map );
    %obj.setPosition( %xpos, %ypos );	
    %obj.setSize( %xsize, %ysize );
}

// .......................................................................................
function makeTextObject( %scenegraph_obj, %text)
{
    %obj = new t2dTextObject() 
    { 
        scenegraph      =  %scenegraph_obj;
        text            = "";
        textAlign       = "Center";
        font            = "Times New Roman Bold";
        hideOverflow    = false;
        autoSize        = true;
        Visible         = true;
        
        blendIgnoreTextureAlpha = "0";
        wordWrap = "0";
        hideOverflow = "0";
        aspectRatio = "1";
        lineSpacing = "0";
        characterSpacing = "0";
        autoSize = "1";
        filter = "1";
        integerPrecision = "1";
        noUnicode = "0";
        hideOverlap = "0";        
        
    };
    %fontsize = 48;
    %obj.removeAllFontSizes();
    %obj.addFontSize( %fontsize );
    %obj.LineHeight = %fontsize + 10;  
    %obj.setBlendColor( 0.0, 0.0, 0.0, 1.0 );
    %obj.setSize( 30 );
    %obj.setLayer( 5 );
    %obj.setVisible( true );
    %obj.setPosition( 0, -200 );
    %obj.text = %text;
    return %obj;
}


// .....................................................................................
function CreateBackground( %scenegraph_obj )
{
    %obj = new t2dStaticSprite() 
    { 
        scenegraph = %scenegraph_obj; 
    };
    %obj.setVisible( true );
    %obj.setLayer( 20 );
    
    
   //landscape
   if ( $pref::iDevice::ScreenOrientation  == $iDevice::constant::Landscape )
   {
      if( $platform $= "ipad" ||  ( $platform $= "windows" && $platform_simul $= "ipad") )
      {
         %obj.setSize( 1024, 768 );
      }
      else 
      {
         %obj.setSize( 480, 320 );
      }
   }
   //portrait
   else if ( $pref::iDevice::ScreenOrientation  == $iDevice::constant::Portrait )
   {
     if( $platform $= "ipad" ||  ( $platform $= "windows" && $platform_simul $= "ipad") )
      {
         %obj.setImageMap( "BackgroundImageMap_ipad" );
         %obj.setSize( 768, 1024);
      }
      else 
      {
         %obj.setImageMap( "BackgroundImageMap_iphone" );
         %obj.setSize( 320, 480 );
      }
   }
   
   return %obj;

   
}
#5
08/07/2011 (1:25 pm)

menu.cs


//---------------------------------------------------------------------------------------------
// menu.cs
//---------------------------------------------------------------------------------------------

// .....................................................................................
function MainMenuSceneGraph::OnAdd(%this)
{
   CreateBackground( %this );
   CreateButton( %this, "Level_01_Button",  "ButtonLevelImageMap",  0, -100,  128, 128);
   CreateButton( %this, "Level_02_Button",  "ButtonLevelImageMap", 0,  100,  128, 128);
   makeTextObject( %this, "I am in the Main menu");
}

// .....................................................................................
function MainMenuSceneGraph::onLevelEnded(%this)
{
   %this.clearScene();
}
#6
08/07/2011 (1:28 pm)

level_01.cs


//---------------------------------------------------------------------------------------------
// level_01.cs
//---------------------------------------------------------------------------------------------

// .....................................................................................
function SceneGraphLevel_01::OnAdd(%this)
{
   CreateBackground( %this );
   CreateButton( %this, "ButtonHome", "ButtonHomeImageMap", 0,  170, 128, 128);
   makeTextObject( %this, "I am in Level 1");
}

// .....................................................................................
function SceneGraphLevel_01::onLevelEnded(%this)
{
   %this.clearScene();
}
#7
09/08/2011 (1:30 pm)

level_02.cs


The ML text level

www.space-research.org/games/garage_games/21169_3.png
//---------------------------------------------------------------------------------------------
// level_02.cs
//---------------------------------------------------------------------------------------------



if(!isObject(GuiModelessDialogProfile)) new GuiControlProfile("GuiModelessDialogProfile")
{
   modal = false;
};

if ( !isObject( GuiMLTextProfile )) new GuiControlProfile( "GuiMLTextProfile" )
{
    fontType       = "Times New Roman Bold";
    fontSize       = 48;
    fontColor      = "255 0 0";
    autoSizeWidth  = true;
    autoSizeHeight = true;  
    border         = false;
    justify        = "center";
    modal          = false;
};


// .....................................................................................
function SceneGraphLevel_02::OnAdd(%this)
{
   CreateBackground( %this );
   CreateButton( %this, "ButtonHome", "ButtonHomeImageMap", 0, 170, 128, 128);
   %this.CreateGuiText();
   
}

// .....................................................................................
function SceneGraphLevel_02::onLevelEnded(%this)
{
   %this.clearScene();
   %this.GuiTextCredits.delete();  
   
}

// .....................................................................................
function SceneGraphLevel_02::CreateGuiText( %this )
{
   %text   = "<just:center><br>I am<br>in level 2";
   
   %this.guiOverlay = new GuiControl() 
   {
        canSaveDynamicFields    = "0";
        Profile                 = "GuiModelessDialogProfile";
        HorizSizing             = "left";
        VertSizing              = "right";
        Position                = "0 0";
        Extent                  = "320 320";
        MinExtent               = "8 8";
        canSave                 = "1";
        Visible                 = "1";
        hovertime               = "1000";
   };
   
   %this.GuiTextCredits = new GuiMLTextCtrl()
    {
        canSaveDynamicFields  = "0";
        Profile               = "GuiMLTextProfile";
        HorizSizing           = "width";
        VertSizing            = "height";
        Position              = "0 0";
        Extent                = "320 320";
        MinExtent             = "8 2";
        canSave               = "1";
        Visible               = "1";
        hovertime             = "1000";
        lineSpacing           = "2";
        allowColorChars       = "0";
        maxChars              = "-1";
    };
    
   %this.GuiTextCredits.SetText( %text );  
   %this.guiOverlay.addGuiControl( %this.GuiTextCredits );
   canvas.pushDialog( %this.guiOverlay );  

   
}
#8
09/08/2011 (1:31 pm)

datablocks.cs


new t2dImageMapDatablock(BackgroundImageMap_iphone) 
{
      imageName = "data/images/background_iphone.png";
      imageMode = "FULL";
      filterPad = "1";
};

new t2dImageMapDatablock(BackgroundImageMap_ipad) 
{
      imageName = "data/images/background_ipad.png";
      imageMode = "FULL";
      filterPad = "1";
};



   
//---------------------------------------------------------------------------------------------
// buttons
//---------------------------------------------------------------------------------------------   


new t2dImageMapDatablock(ButtonHomeImageMap) 
{
      imageName = "data/images/button_home.png";
      imageMode = "FULL";
      filterPad = "1";
};


   
new t2dImageMapDatablock(ButtonLevelImageMap) 
{
      imageName = "data/images/button_level.png";
      imageMode = "FULL";
      filterPad = "1";
};
   
//---------------------------------------------------------------------------------------------
// audio
//---------------------------------------------------------------------------------------------      
  
new AudioDescription(SoundOnce)
{
   volume		= 1.0;
   type		   = 0;
   isLooping	= false;
   is3D		   = false;
};

new AudioProfile(beepSound)
{
   filename	   = "data/audio/beep.wav";
   description = "SoundOnce";
   preload 	   = true;
}; 

  
//---------------------------------------------------------------------------------------------
// button classes
//---------------------------------------------------------------------------------------------   


// .......................................................................................
function ButtonHome::onMouseUp( %this, %modifier, %worldPosition, %clicks )
{
   %this.schedule(0, "changeLevel" );
   alxPlay("beepSound"); 
}

function ButtonHome::changeLevel(%this)
{
	loadSceneGraph( MainMenuSceneGraph );
}

// .......................................................................................
function Level_01_Button::onMouseUp( %this, %modifier, %worldPosition, %clicks )
{   
   %this.schedule(0, "changeLevel" );
   alxPlay("beepSound"); 
}

function Level_01_Button::changeLevel(%this)
{
	loadSceneGraph( SceneGraphLevel_01 );
}

// .......................................................................................
function Level_02_Button::onMouseUp( %this, %modifier, %worldPosition, %clicks )
{   
   %this.schedule(0, "changeLevel" );
   alxPlay("beepSound"); 
}

function Level_02_Button::changeLevel(%this)
{
	loadSceneGraph( SceneGraphLevel_02 );
}