Guest User

Untitled

a guest
Jan 13th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package
  2. {
  3.     import flash.display.*;
  4.     import flash.events.*;
  5.     import flash.geom.Point;
  6.     import Box2D.Dynamics.*;
  7.     import Box2D.Collision.Shapes.*;
  8.     import Box2D.Common.Math.b2Vec2;
  9.  
  10.     public class Body
  11.     {
  12.         public var perimeterX:Vector.<int >  = new Vector.<int >   ;
  13.         public var perimeterY:Vector.<int >  = new Vector.<int >   ;
  14.         public var currentBoundsX:Vector.<int >  = new Vector.<int >   ;
  15.         public var currentBoundsY:Vector.<int >  = new Vector.<int >   ;
  16.  
  17.  
  18.         public function Body(This:Thing,shape:String,type:uint,density:Number,friction:Number,restitution:Number):void
  19.         {
  20.  
  21. if(type != 3)
  22. {
  23.  
  24.         var bodyDef:b2BodyDef = new b2BodyDef();
  25.             bodyDef.type = type;
  26.             bodyDef.position.Set(This.x/30,This.y/30);
  27.             bodyDef.allowSleep = true;
  28.             bodyDef.bullet = false;
  29.             bodyDef.userData = Main.WorldContainer;
  30.             var shp:b2PolygonShape = new b2PolygonShape();
  31.             shp.SetAsBox(This.width/2/30,This.height/2/30);
  32.             This.body = Main.botWorld.CreateBody(bodyDef);
  33.             var fd:b2FixtureDef = new b2FixtureDef();
  34.             fd.density = density;
  35.             fd.friction = friction;
  36.             fd.restitution = restitution;
  37.             fd.shape = shp;
  38.             This.body.CreateFixture(fd);
  39. }
  40. else
  41. {
  42.    
  43. }
  44.    
  45.  
  46.             //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);
  47.             with (This)
  48.             {
  49.  
  50.  
  51.                 if (shape == 'rectangle')
  52.                 {
  53.  
  54.                     this.perimeterX.push(-Data.width/2,Data.width/2);
  55.                     this.perimeterY.push(Data.height/2,-Data.height/2);
  56.                     this.currentBoundsX.push(-Data.width/2,Data.width/2);
  57.                     this.currentBoundsY.push(Data.height/2,-Data.height/2);
  58.  
  59.                 }
  60.                 if (shape == 'circle')
  61.                 {
  62.                     for (var i:uint = 0; i < 360; i+=2)
  63.                     {
  64.                         this.perimeterX.push((Data.width/2 * Math.sin(i*Math.PI/180)));
  65.                         this.perimeterY.push((Data.height/2 * Math.cos(i*Math.PI/180)));
  66.                         this.currentBoundsX.push((Data.width/2 * Math.sin(i*Math.PI/180)));
  67.                         this.currentBoundsY.push((Data.height/2 * Math.cos(i*Math.PI/180)));
  68.                     }
  69.                 }
  70.  
  71.  
  72.  
  73.             }
  74.  
  75.         }
  76.  
  77.         public static function Update()
  78.         {
  79.             for (var q:int = 0; q < MotionHandler.physObjects.length; q++)
  80.             {
  81.                 for (var w:int = 0; w < 2; w++)
  82.                 {//this.onGround = true;
  83.  
  84.                     if (w == 0)
  85.                     {
  86.                         MotionHandler.physObjects[q].bod.currentBoundsX[w] = MotionHandler.physObjects[q].localToGlobal(new Point(MotionHandler.physObjects[q].bod.perimeterX[w],0)).x;
  87.                         MotionHandler.physObjects[q].bod.currentBoundsY[w] = MotionHandler.physObjects[q].localToGlobal(new Point(0,MotionHandler.physObjects[q].bod.perimeterY[w])).y;
  88.  
  89.                     }
  90.                     if (w == 1)
  91.                     {
  92.                         MotionHandler.physObjects[q].bod.currentBoundsX[w] = MotionHandler.physObjects[q].localToGlobal(new Point(MotionHandler.physObjects[q].bod.perimeterX[w],0)).x;
  93.                         MotionHandler.physObjects[q].bod.currentBoundsY[w] = MotionHandler.physObjects[q].localToGlobal(new Point(0,MotionHandler.physObjects[q].bod.perimeterY[w])).y;
  94.                     }
  95.                 }
  96.             }
  97.         }
  98.  
  99.         public static function makeBody(This:physObject):void
  100.         {
  101.  
  102.  
  103.         }
  104.  
  105.     }
  106. }package
  107. {
  108.     import flash.display.*;
  109.     import flash.events.*;
  110.     import flash.geom.Point;
  111.     import Box2D.Dynamics.*;
  112.     import Box2D.Collision.Shapes.*;
  113.     import Box2D.Common.Math.b2Vec2;
  114.  
  115.     public class Body
  116.     {
  117.         public var perimeterX:Vector.<int >  = new Vector.<int >   ;
  118.         public var perimeterY:Vector.<int >  = new Vector.<int >   ;
  119.         public var currentBoundsX:Vector.<int >  = new Vector.<int >   ;
  120.         public var currentBoundsY:Vector.<int >  = new Vector.<int >   ;
  121.  
  122.  
  123.         public function Body(This:Thing,shape:String,type:uint,density:Number,friction:Number,restitution:Number):void
  124.         {
  125.  
  126. if(type != 3)
  127. {
  128.  
  129.         var bodyDef:b2BodyDef = new b2BodyDef();
  130.             bodyDef.type = type;
  131.             bodyDef.position.Set(This.x/30,This.y/30);
  132.             bodyDef.allowSleep = true;
  133.             bodyDef.bullet = false;
  134.             bodyDef.userData = Main.WorldContainer;
  135.             var shp:b2PolygonShape = new b2PolygonShape();
  136.             shp.SetAsBox(This.width/2/30,This.height/2/30);
  137.             This.body = Main.botWorld.CreateBody(bodyDef);
  138.             var fd:b2FixtureDef = new b2FixtureDef();
  139.             fd.density = density;
  140.             fd.friction = friction;
  141.             fd.restitution = restitution;
  142.             fd.shape = shp;
  143.             This.body.CreateFixture(fd);
  144. }
  145. else
  146. {
  147.    
  148. }
  149.    
  150.  
  151.             //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);
  152.             with (This)
  153.             {
  154.  
  155.  
  156.                 if (shape == 'rectangle')
  157.                 {
  158.  
  159.                     this.perimeterX.push(-Data.width/2,Data.width/2);
  160.                     this.perimeterY.push(Data.height/2,-Data.height/2);
  161.                     this.currentBoundsX.push(-Data.width/2,Data.width/2);
  162.                     this.currentBoundsY.push(Data.height/2,-Data.height/2);
  163.  
  164.                 }
  165.                 if (shape == 'circle')
  166.                 {
  167.                     for (var i:uint = 0; i < 360; i+=2)
  168.                     {
  169.                         this.perimeterX.push((Data.width/2 * Math.sin(i*Math.PI/180)));
  170.                         this.perimeterY.push((Data.height/2 * Math.cos(i*Math.PI/180)));
  171.                         this.currentBoundsX.push((Data.width/2 * Math.sin(i*Math.PI/180)));
  172.                         this.currentBoundsY.push((Data.height/2 * Math.cos(i*Math.PI/180)));
  173.                     }
  174.                 }
  175.  
  176.  
  177.  
  178.             }
  179.  
  180.         }
  181.  
  182.         public static function Update()
  183.         {
  184.             for (var q:int = 0; q < MotionHandler.physObjects.length; q++)
  185.             {
  186.                 for (var w:int = 0; w < 2; w++)
  187.                 {//this.onGround = true;
  188.  
  189.                     if (w == 0)
  190.                     {
  191.                         MotionHandler.physObjects[q].bod.currentBoundsX[w] = MotionHandler.physObjects[q].localToGlobal(new Point(MotionHandler.physObjects[q].bod.perimeterX[w],0)).x;
  192.                         MotionHandler.physObjects[q].bod.currentBoundsY[w] = MotionHandler.physObjects[q].localToGlobal(new Point(0,MotionHandler.physObjects[q].bod.perimeterY[w])).y;
  193.  
  194.                     }
  195.                     if (w == 1)
  196.                     {
  197.                         MotionHandler.physObjects[q].bod.currentBoundsX[w] = MotionHandler.physObjects[q].localToGlobal(new Point(MotionHandler.physObjects[q].bod.perimeterX[w],0)).x;
  198.                         MotionHandler.physObjects[q].bod.currentBoundsY[w] = MotionHandler.physObjects[q].localToGlobal(new Point(0,MotionHandler.physObjects[q].bod.perimeterY[w])).y;
  199.                     }
  200.                 }
  201.             }
  202.         }
  203.  
  204.         public static function makeBody(This:physObject):void
  205.         {
  206.  
  207.  
  208.         }
  209.  
  210.     }
  211. }package
  212. {
  213.     import flash.display.*;
  214.     import flash.events.*;
  215.     import flash.geom.Point;
  216.     import Box2D.Dynamics.*;
  217.     import Box2D.Collision.Shapes.*;
  218.     import Box2D.Common.Math.b2Vec2;
  219.  
  220.     public class Body
  221.     {
  222.         public var perimeterX:Vector.<int >  = new Vector.<int >   ;
  223.         public var perimeterY:Vector.<int >  = new Vector.<int >   ;
  224.         public var currentBoundsX:Vector.<int >  = new Vector.<int >   ;
  225.         public var currentBoundsY:Vector.<int >  = new Vector.<int >   ;
  226.  
  227.  
  228.         public function Body(This:Thing,shape:String,type:uint,density:Number,friction:Number,restitution:Number):void
  229.         {
  230.  
  231. if(type != 3)
  232. {
  233.  
  234.         var bodyDef:b2BodyDef = new b2BodyDef();
  235.             bodyDef.type = type;
  236.             bodyDef.position.Set(This.x/30,This.y/30);
  237.             bodyDef.allowSleep = true;
  238.             bodyDef.bullet = false;
  239.             bodyDef.userData = Main.WorldContainer;
  240.             var shp:b2PolygonShape = new b2PolygonShape();
  241.             shp.SetAsBox(This.width/2/30,This.height/2/30);
  242.             This.body = Main.botWorld.CreateBody(bodyDef);
  243.             var fd:b2FixtureDef = new b2FixtureDef();
  244.             fd.density = density;
  245.             fd.friction = friction;
  246.             fd.restitution = restitution;
  247.             fd.shape = shp;
  248.             This.body.CreateFixture(fd);
  249. }
  250.  
  251.             with (This)
  252.             {
  253.  
  254.  
  255.                 if (shape == 'rectangle')
  256.                 {
  257.  
  258.                     this.perimeterX.push(-Data.width/2,Data.width/2);
  259.                     this.perimeterY.push(Data.height/2,-Data.height/2);
  260.                     this.currentBoundsX.push(-Data.width/2,Data.width/2);
  261.                     this.currentBoundsY.push(Data.height/2,-Data.height/2);
  262.  
  263.                 }
  264.                 if (shape == 'circle')
  265.                 {
  266.                     for (var i:uint = 0; i < 360; i+=2)
  267.                     {
  268.                         this.perimeterX.push((Data.width/2 * Math.sin(i*Math.PI/180)));
  269.                         this.perimeterY.push((Data.height/2 * Math.cos(i*Math.PI/180)));
  270.                         this.currentBoundsX.push((Data.width/2 * Math.sin(i*Math.PI/180)));
  271.                         this.currentBoundsY.push((Data.height/2 * Math.cos(i*Math.PI/180)));
  272.                     }
  273.                 }
  274.  
  275.  
  276.  
  277.             }
  278.  
  279.         }
  280.  
  281.         public static function Update()
  282.         {
  283.             for (var q:int = 0; q < MotionHandler.physObjects.length; q++)
  284.             {
  285.                 for (var w:int = 0; w < 2; w++)
  286.                 {//this.onGround = true;
  287.  
  288.                     if (w == 0)
  289.                     {
  290.                         MotionHandler.physObjects[q].bod.currentBoundsX[w] = MotionHandler.physObjects[q].localToGlobal(new Point(MotionHandler.physObjects[q].bod.perimeterX[w],0)).x;
  291.                         MotionHandler.physObjects[q].bod.currentBoundsY[w] = MotionHandler.physObjects[q].localToGlobal(new Point(0,MotionHandler.physObjects[q].bod.perimeterY[w])).y;
  292.  
  293.                     }
  294.                     if (w == 1)
  295.                     {
  296.                         MotionHandler.physObjects[q].bod.currentBoundsX[w] = MotionHandler.physObjects[q].localToGlobal(new Point(MotionHandler.physObjects[q].bod.perimeterX[w],0)).x;
  297.                         MotionHandler.physObjects[q].bod.currentBoundsY[w] = MotionHandler.physObjects[q].localToGlobal(new Point(0,MotionHandler.physObjects[q].bod.perimeterY[w])).y;
  298.                     }
  299.                 }
  300.             }
  301.         }
  302.  
  303.     }
  304. }
  305.  
  306.  
  307. private function physicsHandler(e:Event):void
  308.         {
  309.  
  310.             Body.Update();
  311.             for (var i:int = physObjects.length - 1; i >= 0; i--)
  312.             {
  313.                 for (var n:int = 0; n < physObjects.length; n++)
  314.                 {
  315.                     if (i != n)
  316.                     {
  317.                         var object1:physObject;
  318.                         var object2:physObject;
  319.                         if (physObjects[i].bod.currentBoundsY[1] > physObjects[n].bod.currentBoundsY[0])
  320.                         {
  321.                             object1 = physObjects[n];
  322.                             object2 = physObjects[i];
  323.  
  324.                         }
  325.                         else
  326.                         {
  327.                             object1 = physObjects[i];
  328.                             object2 = physObjects[n];
  329.                         }
  330.  
  331.                     }
  332.  
  333.                     if (object1 != null && object2 != null)
  334.                     {
  335.                         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)
  336.                         {
  337.  
  338.                             stage.dispatchEvent(new ContactEvent(ContactEvent.CONTACT,object1,object2,false,false));
  339.  
  340.  
  341.                             object1.onGround = true;
  342.                             object2.onGround = true;
  343.  
  344.  
  345.  
  346.                         }
  347.                         else
  348.                         {
  349.                             object2.onGround = false;
  350.                             //object1.onGround = false;
  351.                         }
  352.                     }
  353.                 }
  354.             }private function physicsHandler(e:Event):void
  355.         {
  356.  
  357.             Body.Update();
  358.             for (var i:int = physObjects.length - 1; i >= 0; i--)
  359.             {
  360.                 for (var n:int = 0; n < physObjects.length; n++)
  361.                 {
  362.                     if (i != n)
  363.                     {
  364.                         var object1:physObject;
  365.                         var object2:physObject;
  366.                         if (physObjects[i].bod.currentBoundsY[1] > physObjects[n].bod.currentBoundsY[0])
  367.                         {
  368.                             object1 = physObjects[n];
  369.                             object2 = physObjects[i];
  370.  
  371.                         }
  372.                         else
  373.                         {
  374.                             object1 = physObjects[i];
  375.                             object2 = physObjects[n];
  376.                         }
  377.  
  378.                     }
  379.  
  380.                     if (object1 != null && object2 != null)
  381.                     {
  382.                         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)
  383.                         {
  384.  
  385.                             stage.dispatchEvent(new ContactEvent(ContactEvent.CONTACT,object1,object2,false,false));
  386.  
  387.  
  388.                             object1.onGround = true;
  389.                             object2.onGround = true;
  390.  
  391.  
  392.  
  393.                         }
  394.                         else
  395.                         {
  396.                             object2.onGround = false;
  397.                             //object1.onGround = false;
  398.                         }
  399.                     }
  400.                 }
  401.             }
Add Comment
Please, Sign In to add comment