home *** CD-ROM | disk | FTP | other *** search
- package core.bonuses
- {
- import Box2D.Common.Math.b2Vec2;
- import Box2D.Dynamics.Joints.b2DistanceJoint;
- import Box2D.Dynamics.Joints.b2DistanceJointDef;
- import Box2D.Dynamics.b2Body;
- import core.events.CoreEvent;
- import flash.display.Graphics;
- import flash.geom.Point;
-
- public class BonusAttach extends AbstractBonus
- {
-
-
- private var joint:b2DistanceJoint;
-
- public function BonusAttach()
- {
- super(true);
- }
-
- override protected function init() : void
- {
- super.init();
- lifeTime = 40 * 3;
- }
-
- override protected function updateHandler(e:CoreEvent) : void
- {
- if(!joint)
- {
- fix();
- }
- else
- {
- draw();
- }
- super.updateHandler(e);
- }
-
- override public function activate(activateTime:Number) : void
- {
- super.activate(activateTime);
- }
-
- private function fix() : void
- {
- var djd:b2DistanceJointDef = new b2DistanceJointDef();
- var b1:b2Body = engine.platform.getBody();
- var b2:b2Body = engine.playerBall.getBody();
- djd.Initialize(b1,b2,b1.GetWorldCenter(),b2.GetWorldCenter());
- djd.collideConnected = true;
- joint = engine.m_world.CreateJoint(djd) as b2DistanceJoint;
- }
-
- private function draw() : void
- {
- var pos1:b2Vec2 = engine.platform.getBody().GetPosition();
- var pos2:b2Vec2 = engine.playerBall.getBody().GetPosition();
- var p1:Point = new Point(pos1.x * engine.m_physScale,pos1.y * engine.m_physScale);
- var p2:Point = new Point(pos2.x * engine.m_physScale,pos2.y * engine.m_physScale);
- var gr:Graphics = engine.canvas.effectsContainer.graphics;
- gr.lineStyle(3,4282855177,0.8);
- gr.moveTo(p1.x,p1.y);
- gr.lineTo(p2.x,p2.y);
- }
-
- override protected function initSounds() : void
- {
- var AttachBonusClass:Class = engine.assets.getAssetClass("SndAttachBonus");
- sndActivate = new AttachBonusClass();
- }
-
- override protected function deactivate() : void
- {
- unfix();
- super.deactivate();
- }
-
- private function unfix() : void
- {
- engine.m_world.DestroyJoint(joint);
- joint = null;
- }
- }
- }
-