main.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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 CompositeSpriteToy::create( %this )
  23. {
  24. // Load scripts.
  25. exec( "./scripts/noLayout.cs" );
  26. exec( "./scripts/rectLayout.cs" );
  27. exec( "./scripts/isoLayout.cs" );
  28. exec( "./scripts/customLayout.cs" );
  29. // Set the sandbox drag mode availability.
  30. Sandbox.allowManipulation( pan );
  31. Sandbox.allowManipulation( pull );
  32. // Set the manipulation mode.
  33. Sandbox.useManipulation( pan );
  34. // Configure the toy.
  35. CompositeSpriteToy.LayoutMode = "None";
  36. CompositeSpriteToy.AngularVelocity = 15;
  37. CompositeSpriteToy.SpriteCount = 50;
  38. CompositeSpriteToy.RenderIsolated = false;
  39. // Add the configuration options.
  40. addSelectionOption( "None,Custom,Rectilinear,Isometric", "Layout Mode", 4, "setLayoutMode", true, "Selects the layout mode for the composite sprite." );
  41. addNumericOption("Maximum Sprite Count", 10, 1000, 10, "setSpriteCount", CompositeSpriteToy.SpriteCount, true, "Sets the maximum number of sprites to create." );
  42. addNumericOption("Angular Velocity", -180, 180, 20, "setAngularVelocity", CompositeSpriteToy.AngularVelocity, false, "Sets the rate at which the composite sprite spins." );
  43. addFlagOption("Render Isolated", "setRenderIsolated", CompositeSpriteToy.RenderIsolated, true , "Whether the composite renders its sprites isolated from the scene layer it occupies or not.");
  44. // Reset the toy.
  45. %this.reset();
  46. }
  47. //-----------------------------------------------------------------------------
  48. function CompositeSpriteToy::destroy( %this )
  49. {
  50. }
  51. //-----------------------------------------------------------------------------
  52. function CompositeSpriteToy::reset( %this )
  53. {
  54. // Clear the scene.
  55. SandboxScene.clear();
  56. // Create the background.
  57. %this.createBackground();
  58. // Create the appropriate layout.
  59. switch$( CompositeSpriteToy.LayoutMode )
  60. {
  61. case "None":
  62. %this.createNoLayout();
  63. case "Custom":
  64. %this.createCustomLayout();
  65. case "Rectilinear":
  66. %this.createRectLayout();
  67. case "Isometric":
  68. %this.createIsoLayout();
  69. }
  70. }
  71. //-----------------------------------------------------------------------------
  72. function CompositeSpriteToy::setLayoutMode( %this, %value )
  73. {
  74. CompositeSpriteToy.LayoutMode = %value;
  75. }
  76. //-----------------------------------------------------------------------------
  77. function CompositeSpriteToy::setAngularVelocity( %this, %value )
  78. {
  79. CompositeSpriteToy.AngularVelocity = %value;
  80. // Update any active composite sprite.
  81. if ( isObject(CompositeSpriteToy.CompositeSprite) && CompositeSpriteToy.LayoutMode !$= "Isometric" )
  82. {
  83. CompositeSpriteToy.CompositeSprite.setAngularVelocity( %value );
  84. }
  85. }
  86. //-----------------------------------------------------------------------------
  87. function CompositeSpriteToy::setSpriteCount( %this, %value )
  88. {
  89. CompositeSpriteToy.SpriteCount = %value;
  90. }
  91. //-----------------------------------------------------------------------------
  92. function CompositeSpriteToy::setRenderIsolated( %this, %value )
  93. {
  94. CompositeSpriteToy.RenderIsolated = %value;
  95. }
  96. //-----------------------------------------------------------------------------
  97. function CompositeSpriteToy::createBackground(%this)
  98. {
  99. // Create the checkered background.
  100. %obj = new Scroller();
  101. %obj.Image = "ToyAssets:checkered";
  102. %obj.BlendColor = SlateGray;
  103. %obj.Size = 200;
  104. %obj.RepeatX = 8;
  105. %obj.RepeatY = 8;
  106. %obj.ScrollX = 10;
  107. %obj.ScrollY = 7;
  108. // Add to the scene.
  109. SandboxScene.add( %obj );
  110. }
  111. //-----------------------------------------------------------------------------
  112. function CompositeSpriteToy::onTouchDown(%this, %touchID, %worldPosition)
  113. {
  114. // Fetch the composite sprite.
  115. %compositeSprite = CompositeSpriteToy.CompositeSprite;
  116. // Pick sprites.
  117. %sprites = %compositeSprite.pickPoint( %worldPosition );
  118. // Fetch sprite count.
  119. %spriteCount = %sprites.count;
  120. // Finish if no sprites picked.
  121. if ( %spriteCount == 0 )
  122. return;
  123. // Iterate sprites.
  124. for( %i = 0; %i < %spriteCount; %i++ )
  125. {
  126. // Fetch sprite Id.
  127. %spriteId = getWord( %sprites, %i );
  128. // Select the sprite Id.
  129. %compositeSprite.selectSpriteId( %spriteId );
  130. // Remove the se
  131. %compositeSprite.removeSprite();
  132. }
  133. }