main.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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 LeapToy::create( %this )
  23. {
  24. // Execute toy scripts
  25. exec("./scripts/input.cs");
  26. exec("./scripts/toy.cs");
  27. exec("./scripts/gestureDemo.cs");
  28. exec("./scripts/breakoutDemo.cs");
  29. exec("./scripts/fingerDemo.cs");
  30. exec("./scripts/builderDemo.cs");
  31. exec("./scripts/helpText.cs");
  32. exec("./scripts/DealsDamageBehavior.cs");
  33. exec("./scripts/TakesDamageBehavior.cs");
  34. exec("./scripts/SwapImageOnCollision.cs");
  35. %this.handPosDeadzone = "-1.0 1.0";
  36. %this.handRotDeadzone = "-1.0 1.0";
  37. %this.fingerPosDeadzone = "-1.0 1.0";
  38. %this.enableSwipeGesture = false;
  39. %this.enableCircleGesture = false;
  40. %this.enableScreenTapGesture = false;
  41. %this.enableKeyTapGesture = false;
  42. %this.enableHandRotation = false;
  43. %this.enableFingerTracking = true;
  44. %this.currentLevel = "Builder Demo";
  45. addFlagOption( "Enable Swipe Gesture", "setEnableSwipeGesture", LeapToy.enableSwipeGesture, false, "Turns on swipe gesture recognition" );
  46. addFlagOption( "Enable Circle Gesture", "setEnableCircleGesture", LeapToy.enableCircleGesture, false, "Turns on circle gesture recognition" );
  47. addFlagOption( "Enable Screen Tap Gesture", "setEnableScreenTapGesture", LeapToy.enableScreenTapGesture, false, "Turns on screen tap gesture recognition" );
  48. addFlagOption( "Enable Key Tap Gesture", "setEnableKeyTapGesture", LeapToy.enableKeyTapGesture, false, "Turns on key tap gesture recognition" );
  49. addFlagOption( "Enable Hand Rotation", "setEnableHandRotation", LeapToy.enableHandRotation, false, "Turns on tracking of hand rotation" );
  50. addFlagOption( "Enable Finger Tracking", "setenableFingerTracking", LeapToy.enableFingerTracking, false, "Turns on tracking of finger position" );
  51. %options = "Gestures,Breakout,Finger Tracking,Builder Demo";
  52. addSelectionOption(%options, "Level", 4, setLevel, true, "Choose which Leap Motion Demo to play");
  53. // Set the sandbox drag mode availability.
  54. Sandbox.allowManipulation( pull );
  55. // Configure the toy.
  56. LeapToy.GroundWidth = 40;
  57. LeapToy.BlockSize = 2;
  58. LeapToy.BlockCount = 15;
  59. LeapToy.BrickRows = 4;
  60. LeapToy.BrickColumns = 9;
  61. LeapToy.BrickSize = "3 1";
  62. LeapToy.PaddleSpeed = 30;
  63. LeapToy.maxBallSpeed = 20;
  64. LeapToy.fingerCount = 0;
  65. // Initialize all bindings
  66. %this.initializeInput();
  67. // Build the behaviors
  68. %this.createDealsDamageBehavior();
  69. %this.createTakesDamageBehavior();
  70. %this.createSwapImageBehavior();
  71. %this.selectedObjects = new SimSet();
  72. %this.add(%this.selectedObjects);
  73. // Reset the toy.
  74. LeapToy.reset();
  75. }
  76. //-----------------------------------------------------------------------------
  77. function LeapToy::destroy( %this )
  78. {
  79. // Turn off Leap driven cursor control, if it was activated
  80. if (isLeapCursorControlled())
  81. enableLeapMotionManager(false);
  82. %this.selectedObjects.clear();
  83. %this.selectedObjects.delete();
  84. // Clean up the help text
  85. if (isObject(HelpTextScene))
  86. HelpTextScene.delete();
  87. // Clean up the ActionMaps
  88. %this.destroyInput();
  89. }
  90. //-----------------------------------------------------------------------------
  91. function LeapToy::reset( %this )
  92. {
  93. // Reset the input
  94. FingerMap.pop();
  95. GestureMap.pop();
  96. BreakoutMap.pop();
  97. BuilderMap.pop();
  98. // Clean up the help text if there is one
  99. %this.clearHelpTextScene();
  100. // Clear the scene.
  101. SandboxScene.clear();
  102. // Set the camera size.
  103. SandboxWindow.setCameraSize( 40, 30 );
  104. if (%this.currentLevel $= "Gestures")
  105. %this.createGesturesLevel();
  106. else if (%this.currentLevel $= "Breakout")
  107. %this.createBreakoutLevel();
  108. else if (%this.currentLevel $= "Finger Tracking")
  109. %this.createFingerLevel();
  110. else if (%this.currentLevel $= "Builder Demo")
  111. %this.createBuilderLevel();
  112. }
  113. //-----------------------------------------------------------------------------
  114. function LeapToy::setLevel( %this, %value)
  115. {
  116. %this.currentLevel = %value;
  117. }
  118. //-----------------------------------------------------------------------------
  119. function LeapToy::setEnableSwipeGesture( %this, %value )
  120. {
  121. %this.enableSwipeGesture = %value;
  122. }
  123. //-----------------------------------------------------------------------------
  124. function LeapToy::setEnableCircleGesture( %this, %value )
  125. {
  126. %this.enableCircleGesture = %value;
  127. }
  128. //-----------------------------------------------------------------------------
  129. function LeapToy::setEnableScreenTapGesture( %this, %value )
  130. {
  131. %this.enableScreenTapGesture = %value;
  132. }
  133. //-----------------------------------------------------------------------------
  134. function LeapToy::setEnableKeyTapGesture( %this, %value )
  135. {
  136. %this.enableKeyTapGesture = %value;
  137. }
  138. //-----------------------------------------------------------------------------
  139. function LeapToy::setEnableHandRotation( %this, %value )
  140. {
  141. %this.enableHandRotation = %value;
  142. }
  143. //-----------------------------------------------------------------------------
  144. function LeapToy::setEnableFingerTracking( %this, %value )
  145. {
  146. %this.enableFingerTracking = %value;
  147. }