topical media & game development

talk show tell print [swf] flex

  package {
          import org.cove.ape.*;
          import flash.display.Sprite;
This is an example showing use of the WheelParticles and collidable SpringConstraints used as surfaces in the 'bridge' area. The bouncy area has a high elasticity setting to push the car back up to the top.

          [SWF(width="650", height="350", backgroundColor="#334433")] 
          public class @ax-physic-flex-ape-sample-car-demo extends Sprite {
                  private static var colA:uint = 0x334433;
                  private static var colB:uint = 0x3366aa;
                  private static var colC:uint = 0xaabbbb;
                  private static var colD:uint = 0x6699aa;
                  private static var colE:uint = 0x778877;
                  private var car:physic_flex_ape_sample_car_Car;
                  private var rotator:physic_flex_ape_sample_car_Rotator;
                  public function @ax-physic-flex-ape-sample-car-demo() {
                          // set up the events, main loop handler, and the engine. you don't have to use
                          // enterframe. you just need to call the ApeEngine.step() and ApeEngine.paint() 
                          // wherever and however you're handling your program cycle.
                          stage.frameRate = 55;
                          stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
              stage.addEventListener(KeyboardEvent.KEY_UP, keyUpHandler);
                          addEventListener(Event.ENTER_FRAME, run);
                          // Initialize the engine. The argument here is the time step value. 
                          // Higher values scale the forces in the sim, making it appear to run
                          // faster or slower. Lower values result in more accurate simulations.
                          // set up the default diplay container
                          APEngine.container = this;
                          // gravity -- particles of varying masses are affected the same
                          APEngine.addMasslessForce(new AVector(0, 3));
                          // groups - all these classes extend group
                          var surfaces:physic_flex_ape_sample_car_Surfaces = new physic_flex_ape_sample_car_Surfaces(colA, colB, colC, colD, colE);
                          var bridge:physic_flex_ape_sample_car_Bridge = new physic_flex_ape_sample_car_Bridge(colB, colC, colD);
                          var capsule:physic_flex_ape_sample_car_Capsule = new physic_flex_ape_sample_car_Capsule(colC);
                          rotator = new physic_flex_ape_sample_car_Rotator(colB, colE);
                          var swingDoor:physic_flex_ape_sample_car_SwingDoor = new physic_flex_ape_sample_car_SwingDoor(colC);
                          car = new physic_flex_ape_sample_car_Car(colC, colE);
                          // determine what collides with what.
                          car.addCollidableList(new Array(surfaces, bridge, rotator, swingDoor, capsule));
                          capsule.addCollidableList(new Array(surfaces, bridge, rotator, swingDoor));
                  private function run(evt:Event):void {
                  private function keyDownHandler(keyEvt:KeyboardEvent):void {
                          var keySpeed:Number = 0.2;
                          if (keyEvt.keyCode == 65) {
                                  car.speed = -keySpeed;
                          } else if (keyEvt.keyCode == 68) {
                                  car.speed = keySpeed;
                  private function keyUpHandler(keyEvt:KeyboardEvent):void {
                          car.speed = 0;

(C) Æliens 04/09/2009

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.