Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package
- {
- import flash.display.*;
- import flash.events.*;
- import flash.geom.Point;
- import Box2D.Dynamics.*;
- import Box2D.Collision.Shapes.*;
- import Box2D.Common.Math.b2Vec2;
- public class Body
- {
- public var perimeterX:Vector.<int > = new Vector.<int > ;
- public var perimeterY:Vector.<int > = new Vector.<int > ;
- public var currentBoundsX:Vector.<int > = new Vector.<int > ;
- public var currentBoundsY:Vector.<int > = new Vector.<int > ;
- public function Body(This:Thing,shape:String,type:uint,density:Number,friction:Number,restitution:Number):void
- {
- if(type != 3)
- {
- var bodyDef:b2BodyDef = new b2BodyDef();
- bodyDef.type = type;
- bodyDef.position.Set(This.x/30,This.y/30);
- bodyDef.allowSleep = true;
- bodyDef.bullet = false;
- bodyDef.userData = Main.WorldContainer;
- var shp:b2PolygonShape = new b2PolygonShape();
- shp.SetAsBox(This.width/2/30,This.height/2/30);
- This.body = Main.botWorld.CreateBody(bodyDef);
- var fd:b2FixtureDef = new b2FixtureDef();
- fd.density = density;
- fd.friction = friction;
- fd.restitution = restitution;
- fd.shape = shp;
- This.body.CreateFixture(fd);
- }
- else
- {
- }
- //trace(This.Data.width + This.localToGlobal(new Point(This.x,This.y)).x,This.localToGlobal(new Point(This.Data.width + This.x,This.y)).x);
- with (This)
- {
- if (shape == 'rectangle')
- {
- this.perimeterX.push(-Data.width/2,Data.width/2);
- this.perimeterY.push(Data.height/2,-Data.height/2);
- this.currentBoundsX.push(-Data.width/2,Data.width/2);
- this.currentBoundsY.push(Data.height/2,-Data.height/2);
- }
- if (shape == 'circle')
- {
- for (var i:uint = 0; i < 360; i+=2)
- {
- this.perimeterX.push((Data.width/2 * Math.sin(i*Math.PI/180)));
- this.perimeterY.push((Data.height/2 * Math.cos(i*Math.PI/180)));
- this.currentBoundsX.push((Data.width/2 * Math.sin(i*Math.PI/180)));
- this.currentBoundsY.push((Data.height/2 * Math.cos(i*Math.PI/180)));
- }
- }
- }
- }
- public static function Update()
- {
- for (var q:int = 0; q < MotionHandler.physObjects.length; q++)
- {
- for (var w:int = 0; w < 2; w++)
- {//this.onGround = true;
- if (w == 0)
- {
- MotionHandler.physObjects[q].bod.currentBoundsX[w] = MotionHandler.physObjects[q].localToGlobal(new Point(MotionHandler.physObjects[q].bod.perimeterX[w],0)).x;
- MotionHandler.physObjects[q].bod.currentBoundsY[w] = MotionHandler.physObjects[q].localToGlobal(new Point(0,MotionHandler.physObjects[q].bod.perimeterY[w])).y;
- }
- if (w == 1)
- {
- MotionHandler.physObjects[q].bod.currentBoundsX[w] = MotionHandler.physObjects[q].localToGlobal(new Point(MotionHandler.physObjects[q].bod.perimeterX[w],0)).x;
- MotionHandler.physObjects[q].bod.currentBoundsY[w] = MotionHandler.physObjects[q].localToGlobal(new Point(0,MotionHandler.physObjects[q].bod.perimeterY[w])).y;
- }
- }
- }
- }
- public static function makeBody(This:physObject):void
- {
- }
- }
- }package
- {
- import flash.display.*;
- import flash.events.*;
- import flash.geom.Point;
- import Box2D.Dynamics.*;
- import Box2D.Collision.Shapes.*;
- import Box2D.Common.Math.b2Vec2;
- public class Body
- {
- public var perimeterX:Vector.<int > = new Vector.<int > ;
- public var perimeterY:Vector.<int > = new Vector.<int > ;
- public var currentBoundsX:Vector.<int > = new Vector.<int > ;
- public var currentBoundsY:Vector.<int > = new Vector.<int > ;
- public function Body(This:Thing,shape:String,type:uint,density:Number,friction:Number,restitution:Number):void
- {
- if(type != 3)
- {
- var bodyDef:b2BodyDef = new b2BodyDef();
- bodyDef.type = type;
- bodyDef.position.Set(This.x/30,This.y/30);
- bodyDef.allowSleep = true;
- bodyDef.bullet = false;
- bodyDef.userData = Main.WorldContainer;
- var shp:b2PolygonShape = new b2PolygonShape();
- shp.SetAsBox(This.width/2/30,This.height/2/30);
- This.body = Main.botWorld.CreateBody(bodyDef);
- var fd:b2FixtureDef = new b2FixtureDef();
- fd.density = density;
- fd.friction = friction;
- fd.restitution = restitution;
- fd.shape = shp;
- This.body.CreateFixture(fd);
- }
- else
- {
- }
- //trace(This.Data.width + This.localToGlobal(new Point(This.x,This.y)).x,This.localToGlobal(new Point(This.Data.width + This.x,This.y)).x);
- with (This)
- {
- if (shape == 'rectangle')
- {
- this.perimeterX.push(-Data.width/2,Data.width/2);
- this.perimeterY.push(Data.height/2,-Data.height/2);
- this.currentBoundsX.push(-Data.width/2,Data.width/2);
- this.currentBoundsY.push(Data.height/2,-Data.height/2);
- }
- if (shape == 'circle')
- {
- for (var i:uint = 0; i < 360; i+=2)
- {
- this.perimeterX.push((Data.width/2 * Math.sin(i*Math.PI/180)));
- this.perimeterY.push((Data.height/2 * Math.cos(i*Math.PI/180)));
- this.currentBoundsX.push((Data.width/2 * Math.sin(i*Math.PI/180)));
- this.currentBoundsY.push((Data.height/2 * Math.cos(i*Math.PI/180)));
- }
- }
- }
- }
- public static function Update()
- {
- for (var q:int = 0; q < MotionHandler.physObjects.length; q++)
- {
- for (var w:int = 0; w < 2; w++)
- {//this.onGround = true;
- if (w == 0)
- {
- MotionHandler.physObjects[q].bod.currentBoundsX[w] = MotionHandler.physObjects[q].localToGlobal(new Point(MotionHandler.physObjects[q].bod.perimeterX[w],0)).x;
- MotionHandler.physObjects[q].bod.currentBoundsY[w] = MotionHandler.physObjects[q].localToGlobal(new Point(0,MotionHandler.physObjects[q].bod.perimeterY[w])).y;
- }
- if (w == 1)
- {
- MotionHandler.physObjects[q].bod.currentBoundsX[w] = MotionHandler.physObjects[q].localToGlobal(new Point(MotionHandler.physObjects[q].bod.perimeterX[w],0)).x;
- MotionHandler.physObjects[q].bod.currentBoundsY[w] = MotionHandler.physObjects[q].localToGlobal(new Point(0,MotionHandler.physObjects[q].bod.perimeterY[w])).y;
- }
- }
- }
- }
- public static function makeBody(This:physObject):void
- {
- }
- }
- }package
- {
- import flash.display.*;
- import flash.events.*;
- import flash.geom.Point;
- import Box2D.Dynamics.*;
- import Box2D.Collision.Shapes.*;
- import Box2D.Common.Math.b2Vec2;
- public class Body
- {
- public var perimeterX:Vector.<int > = new Vector.<int > ;
- public var perimeterY:Vector.<int > = new Vector.<int > ;
- public var currentBoundsX:Vector.<int > = new Vector.<int > ;
- public var currentBoundsY:Vector.<int > = new Vector.<int > ;
- public function Body(This:Thing,shape:String,type:uint,density:Number,friction:Number,restitution:Number):void
- {
- if(type != 3)
- {
- var bodyDef:b2BodyDef = new b2BodyDef();
- bodyDef.type = type;
- bodyDef.position.Set(This.x/30,This.y/30);
- bodyDef.allowSleep = true;
- bodyDef.bullet = false;
- bodyDef.userData = Main.WorldContainer;
- var shp:b2PolygonShape = new b2PolygonShape();
- shp.SetAsBox(This.width/2/30,This.height/2/30);
- This.body = Main.botWorld.CreateBody(bodyDef);
- var fd:b2FixtureDef = new b2FixtureDef();
- fd.density = density;
- fd.friction = friction;
- fd.restitution = restitution;
- fd.shape = shp;
- This.body.CreateFixture(fd);
- }
- with (This)
- {
- if (shape == 'rectangle')
- {
- this.perimeterX.push(-Data.width/2,Data.width/2);
- this.perimeterY.push(Data.height/2,-Data.height/2);
- this.currentBoundsX.push(-Data.width/2,Data.width/2);
- this.currentBoundsY.push(Data.height/2,-Data.height/2);
- }
- if (shape == 'circle')
- {
- for (var i:uint = 0; i < 360; i+=2)
- {
- this.perimeterX.push((Data.width/2 * Math.sin(i*Math.PI/180)));
- this.perimeterY.push((Data.height/2 * Math.cos(i*Math.PI/180)));
- this.currentBoundsX.push((Data.width/2 * Math.sin(i*Math.PI/180)));
- this.currentBoundsY.push((Data.height/2 * Math.cos(i*Math.PI/180)));
- }
- }
- }
- }
- public static function Update()
- {
- for (var q:int = 0; q < MotionHandler.physObjects.length; q++)
- {
- for (var w:int = 0; w < 2; w++)
- {//this.onGround = true;
- if (w == 0)
- {
- MotionHandler.physObjects[q].bod.currentBoundsX[w] = MotionHandler.physObjects[q].localToGlobal(new Point(MotionHandler.physObjects[q].bod.perimeterX[w],0)).x;
- MotionHandler.physObjects[q].bod.currentBoundsY[w] = MotionHandler.physObjects[q].localToGlobal(new Point(0,MotionHandler.physObjects[q].bod.perimeterY[w])).y;
- }
- if (w == 1)
- {
- MotionHandler.physObjects[q].bod.currentBoundsX[w] = MotionHandler.physObjects[q].localToGlobal(new Point(MotionHandler.physObjects[q].bod.perimeterX[w],0)).x;
- MotionHandler.physObjects[q].bod.currentBoundsY[w] = MotionHandler.physObjects[q].localToGlobal(new Point(0,MotionHandler.physObjects[q].bod.perimeterY[w])).y;
- }
- }
- }
- }
- }
- }
- private function physicsHandler(e:Event):void
- {
- Body.Update();
- for (var i:int = physObjects.length - 1; i >= 0; i--)
- {
- for (var n:int = 0; n < physObjects.length; n++)
- {
- if (i != n)
- {
- var object1:physObject;
- var object2:physObject;
- if (physObjects[i].bod.currentBoundsY[1] > physObjects[n].bod.currentBoundsY[0])
- {
- object1 = physObjects[n];
- object2 = physObjects[i];
- }
- else
- {
- object1 = physObjects[i];
- object2 = physObjects[n];
- }
- }
- if (object1 != null && object2 != null)
- {
- if (object1.bod.currentBoundsY[0] >= object2.bod.currentBoundsY[1] - 2 && object1.bod.currentBoundsY[1] <= object2.bod.currentBoundsY[0] + 2 && object1.bod.currentBoundsX[0] >= object2.bod.currentBoundsX[0] - 2 && object1.bod.currentBoundsX[1] <= object2.bod.currentBoundsX[1] + 2)
- {
- stage.dispatchEvent(new ContactEvent(ContactEvent.CONTACT,object1,object2,false,false));
- object1.onGround = true;
- object2.onGround = true;
- }
- else
- {
- object2.onGround = false;
- //object1.onGround = false;
- }
- }
- }
- }private function physicsHandler(e:Event):void
- {
- Body.Update();
- for (var i:int = physObjects.length - 1; i >= 0; i--)
- {
- for (var n:int = 0; n < physObjects.length; n++)
- {
- if (i != n)
- {
- var object1:physObject;
- var object2:physObject;
- if (physObjects[i].bod.currentBoundsY[1] > physObjects[n].bod.currentBoundsY[0])
- {
- object1 = physObjects[n];
- object2 = physObjects[i];
- }
- else
- {
- object1 = physObjects[i];
- object2 = physObjects[n];
- }
- }
- if (object1 != null && object2 != null)
- {
- if (object1.bod.currentBoundsY[0] >= object2.bod.currentBoundsY[1] - 2 && object1.bod.currentBoundsY[1] <= object2.bod.currentBoundsY[0] + 2 && object1.bod.currentBoundsX[0] >= object2.bod.currentBoundsX[0] - 2 && object1.bod.currentBoundsX[1] <= object2.bod.currentBoundsX[1] + 2)
- {
- stage.dispatchEvent(new ContactEvent(ContactEvent.CONTACT,object1,object2,false,false));
- object1.onGround = true;
- object2.onGround = true;
- }
- else
- {
- object2.onGround = false;
- //object1.onGround = false;
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment