module.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2014 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. function AudioToy::create(%this)
  23. {
  24. // Load script files.
  25. exec("./scripts/ButtonBehavior.cs");
  26. exec("./scripts/AnimationBehavior.cs");
  27. exec("./scripts/SoundBehavior.cs");
  28. exec("./scripts/MusicBehavior.cs");
  29. exec("./scripts/MuteBehavior.cs");
  30. // Turn on input events for scene objects.
  31. SandboxWindow.setUseObjectInputEvents(true);
  32. // Set the camera.
  33. SandboxWindow.setCameraSize(40, 30);
  34. // Setup default values.
  35. AudioToy.Music = "ToyAssets:titleMusic";
  36. // Sandbox options
  37. addSelectionOption("Title Music,Level Music,Win Music,Lose Music", "Background Music", 4, "setupMusic", true, "Choose a music file");
  38. // Reset the toy initially.
  39. AudioToy.reset();
  40. }
  41. //-----------------------------------------------------------------------------
  42. function AudioToy::destroy(%this)
  43. {
  44. // Stop all audio when quitting the module.
  45. alxStopAll();
  46. }
  47. //-----------------------------------------------------------------------------
  48. function AudioToy::reset(%this)
  49. {
  50. // Clear the scene.
  51. SandboxScene.clear();
  52. // Stop all music.
  53. alxStopAll();
  54. // Load scene objects from TAML.
  55. %background = TamlRead("./objects/Background.taml");
  56. %ground = TamlRead("./objects/Ground.taml");
  57. %grass = TamlRead("./objects/Grass.taml");
  58. %barbarian = TamlRead("./objects/Barbarian.taml");
  59. %dwarf = TamlRead("./objects/Dwarf.taml");
  60. %knight = TamlRead("./objects/Knight.taml");
  61. %wizard = TamlRead("./objects/Wizard.taml");
  62. %play = TamlRead("./objects/PlayButton.taml");
  63. %mute = TamlRead("./objects/MuteButton.taml");
  64. // Add objects to the Scene.
  65. SandboxScene.add(%background);
  66. SandboxScene.add(%ground);
  67. SandboxScene.add(%grass);
  68. SandboxScene.add(%barbarian);
  69. SandboxScene.add(%dwarf);
  70. SandboxScene.add(%knight);
  71. SandboxScene.add(%wizard);
  72. SandboxScene.add(%play);
  73. SandboxScene.add(%mute);
  74. }
  75. //-----------------------------------------------------------------------------
  76. function AudioToy::setupMusic(%this, %value)
  77. {
  78. // Reset the toy.
  79. AudioToy.reset();
  80. // Set the music to the proper audio asset.
  81. switch$(%value)
  82. {
  83. case "Title Music":
  84. AudioToy.Music = "ToyAssets:titleMusic";
  85. case "Level Music":
  86. AudioToy.Music = "ToyAssets:level1Music";
  87. case "Win Music":
  88. AudioToy.Music = "ToyAssets:winMusic";
  89. case "Lose Music":
  90. AudioToy.Music = "ToyAssets:loseMusic";
  91. }
  92. }