main.cs 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 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 NoiseToy::create( %this )
  23. {
  24. // Load scripts.
  25. exec( "./scripts/terrainMap.cs" );
  26. // Set the sandbox drag mode availability.
  27. Sandbox.allowManipulation( pan );
  28. Sandbox.allowManipulation( pull );
  29. // Set the manipulation mode.
  30. Sandbox.useManipulation( pan );
  31. // Configure the toy.
  32. NoiseToy.Seed = getRandom(1, 100);
  33. NoiseToy.OctaveCount = 4;
  34. NoiseToy.Persistence = 0.5;
  35. SandboxScene.clear();
  36. //Create our noise generator
  37. NoiseToy.generator = new NoiseGenerator();
  38. //Create our map
  39. NoiseToy.terrain = new CompositeSprite()
  40. {
  41. class = "TerrainMap";
  42. };
  43. // Add the configuration options.
  44. addSelectionOption( "Earth,Moon,Mars,PlanetX", "Color Mode", 4, "setColorMode", false, "Changes the colors used for different values." );
  45. addNumericOption("Seed", 1, 999999, 1, "setNoiseSeed", NoiseToy.Seed, false, "A given seed always prouduces the same result." );
  46. addNumericOption("Octave Count", 1, 8, 1, "setOctaveCount", NoiseToy.OctaveCount, false, "Each octave produces a smaller layer of noise added to the result." );
  47. addNumericOption("Persistence", 0.05, 0.95, 0.05, "setPersistence", NoiseToy.persistence, false, "Higher values of persistence allow each octave to have a greater impact on the result." );
  48. // Reset the toy.
  49. %this.reset();
  50. }
  51. function NoiseToy::destroy( %this )
  52. {
  53. }
  54. function NoiseToy::reset(%this)
  55. {
  56. %this.generator.setSeed(%this.seed);
  57. %this.terrain.generate(%this.generator, %this.octaveCount, %this.persistence);
  58. }
  59. function NoiseToy::setColorMode(%this, %value)
  60. {
  61. %this.terrain.colorMode = %value;
  62. %this.terrain.generate(%this.generator, %this.octaveCount, %this.persistence);
  63. }
  64. function NoiseToy::setNoiseSeed( %this, %value )
  65. {
  66. NoiseToy.Seed = %value;
  67. %this.reset();
  68. }
  69. function NoiseToy::setOctaveCount( %this, %value )
  70. {
  71. NoiseToy.OctaveCount = %value;
  72. %this.terrain.generate(%this.generator, %this.octaveCount, %this.persistence);
  73. }
  74. function NoiseToy::setPersistence( %this, %value )
  75. {
  76. NoiseToy.Persistence = %value;
  77. %this.terrain.generate(%this.generator, %this.octaveCount, %this.persistence);
  78. }