home *** CD-ROM | disk | FTP | other *** search
- package core.objects
- {
- import Box2D.Collision.Shapes.b2CircleDef;
- import Box2D.Collision.Shapes.b2ShapeDef;
- import Box2D.Dynamics.b2Body;
- import Box2D.Dynamics.b2BodyDef;
- import core.events.CoreEvent;
-
- public class Ball extends BaseObject
- {
-
-
- public var ballDef:BallDef;
-
- public function Ball(def:BallDef)
- {
- ballDef = def;
- super(def);
- }
-
- override protected function init() : void
- {
- super.init();
- engine.dispatcher.addEventListener(CoreEvent.UPDATE,updateHandler);
- updateSkin();
- initSounds();
- }
-
- protected function updateHandler(e:CoreEvent) : void
- {
- updateSkin();
- var posY:Number = body.GetPosition().y * engine.m_physScale;
- if(posY > 480 + ballDef.r)
- {
- isDead = true;
- }
- }
-
- protected function initSounds() : void
- {
- }
-
- override protected function createBody(bodyDef:b2BodyDef, shapeDef:b2ShapeDef) : b2Body
- {
- var body:b2Body = engine.m_world.CreateBody(bodyDef);
- body.CreateShape(shapeDef);
- body.SetMassFromShapes();
- return body;
- }
-
- override protected function createShapeDef() : b2ShapeDef
- {
- var shapeDef:b2CircleDef = null;
- shapeDef = new b2CircleDef();
- shapeDef.radius = ballDef.r / engine.m_physScale;
- shapeDef.density = 1;
- shapeDef.friction = 0.5;
- shapeDef.restitution = 0.2;
- shapeDef.filter.categoryBits = 2;
- shapeDef.filter.maskBits = 65535 & ~2;
- return shapeDef;
- }
-
- override public function destroy(e:CoreEvent = null) : void
- {
- super.destroy(e);
- engine.dispatcher.removeEventListener(CoreEvent.UPDATE,updateHandler);
- }
-
- override protected function createBodyDef() : b2BodyDef
- {
- var bodyDef:b2BodyDef = new b2BodyDef();
- bodyDef.position.Set(ballDef.x / engine.m_physScale,ballDef.y / engine.m_physScale);
- bodyDef.isBullet = true;
- bodyDef.userData = this;
- return bodyDef;
- }
- }
- }
-