home *** CD-ROM | disk | FTP | other *** search
/ 404 Jogos / CLJG.iso / Diversos / Beez.swf / scripts / core / bonuses / BonusAttach.as < prev    next >
Encoding:
Text File  |  2008-09-03  |  2.4 KB  |  87 lines

  1. package core.bonuses
  2. {
  3.    import Box2D.Common.Math.b2Vec2;
  4.    import Box2D.Dynamics.Joints.b2DistanceJoint;
  5.    import Box2D.Dynamics.Joints.b2DistanceJointDef;
  6.    import Box2D.Dynamics.b2Body;
  7.    import core.events.CoreEvent;
  8.    import flash.display.Graphics;
  9.    import flash.geom.Point;
  10.    
  11.    public class BonusAttach extends AbstractBonus
  12.    {
  13.        
  14.       
  15.       private var joint:b2DistanceJoint;
  16.       
  17.       public function BonusAttach()
  18.       {
  19.          super(true);
  20.       }
  21.       
  22.       override protected function init() : void
  23.       {
  24.          super.init();
  25.          lifeTime = 40 * 3;
  26.       }
  27.       
  28.       override protected function updateHandler(e:CoreEvent) : void
  29.       {
  30.          if(!joint)
  31.          {
  32.             fix();
  33.          }
  34.          else
  35.          {
  36.             draw();
  37.          }
  38.          super.updateHandler(e);
  39.       }
  40.       
  41.       override public function activate(activateTime:Number) : void
  42.       {
  43.          super.activate(activateTime);
  44.       }
  45.       
  46.       private function fix() : void
  47.       {
  48.          var djd:b2DistanceJointDef = new b2DistanceJointDef();
  49.          var b1:b2Body = engine.platform.getBody();
  50.          var b2:b2Body = engine.playerBall.getBody();
  51.          djd.Initialize(b1,b2,b1.GetWorldCenter(),b2.GetWorldCenter());
  52.          djd.collideConnected = true;
  53.          joint = engine.m_world.CreateJoint(djd) as b2DistanceJoint;
  54.       }
  55.       
  56.       private function draw() : void
  57.       {
  58.          var pos1:b2Vec2 = engine.platform.getBody().GetPosition();
  59.          var pos2:b2Vec2 = engine.playerBall.getBody().GetPosition();
  60.          var p1:Point = new Point(pos1.x * engine.m_physScale,pos1.y * engine.m_physScale);
  61.          var p2:Point = new Point(pos2.x * engine.m_physScale,pos2.y * engine.m_physScale);
  62.          var gr:Graphics = engine.canvas.effectsContainer.graphics;
  63.          gr.lineStyle(3,4282855177,0.8);
  64.          gr.moveTo(p1.x,p1.y);
  65.          gr.lineTo(p2.x,p2.y);
  66.       }
  67.       
  68.       override protected function initSounds() : void
  69.       {
  70.          var AttachBonusClass:Class = engine.assets.getAssetClass("SndAttachBonus");
  71.          sndActivate = new AttachBonusClass();
  72.       }
  73.       
  74.       override protected function deactivate() : void
  75.       {
  76.          unfix();
  77.          super.deactivate();
  78.       }
  79.       
  80.       private function unfix() : void
  81.       {
  82.          engine.m_world.DestroyJoint(joint);
  83.          joint = null;
  84.       }
  85.    }
  86. }
  87.