main.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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 SceneLayerToy::create( %this )
  23. {
  24. // Configure the toy.
  25. SceneLayerToy.AngularSpeed = 1;
  26. // Add the configuration options.
  27. addNumericOption("Angular Speed", -50, 50, 1, "setAngularScale", SceneLayerToy.AngularSpeed, true, "Sets the rotational speed for the blocks." );
  28. // Reset the toy.
  29. SceneLayerToy.reset();
  30. }
  31. //-----------------------------------------------------------------------------
  32. function SceneLayerToy::destroy( %this )
  33. {
  34. }
  35. //-----------------------------------------------------------------------------
  36. function SceneLayerToy::reset( %this )
  37. {
  38. // Clear the scene.
  39. SandboxScene.clear();
  40. // Create background.
  41. %this.createBackground();
  42. // Create scene layers.
  43. %this.createSceneLayers();
  44. }
  45. //-----------------------------------------------------------------------------
  46. function SceneLayerToy::createBackground( %this )
  47. {
  48. // Create the sprite.
  49. %object = new Sprite();
  50. // Set the sprite as "static" so it is not affected by gravity.
  51. %object.setBodyType( static );
  52. // Always try to configure a scene-object prior to adding it to a scene for best performance.
  53. // Set the position.
  54. %object.Position = "0 0";
  55. // Set the size.
  56. %object.Size = "100 75";
  57. // Set to the furthest background layer.
  58. %object.SceneLayer = 31;
  59. // Set an image.
  60. %object.Image = "ToyAssets:highlightBackground";
  61. // Set the blend color.
  62. %object.BlendColor = SlateGray;
  63. // Add the sprite to the scene.
  64. SandboxScene.add( %object );
  65. }
  66. //-----------------------------------------------------------------------------
  67. function SceneLayerToy::createSceneLayers( %this )
  68. {
  69. // Add a sprite to all scene layers.
  70. for( %layer = 0; %layer <= 31; %layer++ )
  71. {
  72. // Create the sprite.
  73. %object = new Sprite();
  74. // Set the position so each layer is in a different Y position.
  75. %object.SetPosition( -32 + (%layer * 2), -27 + (%layer * 1.5) );
  76. // Set the size.
  77. %object.Size = "30 10";
  78. // Set the scene layer.
  79. %object.SceneLayer = %layer;
  80. // Set the image.
  81. %object.Image = "ToyAssets:Blocks";
  82. // Set the frame to be the layer number.
  83. %object.Frame = %layer;
  84. // Set the object randomly spinning to make it more interesting.
  85. %object.AngularVelocity = %layer * SceneLayerToy.AngularSpeed;
  86. // Don't let it sleep.
  87. // This is done because the sprites rotating VERY slowly might get
  88. // put to sleep.
  89. %object.SleepingAllowed = false;
  90. // Add the object to the scene.
  91. SandboxScene.add( %object );
  92. }
  93. }
  94. //-----------------------------------------------------------------------------
  95. function SceneLayerToy::setAngularScale( %this, %value )
  96. {
  97. SceneLayerToy.AngularSpeed = %value;
  98. }