1. /* ====================
  2. M A I N
  3. ======================= */
  4.  
  5.  
  6. /*
  7. * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
  8. *
  9. * This software is provided 'as-is', without any express or implied
  10. * warranty. In no event will the authors be held liable for any damages
  11. * arising from the use of this software.
  12. * Permission is granted to anyone to use this software for any purpose,
  13. * including commercial applications, and to alter it and redistribute it
  14. * freely, subject to the following restrictions:
  15. * 1. The origin of this software must not be misrepresented; you must not
  16. * claim that you wrote the original software. If you use this software
  17. * in a product, an acknowledgment in the product documentation would be
  18. * appreciated but is not required.
  19. * 2. Altered source versions must be plainly marked as such, and must not be
  20. * misrepresented as being the original software.
  21. * 3. This notice may not be removed or altered from any source distribution.
  22. */
  23.  
  24. package{
  25.  
  26. import Box2D.Dynamics.*
  27. import Box2D.Collision.*
  28. import Box2D.Collision.Shapes.*
  29. import Box2D.Dynamics.Joints.*
  30. import Box2D.Dynamics.Contacts.*
  31. import Box2D.Common.Math.*
  32. import flash.events.Event;
  33. import flash.display.*;
  34. import flash.text.*;
  35. import General.*
  36. import TestBed.*;
  37. import TestBed.TestBridge;
  38.  
  39.  
  40. import flash.display.MovieClip;
  41. public class Main extends MovieClip{
  42. public function Main(){
  43.  
  44. addEventListener(Event.ENTER_FRAME, update, false, 0, true);
  45.  
  46. m_fpsCounter.x = 7;
  47. m_fpsCounter.y = 5;
  48. addChildAt(m_fpsCounter, 0);
  49.  
  50. m_sprite = new Sprite();
  51. addChild(m_sprite);
  52. // input
  53. m_input = new Input(m_sprite);
  54.  
  55.  
  56. //Instructions Text
  57. var instructions_text:TextField = new TextField();
  58.  
  59. var instructions_text_format:TextFormat = new TextFormat("Arial", 16, 0xffffff, false, false, false);
  60. instructions_text_format.align = TextFormatAlign.RIGHT;
  61.  
  62. instructions_text.defaultTextFormat = instructions_text_format
  63. instructions_text.x = 140
  64. instructions_text.y = 4.5
  65. instructions_text.width = 495
  66. instructions_text.height = 61
  67. instructions_text.text = ""
  68. addChild(instructions_text);
  69.  
  70. // textfield pointer
  71. m_aboutText = new TextField();
  72. var m_aboutTextFormat:TextFormat = new TextFormat("Arial", 16, 0x00CCFF, true, false, false);
  73. m_aboutTextFormat.align = TextFormatAlign.RIGHT;
  74. m_aboutText.defaultTextFormat = m_aboutTextFormat
  75. m_aboutText.x = 334
  76. m_aboutText.y = 71
  77. m_aboutText.width = 300
  78. m_aboutText.height = 30
  79. addChild(m_aboutText);
  80.  
  81. // Thanks to everyone who contacted me about this fix
  82. instructions_text.mouseEnabled = false;
  83. m_aboutText.mouseEnabled = false;
  84. m_currTest = new TestCompound(4);
  85. }
  86.  
  87. public function update(e:Event):void{
  88. // clear for rendering
  89. m_sprite.graphics.clear()
  90.  
  91. // toggle between tests
  92. if (Input.isKeyPressed(39)){ // Right Arrow
  93. m_currId++;
  94. m_currTest = null;
  95. }
  96. else if (Input.isKeyPressed(37)){ // Left Arrow
  97. m_currId--;
  98. m_currTest = null
  99. }
  100. // Reset
  101. else if (Input.isKeyPressed(82)){ // R
  102. m_currTest = null
  103. }
  104.  
  105. else if (Input.isKeyPressed(103)){ // g
  106. m_currTest = new TestCompound(this.num_legs);
  107. }
  108.  
  109. m_currTest = new TestCompound(this.num_legs);
  110.  
  111. // update current test
  112. m_currTest.Update();
  113.  
  114. // Update input (last)
  115. Input.update();
  116.  
  117. // update counter and limit framerate
  118. m_fpsCounter.update();
  119. FRateLimiter.limitFrame(30);
  120.  
  121. }
  122.  
  123. public function go (e:Event) :void
  124. {
  125. m_currTest = new TestCompound(this.num_legs);
  126. }
  127.  
  128. //======================
  129. // Member data
  130. //======================
  131. static public var m_fpsCounter:FpsCounter = new FpsCounter();
  132. public var m_currId:int = 0;
  133. public var m_currTest:Test;
  134. static public var m_sprite:Sprite;
  135. static public var m_aboutText:TextField;
  136. // input
  137. public var m_input:Input;
  138. }
  139. }
  140.  
  141. /* ====================
  142. T e s t C o m p o u n d
  143. ======================= */