Skip to content

Duff Physics Alpha

by Colin on April 8th, 2011



This example was made using the following code:

  1. public function createEngine():void
  2. {
  3. midPoint = new Point();
  4. midPoint.x = stage.stageWidth / 2;
  5. midPoint.y = stage.stageHeight / 2;
  6. engine = new PhysicsEngine();
  7. var iterator:Ball;
  8. var pFactor:PauliFactor;
  9. for( var i:int = 0; i < TOTAL_BALLS; i++ ) {
  10. iterator = new Ball();
  11. iterator.x = MathUtil.randRange( 100, 700 );
  12. iterator.y = MathUtil.randRange( 100, 500 );
  13. addChild( iterator );
  14.  
  15. pFactor = new PauliFactor( iterator, i, 10 );
  16. pFactor.engine = engine;
  17. pFactor.magneticPoint = midPoint;
  18. pFactor.gravity = GRAVITY_STRENGTH;
  19. pFactor.aggression = pauliStrength;
  20. engine.addFactor( pFactor );
  21. }
  22. iterator = null;
  23. engine.addEventListener( PhysicsEvent.RENDER, updateEngine );
  24. engine.start();
  25. }
  26.  
  27. private function updateEngine( evt:PhysicsEvent ):void
  28. {
  29. var iterator:PauliFactor;
  30. if( FOLLOW_MOUSE ) {
  31. midPoint.x = mouseX;
  32. midPoint.y = mouseY;
  33. } else {
  34. midPoint.x = STAGE_MID_WID;
  35. midPoint.y = STAGE_MID_HEI;
  36. }
  37.  
  38. graph.clear();
  39. graph.lineStyle( 1, 0x262626, 1 );
  40. graph.moveTo( engine.factors[0].x, engine.factors[0].y );
  41.  
  42. for( var i:int = 0; i < engine.totalFactors; i++ ) {
  43. iterator = PauliFactor( engine.factors[i] );
  44. iterator.magneticPoint = midPoint;
  45. iterator.useMagnetism = USE_MAGNETISM;
  46. iterator.usePauli = USE_PAULI;
  47. iterator.aggression = pauliStrength;
  48. iterator.gravity = GRAVITY_STRENGTH;
  49. graph.lineTo( iterator.x, iterator.y );
  50. }
  51. graph.lineTo( engine.factors[0].x, engine.factors[0].y );
  52. }

The goal of this physics engine is to simplify common physics scenarios with ease.
I plan on converting this to Objective C once the official release is complete.

From → Flash

No comments yet

Leave a Reply

Note: XHTML is allowed. Your email address will never be published.

Subscribe to this comment feed via RSS