STORY   LOOP   FURRY   PORN   GAMES
• C •   SERVICES [?] [R] RND   POPULAR
Archived flashes:
229494
/disc/ · /res/     /show/ · /fap/ · /gg/ · /swf/P0001 · P2575 · P5149

<div style="position:absolute;top:-99px;left:-99px;"><img src="http://swfchan.com:57475/43935528?noj=FRM43935528-14DC" width="1" height="1"></div>

Glass Tower - a little game of stacking and balance.swf

This is the info page for
Flash #92958

(Click the ID number above for more basic data on this flash file.)


ActionScript [AS3]
Section 1
//b2CircleDef (Box2D.Collision.Shapes.b2CircleDef) package Box2D.Collision.Shapes { import Box2D.Common.Math.*; public class b2CircleDef extends b2ShapeDef { public var radius:Number; public var localPosition:b2Vec2; public function b2CircleDef(){ localPosition = new b2Vec2(0, 0); super(); type = b2Shape.e_circleShape; radius = 1; } } }//package Box2D.Collision.Shapes
Section 2
//b2CircleShape (Box2D.Collision.Shapes.b2CircleShape) package Box2D.Collision.Shapes { import Box2D.Dynamics.*; import Box2D.Collision.*; import Box2D.Common.Math.*; import Box2D.Common.*; public class b2CircleShape extends b2Shape { b2internal var m_localPosition:b2Vec2; b2internal var m_radius:Number; public function b2CircleShape(def:b2ShapeDef){ m_localPosition = new b2Vec2(); super(def); var circleDef:b2CircleDef = (def as b2CircleDef); m_type = e_circleShape; m_localPosition.SetV(circleDef.localPosition); m_radius = circleDef.radius; } override public function TestSegment(transform:b2XForm, lambda:Array, normal:b2Vec2, segment:b2Segment, maxLambda:Number):int{ var sY:Number; var tMat:b2Mat22 = transform.R; var positionX:Number = (transform.position.x + ((tMat.col1.x * m_localPosition.x) + (tMat.col2.x * m_localPosition.y))); var positionY:Number = (transform.position.y + ((tMat.col1.y * m_localPosition.x) + (tMat.col2.y * m_localPosition.y))); var sX:Number = (segment.p1.x - positionX); sY = (segment.p1.y - positionY); var b:Number = (((sX * sX) + (sY * sY)) - (m_radius * m_radius)); if (b < 0){ lambda[0] = 0; return (e_startsInsideCollide); }; var rX:Number = (segment.p2.x - segment.p1.x); var rY:Number = (segment.p2.y - segment.p1.y); var c:Number = ((sX * rX) + (sY * rY)); var rr:Number = ((rX * rX) + (rY * rY)); var sigma:Number = ((c * c) - (rr * b)); if ((((sigma < 0)) || ((rr < Number.MIN_VALUE)))){ return (e_missCollide); }; var a:Number = -((c + Math.sqrt(sigma))); if ((((0 <= a)) && ((a <= (maxLambda * rr))))){ a = (a / rr); lambda[0] = a; normal.x = (sX + (a * rX)); normal.y = (sY + (a * rY)); normal.Normalize(); return (e_hitCollide); }; return (e_missCollide); } public function GetLocalPosition():b2Vec2{ return (m_localPosition); } public function GetRadius():Number{ return (m_radius); } override public function ComputeSweptAABB(aabb:b2AABB, transform1:b2XForm, transform2:b2XForm):void{ var tMat:b2Mat22; tMat = transform1.R; var p1X:Number = (transform1.position.x + ((tMat.col1.x * m_localPosition.x) + (tMat.col2.x * m_localPosition.y))); var p1Y:Number = (transform1.position.y + ((tMat.col1.y * m_localPosition.x) + (tMat.col2.y * m_localPosition.y))); tMat = transform2.R; var p2X:Number = (transform2.position.x + ((tMat.col1.x * m_localPosition.x) + (tMat.col2.x * m_localPosition.y))); var p2Y:Number = (transform2.position.y + ((tMat.col1.y * m_localPosition.x) + (tMat.col2.y * m_localPosition.y))); aabb.lowerBound.Set((((p1X < p2X)) ? p1X : p2X - m_radius), (((p1Y < p2Y)) ? p1Y : p2Y - m_radius)); aabb.upperBound.Set((((p1X > p2X)) ? p1X : p2X + m_radius), (((p1Y > p2Y)) ? p1Y : p2Y + m_radius)); } override public function ComputeMass(massData:b2MassData):void{ massData.mass = (((m_density * b2Settings.b2_pi) * m_radius) * m_radius); massData.center.SetV(m_localPosition); massData.I = (massData.mass * (((0.5 * m_radius) * m_radius) + ((m_localPosition.x * m_localPosition.x) + (m_localPosition.y * m_localPosition.y)))); } override b2internal function UpdateSweepRadius(center:b2Vec2):void{ var dX:Number = (m_localPosition.x - center.x); var dY:Number = (m_localPosition.y - center.y); dX = Math.sqrt(((dX * dX) + (dY * dY))); m_sweepRadius = ((dX + m_radius) - b2Settings.b2_toiSlop); } override public function ComputeAABB(aabb:b2AABB, transform:b2XForm):void{ var tMat:b2Mat22 = transform.R; var pX:Number = (transform.position.x + ((tMat.col1.x * m_localPosition.x) + (tMat.col2.x * m_localPosition.y))); var pY:Number = (transform.position.y + ((tMat.col1.y * m_localPosition.x) + (tMat.col2.y * m_localPosition.y))); aabb.lowerBound.Set((pX - m_radius), (pY - m_radius)); aabb.upperBound.Set((pX + m_radius), (pY + m_radius)); } override public function TestPoint(transform:b2XForm, p:b2Vec2):Boolean{ var tMat:b2Mat22 = transform.R; var dX:Number = (transform.position.x + ((tMat.col1.x * m_localPosition.x) + (tMat.col2.x * m_localPosition.y))); var dY:Number = (transform.position.y + ((tMat.col1.y * m_localPosition.x) + (tMat.col2.y * m_localPosition.y))); dX = (p.x - dX); dY = (p.y - dY); return ((((dX * dX) + (dY * dY)) <= (m_radius * m_radius))); } } }//package Box2D.Collision.Shapes
Section 3
//b2EdgeChainDef (Box2D.Collision.Shapes.b2EdgeChainDef) package Box2D.Collision.Shapes { public class b2EdgeChainDef extends b2ShapeDef { public var vertices:Array; public var vertexCount:int; public var isALoop:Boolean; public function b2EdgeChainDef(){ super(); type = b2Shape.e_edgeShape; vertexCount = 0; isALoop = true; vertices = []; } } }//package Box2D.Collision.Shapes
Section 4
//b2EdgeShape (Box2D.Collision.Shapes.b2EdgeShape) package Box2D.Collision.Shapes { import Box2D.Dynamics.*; import Box2D.Collision.*; import Box2D.Common.Math.*; import Box2D.Common.*; public class b2EdgeShape extends b2Shape { b2internal var m_v1:b2Vec2; b2internal var m_v2:b2Vec2; private var s_supportVec:b2Vec2; b2internal var m_coreV1:b2Vec2; b2internal var m_coreV2:b2Vec2; b2internal var m_prevEdge:b2EdgeShape; b2internal var m_direction:b2Vec2; b2internal var m_cornerConvex1:Boolean; b2internal var m_cornerConvex2:Boolean; b2internal var m_cornerDir1:b2Vec2; b2internal var m_cornerDir2:b2Vec2; b2internal var m_nextEdge:b2EdgeShape; b2internal var m_normal:b2Vec2; b2internal var m_length:Number; public function b2EdgeShape(v1:b2Vec2, v2:b2Vec2, def:b2ShapeDef){ s_supportVec = new b2Vec2(); m_v1 = new b2Vec2(); m_v2 = new b2Vec2(); m_coreV1 = new b2Vec2(); m_coreV2 = new b2Vec2(); m_normal = new b2Vec2(); m_direction = new b2Vec2(); m_cornerDir1 = new b2Vec2(); m_cornerDir2 = new b2Vec2(); super(def); m_type = e_edgeShape; m_prevEdge = null; m_nextEdge = null; m_v1 = v1; m_v2 = v2; m_direction.Set((m_v2.x - m_v1.x), (m_v2.y - m_v1.y)); m_length = m_direction.Normalize(); m_normal.Set(m_direction.y, -(m_direction.x)); m_coreV1.Set(((-(b2Settings.b2_toiSlop) * (m_normal.x - m_direction.x)) + m_v1.x), ((-(b2Settings.b2_toiSlop) * (m_normal.y - m_direction.y)) + m_v1.y)); m_coreV2.Set(((-(b2Settings.b2_toiSlop) * (m_normal.x + m_direction.x)) + m_v2.x), ((-(b2Settings.b2_toiSlop) * (m_normal.y + m_direction.y)) + m_v2.y)); m_cornerDir1 = m_normal; m_cornerDir2.Set(-(m_normal.x), -(m_normal.y)); } b2internal function SetPrevEdge(edge:b2EdgeShape, core:b2Vec2, cornerDir:b2Vec2, convex:Boolean):void{ m_prevEdge = edge; m_coreV1 = core; m_cornerDir1 = cornerDir; m_cornerConvex1 = convex; } public function GetCorner2Vector():b2Vec2{ return (m_cornerDir2); } public function GetDirectionVector():b2Vec2{ return (m_direction); } override public function ComputeAABB(aabb:b2AABB, transform:b2XForm):void{ var tMat:b2Mat22 = transform.R; var v1X:Number = (transform.position.x + ((tMat.col1.x * m_v1.x) + (tMat.col2.x * m_v1.y))); var v1Y:Number = (transform.position.y + ((tMat.col1.y * m_v1.x) + (tMat.col2.y * m_v1.y))); var v2X:Number = (transform.position.x + ((tMat.col1.x * m_v2.x) + (tMat.col2.x * m_v2.y))); var v2Y:Number = (transform.position.y + ((tMat.col1.y * m_v2.x) + (tMat.col2.y * m_v2.y))); if (v1X < v2X){ aabb.lowerBound.x = v1X; aabb.upperBound.x = v2X; } else { aabb.lowerBound.x = v2X; aabb.upperBound.x = v1X; }; if (v1Y < v2Y){ aabb.lowerBound.y = v1Y; aabb.upperBound.y = v2Y; } else { aabb.lowerBound.y = v2Y; aabb.upperBound.y = v1Y; }; } override public function TestSegment(transform:b2XForm, lambda:Array, normal:b2Vec2, segment:b2Segment, maxLambda:Number):int{ var tMat:b2Mat22; var nY:Number; var bX:Number; var bY:Number; var a:Number; var mu2:Number; var nLen:Number; var rX:Number = (segment.p2.x - segment.p1.x); var rY:Number = (segment.p2.y - segment.p1.y); tMat = transform.R; var v1X:Number = (transform.position.x + ((tMat.col1.x * m_v1.x) + (tMat.col2.x * m_v1.y))); var v1Y:Number = (transform.position.y + ((tMat.col1.y * m_v1.x) + (tMat.col2.y * m_v1.y))); var nX:Number = ((transform.position.y + ((tMat.col1.y * m_v2.x) + (tMat.col2.y * m_v2.y))) - v1Y); nY = -(((transform.position.x + ((tMat.col1.x * m_v2.x) + (tMat.col2.x * m_v2.y))) - v1X)); var k_slop:Number = (100 * Number.MIN_VALUE); var denom:Number = -(((rX * nX) + (rY * nY))); if (denom > k_slop){ bX = (segment.p1.x - v1X); bY = (segment.p1.y - v1Y); a = ((bX * nX) + (bY * nY)); if ((((0 <= a)) && ((a <= (maxLambda * denom))))){ mu2 = ((-(rX) * bY) + (rY * bX)); if (((((-(k_slop) * denom) <= mu2)) && ((mu2 <= (denom * (1 + k_slop)))))){ a = (a / denom); lambda[0] = a; nLen = Math.sqrt(((nX * nX) + (nY * nY))); normal.x = (nX / nLen); normal.y = (nY / nLen); return (e_hitCollide); }; }; }; return (e_missCollide); } public function GetNextEdge():b2EdgeShape{ return (m_nextEdge); } override public function ComputeMass(massData:b2MassData):void{ massData.mass = 0; massData.center.SetV(m_v1); massData.I = 0; } public function Corner1IsConvex():Boolean{ return (m_cornerConvex1); } public function Corner2IsConvex():Boolean{ return (m_cornerConvex2); } public function Support(xf:b2XForm, dX:Number, dY:Number):b2Vec2{ var tMat:b2Mat22 = xf.R; var v1X:Number = (xf.position.x + ((tMat.col1.x * m_coreV1.x) + (tMat.col2.x * m_coreV1.y))); var v1Y:Number = (xf.position.y + ((tMat.col1.y * m_coreV1.x) + (tMat.col2.y * m_coreV1.y))); var v2X:Number = (xf.position.x + ((tMat.col1.x * m_coreV2.x) + (tMat.col2.x * m_coreV2.y))); var v2Y:Number = (xf.position.y + ((tMat.col1.y * m_coreV2.x) + (tMat.col2.y * m_coreV2.y))); if (((v1X * dX) + (v1Y * dY)) > ((v2X * dX) + (v2Y * dY))){ s_supportVec.x = v1X; s_supportVec.y = v1Y; } else { s_supportVec.x = v2X; s_supportVec.y = v2Y; }; return (s_supportVec); } b2internal function SetNextEdge(edge:b2EdgeShape, core:b2Vec2, cornerDir:b2Vec2, convex:Boolean):void{ m_nextEdge = edge; m_coreV2 = core; m_cornerDir2 = cornerDir; m_cornerConvex2 = convex; } public function GetLength():Number{ return (m_length); } public function GetCorner1Vector():b2Vec2{ return (m_cornerDir1); } override public function ComputeSweptAABB(aabb:b2AABB, transform1:b2XForm, transform2:b2XForm):void{ var tMat:b2Mat22; tMat = transform1.R; var v1X:Number = (transform1.position.x + ((tMat.col1.x * m_v1.x) + (tMat.col2.x * m_v1.y))); var v1Y:Number = (transform1.position.y + ((tMat.col1.y * m_v1.x) + (tMat.col2.y * m_v1.y))); var v2X:Number = (transform1.position.x + ((tMat.col1.x * m_v2.x) + (tMat.col2.x * m_v2.y))); var v2Y:Number = (transform1.position.y + ((tMat.col1.y * m_v2.x) + (tMat.col2.y * m_v2.y))); tMat = transform2.R; var v3X:Number = (transform2.position.x + ((tMat.col1.x * m_v1.x) + (tMat.col2.x * m_v1.y))); var v3Y:Number = (transform2.position.y + ((tMat.col1.y * m_v1.x) + (tMat.col2.y * m_v1.y))); var v4X:Number = (transform2.position.x + ((tMat.col1.x * m_v2.x) + (tMat.col2.x * m_v2.y))); var v4Y:Number = (transform2.position.y + ((tMat.col1.y * m_v2.x) + (tMat.col2.y * m_v2.y))); aabb.lowerBound.x = ((((((v1X < v2X)) ? v1X : v2X < v3X)) ? ((v1X < v2X)) ? v1X : v2X : v3X < v4X)) ? ((((v1X < v2X)) ? v1X : v2X < v3X)) ? ((v1X < v2X)) ? v1X : v2X : v3X : v4X; aabb.lowerBound.y = ((((((v1Y < v2Y)) ? v1Y : v2Y < v3Y)) ? ((v1Y < v2Y)) ? v1Y : v2Y : v3Y < v4Y)) ? ((((v1Y < v2Y)) ? v1Y : v2Y < v3Y)) ? ((v1Y < v2Y)) ? v1Y : v2Y : v3Y : v4Y; aabb.upperBound.x = ((((((v1X > v2X)) ? v1X : v2X > v3X)) ? ((v1X > v2X)) ? v1X : v2X : v3X > v4X)) ? ((((v1X > v2X)) ? v1X : v2X > v3X)) ? ((v1X > v2X)) ? v1X : v2X : v3X : v4X; aabb.upperBound.y = ((((((v1Y > v2Y)) ? v1Y : v2Y > v3Y)) ? ((v1Y > v2Y)) ? v1Y : v2Y : v3Y > v4Y)) ? ((((v1Y > v2Y)) ? v1Y : v2Y > v3Y)) ? ((v1Y > v2Y)) ? v1Y : v2Y : v3Y : v4Y; } public function GetCoreVertex1():b2Vec2{ return (m_coreV1); } public function GetCoreVertex2():b2Vec2{ return (m_coreV2); } public function GetFirstVertex(xf:b2XForm):b2Vec2{ var tMat:b2Mat22 = xf.R; return (new b2Vec2((xf.position.x + ((tMat.col1.x * m_coreV1.x) + (tMat.col2.x * m_coreV1.y))), (xf.position.y + ((tMat.col1.y * m_coreV1.x) + (tMat.col2.y * m_coreV1.y))))); } public function GetNormalVector():b2Vec2{ return (m_normal); } public function GetPrevEdge():b2EdgeShape{ return (m_prevEdge); } override b2internal function UpdateSweepRadius(center:b2Vec2):void{ var dX:Number = (m_coreV1.x - center.x); var dY:Number = (m_coreV1.y - center.y); var d1:Number = ((dX * dX) + (dY * dY)); dX = (m_coreV2.x - center.x); dY = (m_coreV2.y - center.y); var d2:Number = ((dX * dX) + (dY * dY)); m_sweepRadius = Math.sqrt(((d1 > d2)) ? d1 : d2); } public function GetVertex1():b2Vec2{ return (m_v1); } public function GetVertex2():b2Vec2{ return (m_v2); } override public function TestPoint(transform:b2XForm, p:b2Vec2):Boolean{ return (false); } } }//package Box2D.Collision.Shapes
Section 5
//b2FilterData (Box2D.Collision.Shapes.b2FilterData) package Box2D.Collision.Shapes { public class b2FilterData { public var maskBits:uint;// = 0xFFFF public var groupIndex:int;// = 0 public var categoryBits:uint;// = 1 public function b2FilterData(){ super(); } public function Copy():b2FilterData{ var copy:b2FilterData = new b2FilterData(); copy.categoryBits = categoryBits; copy.maskBits = maskBits; copy.groupIndex = groupIndex; return (copy); } } }//package Box2D.Collision.Shapes
Section 6
//b2MassData (Box2D.Collision.Shapes.b2MassData) package Box2D.Collision.Shapes { import Box2D.Common.Math.*; public class b2MassData { public var mass:Number;// = 0 public var center:b2Vec2; public var I:Number;// = 0 public function b2MassData(){ center = new b2Vec2(0, 0); super(); } } }//package Box2D.Collision.Shapes
Section 7
//b2PolygonDef (Box2D.Collision.Shapes.b2PolygonDef) package Box2D.Collision.Shapes { import Box2D.Common.Math.*; import Box2D.Common.*; public class b2PolygonDef extends b2ShapeDef { public var vertices:Array; public var vertexCount:int; private static var s_mat:b2Mat22 = new b2Mat22(); public function b2PolygonDef(){ vertices = new Array(b2Settings.b2_maxPolygonVertices); super(); type = b2Shape.e_polygonShape; vertexCount = 0; var i:int; while (i < b2Settings.b2_maxPolygonVertices) { vertices[i] = new b2Vec2(); i++; }; } public function SetAsOrientedBox(hx:Number, hy:Number, center:b2Vec2=null, angle:Number=0):void{ var xfPosition:b2Vec2; var xfR:b2Mat22; var i:int; vertexCount = 4; vertices[0].Set(-(hx), -(hy)); vertices[1].Set(hx, -(hy)); vertices[2].Set(hx, hy); vertices[3].Set(-(hx), hy); if (center){ xfPosition = center; xfR = s_mat; xfR.Set(angle); i = 0; while (i < vertexCount) { center = vertices[i]; hx = (xfPosition.x + ((xfR.col1.x * center.x) + (xfR.col2.x * center.y))); center.y = (xfPosition.y + ((xfR.col1.y * center.x) + (xfR.col2.y * center.y))); center.x = hx; i++; }; }; } public function SetAsBox(hx:Number, hy:Number):void{ vertexCount = 4; vertices[0].Set(-(hx), -(hy)); vertices[1].Set(hx, -(hy)); vertices[2].Set(hx, hy); vertices[3].Set(-(hx), hy); } } }//package Box2D.Collision.Shapes
Section 8
//b2PolygonShape (Box2D.Collision.Shapes.b2PolygonShape) package Box2D.Collision.Shapes { import Box2D.Dynamics.*; import Box2D.Collision.*; import Box2D.Common.Math.*; import Box2D.Common.*; public class b2PolygonShape extends b2Shape { private var m_coreVertices:Array; b2internal var m_vertices:Array; private var s_supportVec:b2Vec2; b2internal var m_centroid:b2Vec2; b2internal var m_normals:Array; private var m_obb:b2OBB; b2internal var m_vertexCount:int; private static var s_computeMat:b2Mat22 = new b2Mat22(); private static var s_sweptAABB1:b2AABB = new b2AABB(); private static var s_sweptAABB2:b2AABB = new b2AABB(); public function b2PolygonShape(def:b2ShapeDef){ var i:int; var edgeX:Number; var edgeY:Number; var len:Number; var n1X:Number; var n1Y:Number; var n2X:Number; var n2Y:Number; var vX:Number; var vY:Number; var dX:Number; var dY:Number; var det:Number; s_supportVec = new b2Vec2(); m_obb = new b2OBB(); m_vertices = new Array(b2Settings.b2_maxPolygonVertices); m_normals = new Array(b2Settings.b2_maxPolygonVertices); m_coreVertices = new Array(b2Settings.b2_maxPolygonVertices); super(def); m_type = e_polygonShape; var poly:b2PolygonDef = (def as b2PolygonDef); m_vertexCount = poly.vertexCount; var i1:int = i; var i2:int = i; i = 0; while (i < m_vertexCount) { m_vertices[i] = poly.vertices[i].Copy(); i++; }; i = 0; while (i < m_vertexCount) { i1 = i; i2 = (((i + 1) < m_vertexCount)) ? (i + 1) : 0; edgeX = (m_vertices[i2].x - m_vertices[i1].x); edgeY = (m_vertices[i2].y - m_vertices[i1].y); len = Math.sqrt(((edgeX * edgeX) + (edgeY * edgeY))); m_normals[i] = new b2Vec2((edgeY / len), (-(edgeX) / len)); i++; }; m_centroid = ComputeCentroid(poly.vertices, poly.vertexCount); ComputeOBB(m_obb, m_vertices, m_vertexCount); i = 0; while (i < m_vertexCount) { i1 = (((i - 1) >= 0)) ? (i - 1) : (m_vertexCount - 1); i2 = i; n1X = m_normals[i1].x; n1Y = m_normals[i1].y; n2X = m_normals[i2].x; n2Y = m_normals[i2].y; vX = (m_vertices[i].x - m_centroid.x); vY = (m_vertices[i].y - m_centroid.y); dX = (((n1X * vX) + (n1Y * vY)) - b2Settings.b2_toiSlop); dY = (((n2X * vX) + (n2Y * vY)) - b2Settings.b2_toiSlop); det = (1 / ((n1X * n2Y) - (n1Y * n2X))); m_coreVertices[i] = new b2Vec2(((det * ((n2Y * dX) - (n1Y * dY))) + m_centroid.x), ((det * ((n1X * dY) - (n2X * dX))) + m_centroid.y)); i++; }; } override public function ComputeSweptAABB(aabb:b2AABB, transform1:b2XForm, transform2:b2XForm):void{ var aabb1:b2AABB = s_sweptAABB1; var aabb2:b2AABB = s_sweptAABB2; ComputeAABB(aabb1, transform1); ComputeAABB(aabb2, transform2); aabb.lowerBound.Set(((aabb1.lowerBound.x < aabb2.lowerBound.x)) ? aabb1.lowerBound.x : aabb2.lowerBound.x, ((aabb1.lowerBound.y < aabb2.lowerBound.y)) ? aabb1.lowerBound.y : aabb2.lowerBound.y); aabb.upperBound.Set(((aabb1.upperBound.x > aabb2.upperBound.x)) ? aabb1.upperBound.x : aabb2.upperBound.x, ((aabb1.upperBound.y > aabb2.upperBound.y)) ? aabb1.upperBound.y : aabb2.upperBound.y); } public function GetVertices():Array{ return (m_vertices); } public function GetCoreVertices():Array{ return (m_coreVertices); } public function GetCentroid():b2Vec2{ return (m_centroid); } public function GetOBB():b2OBB{ return (m_obb); } public function GetFirstVertex(xf:b2XForm):b2Vec2{ return (b2Math.b2MulX(xf, m_coreVertices[0])); } public function Centroid(xf:b2XForm):b2Vec2{ return (b2Math.b2MulX(xf, m_centroid)); } override public function TestSegment(xf:b2XForm, lambda:Array, normal:b2Vec2, segment:b2Segment, maxLambda:Number):int{ var tX:Number; var tY:Number; var tMat:b2Mat22; var tVec:b2Vec2; var numerator:Number; var denominator:Number; var lower:Number = 0; var upper:Number = maxLambda; tX = (segment.p1.x - xf.position.x); tY = (segment.p1.y - xf.position.y); tMat = xf.R; var p1X:Number = ((tX * tMat.col1.x) + (tY * tMat.col1.y)); var p1Y:Number = ((tX * tMat.col2.x) + (tY * tMat.col2.y)); tX = (segment.p2.x - xf.position.x); tY = (segment.p2.y - xf.position.y); tMat = xf.R; var p2X:Number = ((tX * tMat.col1.x) + (tY * tMat.col1.y)); var p2Y:Number = ((tX * tMat.col2.x) + (tY * tMat.col2.y)); var dX:Number = (p2X - p1X); var dY:Number = (p2Y - p1Y); var index = -1; var i:int; while (i < m_vertexCount) { tVec = m_vertices[i]; tX = (tVec.x - p1X); tY = (tVec.y - p1Y); tVec = m_normals[i]; numerator = ((tVec.x * tX) + (tVec.y * tY)); denominator = ((tVec.x * dX) + (tVec.y * dY)); if (denominator == 0){ if (numerator < 0){ return (e_missCollide); }; } else { if ((((denominator < 0)) && ((numerator < (lower * denominator))))){ lower = (numerator / denominator); index = i; } else { if ((((denominator > 0)) && ((numerator < (upper * denominator))))){ upper = (numerator / denominator); }; }; }; if (upper < lower){ return (e_missCollide); }; i++; }; if (index >= 0){ lambda[0] = lower; tMat = xf.R; tVec = m_normals[index]; normal.x = ((tMat.col1.x * tVec.x) + (tMat.col2.x * tVec.y)); normal.y = ((tMat.col1.y * tVec.x) + (tMat.col2.y * tVec.y)); return (e_hitCollide); }; lambda[0] = 0; return (e_startsInsideCollide); } override public function ComputeMass(massData:b2MassData):void{ var p2:b2Vec2; var p3:b2Vec2; var e1X:Number; var e1Y:Number; var e2X:Number; var e2Y:Number; var D:Number; var triangleArea:Number; var px:Number; var py:Number; var ex1:Number; var ey1:Number; var ex2:Number; var ey2:Number; var intx2:Number; var inty2:Number; var centerX:Number = 0; var centerY:Number = 0; var area:Number = 0; var I:Number = 0; var p1X:Number = 0; var p1Y:Number = 0; var k_inv3:Number = (1 / 3); var i:int; while (i < m_vertexCount) { p2 = m_vertices[i]; p3 = (((i + 1) < m_vertexCount)) ? m_vertices[int((i + 1))] : m_vertices[0]; e1X = (p2.x - p1X); e1Y = (p2.y - p1Y); e2X = (p3.x - p1X); e2Y = (p3.y - p1Y); D = ((e1X * e2Y) - (e1Y * e2X)); triangleArea = (0.5 * D); area = (area + triangleArea); centerX = (centerX + ((triangleArea * k_inv3) * ((p1X + p2.x) + p3.x))); centerY = (centerY + ((triangleArea * k_inv3) * ((p1Y + p2.y) + p3.y))); px = p1X; py = p1Y; ex1 = e1X; ey1 = e1Y; ex2 = e2X; ey2 = e2Y; intx2 = ((k_inv3 * ((0.25 * (((ex1 * ex1) + (ex2 * ex1)) + (ex2 * ex2))) + ((px * ex1) + (px * ex2)))) + ((0.5 * px) * px)); inty2 = ((k_inv3 * ((0.25 * (((ey1 * ey1) + (ey2 * ey1)) + (ey2 * ey2))) + ((py * ey1) + (py * ey2)))) + ((0.5 * py) * py)); I = (I + (D * (intx2 + inty2))); i++; }; massData.mass = (m_density * area); centerX = (centerX * (1 / area)); centerY = (centerY * (1 / area)); massData.center.Set(centerX, centerY); massData.I = (m_density * I); } public function GetNormals():Array{ return (m_normals); } public function Support(xf:b2XForm, dX:Number, dY:Number):b2Vec2{ var tVec:b2Vec2; var tMat:b2Mat22; var value:Number; tMat = xf.R; var dLocalX:Number = ((dX * tMat.col1.x) + (dY * tMat.col1.y)); var dLocalY:Number = ((dX * tMat.col2.x) + (dY * tMat.col2.y)); var bestIndex:int; tVec = m_coreVertices[0]; var bestValue:Number = ((tVec.x * dLocalX) + (tVec.y * dLocalY)); var i = 1; while (i < m_vertexCount) { tVec = m_coreVertices[i]; value = ((tVec.x * dLocalX) + (tVec.y * dLocalY)); if (value > bestValue){ bestIndex = i; bestValue = value; }; i++; }; tMat = xf.R; tVec = m_coreVertices[bestIndex]; s_supportVec.x = (xf.position.x + ((tMat.col1.x * tVec.x) + (tMat.col2.x * tVec.y))); s_supportVec.y = (xf.position.y + ((tMat.col1.y * tVec.x) + (tMat.col2.y * tVec.y))); return (s_supportVec); } public function GetVertexCount():int{ return (m_vertexCount); } override public function ComputeAABB(aabb:b2AABB, xf:b2XForm):void{ var tMat:b2Mat22; var tVec:b2Vec2; var R:b2Mat22 = s_computeMat; tMat = xf.R; tVec = m_obb.R.col1; R.col1.x = ((tMat.col1.x * tVec.x) + (tMat.col2.x * tVec.y)); R.col1.y = ((tMat.col1.y * tVec.x) + (tMat.col2.y * tVec.y)); tVec = m_obb.R.col2; R.col2.x = ((tMat.col1.x * tVec.x) + (tMat.col2.x * tVec.y)); R.col2.y = ((tMat.col1.y * tVec.x) + (tMat.col2.y * tVec.y)); R.Abs(); var absR:b2Mat22 = R; tVec = m_obb.extents; var hX:Number = ((absR.col1.x * tVec.x) + (absR.col2.x * tVec.y)); var hY:Number = ((absR.col1.y * tVec.x) + (absR.col2.y * tVec.y)); tMat = xf.R; tVec = m_obb.center; var positionX:Number = (xf.position.x + ((tMat.col1.x * tVec.x) + (tMat.col2.x * tVec.y))); var positionY:Number = (xf.position.y + ((tMat.col1.y * tVec.x) + (tMat.col2.y * tVec.y))); aabb.lowerBound.Set((positionX - hX), (positionY - hY)); aabb.upperBound.Set((positionX + hX), (positionY + hY)); } override b2internal function UpdateSweepRadius(center:b2Vec2):void{ var tVec:b2Vec2; var dX:Number; var dY:Number; m_sweepRadius = 0; var i:int; while (i < m_vertexCount) { tVec = m_coreVertices[i]; dX = (tVec.x - center.x); dY = (tVec.y - center.y); dX = Math.sqrt(((dX * dX) + (dY * dY))); if (dX > m_sweepRadius){ m_sweepRadius = dX; }; i++; }; } override public function TestPoint(xf:b2XForm, p:b2Vec2):Boolean{ var tVec:b2Vec2; var dot:Number; var tMat:b2Mat22 = xf.R; var tX:Number = (p.x - xf.position.x); var tY:Number = (p.y - xf.position.y); var pLocalX:Number = ((tX * tMat.col1.x) + (tY * tMat.col1.y)); var pLocalY:Number = ((tX * tMat.col2.x) + (tY * tMat.col2.y)); var i:int; while (i < m_vertexCount) { tVec = m_vertices[i]; tX = (pLocalX - tVec.x); tY = (pLocalY - tVec.y); tVec = m_normals[i]; dot = ((tVec.x * tX) + (tVec.y * tY)); if (dot > 0){ return (false); }; i++; }; return (true); } public static function ComputeCentroid(vs:Array, count:int):b2Vec2{ var c:b2Vec2; var inv3:Number; var p2:b2Vec2; var p3:b2Vec2; var e1X:Number; var e1Y:Number; var e2X:Number; var e2Y:Number; var D:Number; var triangleArea:Number; c = new b2Vec2(); var area:Number = 0; var p1X:Number = 0; var p1Y:Number = 0; inv3 = (1 / 3); var i:int; while (i < count) { p2 = vs[i]; p3 = (((i + 1) < count)) ? vs[int((i + 1))] : vs[0]; e1X = (p2.x - p1X); e1Y = (p2.y - p1Y); e2X = (p3.x - p1X); e2Y = (p3.y - p1Y); D = ((e1X * e2Y) - (e1Y * e2X)); triangleArea = (0.5 * D); area = (area + triangleArea); c.x = (c.x + ((triangleArea * inv3) * ((p1X + p2.x) + p3.x))); c.y = (c.y + ((triangleArea * inv3) * ((p1Y + p2.y) + p3.y))); i++; }; c.x = (c.x * (1 / area)); c.y = (c.y * (1 / area)); return (c); } b2internal static function ComputeOBB(obb:b2OBB, vs:Array, count:int):void{ var i:int; var root:b2Vec2; var uxX:Number; var uxY:Number; var length:Number; var uyX:Number; var uyY:Number; var lowerX:Number; var lowerY:Number; var upperX:Number; var upperY:Number; var j:int; var area:Number; var dX:Number; var dY:Number; var rX:Number; var rY:Number; var centerX:Number; var centerY:Number; var tMat:b2Mat22; var p:Array = new Array((b2Settings.b2_maxPolygonVertices + 1)); i = 0; while (i < count) { p[i] = vs[i]; i++; }; p[count] = p[0]; var minArea:Number = Number.MAX_VALUE; i = 1; while (i <= count) { root = p[int((i - 1))]; uxX = (p[i].x - root.x); uxY = (p[i].y - root.y); length = Math.sqrt(((uxX * uxX) + (uxY * uxY))); uxX = (uxX / length); uxY = (uxY / length); uyX = -(uxY); uyY = uxX; lowerX = Number.MAX_VALUE; lowerY = Number.MAX_VALUE; upperX = -(Number.MAX_VALUE); upperY = -(Number.MAX_VALUE); j = 0; while (j < count) { dX = (p[j].x - root.x); dY = (p[j].y - root.y); rX = ((uxX * dX) + (uxY * dY)); rY = ((uyX * dX) + (uyY * dY)); if (rX < lowerX){ lowerX = rX; }; if (rY < lowerY){ lowerY = rY; }; if (rX > upperX){ upperX = rX; }; if (rY > upperY){ upperY = rY; }; j++; }; area = ((upperX - lowerX) * (upperY - lowerY)); if (area < (0.95 * minArea)){ minArea = area; obb.R.col1.x = uxX; obb.R.col1.y = uxY; obb.R.col2.x = uyX; obb.R.col2.y = uyY; centerX = (0.5 * (lowerX + upperX)); centerY = (0.5 * (lowerY + upperY)); tMat = obb.R; obb.center.x = (root.x + ((tMat.col1.x * centerX) + (tMat.col2.x * centerY))); obb.center.y = (root.y + ((tMat.col1.y * centerX) + (tMat.col2.y * centerY))); obb.extents.x = (0.5 * (upperX - lowerX)); obb.extents.y = (0.5 * (upperY - lowerY)); }; i++; }; } } }//package Box2D.Collision.Shapes
Section 9
//b2Shape (Box2D.Collision.Shapes.b2Shape) package Box2D.Collision.Shapes { import Box2D.Dynamics.*; import Box2D.Collision.*; import Box2D.Common.Math.*; import Box2D.Common.*; public class b2Shape { b2internal var m_next:b2Shape; b2internal var m_type:int; b2internal var m_sweepRadius:Number; private var m_proxy:b2Proxy; b2internal var m_density:Number; private var m_filter:b2FilterData; b2internal var m_friction:Number; private var m_isSensor:Boolean; b2internal var m_restitution:Number; private var m_userData; b2internal var m_body:b2Body; b2internal static const e_polygonShape:int = 1; public static const e_hitCollide:int = 1; public static const e_missCollide:int = 0; b2internal static const e_edgeShape:int = 2; b2internal static const e_unknownShape:int = -1; b2internal static const e_circleShape:int = 0; b2internal static const e_shapeTypeCount:int = 3; public static const e_startsInsideCollide:int = -1; private static var s_resetAABB:b2AABB = new b2AABB(); private static var s_syncAABB:b2AABB = new b2AABB(); private static var s_proxyAABB:b2AABB = new b2AABB(); public function b2Shape(def:b2ShapeDef){ super(); m_userData = def.userData; m_friction = def.friction; m_restitution = def.restitution; m_density = def.density; m_body = null; m_sweepRadius = 0; m_next = null; m_proxy = null; m_filter = def.filter.Copy(); m_isSensor = def.isSensor; } public function SetUserData(data):void{ m_userData = data; } public function GetSweepRadius():Number{ return (m_sweepRadius); } public function GetNext():b2Shape{ return (m_next); } public function ComputeSweptAABB(aabb:b2AABB, xf1:b2XForm, xf2:b2XForm):void{ } public function SetRestitution(restitution:Number):void{ m_restitution = restitution; } public function GetType():int{ return (m_type); } public function GetRestitution():Number{ return (m_restitution); } public function GetFriction():Number{ return (m_friction); } public function GetFilterData():b2FilterData{ return (m_filter.Copy()); } public function SetFriction(friction:Number):void{ m_friction = friction; } public function TestSegment(xf:b2XForm, lambda:Array, normal:b2Vec2, segment:b2Segment, maxLambda:Number):int{ return (e_missCollide); } b2internal function RefilterProxy(broadPhase:b2BroadPhase, transform:b2XForm):void{ if (m_proxy == null){ return; }; broadPhase.DestroyProxy(m_proxy); var aabb:b2AABB = s_resetAABB; ComputeAABB(aabb, transform); var inRange:Boolean = broadPhase.InRange(aabb); if (inRange){ m_proxy = broadPhase.CreateProxy(aabb, this); } else { m_proxy = null; }; } public function SetFilterData(filter:b2FilterData):void{ m_filter = filter.Copy(); } public function GetUserData(){ return (m_userData); } b2internal function Synchronize(broadPhase:b2BroadPhase, transform1:b2XForm, transform2:b2XForm):Boolean{ if (m_proxy == null){ return (false); }; var aabb:b2AABB = s_syncAABB; ComputeSweptAABB(aabb, transform1, transform2); if (broadPhase.InRange(aabb)){ broadPhase.MoveProxy(m_proxy, aabb); return (true); }; return (false); } public function ComputeMass(massData:b2MassData):void{ } public function IsSensor():Boolean{ return (m_isSensor); } b2internal function DestroyProxy(broadPhase:b2BroadPhase):void{ if (m_proxy){ broadPhase.DestroyProxy(m_proxy); m_proxy = null; }; } b2internal function UpdateSweepRadius(center:b2Vec2):void{ } public function ComputeAABB(aabb:b2AABB, xf:b2XForm):void{ } public function GetBody():b2Body{ return (m_body); } b2internal function CreateProxy(broadPhase:b2BroadPhase, transform:b2XForm):void{ var aabb:b2AABB = s_proxyAABB; ComputeAABB(aabb, transform); var inRange:Boolean = broadPhase.InRange(aabb); if (inRange){ m_proxy = broadPhase.CreateProxy(aabb, this); } else { m_proxy = null; }; } public function TestPoint(xf:b2XForm, p:b2Vec2):Boolean{ return (false); } b2internal static function Destroy(shape:b2Shape, allocator):void{ var _local3:b2EdgeShape; switch (shape.m_type){ case e_edgeShape: _local3 = (shape as b2EdgeShape); if (_local3.m_nextEdge != null){ _local3.m_nextEdge.m_prevEdge = null; }; if (_local3.m_prevEdge != null){ _local3.m_prevEdge.m_nextEdge = null; }; break; }; } b2internal static function Create(def:b2ShapeDef, allocator):b2Shape{ switch (def.type){ case e_circleShape: return (new b2CircleShape(def)); case e_polygonShape: return (new b2PolygonShape(def)); default: return (null); }; } } }//package Box2D.Collision.Shapes
Section 10
//b2ShapeDef (Box2D.Collision.Shapes.b2ShapeDef) package Box2D.Collision.Shapes { public class b2ShapeDef { public var friction:Number;// = 0.2 public var isSensor:Boolean;// = false public var density:Number;// = 0 public var restitution:Number;// = 0 public var userData;// = null public var filter:b2FilterData; public var type:int;// = -1 public function b2ShapeDef(){ filter = new b2FilterData(); super(); } } }//package Box2D.Collision.Shapes
Section 11
//b2AABB (Box2D.Collision.b2AABB) package Box2D.Collision { import Box2D.Common.Math.*; public class b2AABB { public var upperBound:b2Vec2; public var lowerBound:b2Vec2; public function b2AABB(){ lowerBound = new b2Vec2(); upperBound = new b2Vec2(); super(); } public function IsValid():Boolean{ var dX:Number = (upperBound.x - lowerBound.x); var dY:Number = (upperBound.y - lowerBound.y); var valid:Boolean = (((dX >= 0)) && ((dY >= 0))); valid = ((((valid) && (lowerBound.IsValid()))) && (upperBound.IsValid())); return (valid); } } }//package Box2D.Collision
Section 12
//b2Bound (Box2D.Collision.b2Bound) package Box2D.Collision { public class b2Bound { public var value:uint; public var stabbingCount:uint; public var proxy:b2Proxy; public function b2Bound(){ super(); } public function Swap(b:b2Bound):void{ var tempValue:uint = value; var tempProxy:b2Proxy = proxy; var tempStabbingCount:uint = stabbingCount; value = b.value; proxy = b.proxy; stabbingCount = b.stabbingCount; b.value = tempValue; b.proxy = tempProxy; b.stabbingCount = tempStabbingCount; } public function IsLower():Boolean{ return (((value & 1) == 0)); } public function IsUpper():Boolean{ return (((value & 1) == 1)); } } }//package Box2D.Collision
Section 13
//b2BoundValues (Box2D.Collision.b2BoundValues) package Box2D.Collision { public class b2BoundValues { public var lowerValues:Array; public var upperValues:Array; public function b2BoundValues(){ lowerValues = [0, 0]; upperValues = [0, 0]; super(); } } }//package Box2D.Collision
Section 14
//b2BroadPhase (Box2D.Collision.b2BroadPhase) package Box2D.Collision { import Box2D.Common.Math.*; import Box2D.Common.*; public class b2BroadPhase { b2internal var m_bounds:Array; b2internal var m_quantizationFactor:b2Vec2; b2internal var m_worldAABB:b2AABB; private var m_querySortKeys:Array; private var m_freeProxy:b2Proxy; b2internal var m_proxyCount:int; b2internal var m_proxyPool:Array; private var m_queryResultCount:int; b2internal var m_pairManager:b2PairManager; private var m_timeStamp:uint; private var m_queryResults:Array; public static const b2_nullEdge:uint = 0xFFFF; public static const b2_invalid:uint = 0xFFFF; public static var s_validate:Boolean = false; public function b2BroadPhase(worldAABB:b2AABB, callback:b2PairCallback){ var i:int; m_pairManager = new b2PairManager(); m_proxyPool = new Array(); m_bounds = new Array(); m_querySortKeys = new Array(); m_queryResults = new Array(); m_quantizationFactor = new b2Vec2(); super(); m_pairManager.Initialize(this, callback); m_worldAABB = worldAABB; m_proxyCount = 0; m_bounds = new Array(2); i = 0; while (i < 2) { m_bounds[i] = new Array(); i++; }; var dX:Number = (worldAABB.upperBound.x - worldAABB.lowerBound.x); var dY:Number = (worldAABB.upperBound.y - worldAABB.lowerBound.y); m_quantizationFactor.x = (b2Settings.USHRT_MAX / dX); m_quantizationFactor.y = (b2Settings.USHRT_MAX / dY); m_timeStamp = 1; m_queryResultCount = 0; } public function QueryAABB(aabb:b2AABB, userData, maxCount:int):int{ var lowerIndex:uint; var upperIndex:uint; var proxy:b2Proxy; var lowerValues:Array = new Array(); var upperValues:Array = new Array(); ComputeBounds(lowerValues, upperValues, aabb); var lowerIndexOut:Array = [lowerIndex]; var upperIndexOut:Array = [upperIndex]; Query(lowerIndexOut, upperIndexOut, lowerValues[0], upperValues[0], m_bounds[0], (2 * m_proxyCount), 0); Query(lowerIndexOut, upperIndexOut, lowerValues[1], upperValues[1], m_bounds[1], (2 * m_proxyCount), 1); var count:int; var i:int; while ((((i < m_queryResultCount)) && ((count < maxCount)))) { proxy = m_queryResults[i]; userData[i] = proxy.userData; i++; count++; }; m_queryResultCount = 0; IncrementTimeStamp(); return (count); } public function Commit():void{ m_pairManager.Commit(); } private function IncrementTimeStamp():void{ var i:uint; if (m_timeStamp == b2Settings.USHRT_MAX){ i = 0; while (i < m_proxyPool.length) { (m_proxyPool[i] as b2Proxy).timeStamp = 0; i++; }; m_timeStamp = 1; } else { m_timeStamp++; }; } private function Query(lowerQueryOut:Array, upperQueryOut:Array, lowerValue:uint, upperValue:uint, bounds:Array, boundCount:uint, axis:int):void{ var bound:b2Bound; var i:int; var s:int; var proxy:b2Proxy; var lowerQuery:uint = BinarySearch(bounds, boundCount, lowerValue); var upperQuery:uint = BinarySearch(bounds, boundCount, upperValue); var j:uint = lowerQuery; while (j < upperQuery) { bound = bounds[j]; if (bound.IsLower()){ IncrementOverlapCount(bound.proxy); }; j++; }; if (lowerQuery > 0){ i = (lowerQuery - 1); bound = bounds[i]; s = bound.stabbingCount; while (s) { bound = bounds[i]; if (bound.IsLower()){ proxy = bound.proxy; if (lowerQuery <= proxy.upperBounds[axis]){ IncrementOverlapCount(bound.proxy); s--; }; }; i--; }; }; lowerQueryOut[0] = lowerQuery; upperQueryOut[0] = upperQuery; } private function AddProxyResult(proxy:b2Proxy, maxCount:Number, sortKey:Function):void{ var tempKey2:Number; var tempProxy2:b2Proxy; var key:Number = sortKey(proxy.userData); if (key < 0){ return; }; var i:Number = 0; while ((((i < m_queryResultCount)) && ((m_querySortKeys[i] < key)))) { i++; }; var tempKey:Number = key; var tempProxy:b2Proxy = proxy; m_queryResultCount = (m_queryResultCount + 1); if (m_queryResultCount > maxCount){ m_queryResultCount = maxCount; }; while (i < m_queryResultCount) { tempKey2 = m_querySortKeys[i]; tempProxy2 = m_queryResults[i]; m_querySortKeys[i] = tempKey; m_queryResults[i] = tempProxy; tempKey = tempKey2; tempProxy = tempProxy2; i++; }; } private function TestOverlapValidate(p1:b2Proxy, p2:b2Proxy):Boolean{ var bounds:Array; var bound1:b2Bound; var bound2:b2Bound; var axis:int; while (axis < 2) { bounds = m_bounds[axis]; bound1 = bounds[p1.lowerBounds[axis]]; bound2 = bounds[p2.upperBounds[axis]]; if (bound1.value > bound2.value){ return (false); }; bound1 = bounds[p1.upperBounds[axis]]; bound2 = bounds[p2.lowerBounds[axis]]; if (bound1.value < bound2.value){ return (false); }; axis++; }; return (true); } private function ComputeBounds(lowerValues:Array, upperValues:Array, aabb:b2AABB):void{ var minVertexX:Number = aabb.lowerBound.x; var minVertexY:Number = aabb.lowerBound.y; minVertexX = b2Math.b2Min(minVertexX, m_worldAABB.upperBound.x); minVertexY = b2Math.b2Min(minVertexY, m_worldAABB.upperBound.y); minVertexX = b2Math.b2Max(minVertexX, m_worldAABB.lowerBound.x); minVertexY = b2Math.b2Max(minVertexY, m_worldAABB.lowerBound.y); var maxVertexX:Number = aabb.upperBound.x; var maxVertexY:Number = aabb.upperBound.y; maxVertexX = b2Math.b2Min(maxVertexX, m_worldAABB.upperBound.x); maxVertexY = b2Math.b2Min(maxVertexY, m_worldAABB.upperBound.y); maxVertexX = b2Math.b2Max(maxVertexX, m_worldAABB.lowerBound.x); maxVertexY = b2Math.b2Max(maxVertexY, m_worldAABB.lowerBound.y); lowerValues[0] = (uint((m_quantizationFactor.x * (minVertexX - m_worldAABB.lowerBound.x))) & (b2Settings.USHRT_MAX - 1)); upperValues[0] = ((uint((m_quantizationFactor.x * (maxVertexX - m_worldAABB.lowerBound.x))) & 0xFFFF) | 1); lowerValues[1] = (uint((m_quantizationFactor.y * (minVertexY - m_worldAABB.lowerBound.y))) & (b2Settings.USHRT_MAX - 1)); upperValues[1] = ((uint((m_quantizationFactor.y * (maxVertexY - m_worldAABB.lowerBound.y))) & 0xFFFF) | 1); } public function CreateProxy(aabb:b2AABB, userData):b2Proxy{ var index:uint; var proxy:b2Proxy; var i:int; var j:int; var bounds:Array; var lowerIndex:uint; var upperIndex:uint; var lowerIndexOut:Array; var upperIndexOut:Array; var tBound1:b2Bound; var tBound2:b2Bound; var tBoundAS3:b2Bound; var proxy2:b2Proxy; if (!m_freeProxy){ m_freeProxy = (m_proxyPool[m_proxyCount] = new b2Proxy()); m_freeProxy.next = null; m_freeProxy.timeStamp = 0; m_freeProxy.overlapCount = b2_invalid; m_freeProxy.userData = null; i = 0; while (i < 2) { j = (m_proxyCount * 2); var _temp1 = j; j = (j + 1); var _local20 = _temp1; m_bounds[i][_local20] = new b2Bound(); m_bounds[i][j] = new b2Bound(); i++; }; }; proxy = m_freeProxy; m_freeProxy = proxy.next; proxy.overlapCount = 0; proxy.userData = userData; var boundCount:uint = (2 * m_proxyCount); var lowerValues:Array = new Array(); var upperValues:Array = new Array(); ComputeBounds(lowerValues, upperValues, aabb); var axis:int; while (axis < 2) { bounds = m_bounds[axis]; lowerIndexOut = [lowerIndex]; upperIndexOut = [upperIndex]; Query(lowerIndexOut, upperIndexOut, lowerValues[axis], upperValues[axis], bounds, boundCount, axis); lowerIndex = lowerIndexOut[0]; upperIndex = upperIndexOut[0]; bounds.splice(upperIndex, 0, bounds[(bounds.length - 1)]); bounds.length--; bounds.splice(lowerIndex, 0, bounds[(bounds.length - 1)]); bounds.length--; upperIndex++; tBound1 = bounds[lowerIndex]; tBound2 = bounds[upperIndex]; tBound1.value = lowerValues[axis]; tBound1.proxy = proxy; tBound2.value = upperValues[axis]; tBound2.proxy = proxy; tBoundAS3 = bounds[int((lowerIndex - 1))]; tBound1.stabbingCount = ((lowerIndex == 0)) ? 0 : tBoundAS3.stabbingCount; tBoundAS3 = bounds[int((upperIndex - 1))]; tBound2.stabbingCount = tBoundAS3.stabbingCount; index = lowerIndex; while (index < upperIndex) { tBoundAS3 = bounds[index]; tBoundAS3.stabbingCount++; index++; }; index = lowerIndex; while (index < (boundCount + 2)) { tBound1 = bounds[index]; proxy2 = tBound1.proxy; if (tBound1.IsLower()){ proxy2.lowerBounds[axis] = index; } else { proxy2.upperBounds[axis] = index; }; index++; }; axis++; }; m_proxyCount++; i = 0; while (i < m_queryResultCount) { m_pairManager.AddBufferedPair(proxy, m_queryResults[i]); i++; }; m_pairManager.Commit(); m_queryResultCount = 0; IncrementTimeStamp(); return (proxy); } public function DestroyProxy(proxy:b2Proxy):void{ var tBound1:b2Bound; var tBound2:b2Bound; var bounds:Array; var lowerIndex:uint; var upperIndex:uint; var lowerValue:uint; var upperValue:uint; var tEnd:int; var index:uint; var index2:int; var proxy2:b2Proxy; var boundCount:int = (2 * m_proxyCount); var axis:int; while (axis < 2) { bounds = m_bounds[axis]; lowerIndex = proxy.lowerBounds[axis]; upperIndex = proxy.upperBounds[axis]; tBound1 = bounds[lowerIndex]; lowerValue = tBound1.value; tBound2 = bounds[upperIndex]; upperValue = tBound2.value; bounds.splice(upperIndex, 1); bounds.splice(lowerIndex, 1); bounds.push(tBound1); bounds.push(tBound2); tEnd = (boundCount - 2); index = lowerIndex; while (index < tEnd) { tBound1 = bounds[index]; proxy2 = tBound1.proxy; if (tBound1.IsLower()){ proxy2.lowerBounds[axis] = index; } else { proxy2.upperBounds[axis] = index; }; index++; }; tEnd = (upperIndex - 1); index2 = lowerIndex; while (index2 < tEnd) { tBound1 = bounds[index2]; tBound1.stabbingCount--; index2++; }; Query([0], [0], lowerValue, upperValue, bounds, (boundCount - 2), axis); axis++; }; var i:int; while (i < m_queryResultCount) { m_pairManager.RemoveBufferedPair(proxy, m_queryResults[i]); i++; }; m_pairManager.Commit(); m_queryResultCount = 0; IncrementTimeStamp(); proxy.userData = null; proxy.overlapCount = b2_invalid; proxy.lowerBounds[0] = b2_invalid; proxy.lowerBounds[1] = b2_invalid; proxy.upperBounds[0] = b2_invalid; proxy.upperBounds[1] = b2_invalid; proxy.next = m_freeProxy; m_freeProxy = proxy; m_proxyCount--; } public function TestOverlap(b:b2BoundValues, p:b2Proxy):Boolean{ var bounds:Array; var bound:b2Bound; var axis:int; while (axis < 2) { bounds = m_bounds[axis]; bound = bounds[p.upperBounds[axis]]; if (b.lowerValues[axis] > bound.value){ return (false); }; bound = bounds[p.lowerBounds[axis]]; if (b.upperValues[axis] < bound.value){ return (false); }; axis++; }; return (true); } public function Validate():void{ var pair:b2Pair; var proxy1:b2Proxy; var proxy2:b2Proxy; var overlap:Boolean; var bounds:b2Bound; var boundCount:uint; var stabbingCount:uint; var i:uint; var bound:b2Bound; var axis:int; while (axis < 2) { bounds = m_bounds[axis]; boundCount = (2 * m_proxyCount); stabbingCount = 0; i = 0; while (i < boundCount) { bound = bounds[i]; if (bound.IsLower() == true){ stabbingCount++; } else { stabbingCount--; }; i++; }; axis++; }; } private function IncrementOverlapCount(proxy:b2Proxy):void{ if (proxy.timeStamp < m_timeStamp){ proxy.timeStamp = m_timeStamp; proxy.overlapCount = 1; } else { proxy.overlapCount = 2; m_queryResults[m_queryResultCount] = proxy; m_queryResultCount++; }; } public function InRange(aabb:b2AABB):Boolean{ var dX:Number; var dY:Number; var d2X:Number; var d2Y:Number; dX = aabb.lowerBound.x; dY = aabb.lowerBound.y; dX = (dX - m_worldAABB.upperBound.x); dY = (dY - m_worldAABB.upperBound.y); d2X = m_worldAABB.lowerBound.x; d2Y = m_worldAABB.lowerBound.y; d2X = (d2X - aabb.upperBound.x); d2Y = (d2Y - aabb.upperBound.y); dX = b2Math.b2Max(dX, d2X); dY = b2Math.b2Max(dY, d2Y); return ((b2Math.b2Max(dX, dY) < 0)); } public function QuerySegment(segment:b2Segment, userData, maxCount:int, sortKey:Function):int{ var xIndex:int; var yIndex:int; var proxy:b2Proxy; var lowerIndex:uint; var upperIndex:uint; var count:int; var i:Number; var A:Number; var B:Number; var tempValue:b2Proxy; var xProgress:Number; var yProgress:Number; var maxLamda:Number = 1; var dx:Number = ((segment.p2.x - segment.p1.x) * m_quantizationFactor.x); var dy:Number = ((segment.p2.y - segment.p1.y) * m_quantizationFactor.y); var sx:int = ((dx < -(Number.MIN_VALUE))) ? -1 : ((dx > Number.MIN_VALUE)) ? 1 : 0; var sy:int = ((dy < -(Number.MIN_VALUE))) ? -1 : ((dy > Number.MIN_VALUE)) ? 1 : 0; var p1x:Number = (m_quantizationFactor.x * (segment.p1.x - m_worldAABB.lowerBound.x)); var p1y:Number = (m_quantizationFactor.y * (segment.p1.y - m_worldAABB.lowerBound.y)); var startValues:Array = new Array(); var startValues2:Array = new Array(); startValues[0] = (uint(p1x) & (b2Settings.USHRT_MAX - 1)); startValues[1] = (uint(p1y) & (b2Settings.USHRT_MAX - 1)); startValues2[0] = (startValues[0] + 1); startValues2[1] = (startValues[1] + 1); var startIndices:Array = new Array(); var lowerIndexOut:Array = [lowerIndex]; var upperIndexOut:Array = [upperIndex]; Query(lowerIndexOut, upperIndexOut, startValues[0], startValues2[0], m_bounds[0], (2 * m_proxyCount), 0); if (sx >= 0){ xIndex = (upperIndexOut[0] - 1); } else { xIndex = lowerIndexOut[0]; }; Query(lowerIndexOut, upperIndexOut, startValues[1], startValues2[1], m_bounds[1], (2 * m_proxyCount), 1); if (sy >= 0){ yIndex = (upperIndexOut[0] - 1); } else { yIndex = lowerIndexOut[0]; }; if (sortKey != null){ i = 0; while (i < m_queryResultCount) { m_querySortKeys[i] = sortKey(m_queryResults[i].userData); i++; }; i = 0; while (i < (m_queryResultCount - 1)) { A = m_querySortKeys[i]; B = m_querySortKeys[(i + 1)]; if (((A)<0) ? (B >= 0) : (((A > B)) && ((B >= 0)))){ m_querySortKeys[(i + 1)] = A; m_querySortKeys[i] = B; tempValue = m_queryResults[(i + 1)]; m_queryResults[(i + 1)] = m_queryResults[i]; m_queryResults[i] = tempValue; i--; if (i == -1){ i = 1; }; } else { i++; }; }; while ((((m_queryResultCount > 0)) && ((m_querySortKeys[(m_queryResultCount - 1)] < 0)))) { m_queryResultCount--; }; }; while (true) { xProgress = 0; yProgress = 0; xIndex = (xIndex + ((sx >= 0)) ? 1 : -1); if ((((xIndex < 0)) || ((xIndex >= (m_proxyCount * 2))))){ break; }; if (sx != 0){ xProgress = ((m_bounds[0][xIndex].value - p1x) / dx); }; yIndex = (yIndex + ((sy >= 0)) ? 1 : -1); if ((((yIndex < 0)) || ((yIndex >= (m_proxyCount * 2))))){ break; }; if (sy != 0){ yProgress = ((m_bounds[1][yIndex].value - p1y) / dy); }; while (true) { if ((((sy == 0)) || (((!((sx == 0))) && ((xProgress < yProgress)))))){ if (xProgress > maxLamda){ break; }; if (((sx > 0)) ? m_bounds[0][xIndex].IsLower() : m_bounds[0][xIndex].IsUpper()){ proxy = m_bounds[0][xIndex].proxy; if (sy >= 0){ if ((((proxy.lowerBounds[1] <= (yIndex - 1))) && ((proxy.upperBounds[1] >= yIndex)))){ if (sortKey != null){ AddProxyResult(proxy, maxCount, sortKey); } else { m_queryResults[m_queryResultCount] = proxy; m_queryResultCount++; }; }; } else { if ((((proxy.lowerBounds[1] <= yIndex)) && ((proxy.upperBounds[1] >= (yIndex + 1))))){ if (sortKey != null){ AddProxyResult(proxy, maxCount, sortKey); } else { m_queryResults[m_queryResultCount] = proxy; m_queryResultCount++; }; }; }; }; if (((((((!((sortKey == null))) && ((m_queryResultCount == maxCount)))) && ((m_queryResultCount > 0)))) && ((xProgress > m_querySortKeys[(m_queryResultCount - 1)])))){ break; }; if (sx > 0){ xIndex++; if (xIndex == (m_proxyCount * 2)){ break; }; } else { xIndex--; if (xIndex < 0){ break; }; }; xProgress = ((m_bounds[0][xIndex].value - p1x) / dx); } else { if (yProgress > maxLamda){ break; }; if (((sy > 0)) ? m_bounds[1][yIndex].IsLower() : m_bounds[1][yIndex].IsUpper()){ proxy = m_bounds[1][yIndex].proxy; if (sx >= 0){ if ((((proxy.lowerBounds[0] <= (xIndex - 1))) && ((proxy.upperBounds[0] >= xIndex)))){ if (sortKey != null){ AddProxyResult(proxy, maxCount, sortKey); } else { m_queryResults[m_queryResultCount] = proxy; m_queryResultCount++; }; }; } else { if ((((proxy.lowerBounds[0] <= xIndex)) && ((proxy.upperBounds[0] >= (xIndex + 1))))){ if (sortKey != null){ AddProxyResult(proxy, maxCount, sortKey); } else { m_queryResults[m_queryResultCount] = proxy; m_queryResultCount++; }; }; }; }; if (((((((!((sortKey == null))) && ((m_queryResultCount == maxCount)))) && ((m_queryResultCount > 0)))) && ((yProgress > m_querySortKeys[(m_queryResultCount - 1)])))){ break; }; if (sy > 0){ yIndex++; if (yIndex == (m_proxyCount * 2)){ break; }; } else { yIndex--; if (yIndex < 0){ break; }; }; yProgress = ((m_bounds[1][yIndex].value - p1y) / dy); }; }; break; }; count = 0; i = 0; while ((((i < m_queryResultCount)) && ((count < maxCount)))) { proxy = m_queryResults[i]; userData[i] = proxy.userData; i++; count++; }; m_queryResultCount = 0; IncrementTimeStamp(); return (count); } public function MoveProxy(proxy:b2Proxy, aabb:b2AABB):void{ var as3arr:Array; var as3int:int; var axis:uint; var index:uint; var bound:b2Bound; var prevBound:b2Bound; var nextBound:b2Bound; var nextProxyId:uint; var nextProxy:b2Proxy; var bounds:Array; var lowerIndex:uint; var upperIndex:uint; var lowerValue:uint; var upperValue:uint; var deltaLower:int; var deltaUpper:int; var prevProxy:b2Proxy; if (proxy == null){ return; }; if (aabb.IsValid() == false){ return; }; var boundCount:uint = (2 * m_proxyCount); var newValues:b2BoundValues = new b2BoundValues(); ComputeBounds(newValues.lowerValues, newValues.upperValues, aabb); var oldValues:b2BoundValues = new b2BoundValues(); axis = 0; while (axis < 2) { bound = m_bounds[axis][proxy.lowerBounds[axis]]; oldValues.lowerValues[axis] = bound.value; bound = m_bounds[axis][proxy.upperBounds[axis]]; oldValues.upperValues[axis] = bound.value; axis++; }; axis = 0; while (axis < 2) { bounds = m_bounds[axis]; lowerIndex = proxy.lowerBounds[axis]; upperIndex = proxy.upperBounds[axis]; lowerValue = newValues.lowerValues[axis]; upperValue = newValues.upperValues[axis]; bound = bounds[lowerIndex]; deltaLower = (lowerValue - bound.value); bound.value = lowerValue; bound = bounds[upperIndex]; deltaUpper = (upperValue - bound.value); bound.value = upperValue; if (deltaLower < 0){ index = lowerIndex; while ((((index > 0)) && ((lowerValue < (bounds[int((index - 1))] as b2Bound).value)))) { bound = bounds[index]; prevBound = bounds[int((index - 1))]; prevProxy = prevBound.proxy; prevBound.stabbingCount++; if (prevBound.IsUpper() == true){ if (TestOverlap(newValues, prevProxy)){ m_pairManager.AddBufferedPair(proxy, prevProxy); }; as3arr = prevProxy.upperBounds; as3int = as3arr[axis]; as3int++; as3arr[axis] = as3int; bound.stabbingCount++; } else { as3arr = prevProxy.lowerBounds; as3int = as3arr[axis]; as3int++; as3arr[axis] = as3int; bound.stabbingCount--; }; as3arr = proxy.lowerBounds; as3int = as3arr[axis]; as3int--; as3arr[axis] = as3int; bound.Swap(prevBound); index--; }; }; if (deltaUpper > 0){ index = upperIndex; while ((((index < (boundCount - 1))) && (((bounds[int((index + 1))] as b2Bound).value <= upperValue)))) { bound = bounds[index]; nextBound = bounds[int((index + 1))]; nextProxy = nextBound.proxy; nextBound.stabbingCount++; if (nextBound.IsLower() == true){ if (TestOverlap(newValues, nextProxy)){ m_pairManager.AddBufferedPair(proxy, nextProxy); }; as3arr = nextProxy.lowerBounds; as3int = as3arr[axis]; as3int--; as3arr[axis] = as3int; bound.stabbingCount++; } else { as3arr = nextProxy.upperBounds; as3int = as3arr[axis]; as3int--; as3arr[axis] = as3int; bound.stabbingCount--; }; as3arr = proxy.upperBounds; as3int = as3arr[axis]; as3int++; as3arr[axis] = as3int; bound.Swap(nextBound); index++; }; }; if (deltaLower > 0){ index = lowerIndex; while ((((index < (boundCount - 1))) && (((bounds[int((index + 1))] as b2Bound).value <= lowerValue)))) { bound = bounds[index]; nextBound = bounds[int((index + 1))]; nextProxy = nextBound.proxy; nextBound.stabbingCount--; if (nextBound.IsUpper()){ if (TestOverlap(oldValues, nextProxy)){ m_pairManager.RemoveBufferedPair(proxy, nextProxy); }; as3arr = nextProxy.upperBounds; as3int = as3arr[axis]; as3int--; as3arr[axis] = as3int; bound.stabbingCount--; } else { as3arr = nextProxy.lowerBounds; as3int = as3arr[axis]; as3int--; as3arr[axis] = as3int; bound.stabbingCount++; }; as3arr = proxy.lowerBounds; as3int = as3arr[axis]; as3int++; as3arr[axis] = as3int; bound.Swap(nextBound); index++; }; }; if (deltaUpper < 0){ index = upperIndex; while ((((index > 0)) && ((upperValue < (bounds[int((index - 1))] as b2Bound).value)))) { bound = bounds[index]; prevBound = bounds[int((index - 1))]; prevProxy = prevBound.proxy; prevBound.stabbingCount--; if (prevBound.IsLower() == true){ if (TestOverlap(oldValues, prevProxy)){ m_pairManager.RemoveBufferedPair(proxy, prevProxy); }; as3arr = prevProxy.lowerBounds; as3int = as3arr[axis]; as3int++; as3arr[axis] = as3int; bound.stabbingCount--; } else { as3arr = prevProxy.upperBounds; as3int = as3arr[axis]; as3int++; as3arr[axis] = as3int; bound.stabbingCount++; }; as3arr = proxy.upperBounds; as3int = as3arr[axis]; as3int--; as3arr[axis] = as3int; bound.Swap(prevBound); index--; }; }; axis++; }; } public static function BinarySearch(bounds:Array, count:int, value:uint):uint{ var mid:int; var bound:b2Bound; var low:int; var high:int = (count - 1); while (low <= high) { mid = ((low + high) / 2); bound = bounds[mid]; if (bound.value > value){ high = (mid - 1); } else { if (bound.value < value){ low = (mid + 1); } else { return (uint(mid)); }; }; }; return (uint(low)); } } }//package Box2D.Collision
Section 15
//b2Collision (Box2D.Collision.b2Collision) package Box2D.Collision { import Box2D.Collision.Shapes.*; import Box2D.Common.Math.*; import Box2D.Common.*; public class b2Collision { public static const b2_nullFeature:uint = 0xFF; private static var b2CollidePolyTempVec:b2Vec2 = new b2Vec2(); public function b2Collision(){ super(); } public static function EdgeSeparation(poly1:b2PolygonShape, xf1:b2XForm, edge1:int, poly2:b2PolygonShape, xf2:b2XForm):Number{ var tMat:b2Mat22; var tVec:b2Vec2; var dot:Number; var count1:int = poly1.m_vertexCount; var vertices1:Array = poly1.m_vertices; var normals1:Array = poly1.m_normals; var count2:int = poly2.m_vertexCount; var vertices2:Array = poly2.m_vertices; tMat = xf1.R; tVec = normals1[edge1]; var normal1WorldX:Number = ((tMat.col1.x * tVec.x) + (tMat.col2.x * tVec.y)); var normal1WorldY:Number = ((tMat.col1.y * tVec.x) + (tMat.col2.y * tVec.y)); tMat = xf2.R; var normal1X:Number = ((tMat.col1.x * normal1WorldX) + (tMat.col1.y * normal1WorldY)); var normal1Y:Number = ((tMat.col2.x * normal1WorldX) + (tMat.col2.y * normal1WorldY)); var index:int; var minDot:Number = Number.MAX_VALUE; var i:int; while (i < count2) { tVec = vertices2[i]; dot = ((tVec.x * normal1X) + (tVec.y * normal1Y)); if (dot < minDot){ minDot = dot; index = i; }; i++; }; tVec = vertices1[edge1]; tMat = xf1.R; var v1X:Number = (xf1.position.x + ((tMat.col1.x * tVec.x) + (tMat.col2.x * tVec.y))); var v1Y:Number = (xf1.position.y + ((tMat.col1.y * tVec.x) + (tMat.col2.y * tVec.y))); tVec = vertices2[index]; tMat = xf2.R; var v2X:Number = (xf2.position.x + ((tMat.col1.x * tVec.x) + (tMat.col2.x * tVec.y))); var v2Y:Number = (xf2.position.y + ((tMat.col1.y * tVec.x) + (tMat.col2.y * tVec.y))); v2X = (v2X - v1X); v2Y = (v2Y - v1Y); var separation:Number = ((v2X * normal1WorldX) + (v2Y * normal1WorldY)); return (separation); } public static function b2TestOverlap(a:b2AABB, b:b2AABB):Boolean{ var t1:b2Vec2 = b.lowerBound; var t2:b2Vec2 = a.upperBound; var d1X:Number = (t1.x - t2.x); var d1Y:Number = (t1.y - t2.y); t1 = a.lowerBound; t2 = b.upperBound; var d2X:Number = (t1.x - t2.x); var d2Y:Number = (t1.y - t2.y); if ((((d1X > 0)) || ((d1Y > 0)))){ return (false); }; if ((((d2X > 0)) || ((d2Y > 0)))){ return (false); }; return (true); } public static function FindIncidentEdge(c:Array, poly1:b2PolygonShape, xf1:b2XForm, edge1:int, poly2:b2PolygonShape, xf2:b2XForm):void{ var tMat:b2Mat22; var tVec:b2Vec2; var tClip:ClipVertex; var dot:Number; var count1:int = poly1.m_vertexCount; var normals1:Array = poly1.m_normals; var count2:int = poly2.m_vertexCount; var vertices2:Array = poly2.m_vertices; var normals2:Array = poly2.m_normals; tMat = xf1.R; tVec = normals1[edge1]; var normal1X:Number = ((tMat.col1.x * tVec.x) + (tMat.col2.x * tVec.y)); var normal1Y:Number = ((tMat.col1.y * tVec.x) + (tMat.col2.y * tVec.y)); tMat = xf2.R; var tX:Number = ((tMat.col1.x * normal1X) + (tMat.col1.y * normal1Y)); normal1Y = ((tMat.col2.x * normal1X) + (tMat.col2.y * normal1Y)); normal1X = tX; var index:int; var minDot:Number = Number.MAX_VALUE; var i:int; while (i < count2) { tVec = normals2[i]; dot = ((normal1X * tVec.x) + (normal1Y * tVec.y)); if (dot < minDot){ minDot = dot; index = i; }; i++; }; var i1:int = index; var i2:int = (((i1 + 1) < count2)) ? (i1 + 1) : 0; tClip = c[0]; tVec = vertices2[i1]; tMat = xf2.R; tClip.v.x = (xf2.position.x + ((tMat.col1.x * tVec.x) + (tMat.col2.x * tVec.y))); tClip.v.y = (xf2.position.y + ((tMat.col1.y * tVec.x) + (tMat.col2.y * tVec.y))); tClip.id.features.referenceEdge = edge1; tClip.id.features.incidentEdge = i1; tClip.id.features.incidentVertex = 0; tClip = c[1]; tVec = vertices2[i2]; tMat = xf2.R; tClip.v.x = (xf2.position.x + ((tMat.col1.x * tVec.x) + (tMat.col2.x * tVec.y))); tClip.v.y = (xf2.position.y + ((tMat.col1.y * tVec.x) + (tMat.col2.y * tVec.y))); tClip.id.features.referenceEdge = edge1; tClip.id.features.incidentEdge = i2; tClip.id.features.incidentVertex = 1; } public static function b2CollidePolygons(manifold:b2Manifold, polyA:b2PolygonShape, xfA:b2XForm, polyB:b2PolygonShape, xfB:b2XForm):void{ var cv:ClipVertex; var poly1:b2PolygonShape; var poly2:b2PolygonShape; var edge1:int; var flip:uint; var np:int; var v12:b2Vec2; var separation:Number; var cp:b2ManifoldPoint; manifold.pointCount = 0; var edgeA:int; var edgeAO:Array = [edgeA]; var separationA:Number = FindMaxSeparation(edgeAO, polyA, xfA, polyB, xfB); edgeA = edgeAO[0]; if (separationA > 0){ return; }; var edgeB:int; var edgeBO:Array = [edgeB]; var separationB:Number = FindMaxSeparation(edgeBO, polyB, xfB, polyA, xfA); edgeB = edgeBO[0]; if (separationB > 0){ return; }; var xf1:b2XForm = new b2XForm(); var xf2:b2XForm = new b2XForm(); var k_relativeTol:Number = 0.98; var k_absoluteTol:Number = 0.001; if (separationB > ((k_relativeTol * separationA) + k_absoluteTol)){ poly1 = polyB; poly2 = polyA; xf1.Set(xfB); xf2.Set(xfA); edge1 = edgeB; flip = 1; } else { poly1 = polyA; poly2 = polyB; xf1.Set(xfA); xf2.Set(xfB); edge1 = edgeA; flip = 0; }; var incidentEdge:Array = [new ClipVertex(), new ClipVertex()]; FindIncidentEdge(incidentEdge, poly1, xf1, edge1, poly2, xf2); var count1:int = poly1.m_vertexCount; var vertices1:Array = poly1.m_vertices; var tVec:b2Vec2 = vertices1[edge1]; var v11:b2Vec2 = tVec.Copy(); if ((edge1 + 1) < count1){ tVec = vertices1[int((edge1 + 1))]; v12 = tVec.Copy(); } else { tVec = vertices1[0]; v12 = tVec.Copy(); }; var dv:b2Vec2 = b2Math.SubtractVV(v12, v11); var sideNormal:b2Vec2 = b2Math.b2MulMV(xf1.R, b2Math.SubtractVV(v12, v11)); sideNormal.Normalize(); var frontNormal:b2Vec2 = b2Math.b2CrossVF(sideNormal, 1); v11 = b2Math.b2MulX(xf1, v11); v12 = b2Math.b2MulX(xf1, v12); var frontOffset:Number = b2Math.b2Dot(frontNormal, v11); var sideOffset1:Number = -(b2Math.b2Dot(sideNormal, v11)); var sideOffset2:Number = b2Math.b2Dot(sideNormal, v12); var clipPoints1:Array = [new ClipVertex(), new ClipVertex()]; var clipPoints2:Array = [new ClipVertex(), new ClipVertex()]; np = ClipSegmentToLine(clipPoints1, incidentEdge, sideNormal.Negative(), sideOffset1); if (np < 2){ return; }; np = ClipSegmentToLine(clipPoints2, clipPoints1, sideNormal, sideOffset2); if (np < 2){ return; }; manifold.normal = (flip) ? frontNormal.Negative() : frontNormal.Copy(); var pointCount:int; var i:int; while (i < b2Settings.b2_maxManifoldPoints) { cv = clipPoints2[i]; separation = (((frontNormal.x * cv.v.x) + (frontNormal.y * cv.v.y)) - frontOffset); if (separation <= 0){ cp = manifold.points[pointCount]; cp.separation = separation; cp.localPoint1 = b2Math.b2MulXT(xfA, cv.v); cp.localPoint2 = b2Math.b2MulXT(xfB, cv.v); cp.id.key = cv.id._key; cp.id.features.flip = flip; pointCount++; }; i++; }; manifold.pointCount = pointCount; } public static function FindMaxSeparation(edgeIndex:Array, poly1:b2PolygonShape, xf1:b2XForm, poly2:b2PolygonShape, xf2:b2XForm):Number{ var tVec:b2Vec2; var tMat:b2Mat22; var bestEdge:int; var bestSeparation:Number; var increment:int; var dot:Number; var count1:int = poly1.m_vertexCount; var normals1:Array = poly1.m_normals; tMat = xf2.R; tVec = poly2.m_centroid; var dX:Number = (xf2.position.x + ((tMat.col1.x * tVec.x) + (tMat.col2.x * tVec.y))); var dY:Number = (xf2.position.y + ((tMat.col1.y * tVec.x) + (tMat.col2.y * tVec.y))); tMat = xf1.R; tVec = poly1.m_centroid; dX = (dX - (xf1.position.x + ((tMat.col1.x * tVec.x) + (tMat.col2.x * tVec.y)))); dY = (dY - (xf1.position.y + ((tMat.col1.y * tVec.x) + (tMat.col2.y * tVec.y)))); var dLocal1X:Number = ((dX * xf1.R.col1.x) + (dY * xf1.R.col1.y)); var dLocal1Y:Number = ((dX * xf1.R.col2.x) + (dY * xf1.R.col2.y)); var edge:int; var maxDot:Number = -(Number.MAX_VALUE); var i:int; while (i < count1) { tVec = normals1[i]; dot = ((tVec.x * dLocal1X) + (tVec.y * dLocal1Y)); if (dot > maxDot){ maxDot = dot; edge = i; }; i++; }; var s:Number = EdgeSeparation(poly1, xf1, edge, poly2, xf2); if (s > 0){ return (s); }; var prevEdge:int = (((edge - 1) >= 0)) ? (edge - 1) : (count1 - 1); var sPrev:Number = EdgeSeparation(poly1, xf1, prevEdge, poly2, xf2); if (sPrev > 0){ return (sPrev); }; var nextEdge:int = (((edge + 1) < count1)) ? (edge + 1) : 0; var sNext:Number = EdgeSeparation(poly1, xf1, nextEdge, poly2, xf2); if (sNext > 0){ return (sNext); }; if ((((sPrev > s)) && ((sPrev > sNext)))){ increment = -1; bestEdge = prevEdge; bestSeparation = sPrev; } else { if (sNext > s){ increment = 1; bestEdge = nextEdge; bestSeparation = sNext; } else { edgeIndex[0] = edge; return (s); }; }; while (true) { if (increment == -1){ edge = (((bestEdge - 1) >= 0)) ? (bestEdge - 1) : (count1 - 1); } else { edge = (((bestEdge + 1) < count1)) ? (bestEdge + 1) : 0; }; s = EdgeSeparation(poly1, xf1, edge, poly2, xf2); if (s > 0){ return (s); }; if (s > bestSeparation){ bestEdge = edge; bestSeparation = s; } else { break; }; }; edgeIndex[0] = bestEdge; return (bestSeparation); } public static function ClipSegmentToLine(vOut:Array, vIn:Array, normal:b2Vec2, offset:Number):int{ var cv:ClipVertex; var numOut:int; var vIn0:b2Vec2; var vIn1:b2Vec2; var distance0:Number; var interp:Number; var tVec:b2Vec2; var cv2:ClipVertex; numOut = 0; cv = vIn[0]; vIn0 = cv.v; cv = vIn[1]; vIn1 = cv.v; distance0 = (b2Math.b2Dot(normal, vIn0) - offset); var distance1:Number = (b2Math.b2Dot(normal, vIn1) - offset); if (distance0 <= 0){ var _temp1 = numOut; numOut = (numOut + 1); var _local14 = _temp1; vOut[_local14] = vIn[0]; }; if (distance1 <= 0){ var _temp2 = numOut; numOut = (numOut + 1); _local14 = _temp2; vOut[_local14] = vIn[1]; }; if ((distance0 * distance1) < 0){ interp = (distance0 / (distance0 - distance1)); cv = vOut[numOut]; tVec = cv.v; tVec.x = (vIn0.x + (interp * (vIn1.x - vIn0.x))); tVec.y = (vIn0.y + (interp * (vIn1.y - vIn0.y))); cv = vOut[numOut]; if (distance0 > 0){ cv2 = vIn[0]; cv.id = cv2.id; } else { cv2 = vIn[1]; cv.id = cv2.id; }; numOut++; }; return (numOut); } public static function b2CollideCircles(manifold:b2Manifold, circle1:b2CircleShape, xf1:b2XForm, circle2:b2CircleShape, xf2:b2XForm):void{ var tMat:b2Mat22; var tVec:b2Vec2; var separation:Number; var dist:Number; var a:Number; manifold.pointCount = 0; tMat = xf1.R; tVec = circle1.m_localPosition; var p1X:Number = (xf1.position.x + ((tMat.col1.x * tVec.x) + (tMat.col2.x * tVec.y))); var p1Y:Number = (xf1.position.y + ((tMat.col1.y * tVec.x) + (tMat.col2.y * tVec.y))); tMat = xf2.R; tVec = circle2.m_localPosition; var p2X:Number = (xf2.position.x + ((tMat.col1.x * tVec.x) + (tMat.col2.x * tVec.y))); var p2Y:Number = (xf2.position.y + ((tMat.col1.y * tVec.x) + (tMat.col2.y * tVec.y))); var dX:Number = (p2X - p1X); var dY:Number = (p2Y - p1Y); var distSqr:Number = ((dX * dX) + (dY * dY)); var r1:Number = circle1.m_radius; var r2:Number = circle2.m_radius; var radiusSum:Number = (r1 + r2); if (distSqr > (radiusSum * radiusSum)){ return; }; if (distSqr < Number.MIN_VALUE){ separation = -(radiusSum); manifold.normal.Set(0, 1); } else { dist = Math.sqrt(distSqr); separation = (dist - radiusSum); a = (1 / dist); manifold.normal.x = (a * dX); manifold.normal.y = (a * dY); }; manifold.pointCount = 1; var tPoint:b2ManifoldPoint = manifold.points[0]; tPoint.id.key = 0; tPoint.separation = separation; p1X = (p1X + (r1 * manifold.normal.x)); p1Y = (p1Y + (r1 * manifold.normal.y)); p2X = (p2X - (r2 * manifold.normal.x)); p2Y = (p2Y - (r2 * manifold.normal.y)); var pX:Number = (0.5 * (p1X + p2X)); var pY:Number = (0.5 * (p1Y + p2Y)); var tX:Number = (pX - xf1.position.x); var tY:Number = (pY - xf1.position.y); tPoint.localPoint1.x = ((tX * xf1.R.col1.x) + (tY * xf1.R.col1.y)); tPoint.localPoint1.y = ((tX * xf1.R.col2.x) + (tY * xf1.R.col2.y)); tX = (pX - xf2.position.x); tY = (pY - xf2.position.y); tPoint.localPoint2.x = ((tX * xf2.R.col1.x) + (tY * xf2.R.col1.y)); tPoint.localPoint2.y = ((tX * xf2.R.col2.x) + (tY * xf2.R.col2.y)); } public static function b2CollidePolygonAndCircle(manifold:b2Manifold, polygon:b2PolygonShape, xf1:b2XForm, circle:b2CircleShape, xf2:b2XForm):void{ var tPoint:b2ManifoldPoint; var dX:Number; var dY:Number; var positionX:Number; var positionY:Number; var tVec:b2Vec2; var tMat:b2Mat22; var dist:Number; var pX:Number; var pY:Number; var s:Number; manifold.pointCount = 0; tMat = xf2.R; tVec = circle.m_localPosition; var cX:Number = (xf2.position.x + ((tMat.col1.x * tVec.x) + (tMat.col2.x * tVec.y))); var cY:Number = (xf2.position.y + ((tMat.col1.y * tVec.x) + (tMat.col2.y * tVec.y))); dX = (cX - xf1.position.x); dY = (cY - xf1.position.y); tMat = xf1.R; var cLocalX:Number = ((dX * tMat.col1.x) + (dY * tMat.col1.y)); var cLocalY:Number = ((dX * tMat.col2.x) + (dY * tMat.col2.y)); var normalIndex:int; var separation:Number = -(Number.MAX_VALUE); var radius:Number = circle.m_radius; var vertexCount:int = polygon.m_vertexCount; var vertices:Array = polygon.m_vertices; var normals:Array = polygon.m_normals; var i:int; while (i < vertexCount) { tVec = vertices[i]; dX = (cLocalX - tVec.x); dY = (cLocalY - tVec.y); tVec = normals[i]; s = ((tVec.x * dX) + (tVec.y * dY)); if (s > radius){ return; }; if (s > separation){ separation = s; normalIndex = i; }; i++; }; if (separation < Number.MIN_VALUE){ manifold.pointCount = 1; tVec = normals[normalIndex]; tMat = xf1.R; manifold.normal.x = ((tMat.col1.x * tVec.x) + (tMat.col2.x * tVec.y)); manifold.normal.y = ((tMat.col1.y * tVec.x) + (tMat.col2.y * tVec.y)); tPoint = manifold.points[0]; tPoint.id.features.incidentEdge = normalIndex; tPoint.id.features.incidentVertex = b2_nullFeature; tPoint.id.features.referenceEdge = 0; tPoint.id.features.flip = 0; positionX = (cX - (radius * manifold.normal.x)); positionY = (cY - (radius * manifold.normal.y)); dX = (positionX - xf1.position.x); dY = (positionY - xf1.position.y); tMat = xf1.R; tPoint.localPoint1.x = ((dX * tMat.col1.x) + (dY * tMat.col1.y)); tPoint.localPoint1.y = ((dX * tMat.col2.x) + (dY * tMat.col2.y)); dX = (positionX - xf2.position.x); dY = (positionY - xf2.position.y); tMat = xf2.R; tPoint.localPoint2.x = ((dX * tMat.col1.x) + (dY * tMat.col1.y)); tPoint.localPoint2.y = ((dX * tMat.col2.x) + (dY * tMat.col2.y)); tPoint.separation = (separation - radius); return; }; var vertIndex1:int = normalIndex; var vertIndex2:int = (((vertIndex1 + 1) < vertexCount)) ? (vertIndex1 + 1) : 0; tVec = vertices[vertIndex1]; var tVec2:b2Vec2 = vertices[vertIndex2]; var eX:Number = (tVec2.x - tVec.x); var eY:Number = (tVec2.y - tVec.y); var length:Number = Math.sqrt(((eX * eX) + (eY * eY))); eX = (eX / length); eY = (eY / length); dX = (cLocalX - tVec.x); dY = (cLocalY - tVec.y); var u:Number = ((dX * eX) + (dY * eY)); tPoint = manifold.points[0]; if (u <= 0){ pX = tVec.x; pY = tVec.y; tPoint.id.features.incidentEdge = b2_nullFeature; tPoint.id.features.incidentVertex = vertIndex1; } else { if (u >= length){ pX = tVec2.x; pY = tVec2.y; tPoint.id.features.incidentEdge = b2_nullFeature; tPoint.id.features.incidentVertex = vertIndex2; } else { pX = ((eX * u) + tVec.x); pY = ((eY * u) + tVec.y); tPoint.id.features.incidentEdge = normalIndex; tPoint.id.features.incidentVertex = b2_nullFeature; }; }; dX = (cLocalX - pX); dY = (cLocalY - pY); dist = Math.sqrt(((dX * dX) + (dY * dY))); dX = (dX / dist); dY = (dY / dist); if (dist > radius){ return; }; manifold.pointCount = 1; tMat = xf1.R; manifold.normal.x = ((tMat.col1.x * dX) + (tMat.col2.x * dY)); manifold.normal.y = ((tMat.col1.y * dX) + (tMat.col2.y * dY)); positionX = (cX - (radius * manifold.normal.x)); positionY = (cY - (radius * manifold.normal.y)); dX = (positionX - xf1.position.x); dY = (positionY - xf1.position.y); tMat = xf1.R; tPoint.localPoint1.x = ((dX * tMat.col1.x) + (dY * tMat.col1.y)); tPoint.localPoint1.y = ((dX * tMat.col2.x) + (dY * tMat.col2.y)); dX = (positionX - xf2.position.x); dY = (positionY - xf2.position.y); tMat = xf2.R; tPoint.localPoint2.x = ((dX * tMat.col1.x) + (dY * tMat.col1.y)); tPoint.localPoint2.y = ((dX * tMat.col2.x) + (dY * tMat.col2.y)); tPoint.separation = (dist - radius); tPoint.id.features.referenceEdge = 0; tPoint.id.features.flip = 0; } } }//package Box2D.Collision
Section 16
//b2ContactID (Box2D.Collision.b2ContactID) package Box2D.Collision { import Box2D.Common.*; public class b2ContactID { b2internal var _key:uint; public var features:Features; public function b2ContactID(){ features = new Features(); super(); features._m_id = this; } public function Set(id:b2ContactID):void{ key = id._key; } public function Copy():b2ContactID{ var id:b2ContactID = new b2ContactID(); id.key = key; return (id); } public function set key(value:uint):void{ _key = value; features._referenceEdge = (_key & 0xFF); features._incidentEdge = (((_key & 0xFF00) >> 8) & 0xFF); features._incidentVertex = (((_key & 0xFF0000) >> 16) & 0xFF); features._flip = (((_key & 4278190080) >> 24) & 0xFF); } public function get key():uint{ return (_key); } } }//package Box2D.Collision
Section 17
//b2ContactPoint (Box2D.Collision.b2ContactPoint) package Box2D.Collision { import Box2D.Collision.Shapes.*; import Box2D.Common.Math.*; public class b2ContactPoint { public var friction:Number; public var separation:Number; public var normal:b2Vec2; public var position:b2Vec2; public var restitution:Number; public var shape1:b2Shape; public var shape2:b2Shape; public var id:b2ContactID; public var velocity:b2Vec2; public function b2ContactPoint(){ position = new b2Vec2(); velocity = new b2Vec2(); normal = new b2Vec2(); id = new b2ContactID(); super(); } } }//package Box2D.Collision
Section 18
//b2Distance (Box2D.Collision.b2Distance) package Box2D.Collision { import Box2D.Collision.Shapes.*; import Box2D.Common.Math.*; import Box2D.Common.*; public class b2Distance { private static var s_p2s:Array = [new b2Vec2(), new b2Vec2(), new b2Vec2()]; private static var s_p1s:Array = [new b2Vec2(), new b2Vec2(), new b2Vec2()]; private static var s_points:Array = [new b2Vec2(), new b2Vec2(), new b2Vec2()]; private static var gPoint:b2Point = new b2Point(); public static var g_GJK_Iterations:int = 0; public function b2Distance(){ super(); } public static function InPoints(w:b2Vec2, points:Array, pointCount:int):Boolean{ var points_i:b2Vec2; var dX:Number; var dY:Number; var mX:Number; var mY:Number; var k_tolerance:Number = (100 * Number.MIN_VALUE); var i:int; while (i < pointCount) { points_i = points[i]; dX = (((w.x - points_i.x) < 0)) ? -((w.x - points_i.x)) : (w.x - points_i.x); dY = (((w.y - points_i.y) < 0)) ? -((w.y - points_i.y)) : (w.y - points_i.y); mX = ((w.x < 0)) ? -(w.x) : (((w.x > points_i.x) < 0)) ? -(points_i.x) : (points_i.x) ? ((w.x < 0)) ? -(w.x) : w.x : ((points_i.x < 0)) ? -(points_i.x) : points_i.x; mY = ((w.x < 0)) ? -(w.y) : (((w.y > points_i.y) < 0)) ? -(points_i.y) : (points_i.y) ? ((w.y < 0)) ? -(w.y) : w.y : ((points_i.y < 0)) ? -(points_i.y) : points_i.y; if ((((dX < (k_tolerance * (mX + 1)))) && ((dY < (k_tolerance * (mY + 1)))))){ return (true); }; i++; }; return (false); } public static function DistanceGeneric(x1:b2Vec2, x2:b2Vec2, shape1, xf1:b2XForm, shape2, xf2:b2XForm):Number{ var tVec:b2Vec2; var vX:Number; var vY:Number; var w1:b2Vec2; var w2:b2Vec2; var wX:Number; var wY:Number; var vw:Number; var maxSqr:Number; var i:int; var p1s:Array = s_p1s; var p2s:Array = s_p2s; var points:Array = s_points; var pointCount:int; x1.SetV(shape1.GetFirstVertex(xf1)); x2.SetV(shape2.GetFirstVertex(xf2)); var vSqr:Number = 0; var maxIterations = 20; var iter:int; while (iter < maxIterations) { vX = (x2.x - x1.x); vY = (x2.y - x1.y); w1 = shape1.Support(xf1, vX, vY); w2 = shape2.Support(xf2, -(vX), -(vY)); vSqr = ((vX * vX) + (vY * vY)); wX = (w2.x - w1.x); wY = (w2.y - w1.y); vw = ((vX * wX) + (vY * wY)); if ((vSqr - vw) <= (0.01 * vSqr)){ if (pointCount == 0){ x1.SetV(w1); x2.SetV(w2); }; g_GJK_Iterations = iter; return (Math.sqrt(vSqr)); }; switch (pointCount){ case 0: tVec = p1s[0]; tVec.SetV(w1); tVec = p2s[0]; tVec.SetV(w2); tVec = points[0]; tVec.x = wX; tVec.y = wY; x1.SetV(p1s[0]); x2.SetV(p2s[0]); pointCount++; break; case 1: tVec = p1s[1]; tVec.SetV(w1); tVec = p2s[1]; tVec.SetV(w2); tVec = points[1]; tVec.x = wX; tVec.y = wY; pointCount = ProcessTwo(x1, x2, p1s, p2s, points); break; case 2: tVec = p1s[2]; tVec.SetV(w1); tVec = p2s[2]; tVec.SetV(w2); tVec = points[2]; tVec.x = wX; tVec.y = wY; pointCount = ProcessThree(x1, x2, p1s, p2s, points); break; }; if (pointCount == 3){ g_GJK_Iterations = iter; return (0); }; maxSqr = -(Number.MAX_VALUE); i = 0; while (i < pointCount) { tVec = points[i]; maxSqr = b2Math.b2Max(maxSqr, ((tVec.x * tVec.x) + (tVec.y * tVec.y))); i++; }; if (vSqr <= ((100 * Number.MIN_VALUE) * maxSqr)){ g_GJK_Iterations = iter; vX = (x2.x - x1.x); vY = (x2.y - x1.y); vSqr = ((vX * vX) + (vY * vY)); return (Math.sqrt(vSqr)); }; iter++; }; g_GJK_Iterations = maxIterations; return (Math.sqrt(vSqr)); } public static function DistanceEdgeCircle(x1:b2Vec2, x2:b2Vec2, edge:b2EdgeShape, xf1:b2XForm, circle:b2CircleShape, xf2:b2XForm):Number{ var vWorld:b2Vec2; var tMat:b2Mat22; var tVec:b2Vec2; var r:Number = (circle.m_radius - b2Settings.b2_toiSlop); tMat = xf2.R; tVec = circle.m_localPosition; var cWorldX:Number = (xf2.position.x + ((tMat.col1.x * tVec.x) + (tMat.col2.x * tVec.y))); var cWorldY:Number = (xf2.position.y + ((tMat.col1.y * tVec.x) + (tMat.col2.y * tVec.y))); tMat = xf1.R; var tX:Number = (cWorldX - xf1.position.x); var tY:Number = (cWorldY - xf1.position.y); var cLocalX:Number = ((tX * tMat.col1.x) + (tY * tMat.col1.y)); var cLocalY:Number = ((tX * tMat.col2.x) + (tY * tMat.col2.y)); var dLen:Number = (((cLocalX - edge.m_coreV1.x) * edge.m_direction.x) + ((cLocalY - edge.m_coreV1.y) * edge.m_direction.y)); if (dLen <= 0){ tMat = xf1.R; tVec = edge.m_coreV1; x1.x = (xf1.position.x + ((tMat.col1.x * tVec.x) + (tMat.col2.x * tVec.y))); x1.y = (xf1.position.y + ((tMat.col1.y * tVec.x) + (tMat.col2.y * tVec.y))); } else { if (dLen >= edge.m_length){ tMat = xf1.R; tVec = edge.m_coreV2; x1.x = (xf1.position.x + ((tMat.col1.x * tVec.x) + (tMat.col2.x * tVec.y))); x1.y = (xf1.position.y + ((tMat.col1.y * tVec.x) + (tMat.col2.y * tVec.y))); } else { tMat = xf1.R; tX = (edge.m_coreV1.x + (dLen * edge.m_direction.x)); tY = (edge.m_coreV1.y + (dLen * edge.m_direction.y)); x1.x = (xf1.position.x + ((tMat.col1.x * tX) + (tMat.col2.x * tY))); x1.y = (xf1.position.y + ((tMat.col1.y * tX) + (tMat.col2.y * tY))); dLen = (((cLocalX - edge.m_coreV1.x) * edge.m_normal.x) + ((cLocalY - edge.m_coreV1.y) * edge.m_normal.y)); if (dLen < 0){ if (dLen < -(r)){ tMat = xf1.R; tX = (cLocalX + (r * edge.m_normal.x)); tY = (cLocalY + (r * edge.m_normal.y)); x2.x = (xf1.position.x + ((tMat.col1.x * tX) + (tMat.col2.x * tY))); x2.y = (xf1.position.y + ((tMat.col1.y * tX) + (tMat.col2.y * tY))); return ((-(dLen) - r)); }; x2.x = x1.x; x2.y = x1.y; return (0); } else { if (dLen > r){ tMat = xf1.R; tX = (cLocalX - (r * edge.m_normal.x)); tY = (cLocalY - (r * edge.m_normal.y)); x2.x = (xf1.position.x + ((tMat.col1.x * tX) + (tMat.col2.x * tY))); x2.y = (xf1.position.y + ((tMat.col1.y * tX) + (tMat.col2.y * tY))); return ((dLen - r)); }; x2.x = x1.x; x2.y = x1.y; return (0); }; }; }; tX = (cWorldX - x1.x); tY = (cWorldY - x1.y); dLen = ((tX * tX) + (tY * tY)); if (dLen > (r * r)){ dLen = Math.sqrt(dLen); x2.x = (cWorldX - ((r * tX) / dLen)); x2.y = (cWorldY - ((r * tY) / dLen)); return ((dLen - r)); }; x2.x = x1.x; x2.y = x1.y; return (0); } public static function DistanceCC(x1:b2Vec2, x2:b2Vec2, circle1:b2CircleShape, xf1:b2XForm, circle2:b2CircleShape, xf2:b2XForm):Number{ var tMat:b2Mat22; var tVec:b2Vec2; var dLen:Number; var distance:Number; tMat = xf1.R; tVec = circle1.m_localPosition; var p1X:Number = (xf1.position.x + ((tMat.col1.x * tVec.x) + (tMat.col2.x * tVec.y))); var p1Y:Number = (xf1.position.y + ((tMat.col1.y * tVec.x) + (tMat.col2.y * tVec.y))); tMat = xf2.R; tVec = circle2.m_localPosition; var p2X:Number = (xf2.position.x + ((tMat.col1.x * tVec.x) + (tMat.col2.x * tVec.y))); var p2Y:Number = (xf2.position.y + ((tMat.col1.y * tVec.x) + (tMat.col2.y * tVec.y))); var dX:Number = (p2X - p1X); var dY:Number = (p2Y - p1Y); var dSqr:Number = ((dX * dX) + (dY * dY)); var r1:Number = (circle1.m_radius - b2Settings.b2_toiSlop); var r2:Number = (circle2.m_radius - b2Settings.b2_toiSlop); var r:Number = (r1 + r2); if (dSqr > (r * r)){ dLen = Math.sqrt(dSqr); dX = (dX / dLen); dY = (dY / dLen); distance = (dLen - r); x1.x = (p1X + (r1 * dX)); x1.y = (p1Y + (r1 * dY)); x2.x = (p2X - (r2 * dX)); x2.y = (p2Y - (r2 * dY)); return (distance); }; if (dSqr > (Number.MIN_VALUE * Number.MIN_VALUE)){ dLen = Math.sqrt(dSqr); dX = (dX / dLen); dY = (dY / dLen); x1.x = (p1X + (r1 * dX)); x1.y = (p1Y + (r1 * dY)); x2.x = x1.x; x2.y = x1.y; return (0); }; x1.x = p1X; x1.y = p1Y; x2.x = x1.x; x2.y = x1.y; return (0); } public static function ProcessThree(x1:b2Vec2, x2:b2Vec2, p1s:Array, p2s:Array, points:Array):int{ var points_0:b2Vec2; var points_1:b2Vec2; var points_2:b2Vec2; var p1s_0:b2Vec2; var p1s_1:b2Vec2; var p1s_2:b2Vec2; var p2s_0:b2Vec2; var p2s_1:b2Vec2; var lambda:Number; points_0 = points[0]; points_1 = points[1]; points_2 = points[2]; p1s_0 = p1s[0]; p1s_1 = p1s[1]; p1s_2 = p1s[2]; p2s_0 = p2s[0]; p2s_1 = p2s[1]; var p2s_2:b2Vec2 = p2s[2]; var aX:Number = points_0.x; var aY:Number = points_0.y; var bX:Number = points_1.x; var bY:Number = points_1.y; var cX:Number = points_2.x; var cY:Number = points_2.y; var abX:Number = (bX - aX); var abY:Number = (bY - aY); var acX:Number = (cX - aX); var acY:Number = (cY - aY); var bcX:Number = (cX - bX); var bcY:Number = (cY - bY); var sn:Number = -(((aX * abX) + (aY * abY))); var sd:Number = ((bX * abX) + (bY * abY)); var tn:Number = -(((aX * acX) + (aY * acY))); var td:Number = ((cX * acX) + (cY * acY)); var un:Number = -(((bX * bcX) + (bY * bcY))); var ud:Number = ((cX * bcX) + (cY * bcY)); if ((((td <= 0)) && ((ud <= 0)))){ x1.SetV(p1s_2); x2.SetV(p2s_2); p1s_0.SetV(p1s_2); p2s_0.SetV(p2s_2); points_0.SetV(points_2); return (1); }; var n:Number = ((abX * acY) - (abY * acX)); var vc:Number = (n * ((aX * bY) - (aY * bX))); var va:Number = (n * ((bX * cY) - (bY * cX))); if ((((((((va <= 0)) && ((un >= 0)))) && ((ud >= 0)))) && (((un + ud) > 0)))){ lambda = (un / (un + ud)); x1.x = (p1s_1.x + (lambda * (p1s_2.x - p1s_1.x))); x1.y = (p1s_1.y + (lambda * (p1s_2.y - p1s_1.y))); x2.x = (p2s_1.x + (lambda * (p2s_2.x - p2s_1.x))); x2.y = (p2s_1.y + (lambda * (p2s_2.y - p2s_1.y))); p1s_0.SetV(p1s_2); p2s_0.SetV(p2s_2); points_0.SetV(points_2); return (2); }; var vb:Number = (n * ((cX * aY) - (cY * aX))); if ((((((((vb <= 0)) && ((tn >= 0)))) && ((td >= 0)))) && (((tn + td) > 0)))){ lambda = (tn / (tn + td)); x1.x = (p1s_0.x + (lambda * (p1s_2.x - p1s_0.x))); x1.y = (p1s_0.y + (lambda * (p1s_2.y - p1s_0.y))); x2.x = (p2s_0.x + (lambda * (p2s_2.x - p2s_0.x))); x2.y = (p2s_0.y + (lambda * (p2s_2.y - p2s_0.y))); p1s_1.SetV(p1s_2); p2s_1.SetV(p2s_2); points_1.SetV(points_2); return (2); }; var denom:Number = ((va + vb) + vc); denom = (1 / denom); var u:Number = (va * denom); var v:Number = (vb * denom); var w:Number = ((1 - u) - v); x1.x = (((u * p1s_0.x) + (v * p1s_1.x)) + (w * p1s_2.x)); x1.y = (((u * p1s_0.y) + (v * p1s_1.y)) + (w * p1s_2.y)); x2.x = (((u * p2s_0.x) + (v * p2s_1.x)) + (w * p2s_2.x)); x2.y = (((u * p2s_0.y) + (v * p2s_1.y)) + (w * p2s_2.y)); return (3); } public static function DistancePC(x1:b2Vec2, x2:b2Vec2, polygon:b2PolygonShape, xf1:b2XForm, circle:b2CircleShape, xf2:b2XForm):Number{ var tMat:b2Mat22; var tVec:b2Vec2; var dX:Number; var dY:Number; var dLen:Number; var point:b2Point = gPoint; tVec = circle.m_localPosition; tMat = xf2.R; point.p.x = (xf2.position.x + ((tMat.col1.x * tVec.x) + (tMat.col2.x * tVec.y))); point.p.y = (xf2.position.y + ((tMat.col1.y * tVec.x) + (tMat.col2.y * tVec.y))); var distance:Number = DistanceGeneric(x1, x2, polygon, xf1, point, b2Math.b2XForm_identity); var r:Number = (circle.m_radius - b2Settings.b2_toiSlop); if (distance > r){ distance = (distance - r); dX = (x2.x - x1.x); dY = (x2.y - x1.y); dLen = Math.sqrt(((dX * dX) + (dY * dY))); dX = (dX / dLen); dY = (dY / dLen); x2.x = (x2.x - (r * dX)); x2.y = (x2.y - (r * dY)); } else { distance = 0; x2.x = x1.x; x2.y = x1.y; }; return (distance); } public static function Distance(x1:b2Vec2, x2:b2Vec2, shape1:b2Shape, xf1:b2XForm, shape2:b2Shape, xf2:b2XForm):Number{ var type1:int = shape1.m_type; var type2:int = shape2.m_type; if ((((type1 == b2Shape.e_circleShape)) && ((type2 == b2Shape.e_circleShape)))){ return (DistanceCC(x1, x2, (shape1 as b2CircleShape), xf1, (shape2 as b2CircleShape), xf2)); }; if ((((type1 == b2Shape.e_polygonShape)) && ((type2 == b2Shape.e_circleShape)))){ return (DistancePC(x1, x2, (shape1 as b2PolygonShape), xf1, (shape2 as b2CircleShape), xf2)); }; if ((((type1 == b2Shape.e_circleShape)) && ((type2 == b2Shape.e_polygonShape)))){ return (DistancePC(x2, x1, (shape2 as b2PolygonShape), xf2, (shape1 as b2CircleShape), xf1)); }; if ((((type1 == b2Shape.e_polygonShape)) && ((type2 == b2Shape.e_polygonShape)))){ return (DistanceGeneric(x1, x2, shape1, xf1, shape2, xf2)); }; if ((((type1 == b2Shape.e_edgeShape)) && ((type2 == b2Shape.e_circleShape)))){ return (DistanceEdgeCircle(x1, x2, (shape1 as b2EdgeShape), xf1, (shape2 as b2CircleShape), xf2)); }; if ((((type1 == b2Shape.e_circleShape)) && ((type2 == b2Shape.e_edgeShape)))){ return (DistanceEdgeCircle(x2, x1, (shape2 as b2EdgeShape), xf2, (shape1 as b2CircleShape), xf1)); }; if ((((type1 == b2Shape.e_polygonShape)) && ((type2 == b2Shape.e_edgeShape)))){ return (DistanceGeneric(x2, x1, shape2, xf2, shape1, xf1)); }; if ((((type1 == b2Shape.e_edgeShape)) && ((type2 == b2Shape.e_polygonShape)))){ return (DistanceGeneric(x1, x2, shape1, xf1, shape2, xf2)); }; return (0); } public static function ProcessTwo(x1:b2Vec2, x2:b2Vec2, p1s:Array, p2s:Array, points:Array):int{ var p1s_1:b2Vec2; var p2s_0:b2Vec2; var p2s_1:b2Vec2; var lambda:Number; var points_0:b2Vec2 = points[0]; var points_1:b2Vec2 = points[1]; var p1s_0:b2Vec2 = p1s[0]; p1s_1 = p1s[1]; p2s_0 = p2s[0]; p2s_1 = p2s[1]; var rX:Number = -(points_1.x); var rY:Number = -(points_1.y); var dX:Number = (points_0.x - points_1.x); var dY:Number = (points_0.y - points_1.y); var length:Number = Math.sqrt(((dX * dX) + (dY * dY))); dX = (dX / length); dY = (dY / length); lambda = ((rX * dX) + (rY * dY)); if ((((lambda <= 0)) || ((length < Number.MIN_VALUE)))){ x1.SetV(p1s_1); x2.SetV(p2s_1); p1s_0.SetV(p1s_1); p2s_0.SetV(p2s_1); points_0.SetV(points_1); return (1); }; lambda = (lambda / length); x1.x = (p1s_1.x + (lambda * (p1s_0.x - p1s_1.x))); x1.y = (p1s_1.y + (lambda * (p1s_0.y - p1s_1.y))); x2.x = (p2s_1.x + (lambda * (p2s_0.x - p2s_1.x))); x2.y = (p2s_1.y + (lambda * (p2s_0.y - p2s_1.y))); return (2); } } }//package Box2D.Collision
Section 19
//b2Manifold (Box2D.Collision.b2Manifold) package Box2D.Collision { import Box2D.Common.Math.*; import Box2D.Common.*; public class b2Manifold { public var pointCount:int;// = 0 public var normal:b2Vec2; public var points:Array; public function b2Manifold(){ super(); points = new Array(b2Settings.b2_maxManifoldPoints); var i:int; while (i < b2Settings.b2_maxManifoldPoints) { points[i] = new b2ManifoldPoint(); i++; }; normal = new b2Vec2(); } public function Set(m:b2Manifold):void{ pointCount = m.pointCount; var i:int; while (i < b2Settings.b2_maxManifoldPoints) { (points[i] as b2ManifoldPoint).Set(m.points[i]); i++; }; normal.SetV(m.normal); } public function Reset():void{ var i:int; while (i < b2Settings.b2_maxManifoldPoints) { (points[i] as b2ManifoldPoint).Reset(); i++; }; normal.SetZero(); pointCount = 0; } } }//package Box2D.Collision
Section 20
//b2ManifoldPoint (Box2D.Collision.b2ManifoldPoint) package Box2D.Collision { import Box2D.Common.Math.*; public class b2ManifoldPoint { public var separation:Number; public var localPoint2:b2Vec2; public var normalImpulse:Number; public var tangentImpulse:Number; public var localPoint1:b2Vec2; public var id:b2ContactID; public function b2ManifoldPoint(){ localPoint1 = new b2Vec2(); localPoint2 = new b2Vec2(); id = new b2ContactID(); super(); } public function Set(m:b2ManifoldPoint):void{ localPoint1.SetV(m.localPoint1); localPoint2.SetV(m.localPoint2); separation = m.separation; normalImpulse = m.normalImpulse; tangentImpulse = m.tangentImpulse; id.key = m.id.key; } public function Reset():void{ localPoint1.SetZero(); localPoint2.SetZero(); separation = 0; normalImpulse = 0; tangentImpulse = 0; id.key = 0; } } }//package Box2D.Collision
Section 21
//b2OBB (Box2D.Collision.b2OBB) package Box2D.Collision { import Box2D.Common.Math.*; public class b2OBB { public var R:b2Mat22; public var center:b2Vec2; public var extents:b2Vec2; public function b2OBB(){ R = new b2Mat22(); center = new b2Vec2(); extents = new b2Vec2(); super(); } } }//package Box2D.Collision
Section 22
//b2Pair (Box2D.Collision.b2Pair) package Box2D.Collision { import Box2D.Common.*; public class b2Pair { public var proxy1:b2Proxy; public var proxy2:b2Proxy; public var status:uint; public var userData;// = null public var next:b2Pair; public static var e_pairBuffered:uint = 1; public static var b2_nullProxy:uint = b2Settings.USHRT_MAX; public static var e_pairFinal:uint = 4; public static var e_pairRemoved:uint = 2; public function b2Pair(){ super(); } public function SetBuffered():void{ status = (status | e_pairBuffered); } public function IsBuffered():Boolean{ return (((status & e_pairBuffered) == e_pairBuffered)); } public function IsFinal():Boolean{ return (((status & e_pairFinal) == e_pairFinal)); } public function ClearRemoved():void{ status = (status & ~(e_pairRemoved)); } public function SetFinal():void{ status = (status | e_pairFinal); } public function IsRemoved():Boolean{ return (((status & e_pairRemoved) == e_pairRemoved)); } public function ClearBuffered():void{ status = (status & ~(e_pairBuffered)); } public function SetRemoved():void{ status = (status | e_pairRemoved); } } }//package Box2D.Collision
Section 23
//b2PairCallback (Box2D.Collision.b2PairCallback) package Box2D.Collision { public class b2PairCallback { public function b2PairCallback(){ super(); } public function PairRemoved(proxyUserData1, proxyUserData2, pairUserData):void{ } public function PairAdded(proxyUserData1, proxyUserData2){ return (null); } } }//package Box2D.Collision
Section 24
//b2PairManager (Box2D.Collision.b2PairManager) package Box2D.Collision { import Box2D.Common.Math.*; import Box2D.Common.*; public class b2PairManager { b2internal var m_pairCount:int; private var m_callback:b2PairCallback; b2internal var m_pairs:Array; private var m_pairBufferCount:int; private var m_broadPhase:b2BroadPhase; private var m_pairBuffer:Array; private var m_freePair:b2Pair; public function b2PairManager(){ super(); m_pairs = new Array(); m_pairBuffer = new Array(); m_pairCount = 0; m_pairBufferCount = 0; m_freePair = null; } public function RemoveBufferedPair(proxy1:b2Proxy, proxy2:b2Proxy):void{ var pair:b2Pair = Find(proxy1, proxy2); if (pair == null){ return; }; if (pair.IsBuffered() == false){ pair.SetBuffered(); m_pairBuffer[m_pairBufferCount] = pair; m_pairBufferCount++; }; pair.SetRemoved(); if (b2BroadPhase.s_validate){ ValidateBuffer(); }; } public function Initialize(broadPhase:b2BroadPhase, callback:b2PairCallback):void{ m_broadPhase = broadPhase; m_callback = callback; } public function Commit():void{ var i:int; var pair:b2Pair; var proxy1:b2Proxy; var proxy2:b2Proxy; var removeCount:int; i = 0; while (i < m_pairBufferCount) { pair = m_pairBuffer[i]; pair.ClearBuffered(); proxy1 = pair.proxy1; proxy2 = pair.proxy2; if (pair.IsRemoved()){ if (pair.IsFinal() == true){ m_callback.PairRemoved(proxy1.userData, proxy2.userData, pair.userData); }; m_pairBuffer[removeCount] = pair; removeCount++; } else { if (pair.IsFinal() == false){ pair.userData = m_callback.PairAdded(proxy1.userData, proxy2.userData); pair.SetFinal(); }; }; i++; }; i = 0; while (i < removeCount) { pair = m_pairBuffer[i]; RemovePair(pair.proxy1, pair.proxy2); i++; }; m_pairBufferCount = 0; if (b2BroadPhase.s_validate){ ValidateTable(); }; } private function ValidateTable():void{ } private function Find(proxy1:b2Proxy, proxy2:b2Proxy):b2Pair{ return (proxy1.pairs[proxy2]); } public function AddBufferedPair(proxy1:b2Proxy, proxy2:b2Proxy):void{ var pair:b2Pair = AddPair(proxy1, proxy2); if (pair.IsBuffered() == false){ pair.SetBuffered(); m_pairBuffer[m_pairBufferCount] = pair; m_pairBufferCount++; }; pair.ClearRemoved(); if (b2BroadPhase.s_validate){ ValidateBuffer(); }; } private function AddPair(proxy1:b2Proxy, proxy2:b2Proxy):b2Pair{ var pair:b2Pair = proxy1.pairs[proxy2]; if (pair != null){ return (pair); }; if (m_freePair == null){ m_freePair = new b2Pair(); m_pairs.push(m_freePair); }; pair = m_freePair; m_freePair = pair.next; pair.proxy1 = proxy1; pair.proxy2 = proxy2; pair.status = 0; pair.userData = null; pair.next = null; proxy1.pairs[proxy2] = pair; proxy2.pairs[proxy1] = pair; m_pairCount++; return (pair); } private function ValidateBuffer():void{ } private function RemovePair(proxy1:b2Proxy, proxy2:b2Proxy){ var pair:b2Pair = proxy1.pairs[proxy2]; if (pair == null){ return (null); }; var userData:* = pair.userData; delete proxy1.pairs[proxy2]; delete proxy2.pairs[proxy1]; pair.next = m_freePair; pair.proxy1 = null; pair.proxy2 = null; pair.userData = null; pair.status = 0; m_freePair = pair; m_pairCount--; return (userData); } } }//package Box2D.Collision
Section 25
//b2Point (Box2D.Collision.b2Point) package Box2D.Collision { import Box2D.Common.Math.*; public class b2Point { public var p:b2Vec2; public function b2Point(){ p = new b2Vec2(); super(); } public function GetFirstVertex(xf:b2XForm):b2Vec2{ return (p); } public function Support(xf:b2XForm, vX:Number, vY:Number):b2Vec2{ return (p); } } }//package Box2D.Collision
Section 26
//b2Proxy (Box2D.Collision.b2Proxy) package Box2D.Collision { import flash.utils.*; public class b2Proxy { public var pairs:Dictionary; public var overlapCount:uint; public var next:b2Proxy; public var userData;// = null public var lowerBounds:Array; public var upperBounds:Array; public var timeStamp:uint; public function b2Proxy(){ lowerBounds = [uint(0), uint(0)]; upperBounds = [uint(0), uint(0)]; pairs = new Dictionary(); super(); } public function IsValid():Boolean{ return (!((overlapCount == b2BroadPhase.b2_invalid))); } } }//package Box2D.Collision
Section 27
//b2Segment (Box2D.Collision.b2Segment) package Box2D.Collision { import Box2D.Common.Math.*; import Box2D.Common.*; public class b2Segment { public var p1:b2Vec2; public var p2:b2Vec2; public function b2Segment(){ p1 = new b2Vec2(); p2 = new b2Vec2(); super(); } public function TestSegment(lambda:Array, normal:b2Vec2, segment:b2Segment, maxLambda:Number):Boolean{ var bX:Number; var bY:Number; var a:Number; var mu2:Number; var nLen:Number; var s:b2Vec2 = segment.p1; var rX:Number = (segment.p2.x - s.x); var rY:Number = (segment.p2.y - s.y); var dX:Number = (p2.x - p1.x); var dY:Number = (p2.y - p1.y); var nX:Number = dY; var nY:Number = -(dX); var k_slop:Number = (100 * Number.MIN_VALUE); var denom:Number = -(((rX * nX) + (rY * nY))); if (denom > k_slop){ bX = (s.x - p1.x); bY = (s.y - p1.y); a = ((bX * nX) + (bY * nY)); if ((((0 <= a)) && ((a <= (maxLambda * denom))))){ mu2 = ((-(rX) * bY) + (rY * bX)); if (((((-(k_slop) * denom) <= mu2)) && ((mu2 <= (denom * (1 + k_slop)))))){ a = (a / denom); nLen = Math.sqrt(((nX * nX) + (nY * nY))); nX = (nX / nLen); nY = (nY / nLen); lambda[0] = a; normal.Set(nX, nY); return (true); }; }; }; return (false); } public function Extend(aabb:b2AABB):void{ ExtendForward(aabb); ExtendBackward(aabb); } public function ExtendForward(aabb:b2AABB):void{ var lambda:Number; var dX:Number = (p2.x - p1.x); var dY:Number = (p2.y - p1.y); lambda = Math.min(((dX > 0)) ? ((aabb.upperBound.x - p1.x) / dX) : ((dX < 0)) ? ((aabb.lowerBound.x - p1.x) / dX) : Number.POSITIVE_INFINITY, ((dY > 0)) ? ((aabb.upperBound.y - p1.y) / dY) : ((dY < 0)) ? ((aabb.lowerBound.y - p1.y) / dY) : Number.POSITIVE_INFINITY); p2.x = (p1.x + (dX * lambda)); p2.y = (p1.y + (dY * lambda)); } public function ExtendBackward(aabb:b2AABB):void{ var lambda:Number; var dX:Number = (-(p2.x) + p1.x); var dY:Number = (-(p2.y) + p1.y); lambda = Math.min(((dX > 0)) ? ((aabb.upperBound.x - p2.x) / dX) : ((dX < 0)) ? ((aabb.lowerBound.x - p2.x) / dX) : Number.POSITIVE_INFINITY, ((dY > 0)) ? ((aabb.upperBound.y - p2.y) / dY) : ((dY < 0)) ? ((aabb.lowerBound.y - p2.y) / dY) : Number.POSITIVE_INFINITY); p1.x = (p2.x + (dX * lambda)); p1.y = (p2.y + (dY * lambda)); } } }//package Box2D.Collision
Section 28
//b2TimeOfImpact (Box2D.Collision.b2TimeOfImpact) package Box2D.Collision { import Box2D.Collision.Shapes.*; import Box2D.Common.Math.*; import Box2D.Common.*; public class b2TimeOfImpact { public static var s_xf1:b2XForm = new b2XForm(); public static var s_xf2:b2XForm = new b2XForm(); public static var s_p1:b2Vec2 = new b2Vec2(); public static var s_p2:b2Vec2 = new b2Vec2(); public function b2TimeOfImpact(){ super(); } public static function TimeOfImpact(shape1:b2Shape, sweep1:b2Sweep, shape2:b2Shape, sweep2:b2Sweep):Number{ var math1:Number; var math2:Number; var t:Number; var xf1:b2XForm; var xf2:b2XForm; var nLen:Number; var approachVelocityBound:Number; var dAlpha:Number; var newAlpha:Number; var r1:Number = shape1.m_sweepRadius; var r2:Number = shape2.m_sweepRadius; var t0:Number = sweep1.t0; var v1X:Number = (sweep1.c.x - sweep1.c0.x); var v1Y:Number = (sweep1.c.y - sweep1.c0.y); var v2X:Number = (sweep2.c.x - sweep2.c0.x); var v2Y:Number = (sweep2.c.y - sweep2.c0.y); var omega1:Number = (sweep1.a - sweep1.a0); var omega2:Number = (sweep2.a - sweep2.a0); var alpha:Number = 0; var p1:b2Vec2 = s_p1; var p2:b2Vec2 = s_p2; var k_maxIterations = 20; var iter:int; var normalX:Number = 0; var normalY:Number = 0; var distance:Number = 0; var targetDistance:Number = 0; while (true) { t = (((1 - alpha) * t0) + alpha); xf1 = s_xf1; xf2 = s_xf2; sweep1.GetXForm(xf1, t); sweep2.GetXForm(xf2, t); distance = b2Distance.Distance(p1, p2, shape1, xf1, shape2, xf2); if (iter == 0){ if (distance > (2 * b2Settings.b2_toiSlop)){ targetDistance = (1.5 * b2Settings.b2_toiSlop); } else { math1 = (0.05 * b2Settings.b2_toiSlop); math2 = (distance - (0.5 * b2Settings.b2_toiSlop)); targetDistance = ((math1 > math2)) ? math1 : math2; }; }; if (((((distance - targetDistance) < (0.05 * b2Settings.b2_toiSlop))) || ((iter == k_maxIterations)))){ break; }; normalX = (p2.x - p1.x); normalY = (p2.y - p1.y); nLen = Math.sqrt(((normalX * normalX) + (normalY * normalY))); normalX = (normalX / nLen); normalY = (normalY / nLen); approachVelocityBound = ((((normalX * (v1X - v2X)) + (normalY * (v1Y - v2Y))) + (((omega1 < 0)) ? -(omega1) : omega1 * r1)) + (((omega2 < 0)) ? -(omega2) : omega2 * r2)); if (approachVelocityBound == 0){ alpha = 1; break; }; dAlpha = ((distance - targetDistance) / approachVelocityBound); newAlpha = (alpha + dAlpha); if ((((newAlpha < 0)) || ((1 < newAlpha)))){ alpha = 1; break; }; if (newAlpha < ((1 + (100 * Number.MIN_VALUE)) * alpha)){ break; }; alpha = newAlpha; iter++; }; return (alpha); } } }//package Box2D.Collision
Section 29
//ClipVertex (Box2D.Collision.ClipVertex) package Box2D.Collision { import Box2D.Common.Math.*; public class ClipVertex { public var id:b2ContactID; public var v:b2Vec2; public function ClipVertex(){ v = new b2Vec2(); id = new b2ContactID(); super(); } } }//package Box2D.Collision
Section 30
//Features (Box2D.Collision.Features) package Box2D.Collision { import Box2D.Common.*; public class Features { b2internal var _referenceEdge:int; b2internal var _incidentEdge:int; b2internal var _flip:int; b2internal var _incidentVertex:int; b2internal var _m_id:b2ContactID; public function Features(){ super(); } public function get referenceEdge():int{ return (_referenceEdge); } public function set incidentVertex(value:int):void{ _incidentVertex = value; _m_id._key = ((_m_id._key & 4278255615) | ((_incidentVertex << 16) & 0xFF0000)); } public function get flip():int{ return (_flip); } public function get incidentEdge():int{ return (_incidentEdge); } public function set referenceEdge(value:int):void{ _referenceEdge = value; _m_id._key = ((_m_id._key & 4294967040) | (_referenceEdge & 0xFF)); } public function get incidentVertex():int{ return (_incidentVertex); } public function set flip(value:int):void{ _flip = value; _m_id._key = ((_m_id._key & 0xFFFFFF) | ((_flip << 24) & 4278190080)); } public function set incidentEdge(value:int):void{ _incidentEdge = value; _m_id._key = ((_m_id._key & 4294902015) | ((_incidentEdge << 8) & 0xFF00)); } } }//package Box2D.Collision
Section 31
//b2Mat22 (Box2D.Common.Math.b2Mat22) package Box2D.Common.Math { public class b2Mat22 { public var col1:b2Vec2; public var col2:b2Vec2; public function b2Mat22(angle:Number=0, c1:b2Vec2=null, c2:b2Vec2=null){ var c:Number; var s:Number; col1 = new b2Vec2(); col2 = new b2Vec2(); super(); if (((!((c1 == null))) && (!((c2 == null))))){ col1.SetV(c1); col2.SetV(c2); } else { c = Math.cos(angle); s = Math.sin(angle); col1.x = c; col2.x = -(s); col1.y = s; col2.y = c; }; } public function SetIdentity():void{ col1.x = 1; col2.x = 0; col1.y = 0; col2.y = 1; } public function SetVV(c1:b2Vec2, c2:b2Vec2):void{ col1.SetV(c1); col2.SetV(c2); } public function Set(angle:Number):void{ var c:Number; c = Math.cos(angle); var s:Number = Math.sin(angle); col1.x = c; col2.x = -(s); col1.y = s; col2.y = c; } public function SetZero():void{ col1.x = 0; col2.x = 0; col1.y = 0; col2.y = 0; } public function SetM(m:b2Mat22):void{ col1.SetV(m.col1); col2.SetV(m.col2); } public function AddM(m:b2Mat22):void{ col1.x = (col1.x + m.col1.x); col1.y = (col1.y + m.col1.y); col2.x = (col2.x + m.col2.x); col2.y = (col2.y + m.col2.y); } public function Abs():void{ col1.Abs(); col2.Abs(); } public function Copy():b2Mat22{ return (new b2Mat22(0, col1, col2)); } public function GetInverse(out:b2Mat22):b2Mat22{ var a:Number; var c:Number; var det:Number; a = col1.x; var b:Number = col2.x; c = col1.y; var d:Number = col2.y; det = ((a * d) - (b * c)); det = (1 / det); out.col1.x = (det * d); out.col2.x = (-(det) * b); out.col1.y = (-(det) * c); out.col2.y = (det * a); return (out); } public function GetAngle():Number{ return (Math.atan2(col1.y, col1.x)); } public function Solve(out:b2Vec2, bX:Number, bY:Number):b2Vec2{ var a11:Number = col1.x; var a12:Number = col2.x; var a21:Number = col1.y; var a22:Number = col2.y; var det:Number = ((a11 * a22) - (a12 * a21)); det = (1 / det); out.x = (det * ((a22 * bX) - (a12 * bY))); out.y = (det * ((a11 * bY) - (a21 * bX))); return (out); } } }//package Box2D.Common.Math
Section 32
//b2Mat33 (Box2D.Common.Math.b2Mat33) package Box2D.Common.Math { public class b2Mat33 { public var col1:b2Vec3; public var col2:b2Vec3; public var col3:b2Vec3; public function b2Mat33(c1:b2Vec3=null, c2:b2Vec3=null, c3:b2Vec3=null){ col1 = new b2Vec3(); col2 = new b2Vec3(); col3 = new b2Vec3(); super(); if (((((!(c1)) && (!(c2)))) && (!(c3)))){ col1.SetZero(); col2.SetZero(); col3.SetZero(); } else { col1.SetV(c1); col2.SetV(c2); col3.SetV(c3); }; } public function SetIdentity():void{ col1.x = 1; col2.x = 0; col3.x = 0; col1.y = 0; col2.y = 1; col3.y = 0; col1.z = 0; col2.z = 0; col3.z = 1; } public function Solve22(out:b2Vec2, bX:Number, bY:Number):b2Vec2{ var a11:Number; a11 = col1.x; var a12:Number = col2.x; var a21:Number = col1.y; var a22:Number = col2.y; var det:Number = ((a11 * a22) - (a12 * a21)); det = (1 / det); out.x = (det * ((a22 * bX) - (a12 * bY))); out.y = (det * ((a11 * bY) - (a21 * bX))); return (out); } public function SetZero():void{ col1.x = 0; col2.x = 0; col3.x = 0; col1.y = 0; col2.y = 0; col3.y = 0; col1.z = 0; col2.z = 0; col3.z = 0; } public function SetM(m:b2Mat33):void{ col1.SetV(m.col1); col2.SetV(m.col2); col3.SetV(m.col3); } public function AddM(m:b2Mat33):void{ col1.x = (col1.x + m.col1.x); col1.y = (col1.y + m.col1.y); col1.z = (col1.z + m.col1.z); col2.x = (col2.x + m.col2.x); col2.y = (col2.y + m.col2.y); col2.z = (col2.z + m.col2.z); col3.x = (col3.x + m.col3.x); col3.y = (col3.y + m.col3.y); col3.z = (col3.z + m.col3.z); } public function SetVVV(c1:b2Vec3, c2:b2Vec3, c3:b2Vec3):void{ col1.SetV(c1); col2.SetV(c2); col3.SetV(c3); } public function Copy():b2Mat33{ return (new b2Mat33(col1, col2, col3)); } public function Solve33(out:b2Vec3, bX:Number, bY:Number, bZ:Number):b2Vec3{ var a11:Number = col1.x; var a21:Number = col1.y; var a31:Number = col1.z; var a12:Number = col2.x; var a22:Number = col2.y; var a32:Number = col2.z; var a13:Number = col3.x; var a23:Number = col3.y; var a33:Number = col3.z; var det:Number = (((a11 * ((a22 * a33) - (a32 * a23))) + (a21 * ((a32 * a13) - (a12 * a33)))) + (a31 * ((a12 * a23) - (a22 * a13)))); det = (1 / det); out.x = (det * (((bX * ((a22 * a33) - (a32 * a23))) + (bY * ((a32 * a13) - (a12 * a33)))) + (bZ * ((a12 * a23) - (a22 * a13))))); out.y = (det * (((a11 * ((bY * a33) - (bZ * a23))) + (a21 * ((bZ * a13) - (bX * a33)))) + (a31 * ((bX * a23) - (bY * a13))))); out.z = (det * (((a11 * ((a22 * bZ) - (a32 * bY))) + (a21 * ((a32 * bX) - (a12 * bZ)))) + (a31 * ((a12 * bY) - (a22 * bX))))); return (out); } } }//package Box2D.Common.Math
Section 33
//b2Math (Box2D.Common.Math.b2Math) package Box2D.Common.Math { public class b2Math { public static const b2Mat22_identity:b2Mat22 = new b2Mat22(0, new b2Vec2(1, 0), new b2Vec2(0, 1)); public static const b2XForm_identity:b2XForm = new b2XForm(b2Vec2_zero, b2Mat22_identity); public static const b2Vec2_zero:b2Vec2 = new b2Vec2(0, 0); public function b2Math(){ super(); } public static function b2CrossVF(a:b2Vec2, s:Number):b2Vec2{ var v:b2Vec2 = new b2Vec2((s * a.y), (-(s) * a.x)); return (v); } public static function AddVV(a:b2Vec2, b:b2Vec2):b2Vec2{ var v:b2Vec2 = new b2Vec2((a.x + b.x), (a.y + b.y)); return (v); } public static function b2IsValid(x:Number):Boolean{ return (isFinite(x)); } public static function b2MinV(a:b2Vec2, b:b2Vec2):b2Vec2{ var c:b2Vec2 = new b2Vec2(b2Min(a.x, b.x), b2Min(a.y, b.y)); return (c); } public static function b2MulX(T:b2XForm, v:b2Vec2):b2Vec2{ var a:b2Vec2; a = b2MulMV(T.R, v); a.x = (a.x + T.position.x); a.y = (a.y + T.position.y); return (a); } public static function b2DistanceSquared(a:b2Vec2, b:b2Vec2):Number{ var cX:Number = (a.x - b.x); var cY:Number = (a.y - b.y); return (((cX * cX) + (cY * cY))); } public static function b2Swap(a:Array, b:Array):void{ var tmp:* = a[0]; a[0] = b[0]; b[0] = tmp; } public static function b2AbsM(A:b2Mat22):b2Mat22{ var B:b2Mat22 = new b2Mat22(0, b2AbsV(A.col1), b2AbsV(A.col2)); return (B); } public static function SubtractVV(a:b2Vec2, b:b2Vec2):b2Vec2{ var v:b2Vec2 = new b2Vec2((a.x - b.x), (a.y - b.y)); return (v); } public static function b2MulXT(T:b2XForm, v:b2Vec2):b2Vec2{ var a:b2Vec2; var tX:Number; a = SubtractVV(v, T.position); tX = ((a.x * T.R.col1.x) + (a.y * T.R.col1.y)); a.y = ((a.x * T.R.col2.x) + (a.y * T.R.col2.y)); a.x = tX; return (a); } public static function b2Abs(a:Number):Number{ return (((a > 0)) ? a : -(a)); } public static function b2Clamp(a:Number, low:Number, high:Number):Number{ return (b2Max(low, b2Min(a, high))); } public static function b2AbsV(a:b2Vec2):b2Vec2{ var b:b2Vec2 = new b2Vec2(b2Abs(a.x), b2Abs(a.y)); return (b); } public static function MulFV(s:Number, a:b2Vec2):b2Vec2{ var v:b2Vec2 = new b2Vec2((s * a.x), (s * a.y)); return (v); } public static function b2CrossVV(a:b2Vec2, b:b2Vec2):Number{ return (((a.x * b.y) - (a.y * b.x))); } public static function b2Dot(a:b2Vec2, b:b2Vec2):Number{ return (((a.x * b.x) + (a.y * b.y))); } public static function b2CrossFV(s:Number, a:b2Vec2):b2Vec2{ var v:b2Vec2 = new b2Vec2((-(s) * a.y), (s * a.x)); return (v); } public static function AddMM(A:b2Mat22, B:b2Mat22):b2Mat22{ var C:b2Mat22 = new b2Mat22(0, AddVV(A.col1, B.col1), AddVV(A.col2, B.col2)); return (C); } public static function b2Distance(a:b2Vec2, b:b2Vec2):Number{ var cX:Number = (a.x - b.x); var cY:Number = (a.y - b.y); return (Math.sqrt(((cX * cX) + (cY * cY)))); } public static function b2MulTMM(A:b2Mat22, B:b2Mat22):b2Mat22{ var c1:b2Vec2 = new b2Vec2(b2Dot(A.col1, B.col1), b2Dot(A.col2, B.col1)); var c2:b2Vec2 = new b2Vec2(b2Dot(A.col1, B.col2), b2Dot(A.col2, B.col2)); var C:b2Mat22 = new b2Mat22(0, c1, c2); return (C); } public static function b2MaxV(a:b2Vec2, b:b2Vec2):b2Vec2{ var c:b2Vec2 = new b2Vec2(b2Max(a.x, b.x), b2Max(a.y, b.y)); return (c); } public static function b2IsPowerOfTwo(x:uint):Boolean{ var result:Boolean = (((x > 0)) && (((x & (x - 1)) == 0))); return (result); } public static function b2ClampV(a:b2Vec2, low:b2Vec2, high:b2Vec2):b2Vec2{ return (b2MaxV(low, b2MinV(a, high))); } public static function b2RandomRange(lo:Number, hi:Number):Number{ var r:Number = Math.random(); r = (((hi - lo) * r) + lo); return (r); } public static function b2MulTMV(A:b2Mat22, v:b2Vec2):b2Vec2{ var u:b2Vec2 = new b2Vec2(b2Dot(v, A.col1), b2Dot(v, A.col2)); return (u); } public static function b2Min(a:Number, b:Number):Number{ return (((a < b)) ? a : b); } public static function b2Random():Number{ return (((Math.random() * 2) - 1)); } public static function b2MulMM(A:b2Mat22, B:b2Mat22):b2Mat22{ var C:b2Mat22 = new b2Mat22(0, b2MulMV(A, B.col1), b2MulMV(A, B.col2)); return (C); } public static function b2NextPowerOfTwo(x:uint):uint{ x = (x | ((x >> 1) & 2147483647)); x = (x | ((x >> 2) & 1073741823)); x = (x | ((x >> 4) & 268435455)); x = (x | ((x >> 8) & 0xFFFFFF)); x = (x | ((x >> 16) & 0xFFFF)); return ((x + 1)); } public static function b2Max(a:Number, b:Number):Number{ return (((a > b)) ? a : b); } public static function b2MulMV(A:b2Mat22, v:b2Vec2):b2Vec2{ var u:b2Vec2 = new b2Vec2(((A.col1.x * v.x) + (A.col2.x * v.y)), ((A.col1.y * v.x) + (A.col2.y * v.y))); return (u); } } }//package Box2D.Common.Math
Section 34
//b2Sweep (Box2D.Common.Math.b2Sweep) package Box2D.Common.Math { public class b2Sweep { public var localCenter:b2Vec2; public var a:Number; public var c:b2Vec2; public var a0:Number; public var c0:b2Vec2; public var t0:Number; public function b2Sweep(){ localCenter = new b2Vec2(); c0 = new b2Vec2(); c = new b2Vec2(); super(); } public function Advance(t:Number):void{ var alpha:Number; if ((((t0 < t)) && (((1 - t0) > Number.MIN_VALUE)))){ alpha = ((t - t0) / (1 - t0)); c0.x = (((1 - alpha) * c0.x) + (alpha * c.x)); c0.y = (((1 - alpha) * c0.y) + (alpha * c.y)); a0 = (((1 - alpha) * a0) + (alpha * a)); t0 = t; }; } public function GetXForm(xf:b2XForm, t:Number):void{ var alpha:Number; var angle:Number; if ((1 - t0) > Number.MIN_VALUE){ alpha = ((t - t0) / (1 - t0)); xf.position.x = (((1 - alpha) * c0.x) + (alpha * c.x)); xf.position.y = (((1 - alpha) * c0.y) + (alpha * c.y)); angle = (((1 - alpha) * a0) + (alpha * a)); xf.R.Set(angle); } else { xf.position.SetV(c); xf.R.Set(a); }; var tMat:b2Mat22 = xf.R; xf.position.x = (xf.position.x - ((tMat.col1.x * localCenter.x) + (tMat.col2.x * localCenter.y))); xf.position.y = (xf.position.y - ((tMat.col1.y * localCenter.x) + (tMat.col2.y * localCenter.y))); } } }//package Box2D.Common.Math
Section 35
//b2Vec2 (Box2D.Common.Math.b2Vec2) package Box2D.Common.Math { public class b2Vec2 { public var y:Number; public var x:Number; public function b2Vec2(x_:Number=0, y_:Number=0):void{ super(); x = x_; y = y_; } public function Add(v:b2Vec2):void{ x = (x + v.x); y = (y + v.y); } public function Set(x_:Number=0, y_:Number=0):void{ x = x_; y = y_; } public function Multiply(a:Number):void{ x = (x * a); y = (y * a); } public function Length():Number{ return (Math.sqrt(((x * x) + (y * y)))); } public function LengthSquared():Number{ return (((x * x) + (y * y))); } public function MulM(A:b2Mat22):void{ var tX:Number = x; x = ((A.col1.x * tX) + (A.col2.x * y)); y = ((A.col1.y * tX) + (A.col2.y * y)); } public function SetZero():void{ x = 0; y = 0; } public function MinV(b:b2Vec2):void{ x = ((x < b.x)) ? x : b.x; y = ((y < b.y)) ? y : b.y; } public function Normalize():Number{ var length:Number = Math.sqrt(((x * x) + (y * y))); if (length < Number.MIN_VALUE){ return (0); }; var invLength:Number = (1 / length); x = (x * invLength); y = (y * invLength); return (length); } public function CrossVF(s:Number):void{ var tX:Number = x; x = (s * y); y = (-(s) * tX); } public function MaxV(b:b2Vec2):void{ x = ((x > b.x)) ? x : b.x; y = ((y > b.y)) ? y : b.y; } public function SetV(v:b2Vec2):void{ x = v.x; y = v.y; } public function Negative():b2Vec2{ return (new b2Vec2(-(x), -(y))); } public function CrossFV(s:Number):void{ var tX:Number = x; x = (-(s) * y); y = (s * tX); } public function Abs():void{ if (x < 0){ x = -(x); }; if (y < 0){ y = -(y); }; } public function Subtract(v:b2Vec2):void{ x = (x - v.x); y = (y - v.y); } public function Copy():b2Vec2{ return (new b2Vec2(x, y)); } public function MulTM(A:b2Mat22):void{ var tX:Number = b2Math.b2Dot(this, A.col1); y = b2Math.b2Dot(this, A.col2); x = tX; } public function IsValid():Boolean{ return (((b2Math.b2IsValid(x)) && (b2Math.b2IsValid(y)))); } public static function Make(x_:Number, y_:Number):b2Vec2{ return (new b2Vec2(x_, y_)); } } }//package Box2D.Common.Math
Section 36
//b2Vec3 (Box2D.Common.Math.b2Vec3) package Box2D.Common.Math { public class b2Vec3 { public var x:Number; public var y:Number; public var z:Number; public function b2Vec3(x:Number=0, y:Number=0, z:Number=0){ super(); this.x = x; this.y = y; this.z = z; } public function Add(v:b2Vec3):void{ x = (x + v.x); y = (y + v.y); z = (z + v.z); } public function Set(x:Number, y:Number, z:Number):void{ this.x = x; this.y = y; this.z = z; } public function Multiply(a:Number):void{ x = (x * a); y = (y * a); z = (z * a); } public function SetZero():void{ x = (y = (z = 0)); } public function SetV(v:b2Vec3):void{ x = v.x; y = v.y; z = v.z; } public function Negative():b2Vec3{ return (new b2Vec3(-(x), -(y), -(z))); } public function Subtract(v:b2Vec3):void{ x = (x - v.x); y = (y - v.y); z = (z - v.z); } public function Copy():b2Vec3{ return (new b2Vec3(x, y, z)); } } }//package Box2D.Common.Math
Section 37
//b2XForm (Box2D.Common.Math.b2XForm) package Box2D.Common.Math { public class b2XForm { public var position:b2Vec2; public var R:b2Mat22; public function b2XForm(pos:b2Vec2=null, r:b2Mat22=null):void{ position = new b2Vec2(); R = new b2Mat22(); super(); if (pos){ position.SetV(pos); R.SetM(r); }; } public function Initialize(pos:b2Vec2, r:b2Mat22):void{ position.SetV(pos); R.SetM(r); } public function Set(x:b2XForm):void{ position.SetV(x.position); R.SetM(x.R); } public function SetIdentity():void{ position.SetZero(); R.SetIdentity(); } } }//package Box2D.Common.Math
Section 38
//b2Color (Box2D.Common.b2Color) package Box2D.Common { import Box2D.Common.Math.*; public class b2Color { private var _r:uint;// = 0 private var _g:uint;// = 0 private var _b:uint;// = 0 public function b2Color(rr:Number, gg:Number, bb:Number){ super(); _r = uint((0xFF * b2Math.b2Clamp(rr, 0, 1))); _g = uint((0xFF * b2Math.b2Clamp(gg, 0, 1))); _b = uint((0xFF * b2Math.b2Clamp(bb, 0, 1))); } public function Set(rr:Number, gg:Number, bb:Number):void{ _r = uint((0xFF * b2Math.b2Clamp(rr, 0, 1))); _g = uint((0xFF * b2Math.b2Clamp(gg, 0, 1))); _b = uint((0xFF * b2Math.b2Clamp(bb, 0, 1))); } public function set b(bb:Number):void{ _b = uint((0xFF * b2Math.b2Clamp(bb, 0, 1))); } public function get color():uint{ return ((((_r << 16) | (_g << 8)) | _b)); } public function set r(rr:Number):void{ _r = uint((0xFF * b2Math.b2Clamp(rr, 0, 1))); } public function set g(gg:Number):void{ _g = uint((0xFF * b2Math.b2Clamp(gg, 0, 1))); } } }//package Box2D.Common
Section 39
//b2internal (Box2D.Common.b2internal) package Box2D.Common { public namespace b2internal = "http://www.box2d.org/ns/b2internal"; }//package Box2D.Common
Section 40
//b2Settings (Box2D.Common.b2Settings) package Box2D.Common { import Box2D.Common.Math.*; public class b2Settings { public static const b2_maxLinearVelocity:Number = 200; public static const b2_pi:Number = 3.14159265358979; public static const b2_angularSleepTolerance:Number = 0.0111111111111111; public static const b2_linearSleepTolerance:Number = 0.01; public static const b2_angularSlop:Number = 0.0349065850398866; public static const b2_linearSlop:Number = 0.005; public static const b2_maxLinearVelocitySquared:Number = 40000; public static const b2_maxTOIJointsPerIsland:int = 32; public static const b2_maxAngularVelocitySquared:Number = 62500; public static const b2_maxPolygonVertices:int = 8; public static const b2_velocityThreshold:Number = 1; public static const b2_contactBaumgarte:Number = 0.2; public static const b2_maxTOIContactsPerIsland:int = 32; public static const b2_maxManifoldPoints:int = 2; public static const b2_maxAngularVelocity:Number = 250; public static const b2_maxAngularCorrection:Number = 0.139626340159546; public static const b2_timeToSleep:Number = 0.5; public static const USHRT_MAX:int = 0xFFFF; public static const b2_maxLinearCorrection:Number = 0.2; public static const b2_toiSlop:Number = 0.04; public static const VERSION:String = "2.0.2"; public function b2Settings(){ super(); } public static function b2MixFriction(friction1:Number, friction2:Number):Number{ return (Math.sqrt((friction1 * friction2))); } public static function b2MixRestitution(restitution1:Number, restitution2:Number):Number{ return (((restitution1 > restitution2)) ? restitution1 : restitution2); } public static function b2Assert(a:Boolean):void{ var nullVec:b2Vec2; if (!a){ nullVec.x++; }; } } }//package Box2D.Common
Section 41
//b2CircleContact (Box2D.Dynamics.Contacts.b2CircleContact) package Box2D.Dynamics.Contacts { import Box2D.Dynamics.*; import Box2D.Collision.Shapes.*; import Box2D.Collision.*; import Box2D.Common.Math.*; import Box2D.Common.*; public class b2CircleContact extends b2Contact { private var m_manifolds:Array; private var m_manifold:b2Manifold; private var m0:b2Manifold; private static const s_evalCP:b2ContactPoint = new b2ContactPoint(); public function b2CircleContact(shape1:b2Shape, shape2:b2Shape){ m_manifolds = [new b2Manifold()]; m0 = new b2Manifold(); super(shape1, shape2); m_manifold = m_manifolds[0]; m_manifold.pointCount = 0; var point:b2ManifoldPoint = m_manifold.points[0]; point.normalImpulse = 0; point.tangentImpulse = 0; } override b2internal function Evaluate(listener:b2ContactListener):void{ var v1:b2Vec2; var v2:b2Vec2; var mp0:b2ManifoldPoint; var mp:b2ManifoldPoint; var b1:b2Body = m_shape1.m_body; var b2:b2Body = m_shape2.m_body; m0.Set(m_manifold); b2Collision.b2CollideCircles(m_manifold, (m_shape1 as b2CircleShape), b1.m_xf, (m_shape2 as b2CircleShape), b2.m_xf); var cp:b2ContactPoint = s_evalCP; cp.shape1 = m_shape1; cp.shape2 = m_shape2; cp.friction = b2Settings.b2MixFriction(m_shape1.GetFriction(), m_shape2.GetFriction()); cp.restitution = b2Settings.b2MixRestitution(m_shape1.GetRestitution(), m_shape2.GetRestitution()); if (m_manifold.pointCount > 0){ m_manifoldCount = 1; mp = m_manifold.points[0]; if (m0.pointCount == 0){ mp.normalImpulse = 0; mp.tangentImpulse = 0; if (listener){ cp.position = b1.GetWorldPoint(mp.localPoint1); v1 = b1.GetLinearVelocityFromLocalPoint(mp.localPoint1); v2 = b2.GetLinearVelocityFromLocalPoint(mp.localPoint2); cp.velocity.Set((v2.x - v1.x), (v2.y - v1.y)); cp.normal.SetV(m_manifold.normal); cp.separation = mp.separation; cp.id.key = mp.id._key; listener.Add(cp); }; } else { mp0 = m0.points[0]; mp.normalImpulse = mp0.normalImpulse; mp.tangentImpulse = mp0.tangentImpulse; if (listener){ cp.position = b1.GetWorldPoint(mp.localPoint1); v1 = b1.GetLinearVelocityFromLocalPoint(mp.localPoint1); v2 = b2.GetLinearVelocityFromLocalPoint(mp.localPoint2); cp.velocity.Set((v2.x - v1.x), (v2.y - v1.y)); cp.normal.SetV(m_manifold.normal); cp.separation = mp.separation; cp.id.key = mp.id._key; listener.Persist(cp); }; }; } else { m_manifoldCount = 0; if ((((m0.pointCount > 0)) && (listener))){ mp0 = m0.points[0]; cp.position = b1.GetWorldPoint(mp0.localPoint1); v1 = b1.GetLinearVelocityFromLocalPoint(mp0.localPoint1); v2 = b2.GetLinearVelocityFromLocalPoint(mp0.localPoint2); cp.velocity.Set((v2.x - v1.x), (v2.y - v1.y)); cp.normal.SetV(m0.normal); cp.separation = mp0.separation; cp.id.key = mp0.id._key; listener.Remove(cp); }; }; } override public function GetManifolds():Array{ return (m_manifolds); } public static function Destroy(contact:b2Contact, allocator):void{ } public static function Create(shape1:b2Shape, shape2:b2Shape, allocator):b2Contact{ return (new b2CircleContact(shape1, shape2)); } } }//package Box2D.Dynamics.Contacts
Section 42
//b2Contact (Box2D.Dynamics.Contacts.b2Contact) package Box2D.Dynamics.Contacts { import Box2D.Dynamics.*; import Box2D.Collision.Shapes.*; import Box2D.Collision.*; import Box2D.Common.Math.*; import Box2D.Common.*; public class b2Contact { b2internal var m_shape1:b2Shape; b2internal var m_shape2:b2Shape; b2internal var m_prev:b2Contact; b2internal var m_toi:Number; b2internal var m_next:b2Contact; b2internal var m_manifoldCount:int; b2internal var m_node1:b2ContactEdge; b2internal var m_node2:b2ContactEdge; b2internal var m_flags:uint; b2internal static var e_toiFlag:uint = 8; b2internal static var e_nonSolidFlag:uint = 1; b2internal static var e_slowFlag:uint = 2; b2internal static var e_islandFlag:uint = 4; b2internal static var s_registers:Array; b2internal static var s_initialized:Boolean = false; public function b2Contact(s1:b2Shape=null, s2:b2Shape=null){ m_node1 = new b2ContactEdge(); m_node2 = new b2ContactEdge(); super(); m_flags = 0; if (((!(s1)) || (!(s2)))){ m_shape1 = null; m_shape2 = null; return; }; if (((s1.IsSensor()) || (s2.IsSensor()))){ m_flags = (m_flags | e_nonSolidFlag); }; m_shape1 = s1; m_shape2 = s2; m_manifoldCount = 0; m_prev = null; m_next = null; m_node1.contact = null; m_node1.prev = null; m_node1.next = null; m_node1.other = null; m_node2.contact = null; m_node2.prev = null; m_node2.next = null; m_node2.other = null; } public function IsSolid():Boolean{ return (((m_flags & e_nonSolidFlag) == 0)); } public function GetShape1():b2Shape{ return (m_shape1); } public function GetShape2():b2Shape{ return (m_shape2); } public function GetNext():b2Contact{ return (m_next); } public function GetManifoldCount():int{ return (m_manifoldCount); } public function GetManifolds():Array{ return (null); } b2internal function Update(listener:b2ContactListener):void{ var oldCount:int = m_manifoldCount; Evaluate(listener); var newCount:int = m_manifoldCount; var body1:b2Body = m_shape1.m_body; var body2:b2Body = m_shape2.m_body; if ((((newCount == 0)) && ((oldCount > 0)))){ body1.WakeUp(); body2.WakeUp(); }; if (((((((body1.IsStatic()) || (body1.IsBullet()))) || (body2.IsStatic()))) || (body2.IsBullet()))){ m_flags = (m_flags & ~(e_slowFlag)); } else { m_flags = (m_flags | e_slowFlag); }; } b2internal function Evaluate(listener:b2ContactListener):void{ } b2internal static function InitializeRegisters():void{ var j:int; s_registers = new Array(b2Shape.e_shapeTypeCount); var i:int; while (i < b2Shape.e_shapeTypeCount) { s_registers[i] = new Array(b2Shape.e_shapeTypeCount); j = 0; while (j < b2Shape.e_shapeTypeCount) { s_registers[i][j] = new b2ContactRegister(); j++; }; i++; }; AddType(b2CircleContact.Create, b2CircleContact.Destroy, b2Shape.e_circleShape, b2Shape.e_circleShape); AddType(b2PolyAndCircleContact.Create, b2PolyAndCircleContact.Destroy, b2Shape.e_polygonShape, b2Shape.e_circleShape); AddType(b2PolygonContact.Create, b2PolygonContact.Destroy, b2Shape.e_polygonShape, b2Shape.e_polygonShape); AddType(b2EdgeAndCircleContact.Create, b2EdgeAndCircleContact.Destroy, b2Shape.e_edgeShape, b2Shape.e_circleShape); AddType(b2PolyAndEdgeContact.Create, b2PolyAndEdgeContact.Destroy, b2Shape.e_polygonShape, b2Shape.e_edgeShape); } b2internal static function Destroy(contact:b2Contact, allocator):void{ if (contact.m_manifoldCount > 0){ contact.m_shape1.m_body.WakeUp(); contact.m_shape2.m_body.WakeUp(); }; var type1:int = contact.m_shape1.m_type; var type2:int = contact.m_shape2.m_type; var reg:b2ContactRegister = s_registers[type1][type2]; var destroyFcn:Function = reg.destroyFcn; destroyFcn(contact, allocator); } b2internal static function AddType(createFcn:Function, destroyFcn:Function, type1:int, type2:int):void{ s_registers[type1][type2].createFcn = createFcn; s_registers[type1][type2].destroyFcn = destroyFcn; s_registers[type1][type2].primary = true; if (type1 != type2){ s_registers[type2][type1].createFcn = createFcn; s_registers[type2][type1].destroyFcn = destroyFcn; s_registers[type2][type1].primary = false; }; } b2internal static function Create(shape1:b2Shape, shape2:b2Shape, allocator):b2Contact{ var c:b2Contact; var i:int; var m:b2Manifold; if (s_initialized == false){ InitializeRegisters(); s_initialized = true; }; var type1:int = shape1.m_type; var type2:int = shape2.m_type; var reg:b2ContactRegister = s_registers[type1][type2]; var createFcn:Function = reg.createFcn; if (createFcn != null){ if (reg.primary){ return (createFcn(shape1, shape2, allocator)); }; c = createFcn(shape2, shape1, allocator); i = 0; while (i < c.m_manifoldCount) { m = c.GetManifolds()[i]; m.normal = m.normal.Negative(); i++; }; return (c); //unresolved jump }; return (null); } } }//package Box2D.Dynamics.Contacts
Section 43
//b2ContactConstraint (Box2D.Dynamics.Contacts.b2ContactConstraint) package Box2D.Dynamics.Contacts { import Box2D.Dynamics.*; import Box2D.Collision.*; import Box2D.Common.Math.*; import Box2D.Common.*; public class b2ContactConstraint { public var points:Array; public var normal:b2Vec2; public var restitution:Number; public var K:b2Mat22; public var body1:b2Body; public var manifold:b2Manifold; public var body2:b2Body; public var friction:Number; public var normalMass:b2Mat22; public var pointCount:int; public function b2ContactConstraint(){ normal = new b2Vec2(); normalMass = new b2Mat22(); K = new b2Mat22(); super(); points = new Array(b2Settings.b2_maxManifoldPoints); var i:int; while (i < b2Settings.b2_maxManifoldPoints) { points[i] = new b2ContactConstraintPoint(); i++; }; } } }//package Box2D.Dynamics.Contacts
Section 44
//b2ContactConstraintPoint (Box2D.Dynamics.Contacts.b2ContactConstraintPoint) package Box2D.Dynamics.Contacts { import Box2D.Common.Math.*; public class b2ContactConstraintPoint { public var r2:b2Vec2; public var separation:Number; public var normalImpulse:Number; public var tangentImpulse:Number; public var localAnchor1:b2Vec2; public var localAnchor2:b2Vec2; public var equalizedMass:Number; public var tangentMass:Number; public var normalMass:Number; public var velocityBias:Number; public var r1:b2Vec2; public function b2ContactConstraintPoint(){ localAnchor1 = new b2Vec2(); localAnchor2 = new b2Vec2(); r1 = new b2Vec2(); r2 = new b2Vec2(); super(); } } }//package Box2D.Dynamics.Contacts
Section 45
//b2ContactEdge (Box2D.Dynamics.Contacts.b2ContactEdge) package Box2D.Dynamics.Contacts { import Box2D.Dynamics.*; public class b2ContactEdge { public var other:b2Body; public var prev:b2ContactEdge; public var contact:b2Contact; public var next:b2ContactEdge; public function b2ContactEdge(){ super(); } } }//package Box2D.Dynamics.Contacts
Section 46
//b2ContactRegister (Box2D.Dynamics.Contacts.b2ContactRegister) package Box2D.Dynamics.Contacts { public class b2ContactRegister { public var primary:Boolean; public var createFcn:Function; public var destroyFcn:Function; public function b2ContactRegister(){ super(); } } }//package Box2D.Dynamics.Contacts
Section 47
//b2ContactResult (Box2D.Dynamics.Contacts.b2ContactResult) package Box2D.Dynamics.Contacts { import Box2D.Collision.Shapes.*; import Box2D.Collision.*; import Box2D.Common.Math.*; public class b2ContactResult { public var position:b2Vec2; public var shape1:b2Shape; public var shape2:b2Shape; public var normalImpulse:Number; public var normal:b2Vec2; public var tangentImpulse:Number; public var id:b2ContactID; public function b2ContactResult(){ position = new b2Vec2(); normal = new b2Vec2(); id = new b2ContactID(); super(); } } }//package Box2D.Dynamics.Contacts
Section 48
//b2ContactSolver (Box2D.Dynamics.Contacts.b2ContactSolver) package Box2D.Dynamics.Contacts { import Box2D.Dynamics.*; import Box2D.Collision.Shapes.*; import Box2D.Collision.*; import Box2D.Common.Math.*; import Box2D.Common.*; public class b2ContactSolver { private var m_constraintCount:int; b2internal var m_constraints:Array; private var m_allocator; private var m_step:b2TimeStep; public function b2ContactSolver(step:b2TimeStep, contacts:Array, contactCount:int, allocator){ var contact:b2Contact; var i:int; var tVec:b2Vec2; var tMat:b2Mat22; var shape1:b2Shape; var shape2:b2Shape; var b1:b2Body; var b2:b2Body; var manifoldCount:int; var manifolds:Array; var friction:Number; var restitution:Number; var v1X:Number; var v1Y:Number; var v2X:Number; var v2Y:Number; var w1:Number; var w2:Number; var j:int; var manifold:b2Manifold; var normalX:Number; var normalY:Number; var cc:b2ContactConstraint; var k:uint; var cp:b2ManifoldPoint; var ccp:b2ContactConstraintPoint; var tX:Number; var tY:Number; var r1X:Number; var r1Y:Number; var r2X:Number; var r2Y:Number; var rn1:Number; var rn2:Number; var kNormal:Number; var kEqualized:Number; var tangentX:Number; var tangentY:Number; var rt1:Number; var rt2:Number; var kTangent:Number; var vRel:Number; var ccp1:b2ContactConstraintPoint; var ccp2:b2ContactConstraintPoint; var invMass1:Number; var invI1:Number; var invMass2:Number; var invI2:Number; var rn11:Number; var rn12:Number; var rn21:Number; var rn22:Number; var k11:Number; var k22:Number; var k12:Number; var k_maxConditionNumber:Number; m_step = new b2TimeStep(); m_constraints = new Array(); super(); m_step.dt = step.dt; m_step.inv_dt = step.inv_dt; m_step.positionIterations = step.positionIterations; m_step.velocityIterations = step.velocityIterations; m_allocator = allocator; m_constraintCount = 0; i = 0; while (i < contactCount) { contact = contacts[i]; m_constraintCount = (m_constraintCount + contact.m_manifoldCount); i++; }; i = 0; while (i < m_constraintCount) { m_constraints[i] = new b2ContactConstraint(); i++; }; var count:int; i = 0; while (i < contactCount) { contact = contacts[i]; shape1 = contact.m_shape1; shape2 = contact.m_shape2; b1 = shape1.m_body; b2 = shape2.m_body; manifoldCount = contact.m_manifoldCount; manifolds = contact.GetManifolds(); friction = b2Settings.b2MixFriction(shape1.GetFriction(), shape2.GetFriction()); restitution = b2Settings.b2MixRestitution(shape1.GetRestitution(), shape2.GetRestitution()); v1X = b1.m_linearVelocity.x; v1Y = b1.m_linearVelocity.y; v2X = b2.m_linearVelocity.x; v2Y = b2.m_linearVelocity.y; w1 = b1.m_angularVelocity; w2 = b2.m_angularVelocity; j = 0; while (j < manifoldCount) { manifold = manifolds[j]; normalX = manifold.normal.x; normalY = manifold.normal.y; cc = m_constraints[count]; cc.body1 = b1; cc.body2 = b2; cc.manifold = manifold; cc.normal.x = normalX; cc.normal.y = normalY; cc.pointCount = manifold.pointCount; cc.friction = friction; cc.restitution = restitution; k = 0; while (k < cc.pointCount) { cp = manifold.points[k]; ccp = cc.points[k]; ccp.normalImpulse = cp.normalImpulse; ccp.tangentImpulse = cp.tangentImpulse; ccp.separation = cp.separation; ccp.localAnchor1.SetV(cp.localPoint1); ccp.localAnchor2.SetV(cp.localPoint2); tMat = b1.m_xf.R; r1X = (cp.localPoint1.x - b1.m_sweep.localCenter.x); r1Y = (cp.localPoint1.y - b1.m_sweep.localCenter.y); tX = ((tMat.col1.x * r1X) + (tMat.col2.x * r1Y)); r1Y = ((tMat.col1.y * r1X) + (tMat.col2.y * r1Y)); r1X = tX; ccp.r1.Set(r1X, r1Y); tMat = b2.m_xf.R; r2X = (cp.localPoint2.x - b2.m_sweep.localCenter.x); r2Y = (cp.localPoint2.y - b2.m_sweep.localCenter.y); tX = ((tMat.col1.x * r2X) + (tMat.col2.x * r2Y)); r2Y = ((tMat.col1.y * r2X) + (tMat.col2.y * r2Y)); r2X = tX; ccp.r2.Set(r2X, r2Y); rn1 = ((r1X * normalY) - (r1Y * normalX)); rn2 = ((r2X * normalY) - (r2Y * normalX)); rn1 = (rn1 * rn1); rn2 = (rn2 * rn2); kNormal = (((b1.m_invMass + b2.m_invMass) + (b1.m_invI * rn1)) + (b2.m_invI * rn2)); ccp.normalMass = (1 / kNormal); kEqualized = ((b1.m_mass * b1.m_invMass) + (b2.m_mass * b2.m_invMass)); kEqualized = (kEqualized + (((b1.m_mass * b1.m_invI) * rn1) + ((b2.m_mass * b2.m_invI) * rn2))); ccp.equalizedMass = (1 / kEqualized); tangentX = normalY; tangentY = -(normalX); rt1 = ((r1X * tangentY) - (r1Y * tangentX)); rt2 = ((r2X * tangentY) - (r2Y * tangentX)); rt1 = (rt1 * rt1); rt2 = (rt2 * rt2); kTangent = (((b1.m_invMass + b2.m_invMass) + (b1.m_invI * rt1)) + (b2.m_invI * rt2)); ccp.tangentMass = (1 / kTangent); ccp.velocityBias = 0; if (ccp.separation > 0){ ccp.velocityBias = (-60 * ccp.separation); } else { tX = (((v2X + (-(w2) * r2Y)) - v1X) - (-(w1) * r1Y)); tY = (((v2Y + (w2 * r2X)) - v1Y) - (w1 * r1X)); vRel = ((cc.normal.x * tX) + (cc.normal.y * tY)); if (vRel < -(b2Settings.b2_velocityThreshold)){ ccp.velocityBias = (ccp.velocityBias + (-(cc.restitution) * vRel)); }; }; k++; }; if (cc.pointCount == 2){ ccp1 = cc.points[0]; ccp2 = cc.points[1]; invMass1 = b1.m_invMass; invI1 = b1.m_invI; invMass2 = b2.m_invMass; invI2 = b2.m_invI; rn11 = ((ccp1.r1.x * normalY) - (ccp1.r1.y * normalX)); rn12 = ((ccp1.r2.x * normalY) - (ccp1.r2.y * normalX)); rn21 = ((ccp2.r1.x * normalY) - (ccp2.r1.y * normalX)); rn22 = ((ccp2.r2.x * normalY) - (ccp2.r2.y * normalX)); k11 = (((invMass1 + invMass2) + ((invI1 * rn11) * rn11)) + ((invI2 * rn12) * rn12)); k22 = (((invMass1 + invMass2) + ((invI1 * rn21) * rn21)) + ((invI2 * rn22) * rn22)); k12 = (((invMass1 + invMass2) + ((invI1 * rn11) * rn21)) + ((invI2 * rn12) * rn22)); k_maxConditionNumber = 100; if ((k11 * k11) < (k_maxConditionNumber * ((k11 * k22) - (k12 * k12)))){ cc.K.col1.Set(k11, k12); cc.K.col2.Set(k12, k22); cc.K.GetInverse(cc.normalMass); } else { cc.pointCount = 1; }; }; count++; j++; }; i++; }; } public function InitVelocityConstraints(step:b2TimeStep):void{ var tVec:b2Vec2; var tVec2:b2Vec2; var tMat:b2Mat22; var c:b2ContactConstraint; var b1:b2Body; var b2:b2Body; var invMass1:Number; var invI1:Number; var invMass2:Number; var invI2:Number; var normalX:Number; var normalY:Number; var tangentX:Number; var tangentY:Number; var tX:Number; var j:int; var tCount:int; var ccp:b2ContactConstraintPoint; var PX:Number; var PY:Number; var ccp2:b2ContactConstraintPoint; var i:int; while (i < m_constraintCount) { c = m_constraints[i]; b1 = c.body1; b2 = c.body2; invMass1 = b1.m_invMass; invI1 = b1.m_invI; invMass2 = b2.m_invMass; invI2 = b2.m_invI; normalX = c.normal.x; normalY = c.normal.y; tangentX = normalY; tangentY = -(normalX); if (step.warmStarting){ tCount = c.pointCount; j = 0; while (j < tCount) { ccp = c.points[j]; ccp.normalImpulse = (ccp.normalImpulse * step.dtRatio); ccp.tangentImpulse = (ccp.tangentImpulse * step.dtRatio); PX = ((ccp.normalImpulse * normalX) + (ccp.tangentImpulse * tangentX)); PY = ((ccp.normalImpulse * normalY) + (ccp.tangentImpulse * tangentY)); b1.m_angularVelocity = (b1.m_angularVelocity - (invI1 * ((ccp.r1.x * PY) - (ccp.r1.y * PX)))); b1.m_linearVelocity.x = (b1.m_linearVelocity.x - (invMass1 * PX)); b1.m_linearVelocity.y = (b1.m_linearVelocity.y - (invMass1 * PY)); b2.m_angularVelocity = (b2.m_angularVelocity + (invI2 * ((ccp.r2.x * PY) - (ccp.r2.y * PX)))); b2.m_linearVelocity.x = (b2.m_linearVelocity.x + (invMass2 * PX)); b2.m_linearVelocity.y = (b2.m_linearVelocity.y + (invMass2 * PY)); j++; }; } else { tCount = c.pointCount; j = 0; while (j < tCount) { ccp2 = c.points[j]; ccp2.normalImpulse = 0; ccp2.tangentImpulse = 0; j++; }; }; i++; }; } public function SolvePositionConstraints(baumgarte:Number):Boolean{ var tMat:b2Mat22; var tVec:b2Vec2; var c:b2ContactConstraint; var b1:b2Body; var b2:b2Body; var b1_sweep_c:b2Vec2; var b1_sweep_a:Number; var b2_sweep_c:b2Vec2; var b2_sweep_a:Number; var invMass1:Number; var invI1:Number; var invMass2:Number; var invI2:Number; var normalX:Number; var normalY:Number; var tCount:int; var j:int; var ccp:b2ContactConstraintPoint; var r1X:Number; var r1Y:Number; var r2X:Number; var r2Y:Number; var tX:Number; var p1X:Number; var p1Y:Number; var p2X:Number; var p2Y:Number; var dpX:Number; var dpY:Number; var separation:Number; var C:Number; var dImpulse:Number; var PX:Number; var PY:Number; var minSeparation:Number = 0; var i:int; while (i < m_constraintCount) { c = m_constraints[i]; b1 = c.body1; b2 = c.body2; b1_sweep_c = b1.m_sweep.c; b1_sweep_a = b1.m_sweep.a; b2_sweep_c = b2.m_sweep.c; b2_sweep_a = b2.m_sweep.a; invMass1 = (b1.m_mass * b1.m_invMass); invI1 = (b1.m_mass * b1.m_invI); invMass2 = (b2.m_mass * b2.m_invMass); invI2 = (b2.m_mass * b2.m_invI); normalX = c.normal.x; normalY = c.normal.y; tCount = c.pointCount; j = 0; while (j < tCount) { ccp = c.points[j]; tMat = b1.m_xf.R; tVec = b1.m_sweep.localCenter; r1X = (ccp.localAnchor1.x - tVec.x); r1Y = (ccp.localAnchor1.y - tVec.y); tX = ((tMat.col1.x * r1X) + (tMat.col2.x * r1Y)); r1Y = ((tMat.col1.y * r1X) + (tMat.col2.y * r1Y)); r1X = tX; tMat = b2.m_xf.R; tVec = b2.m_sweep.localCenter; r2X = (ccp.localAnchor2.x - tVec.x); r2Y = (ccp.localAnchor2.y - tVec.y); tX = ((tMat.col1.x * r2X) + (tMat.col2.x * r2Y)); r2Y = ((tMat.col1.y * r2X) + (tMat.col2.y * r2Y)); r2X = tX; p1X = (b1_sweep_c.x + r1X); p1Y = (b1_sweep_c.y + r1Y); p2X = (b2_sweep_c.x + r2X); p2Y = (b2_sweep_c.y + r2Y); dpX = (p2X - p1X); dpY = (p2Y - p1Y); separation = (((dpX * normalX) + (dpY * normalY)) + ccp.separation); minSeparation = b2Math.b2Min(minSeparation, separation); C = (baumgarte * b2Math.b2Clamp((separation + b2Settings.b2_linearSlop), -(b2Settings.b2_maxLinearCorrection), 0)); dImpulse = (-(ccp.equalizedMass) * C); PX = (dImpulse * normalX); PY = (dImpulse * normalY); b1_sweep_c.x = (b1_sweep_c.x - (invMass1 * PX)); b1_sweep_c.y = (b1_sweep_c.y - (invMass1 * PY)); b1_sweep_a = (b1_sweep_a - (invI1 * ((r1X * PY) - (r1Y * PX)))); b1.m_sweep.a = b1_sweep_a; b1.SynchronizeTransform(); b2_sweep_c.x = (b2_sweep_c.x + (invMass2 * PX)); b2_sweep_c.y = (b2_sweep_c.y + (invMass2 * PY)); b2_sweep_a = (b2_sweep_a + (invI2 * ((r2X * PY) - (r2Y * PX)))); b2.m_sweep.a = b2_sweep_a; b2.SynchronizeTransform(); j++; }; i++; }; return ((minSeparation >= (-1.5 * b2Settings.b2_linearSlop))); } public function SolveVelocityConstraints():void{ var j:int; var ccp:b2ContactConstraintPoint; var r1X:Number; var r1Y:Number; var r2X:Number; var r2Y:Number; var dvX:Number; var dvY:Number; var vn:Number; var vt:Number; var lambda_n:Number; var lambda_t:Number; var newImpulse_n:Number; var newImpulse_t:Number; var PX:Number; var PY:Number; var dX:Number; var dY:Number; var P1X:Number; var P1Y:Number; var P2X:Number; var P2Y:Number; var tMat:b2Mat22; var tVec:b2Vec2; var c:b2ContactConstraint; var b1:b2Body; var b2:b2Body; var w1:Number; var w2:Number; var v1:b2Vec2; var v2:b2Vec2; var invMass1:Number; var invI1:Number; var invMass2:Number; var invI2:Number; var normalX:Number; var normalY:Number; var tangentX:Number; var tangentY:Number; var friction:Number; var tX:Number; var tCount:int; var maxFriction:Number; var cp1:b2ContactConstraintPoint; var cp2:b2ContactConstraintPoint; var aX:Number; var aY:Number; var dv1X:Number; var dv1Y:Number; var dv2X:Number; var dv2Y:Number; var vn1:Number; var vn2:Number; var bX:Number; var bY:Number; var k_errorTol:Number; var xX:Number; var xY:Number; var i:int; while (i < m_constraintCount) { c = m_constraints[i]; b1 = c.body1; b2 = c.body2; w1 = b1.m_angularVelocity; w2 = b2.m_angularVelocity; v1 = b1.m_linearVelocity; v2 = b2.m_linearVelocity; invMass1 = b1.m_invMass; invI1 = b1.m_invI; invMass2 = b2.m_invMass; invI2 = b2.m_invI; normalX = c.normal.x; normalY = c.normal.y; tangentX = normalY; tangentY = -(normalX); friction = c.friction; tCount = c.pointCount; if (c.pointCount == 1){ ccp = c.points[0]; dvX = (((v2.x + (-(w2) * ccp.r2.y)) - v1.x) - (-(w1) * ccp.r1.y)); dvY = (((v2.y + (w2 * ccp.r2.x)) - v1.y) - (w1 * ccp.r1.x)); vn = ((dvX * normalX) + (dvY * normalY)); lambda_n = (-(ccp.normalMass) * (vn - ccp.velocityBias)); vt = ((dvX * tangentX) + (dvY * tangentY)); lambda_t = (ccp.tangentMass * -(vt)); newImpulse_n = b2Math.b2Max((ccp.normalImpulse + lambda_n), 0); lambda_n = (newImpulse_n - ccp.normalImpulse); maxFriction = (friction * ccp.normalImpulse); newImpulse_t = b2Math.b2Clamp((ccp.tangentImpulse + lambda_t), -(maxFriction), maxFriction); lambda_t = (newImpulse_t - ccp.tangentImpulse); PX = ((lambda_n * normalX) + (lambda_t * tangentX)); PY = ((lambda_n * normalY) + (lambda_t * tangentY)); v1.x = (v1.x - (invMass1 * PX)); v1.y = (v1.y - (invMass1 * PY)); w1 = (w1 - (invI1 * ((ccp.r1.x * PY) - (ccp.r1.y * PX)))); v2.x = (v2.x + (invMass2 * PX)); v2.y = (v2.y + (invMass2 * PY)); w2 = (w2 + (invI2 * ((ccp.r2.x * PY) - (ccp.r2.y * PX)))); ccp.normalImpulse = newImpulse_n; ccp.tangentImpulse = newImpulse_t; } else { cp1 = c.points[0]; cp2 = c.points[1]; aX = cp1.normalImpulse; aY = cp2.normalImpulse; dv1X = (((v2.x - (w2 * cp1.r2.y)) - v1.x) + (w1 * cp1.r1.y)); dv1Y = (((v2.y + (w2 * cp1.r2.x)) - v1.y) - (w1 * cp1.r1.x)); dv2X = (((v2.x - (w2 * cp2.r2.y)) - v1.x) + (w1 * cp2.r1.y)); dv2Y = (((v2.y + (w2 * cp2.r2.x)) - v1.y) - (w1 * cp2.r1.x)); vn1 = ((dv1X * normalX) + (dv1Y * normalY)); vn2 = ((dv2X * normalX) + (dv2Y * normalY)); bX = (vn1 - cp1.velocityBias); bY = (vn2 - cp2.velocityBias); tMat = c.K; bX = (bX - ((tMat.col1.x * aX) + (tMat.col2.x * aY))); bY = (bY - ((tMat.col1.y * aX) + (tMat.col2.y * aY))); k_errorTol = 0.001; while (true) { tMat = c.normalMass; xX = -(((tMat.col1.x * bX) + (tMat.col2.x * bY))); xY = -(((tMat.col1.y * bX) + (tMat.col2.y * bY))); if ((((xX >= 0)) && ((xY >= 0)))){ dX = (xX - aX); dY = (xY - aY); P1X = (dX * normalX); P1Y = (dX * normalY); P2X = (dY * normalX); P2Y = (dY * normalY); v1.x = (v1.x - (invMass1 * (P1X + P2X))); v1.y = (v1.y - (invMass1 * (P1Y + P2Y))); w1 = (w1 - (invI1 * ((((cp1.r1.x * P1Y) - (cp1.r1.y * P1X)) + (cp2.r1.x * P2Y)) - (cp2.r1.y * P2X)))); v2.x = (v2.x + (invMass2 * (P1X + P2X))); v2.y = (v2.y + (invMass2 * (P1Y + P2Y))); w2 = (w2 + (invI2 * ((((cp1.r2.x * P1Y) - (cp1.r2.y * P1X)) + (cp2.r2.x * P2Y)) - (cp2.r2.y * P2X)))); cp1.normalImpulse = xX; cp2.normalImpulse = xY; break; }; xX = (-(cp1.normalMass) * bX); xY = 0; vn1 = 0; vn2 = ((c.K.col1.y * xX) + bY); if ((((xX >= 0)) && ((vn2 >= 0)))){ dX = (xX - aX); dY = (xY - aY); P1X = (dX * normalX); P1Y = (dX * normalY); P2X = (dY * normalX); P2Y = (dY * normalY); v1.x = (v1.x - (invMass1 * (P1X + P2X))); v1.y = (v1.y - (invMass1 * (P1Y + P2Y))); w1 = (w1 - (invI1 * ((((cp1.r1.x * P1Y) - (cp1.r1.y * P1X)) + (cp2.r1.x * P2Y)) - (cp2.r1.y * P2X)))); v2.x = (v2.x + (invMass2 * (P1X + P2X))); v2.y = (v2.y + (invMass2 * (P1Y + P2Y))); w2 = (w2 + (invI2 * ((((cp1.r2.x * P1Y) - (cp1.r2.y * P1X)) + (cp2.r2.x * P2Y)) - (cp2.r2.y * P2X)))); cp1.normalImpulse = xX; cp2.normalImpulse = xY; break; }; xX = 0; xY = (-(cp2.normalMass) * bY); vn1 = ((c.K.col2.x * xY) + bX); vn2 = 0; if ((((xY >= 0)) && ((vn1 >= 0)))){ dX = (xX - aX); dY = (xY - aY); P1X = (dX * normalX); P1Y = (dX * normalY); P2X = (dY * normalX); P2Y = (dY * normalY); v1.x = (v1.x - (invMass1 * (P1X + P2X))); v1.y = (v1.y - (invMass1 * (P1Y + P2Y))); w1 = (w1 - (invI1 * ((((cp1.r1.x * P1Y) - (cp1.r1.y * P1X)) + (cp2.r1.x * P2Y)) - (cp2.r1.y * P2X)))); v2.x = (v2.x + (invMass2 * (P1X + P2X))); v2.y = (v2.y + (invMass2 * (P1Y + P2Y))); w2 = (w2 + (invI2 * ((((cp1.r2.x * P1Y) - (cp1.r2.y * P1X)) + (cp2.r2.x * P2Y)) - (cp2.r2.y * P2X)))); cp1.normalImpulse = xX; cp2.normalImpulse = xY; break; }; xX = 0; xY = 0; vn1 = bX; vn2 = bY; if ((((vn1 >= 0)) && ((vn2 >= 0)))){ dX = (xX - aX); dY = (xY - aY); P1X = (dX * normalX); P1Y = (dX * normalY); P2X = (dY * normalX); P2Y = (dY * normalY); v1.x = (v1.x - (invMass1 * (P1X + P2X))); v1.y = (v1.y - (invMass1 * (P1Y + P2Y))); w1 = (w1 - (invI1 * ((((cp1.r1.x * P1Y) - (cp1.r1.y * P1X)) + (cp2.r1.x * P2Y)) - (cp2.r1.y * P2X)))); v2.x = (v2.x + (invMass2 * (P1X + P2X))); v2.y = (v2.y + (invMass2 * (P1Y + P2Y))); w2 = (w2 + (invI2 * ((((cp1.r2.x * P1Y) - (cp1.r2.y * P1X)) + (cp2.r2.x * P2Y)) - (cp2.r2.y * P2X)))); cp1.normalImpulse = xX; cp2.normalImpulse = xY; break; }; break; }; j = 0; while (j < c.pointCount) { ccp = c.points[j]; dvX = (((v2.x - (w2 * ccp.r2.y)) - v1.x) + (w1 * ccp.r1.y)); dvY = (((v2.y + (w2 * ccp.r2.x)) - v1.y) - (w1 * ccp.r1.x)); vt = ((dvX * tangentX) + (dvY * tangentY)); lambda_t = (ccp.tangentMass * -(vt)); maxFriction = (friction * ccp.normalImpulse); newImpulse_t = b2Math.b2Clamp((ccp.tangentImpulse + lambda_t), -(maxFriction), maxFriction); lambda_t = (newImpulse_t - ccp.tangentImpulse); PX = (lambda_t * tangentX); PY = (lambda_t * tangentY); v1.x = (v1.x - (invMass1 * PX)); v1.y = (v1.y - (invMass1 * PY)); w1 = (w1 - (invI1 * ((ccp.r1.x * PY) - (ccp.r1.y * PX)))); v2.x = (v2.x + (invMass2 * PX)); v2.y = (v2.y + (invMass2 * PY)); w2 = (w2 + (invI2 * ((ccp.r2.x * PY) - (ccp.r2.y * PX)))); ccp.tangentImpulse = newImpulse_t; j++; }; }; b1.m_angularVelocity = w1; b2.m_angularVelocity = w2; i++; }; } public function FinalizeVelocityConstraints():void{ var c:b2ContactConstraint; var m:b2Manifold; var j:int; var point1:b2ManifoldPoint; var point2:b2ContactConstraintPoint; var i:int; while (i < m_constraintCount) { c = m_constraints[i]; m = c.manifold; j = 0; while (j < c.pointCount) { point1 = m.points[j]; point2 = c.points[j]; point1.normalImpulse = point2.normalImpulse; point1.tangentImpulse = point2.tangentImpulse; j++; }; i++; }; } } }//package Box2D.Dynamics.Contacts
Section 49
//b2EdgeAndCircleContact (Box2D.Dynamics.Contacts.b2EdgeAndCircleContact) package Box2D.Dynamics.Contacts { import Box2D.Dynamics.*; import Box2D.Collision.Shapes.*; import Box2D.Collision.*; import Box2D.Common.Math.*; import Box2D.Common.*; public class b2EdgeAndCircleContact extends b2Contact { private var m_manifolds:Array; private var m_manifold:b2Manifold; private var m0:b2Manifold; private static const s_evalCP:b2ContactPoint = new b2ContactPoint(); public function b2EdgeAndCircleContact(shape1:b2Shape, shape2:b2Shape){ m_manifolds = [new b2Manifold()]; m0 = new b2Manifold(); super(shape1, shape2); m_manifold = m_manifolds[0]; m_manifold.pointCount = 0; var point:b2ManifoldPoint = m_manifold.points[0]; point.normalImpulse = 0; point.tangentImpulse = 0; } override b2internal function Evaluate(listener:b2ContactListener):void{ var v1:b2Vec2; var v2:b2Vec2; var mp0:b2ManifoldPoint; var mp:b2ManifoldPoint; var b1:b2Body = m_shape1.m_body; var b2:b2Body = m_shape2.m_body; m0.Set(m_manifold); b2CollideEdgeAndCircle(m_manifold, (m_shape1 as b2EdgeShape), b1.m_xf, (m_shape2 as b2CircleShape), b2.m_xf); var cp:b2ContactPoint = s_evalCP; cp.shape1 = m_shape1; cp.shape2 = m_shape2; cp.friction = b2Settings.b2MixFriction(m_shape1.GetFriction(), m_shape2.GetFriction()); cp.restitution = b2Settings.b2MixRestitution(m_shape1.GetRestitution(), m_shape2.GetRestitution()); if (m_manifold.pointCount > 0){ m_manifoldCount = 1; mp = m_manifold.points[0]; if (m0.pointCount == 0){ mp.normalImpulse = 0; mp.tangentImpulse = 0; if (listener){ cp.position = b1.GetWorldPoint(mp.localPoint1); v1 = b1.GetLinearVelocityFromLocalPoint(mp.localPoint1); v2 = b2.GetLinearVelocityFromLocalPoint(mp.localPoint2); cp.velocity.Set((v2.x - v1.x), (v2.y - v1.y)); cp.normal.SetV(m_manifold.normal); cp.separation = mp.separation; cp.id.key = mp.id._key; listener.Add(cp); }; } else { mp0 = m0.points[0]; mp.normalImpulse = mp0.normalImpulse; mp.tangentImpulse = mp0.tangentImpulse; if (listener){ cp.position = b1.GetWorldPoint(mp.localPoint1); v1 = b1.GetLinearVelocityFromLocalPoint(mp.localPoint1); v2 = b2.GetLinearVelocityFromLocalPoint(mp.localPoint2); cp.velocity.Set((v2.x - v1.x), (v2.y - v1.y)); cp.normal.SetV(m_manifold.normal); cp.separation = mp.separation; cp.id.key = mp.id._key; listener.Persist(cp); }; }; } else { m_manifoldCount = 0; if ((((m0.pointCount > 0)) && (listener))){ mp0 = m0.points[0]; cp.position = b1.GetWorldPoint(mp0.localPoint1); v1 = b1.GetLinearVelocityFromLocalPoint(mp0.localPoint1); v2 = b2.GetLinearVelocityFromLocalPoint(mp0.localPoint2); cp.velocity.Set((v2.x - v1.x), (v2.y - v1.y)); cp.normal.SetV(m0.normal); cp.separation = mp0.separation; cp.id.key = mp0.id._key; listener.Remove(cp); }; }; } private function b2CollideEdgeAndCircle(manifold:b2Manifold, edge:b2EdgeShape, xf1:b2XForm, circle:b2CircleShape, xf2:b2XForm):void{ var tMat:b2Mat22; var tVec:b2Vec2; var dX:Number; var dY:Number; var tX:Number; var tY:Number; var tPoint:b2ManifoldPoint; var separation:Number; var distSqr:Number; manifold.pointCount = 0; tMat = xf2.R; tVec = circle.m_localPosition; var cX:Number = (xf2.position.x + ((tMat.col1.x * tVec.x) + (tMat.col2.x * tVec.y))); var cY:Number = (xf2.position.y + ((tMat.col1.y * tVec.x) + (tMat.col2.y * tVec.y))); tMat = xf1.R; tX = (cX - xf1.position.x); tY = (cY - xf1.position.y); var cLocalX:Number = ((tX * tMat.col1.x) + (tY * tMat.col1.y)); var cLocalY:Number = ((tX * tMat.col2.x) + (tY * tMat.col2.y)); var n:b2Vec2 = edge.m_normal; var v1:b2Vec2 = edge.m_v1; var v2:b2Vec2 = edge.m_v2; var radius:Number = circle.m_radius; var dirDist:Number = (((cLocalX - v1.x) * edge.m_direction.x) + ((cLocalY - v1.y) * edge.m_direction.y)); var normalCalculated:Boolean; if (dirDist <= 0){ dX = (cLocalX - v1.x); dY = (cLocalY - v1.y); if (((dX * edge.m_cornerDir1.x) + (dY * edge.m_cornerDir1.y)) < 0){ return; }; dX = (cX - (xf1.position.x + ((tMat.col1.x * v1.x) + (tMat.col2.x * v1.y)))); dY = (cY - (xf1.position.y + ((tMat.col1.y * v1.x) + (tMat.col2.y * v1.y)))); } else { if (dirDist >= edge.m_length){ dX = (cLocalX - v2.x); dY = (cLocalY - v2.y); if (((dX * edge.m_cornerDir2.x) + (dY * edge.m_cornerDir2.y)) > 0){ return; }; dX = (cX - (xf1.position.x + ((tMat.col1.x * v2.x) + (tMat.col2.x * v2.y)))); dY = (cY - (xf1.position.y + ((tMat.col1.y * v2.x) + (tMat.col2.y * v2.y)))); } else { separation = (((cLocalX - v1.x) * n.x) + ((cLocalY - v1.y) * n.y)); if ((((separation > radius)) || ((separation < -(radius))))){ return; }; separation = (separation - radius); tMat = xf1.R; manifold.normal.x = ((tMat.col1.x * n.x) + (tMat.col2.x * n.y)); manifold.normal.y = ((tMat.col1.y * n.x) + (tMat.col2.y * n.y)); normalCalculated = true; }; }; if (!normalCalculated){ distSqr = ((dX * dX) + (dY * dY)); if (distSqr > (radius * radius)){ return; }; if (distSqr < Number.MIN_VALUE){ separation = -(radius); manifold.normal.x = ((tMat.col1.x * n.x) + (tMat.col2.x * n.y)); manifold.normal.y = ((tMat.col1.y * n.x) + (tMat.col2.y * n.y)); } else { distSqr = Math.sqrt(distSqr); dX = (dX / distSqr); dY = (dY / distSqr); separation = (distSqr - radius); manifold.normal.x = dX; manifold.normal.y = dY; }; }; tPoint = manifold.points[0]; manifold.pointCount = 1; tPoint.id.key = 0; tPoint.separation = separation; cX = (cX - (radius * manifold.normal.x)); cY = (cY - (radius * manifold.normal.y)); tX = (cX - xf1.position.x); tY = (cY - xf1.position.y); tPoint.localPoint1.x = ((tX * tMat.col1.x) + (tY * tMat.col1.y)); tPoint.localPoint1.y = ((tX * tMat.col2.x) + (tY * tMat.col2.y)); tMat = xf2.R; tX = (cX - xf2.position.x); tY = (cY - xf2.position.y); tPoint.localPoint2.x = ((tX * tMat.col1.x) + (tY * tMat.col1.y)); tPoint.localPoint2.y = ((tX * tMat.col2.x) + (tY * tMat.col2.y)); } override public function GetManifolds():Array{ return (m_manifolds); } public static function Destroy(contact:b2Contact, allocator):void{ } public static function Create(shape1:b2Shape, shape2:b2Shape, allocator):b2Contact{ return (new b2EdgeAndCircleContact(shape1, shape2)); } } }//package Box2D.Dynamics.Contacts
Section 50
//b2NullContact (Box2D.Dynamics.Contacts.b2NullContact) package Box2D.Dynamics.Contacts { import Box2D.Dynamics.*; import Box2D.Common.*; public class b2NullContact extends b2Contact { public function b2NullContact(){ super(); } override b2internal function Evaluate(l:b2ContactListener):void{ } override public function GetManifolds():Array{ return (null); } } }//package Box2D.Dynamics.Contacts
Section 51
//b2PolyAndCircleContact (Box2D.Dynamics.Contacts.b2PolyAndCircleContact) package Box2D.Dynamics.Contacts { import Box2D.Dynamics.*; import Box2D.Collision.Shapes.*; import Box2D.Collision.*; import Box2D.Common.Math.*; import Box2D.Common.*; public class b2PolyAndCircleContact extends b2Contact { private var m_manifolds:Array; private var m_manifold:b2Manifold; private var m0:b2Manifold; private static const s_evalCP:b2ContactPoint = new b2ContactPoint(); public function b2PolyAndCircleContact(shape1:b2Shape, shape2:b2Shape){ m_manifolds = [new b2Manifold()]; m0 = new b2Manifold(); super(shape1, shape2); m_manifold = m_manifolds[0]; b2Settings.b2Assert((m_shape1.m_type == b2Shape.e_polygonShape)); b2Settings.b2Assert((m_shape2.m_type == b2Shape.e_circleShape)); m_manifold.pointCount = 0; } override b2internal function Evaluate(listener:b2ContactListener):void{ var i:int; var v1:b2Vec2; var v2:b2Vec2; var mp0:b2ManifoldPoint; var mp:b2ManifoldPoint; var found:Boolean; var idKey:uint; var j:int; var b1:b2Body = m_shape1.m_body; var b2:b2Body = m_shape2.m_body; m0.Set(m_manifold); b2Collision.b2CollidePolygonAndCircle(m_manifold, (m_shape1 as b2PolygonShape), b1.m_xf, (m_shape2 as b2CircleShape), b2.m_xf); var persisted:Array = [false, false]; var cp:b2ContactPoint = s_evalCP; cp.shape1 = m_shape1; cp.shape2 = m_shape2; cp.friction = b2Settings.b2MixFriction(m_shape1.GetFriction(), m_shape2.GetFriction()); cp.restitution = b2Settings.b2MixRestitution(m_shape1.GetRestitution(), m_shape2.GetRestitution()); if (m_manifold.pointCount > 0){ i = 0; while (i < m_manifold.pointCount) { mp = m_manifold.points[i]; mp.normalImpulse = 0; mp.tangentImpulse = 0; found = false; idKey = mp.id._key; j = 0; while (j < m0.pointCount) { if (persisted[j] == true){ } else { mp0 = m0.points[j]; if (mp0.id._key == idKey){ persisted[j] = true; mp.normalImpulse = mp0.normalImpulse; mp.tangentImpulse = mp0.tangentImpulse; found = true; if (listener != null){ cp.position = b1.GetWorldPoint(mp.localPoint1); v1 = b1.GetLinearVelocityFromLocalPoint(mp.localPoint1); v2 = b2.GetLinearVelocityFromLocalPoint(mp.localPoint2); cp.velocity.Set((v2.x - v1.x), (v2.y - v1.y)); cp.normal.SetV(m_manifold.normal); cp.separation = mp.separation; cp.id.key = idKey; listener.Persist(cp); }; break; }; }; j++; }; if ((((found == false)) && (!((listener == null))))){ cp.position = b1.GetWorldPoint(mp.localPoint1); v1 = b1.GetLinearVelocityFromLocalPoint(mp.localPoint1); v2 = b2.GetLinearVelocityFromLocalPoint(mp.localPoint2); cp.velocity.Set((v2.x - v1.x), (v2.y - v1.y)); cp.normal.SetV(m_manifold.normal); cp.separation = mp.separation; cp.id.key = idKey; listener.Add(cp); }; i++; }; m_manifoldCount = 1; } else { m_manifoldCount = 0; }; if (listener == null){ return; }; i = 0; while (i < m0.pointCount) { if (persisted[i]){ } else { mp0 = m0.points[i]; cp.position = b1.GetWorldPoint(mp0.localPoint1); v1 = b1.GetLinearVelocityFromLocalPoint(mp0.localPoint1); v2 = b2.GetLinearVelocityFromLocalPoint(mp0.localPoint2); cp.velocity.Set((v2.x - v1.x), (v2.y - v1.y)); cp.normal.SetV(m0.normal); cp.separation = mp0.separation; cp.id.key = mp0.id._key; listener.Remove(cp); }; i++; }; } override public function GetManifolds():Array{ return (m_manifolds); } public static function Destroy(contact:b2Contact, allocator):void{ } public static function Create(shape1:b2Shape, shape2:b2Shape, allocator):b2Contact{ return (new b2PolyAndCircleContact(shape1, shape2)); } } }//package Box2D.Dynamics.Contacts
Section 52
//b2PolyAndEdgeContact (Box2D.Dynamics.Contacts.b2PolyAndEdgeContact) package Box2D.Dynamics.Contacts { import Box2D.Dynamics.*; import Box2D.Collision.Shapes.*; import Box2D.Collision.*; import Box2D.Common.Math.*; import Box2D.Common.*; public class b2PolyAndEdgeContact extends b2Contact { private var m_manifolds:Array; private var m_manifold:b2Manifold; private var m0:b2Manifold; private static const s_evalCP:b2ContactPoint = new b2ContactPoint(); public function b2PolyAndEdgeContact(shape1:b2Shape, shape2:b2Shape){ m_manifolds = [new b2Manifold()]; m0 = new b2Manifold(); super(shape1, shape2); m_manifold = m_manifolds[0]; b2Settings.b2Assert((m_shape1.m_type == b2Shape.e_polygonShape)); b2Settings.b2Assert((m_shape2.m_type == b2Shape.e_edgeShape)); m_manifold.pointCount = 0; } override b2internal function Evaluate(listener:b2ContactListener):void{ var i:int; var v1:b2Vec2; var v2:b2Vec2; var mp0:b2ManifoldPoint; var mp:b2ManifoldPoint; var found:Boolean; var idKey:uint; var j:int; var b1:b2Body = m_shape1.m_body; var b2:b2Body = m_shape2.m_body; m0.Set(m_manifold); b2CollidePolyAndEdge(m_manifold, (m_shape1 as b2PolygonShape), b1.m_xf, (m_shape2 as b2EdgeShape), b2.m_xf); var persisted:Array = [false, false]; var cp:b2ContactPoint = s_evalCP; cp.shape1 = m_shape1; cp.shape2 = m_shape2; cp.friction = b2Settings.b2MixFriction(m_shape1.GetFriction(), m_shape2.GetFriction()); cp.restitution = b2Settings.b2MixRestitution(m_shape1.GetRestitution(), m_shape2.GetRestitution()); if (m_manifold.pointCount > 0){ i = 0; while (i < m_manifold.pointCount) { mp = m_manifold.points[i]; mp.normalImpulse = 0; mp.tangentImpulse = 0; found = false; idKey = mp.id._key; j = 0; while (j < m0.pointCount) { if (persisted[j] == true){ } else { mp0 = m0.points[j]; if (mp0.id._key == idKey){ persisted[j] = true; mp.normalImpulse = mp0.normalImpulse; mp.tangentImpulse = mp0.tangentImpulse; found = true; if (listener != null){ cp.position = b1.GetWorldPoint(mp.localPoint1); v1 = b1.GetLinearVelocityFromLocalPoint(mp.localPoint1); v2 = b2.GetLinearVelocityFromLocalPoint(mp.localPoint2); cp.velocity.Set((v2.x - v1.x), (v2.y - v1.y)); cp.normal.SetV(m_manifold.normal); cp.separation = mp.separation; cp.id.key = idKey; listener.Persist(cp); }; break; }; }; j++; }; if ((((found == false)) && (!((listener == null))))){ cp.position = b1.GetWorldPoint(mp.localPoint1); v1 = b1.GetLinearVelocityFromLocalPoint(mp.localPoint1); v2 = b2.GetLinearVelocityFromLocalPoint(mp.localPoint2); cp.velocity.Set((v2.x - v1.x), (v2.y - v1.y)); cp.normal.SetV(m_manifold.normal); cp.separation = mp.separation; cp.id.key = idKey; listener.Add(cp); }; i++; }; m_manifoldCount = 1; } else { m_manifoldCount = 0; }; if (listener == null){ return; }; i = 0; while (i < m0.pointCount) { if (persisted[i]){ } else { mp0 = m0.points[i]; cp.position = b1.GetWorldPoint(mp0.localPoint1); v1 = b1.GetLinearVelocityFromLocalPoint(mp0.localPoint1); v2 = b2.GetLinearVelocityFromLocalPoint(mp0.localPoint2); cp.velocity.Set((v2.x - v1.x), (v2.y - v1.y)); cp.normal.SetV(m0.normal); cp.separation = mp0.separation; cp.id.key = mp0.id._key; listener.Remove(cp); }; i++; }; } private function b2CollidePolyAndEdge(manifold:b2Manifold, polygon:b2PolygonShape, xf1:b2XForm, edge:b2EdgeShape, xf2:b2XForm):void{ var tMat:b2Mat22; var tVec1:b2Vec2; var tVec2:b2Vec2; var tX:Number; var tY:Number; var tPoint:b2ManifoldPoint; var ratio:Number; var separation1:Number; var separation2:Number; var dirProj2:Number; manifold.pointCount = 0; tMat = xf2.R; tVec1 = edge.m_v1; var v1X:Number = (xf2.position.x + ((tMat.col1.x * tVec1.x) + (tMat.col2.x * tVec1.y))); var v1Y:Number = (xf2.position.y + ((tMat.col1.y * tVec1.x) + (tMat.col2.y * tVec1.y))); tVec1 = edge.m_v2; var v2X:Number = (xf2.position.x + ((tMat.col1.x * tVec1.x) + (tMat.col2.x * tVec1.y))); var v2Y:Number = (xf2.position.y + ((tMat.col1.y * tVec1.x) + (tMat.col2.y * tVec1.y))); tVec1 = edge.m_normal; var nX:Number = ((tMat.col1.x * tVec1.x) + (tMat.col2.x * tVec1.y)); var nY:Number = ((tMat.col1.y * tVec1.x) + (tMat.col2.y * tVec1.y)); tMat = xf1.R; tX = (v1X - xf1.position.x); tY = (v1Y - xf1.position.y); var v1LocalX:Number = ((tX * tMat.col1.x) + (tY * tMat.col1.y)); var v1LocalY:Number = ((tX * tMat.col2.x) + (tY * tMat.col2.y)); tX = (v2X - xf1.position.x); tY = (v2Y - xf1.position.y); var v2LocalX:Number = ((tX * tMat.col1.x) + (tY * tMat.col1.y)); var v2LocalY:Number = ((tX * tMat.col2.x) + (tY * tMat.col2.y)); var nLocalX:Number = ((nX * tMat.col1.x) + (nY * tMat.col1.y)); var nLocalY:Number = ((nX * tMat.col2.x) + (nY * tMat.col2.y)); var separationIndex1 = -1; var separationMax1:Number = -(Number.MAX_VALUE); var separationIndex2 = -1; var separationMax2:Number = -(Number.MAX_VALUE); var separationMax:Number = -(Number.MAX_VALUE); var separationV1:Boolean; var separationIndex = -1; var vertexCount:int = polygon.m_vertexCount; var vertices:Array = polygon.m_vertices; var normals:Array = polygon.m_normals; var enterStartIndex = -1; var enterEndIndex = -1; var exitStartIndex = -1; var exitEndIndex = -1; var prevSepN:Number = 0; var nextSepN:Number = 0; var enterSepN:Number = 0; var exitSepN:Number = 0; var deepestSepN:Number = Number.MAX_VALUE; tVec1 = vertices[(vertexCount - 1)]; prevSepN = (((tVec1.x - v1LocalX) * nLocalX) + ((tVec1.y - v1LocalY) * nLocalY)); var i:int; while (i < vertexCount) { tVec1 = vertices[i]; tVec2 = normals[i]; separation1 = (((v1LocalX - tVec1.x) * tVec2.x) + ((v1LocalY - tVec1.y) * tVec2.y)); separation2 = (((v2LocalX - tVec1.x) * tVec2.x) + ((v2LocalY - tVec1.y) * tVec2.y)); if (separation2 < separation1){ if (separation2 > separationMax){ separationMax = separation2; separationV1 = false; separationIndex = i; }; } else { if (separation1 > separationMax){ separationMax = separation1; separationV1 = true; separationIndex = i; }; }; if (separation1 > separationMax1){ separationMax1 = separation1; separationIndex1 = i; }; if (separation2 > separationMax2){ separationMax2 = separation2; separationIndex2 = i; }; nextSepN = (((tVec1.x - v1LocalX) * nLocalX) + ((tVec1.y - v1LocalY) * nLocalY)); if ((((nextSepN >= 0)) && ((prevSepN < 0)))){ exitStartIndex = ((i)==0) ? (vertexCount - 1) : (i - 1); exitEndIndex = i; exitSepN = prevSepN; } else { if ((((nextSepN < 0)) && ((prevSepN >= 0)))){ enterStartIndex = ((i)==0) ? (vertexCount - 1) : (i - 1); enterEndIndex = i; enterSepN = nextSepN; }; }; if (nextSepN < deepestSepN){ deepestSepN = nextSepN; }; prevSepN = nextSepN; i++; }; if (enterStartIndex == -1){ return; }; if (separationMax > 0){ return; }; if (((((separationV1) && (edge.m_cornerConvex1))) || (((!(separationV1)) && (edge.m_cornerConvex2))))){ if (separationMax > (deepestSepN + b2Settings.b2_linearSlop)){ if (separationV1){ tMat = xf2.R; tVec1 = edge.m_cornerDir1; tX = ((tMat.col1.x * tVec1.x) + (tMat.col2.x * tVec1.y)); tY = ((tMat.col1.y * tVec1.x) + (tMat.col2.y * tVec1.y)); tMat = xf1.R; v1X = ((tMat.col1.x * tX) + (tMat.col2.x * tY)); v1Y = ((tMat.col1.y * tX) + (tMat.col2.y * tY)); tVec2 = normals[separationIndex1]; if (((tVec2.x * v1X) + (tVec2.y * v1Y)) >= 0){ return; }; } else { tMat = xf2.R; tVec1 = edge.m_cornerDir2; tX = ((tMat.col1.x * tVec1.x) + (tMat.col2.x * tVec1.y)); tY = ((tMat.col1.y * tVec1.x) + (tMat.col2.y * tVec1.y)); tMat = xf1.R; v1X = ((tMat.col1.x * tX) + (tMat.col2.x * tY)); v1Y = ((tMat.col1.y * tX) + (tMat.col2.y * tY)); tVec2 = normals[separationIndex2]; if (((tVec2.x * v1X) + (tVec2.y * v1Y)) <= 0){ return; }; }; tPoint = manifold.points[0]; manifold.pointCount = 1; tMat = xf1.R; tVec2 = normals[separationIndex]; manifold.normal.x = ((tMat.col1.x * tVec2.x) + (tMat.col2.x * tVec2.y)); manifold.normal.y = ((tMat.col1.y * tVec2.x) + (tMat.col2.y * tVec2.y)); tPoint.separation = separationMax; tPoint.id.features.incidentEdge = separationIndex; tPoint.id.features.incidentVertex = b2Collision.b2_nullFeature; tPoint.id.features.referenceEdge = 0; tPoint.id.features.flip = 0; if (separationV1){ tPoint.localPoint1.x = v1LocalX; tPoint.localPoint1.y = v1LocalY; tPoint.localPoint2.x = edge.m_v1.x; tPoint.localPoint2.y = edge.m_v1.y; } else { tPoint.localPoint1.x = v2LocalX; tPoint.localPoint1.y = v2LocalY; tPoint.localPoint2.x = edge.m_v2.x; tPoint.localPoint2.y = edge.m_v2.y; }; return; }; }; manifold.normal.x = -(nX); manifold.normal.y = -(nY); if (enterEndIndex == exitStartIndex){ tPoint = manifold.points[0]; manifold.pointCount = 1; tPoint.id.features.incidentEdge = enterEndIndex; tPoint.id.features.incidentVertex = b2Collision.b2_nullFeature; tPoint.id.features.referenceEdge = 0; tPoint.id.features.flip = 0; tVec1 = vertices[enterEndIndex]; tPoint.localPoint1.x = tVec1.x; tPoint.localPoint1.y = tVec1.y; tMat = xf1.R; tX = ((xf1.position.x + ((tMat.col1.x * tVec1.x) + (tMat.col2.x * tVec1.y))) - xf2.position.x); tY = ((xf1.position.y + ((tMat.col1.y * tVec1.x) + (tMat.col2.y * tVec1.y))) - xf2.position.y); tMat = xf2.R; tPoint.localPoint2.x = ((tX * tMat.col1.x) + (tY * tMat.col1.y)); tPoint.localPoint2.y = ((tX * tMat.col2.x) + (tY * tMat.col2.y)); tPoint.separation = enterSepN; return; }; manifold.pointCount = 2; tX = -(nLocalY); tY = nLocalX; tVec1 = vertices[enterEndIndex]; var dirProj1:Number = ((tX * (tVec1.x - v1LocalX)) + (tY * (tVec1.y - v1LocalY))); exitEndIndex = ((enterEndIndex)==(vertexCount - 1)) ? 0 : (enterEndIndex + 1); tVec1 = vertices[exitStartIndex]; if (exitEndIndex != exitStartIndex){ exitStartIndex = exitEndIndex; exitSepN = ((nLocalX * (tVec1.x - v1LocalX)) + (nLocalY * (tVec1.y - v1LocalY))); }; dirProj2 = ((tX * (tVec1.x - v1LocalX)) + (tY * (tVec1.y - v1LocalY))); tPoint = manifold.points[0]; tPoint.id.features.incidentEdge = enterEndIndex; tPoint.id.features.incidentVertex = b2Collision.b2_nullFeature; tPoint.id.features.referenceEdge = 0; tPoint.id.features.flip = 0; if (dirProj1 > edge.m_length){ tPoint.localPoint1.x = v2LocalX; tPoint.localPoint1.y = v2LocalY; tPoint.localPoint2.x = edge.m_v2.x; tPoint.localPoint2.y = edge.m_v2.y; ratio = ((edge.m_length - dirProj2) / (dirProj1 - dirProj2)); if ((((ratio > (100 * Number.MIN_VALUE))) && ((ratio < 1)))){ tPoint.separation = ((exitSepN * (1 - ratio)) + (enterSepN * ratio)); } else { tPoint.separation = enterSepN; }; } else { tVec1 = vertices[enterEndIndex]; tPoint.localPoint1.x = tVec1.x; tPoint.localPoint1.y = tVec1.y; tMat = xf1.R; tX = ((xf1.position.x + ((tMat.col1.x * tVec1.x) + (tMat.col2.x * tVec1.y))) - xf2.position.x); tY = ((xf1.position.y + ((tMat.col1.y * tVec1.x) + (tMat.col2.y * tVec1.y))) - xf2.position.y); tMat = xf2.R; tPoint.localPoint2.x = ((tX * tMat.col1.x) + (tY * tMat.col1.y)); tPoint.localPoint2.y = ((tX * tMat.col2.x) + (tY * tMat.col2.y)); tPoint.separation = enterSepN; }; tPoint = manifold.points[1]; tPoint.id.features.incidentEdge = exitStartIndex; tPoint.id.features.incidentVertex = b2Collision.b2_nullFeature; tPoint.id.features.referenceEdge = 0; tPoint.id.features.flip = 0; if (dirProj2 < 0){ tPoint.localPoint1.x = v1LocalX; tPoint.localPoint1.y = v1LocalY; tPoint.localPoint2.x = edge.m_v1.x; tPoint.localPoint2.y = edge.m_v1.y; ratio = (-(dirProj1) / (dirProj2 - dirProj1)); if ((((ratio > (100 * Number.MIN_VALUE))) && ((ratio < 1)))){ tPoint.separation = ((enterSepN * (1 - ratio)) + (exitSepN * ratio)); } else { tPoint.separation = exitSepN; }; } else { tVec1 = vertices[exitStartIndex]; tPoint.localPoint1.x = tVec1.x; tPoint.localPoint1.y = tVec1.y; tMat = xf1.R; tX = ((xf1.position.x + ((tMat.col1.x * tVec1.x) + (tMat.col2.x * tVec1.y))) - xf2.position.x); tY = ((xf1.position.y + ((tMat.col1.y * tVec1.x) + (tMat.col2.y * tVec1.y))) - xf2.position.y); tMat = xf2.R; tPoint.localPoint2.x = ((tX * tMat.col1.x) + (tY * tMat.col1.y)); tPoint.localPoint2.y = ((tX * tMat.col2.x) + (tY * tMat.col2.y)); tPoint.separation = exitSepN; }; } override public function GetManifolds():Array{ return (m_manifolds); } public static function Destroy(contact:b2Contact, allocator):void{ } public static function Create(shape1:b2Shape, shape2:b2Shape, allocator):b2Contact{ return (new b2PolyAndEdgeContact(shape1, shape2)); } } }//package Box2D.Dynamics.Contacts
Section 53
//b2PolygonContact (Box2D.Dynamics.Contacts.b2PolygonContact) package Box2D.Dynamics.Contacts { import Box2D.Dynamics.*; import Box2D.Collision.Shapes.*; import Box2D.Collision.*; import Box2D.Common.Math.*; import Box2D.Common.*; public class b2PolygonContact extends b2Contact { private var m_manifolds:Array; private var m0:b2Manifold; private var m_manifold:b2Manifold; private static const s_evalCP:b2ContactPoint = new b2ContactPoint(); public function b2PolygonContact(shape1:b2Shape, shape2:b2Shape):void{ m0 = new b2Manifold(); m_manifolds = [new b2Manifold()]; super(shape1, shape2); m_manifold = m_manifolds[0]; m_manifold.pointCount = 0; } override b2internal function Evaluate(listener:b2ContactListener):void{ var v1:b2Vec2; var v2:b2Vec2; var mp0:b2ManifoldPoint; var cp:b2ContactPoint; var i:int; var mp:b2ManifoldPoint; var found:Boolean; var idKey:uint; var j:int; var b1:b2Body = m_shape1.m_body; var b2:b2Body = m_shape2.m_body; m0.Set(m_manifold); b2Collision.b2CollidePolygons(m_manifold, (m_shape1 as b2PolygonShape), b1.m_xf, (m_shape2 as b2PolygonShape), b2.m_xf); var persisted:Array = [false, false]; cp = s_evalCP; cp.shape1 = m_shape1; cp.shape2 = m_shape2; cp.friction = b2Settings.b2MixFriction(m_shape1.GetFriction(), m_shape2.GetFriction()); cp.restitution = b2Settings.b2MixRestitution(m_shape1.GetRestitution(), m_shape2.GetRestitution()); if (m_manifold.pointCount > 0){ i = 0; while (i < m_manifold.pointCount) { mp = m_manifold.points[i]; mp.normalImpulse = 0; mp.tangentImpulse = 0; found = false; idKey = mp.id._key; j = 0; while (j < m0.pointCount) { if (persisted[j] == true){ } else { mp0 = m0.points[j]; if (mp0.id._key == idKey){ persisted[j] = true; mp.normalImpulse = mp0.normalImpulse; mp.tangentImpulse = mp0.tangentImpulse; found = true; if (listener != null){ cp.position = b1.GetWorldPoint(mp.localPoint1); v1 = b1.GetLinearVelocityFromLocalPoint(mp.localPoint1); v2 = b2.GetLinearVelocityFromLocalPoint(mp.localPoint2); cp.velocity.Set((v2.x - v1.x), (v2.y - v1.y)); cp.normal.SetV(m_manifold.normal); cp.separation = mp.separation; cp.id.key = idKey; listener.Persist(cp); }; break; }; }; j++; }; if ((((found == false)) && (!((listener == null))))){ cp.position = b1.GetWorldPoint(mp.localPoint1); v1 = b1.GetLinearVelocityFromLocalPoint(mp.localPoint1); v2 = b2.GetLinearVelocityFromLocalPoint(mp.localPoint2); cp.velocity.Set((v2.x - v1.x), (v2.y - v1.y)); cp.normal.SetV(m_manifold.normal); cp.separation = mp.separation; cp.id.key = idKey; listener.Add(cp); }; i++; }; m_manifoldCount = 1; } else { m_manifoldCount = 0; }; if (listener == null){ return; }; i = 0; while (i < m0.pointCount) { if (persisted[i]){ } else { mp0 = m0.points[i]; cp.position = b1.GetWorldPoint(mp0.localPoint1); v1 = b1.GetLinearVelocityFromLocalPoint(mp0.localPoint1); v2 = b2.GetLinearVelocityFromLocalPoint(mp0.localPoint2); cp.velocity.Set((v2.x - v1.x), (v2.y - v1.y)); cp.normal.SetV(m0.normal); cp.separation = mp0.separation; cp.id.key = mp0.id._key; listener.Remove(cp); }; i++; }; } override public function GetManifolds():Array{ return (m_manifolds); } public static function Destroy(contact:b2Contact, allocator):void{ } public static function Create(shape1:b2Shape, shape2:b2Shape, allocator):b2Contact{ return (new b2PolygonContact(shape1, shape2)); } } }//package Box2D.Dynamics.Contacts
Section 54
//b2DistanceJoint (Box2D.Dynamics.Joints.b2DistanceJoint) package Box2D.Dynamics.Joints { import Box2D.Dynamics.*; import Box2D.Common.Math.*; import Box2D.Common.*; public class b2DistanceJoint extends b2Joint { private var m_localAnchor1:b2Vec2; private var m_localAnchor2:b2Vec2; private var m_bias:Number; private var m_gamma:Number; private var m_u:b2Vec2; private var m_mass:Number; private var m_impulse:Number; private var m_dampingRatio:Number; private var m_frequencyHz:Number; private var m_length:Number; public function b2DistanceJoint(def:b2DistanceJointDef){ var tMat:b2Mat22; var tX:Number; var tY:Number; m_localAnchor1 = new b2Vec2(); m_localAnchor2 = new b2Vec2(); m_u = new b2Vec2(); super(def); m_localAnchor1.SetV(def.localAnchor1); m_localAnchor2.SetV(def.localAnchor2); m_length = def.length; m_frequencyHz = def.frequencyHz; m_dampingRatio = def.dampingRatio; m_impulse = 0; m_gamma = 0; m_bias = 0; } override public function GetAnchor1():b2Vec2{ return (m_body1.GetWorldPoint(m_localAnchor1)); } override public function GetAnchor2():b2Vec2{ return (m_body2.GetWorldPoint(m_localAnchor2)); } override b2internal function InitVelocityConstraints(step:b2TimeStep):void{ var tMat:b2Mat22; var tX:Number; var b1:b2Body; var b2:b2Body; var r1X:Number; var r1Y:Number; var r2X:Number; var r2Y:Number; var C:Number; var omega:Number; var d:Number; var k:Number; var PX:Number; var PY:Number; b1 = m_body1; b2 = m_body2; tMat = b1.m_xf.R; r1X = (m_localAnchor1.x - b1.m_sweep.localCenter.x); r1Y = (m_localAnchor1.y - b1.m_sweep.localCenter.y); tX = ((tMat.col1.x * r1X) + (tMat.col2.x * r1Y)); r1Y = ((tMat.col1.y * r1X) + (tMat.col2.y * r1Y)); r1X = tX; tMat = b2.m_xf.R; r2X = (m_localAnchor2.x - b2.m_sweep.localCenter.x); r2Y = (m_localAnchor2.y - b2.m_sweep.localCenter.y); tX = ((tMat.col1.x * r2X) + (tMat.col2.x * r2Y)); r2Y = ((tMat.col1.y * r2X) + (tMat.col2.y * r2Y)); r2X = tX; m_u.x = (((b2.m_sweep.c.x + r2X) - b1.m_sweep.c.x) - r1X); m_u.y = (((b2.m_sweep.c.y + r2Y) - b1.m_sweep.c.y) - r1Y); var length:Number = Math.sqrt(((m_u.x * m_u.x) + (m_u.y * m_u.y))); if (length > b2Settings.b2_linearSlop){ m_u.Multiply((1 / length)); } else { m_u.SetZero(); }; var cr1u:Number = ((r1X * m_u.y) - (r1Y * m_u.x)); var cr2u:Number = ((r2X * m_u.y) - (r2Y * m_u.x)); var invMass:Number = (((b1.m_invMass + ((b1.m_invI * cr1u) * cr1u)) + b2.m_invMass) + ((b2.m_invI * cr2u) * cr2u)); m_mass = (1 / invMass); if (m_frequencyHz > 0){ C = (length - m_length); omega = ((2 * Math.PI) * m_frequencyHz); d = (((2 * m_mass) * m_dampingRatio) * omega); k = ((m_mass * omega) * omega); m_gamma = (1 / (step.dt * (d + (step.dt * k)))); m_bias = (((C * step.dt) * k) * m_gamma); m_mass = (1 / (invMass + m_gamma)); }; if (step.warmStarting){ m_impulse = (m_impulse * step.dtRatio); PX = (m_impulse * m_u.x); PY = (m_impulse * m_u.y); b1.m_linearVelocity.x = (b1.m_linearVelocity.x - (b1.m_invMass * PX)); b1.m_linearVelocity.y = (b1.m_linearVelocity.y - (b1.m_invMass * PY)); b1.m_angularVelocity = (b1.m_angularVelocity - (b1.m_invI * ((r1X * PY) - (r1Y * PX)))); b2.m_linearVelocity.x = (b2.m_linearVelocity.x + (b2.m_invMass * PX)); b2.m_linearVelocity.y = (b2.m_linearVelocity.y + (b2.m_invMass * PY)); b2.m_angularVelocity = (b2.m_angularVelocity + (b2.m_invI * ((r2X * PY) - (r2Y * PX)))); } else { m_impulse = 0; }; } override public function GetReactionTorque(inv_dt:Number):Number{ return (0); } override public function GetReactionForce(inv_dt:Number):b2Vec2{ return (new b2Vec2(((inv_dt * m_impulse) * m_u.x), ((inv_dt * m_impulse) * m_u.y))); } override b2internal function SolvePositionConstraints(baumgarte:Number):Boolean{ var tMat:b2Mat22; if (m_frequencyHz > 0){ return (true); }; var b1:b2Body = m_body1; var b2:b2Body = m_body2; tMat = b1.m_xf.R; var r1X:Number = (m_localAnchor1.x - b1.m_sweep.localCenter.x); var r1Y:Number = (m_localAnchor1.y - b1.m_sweep.localCenter.y); var tX:Number = ((tMat.col1.x * r1X) + (tMat.col2.x * r1Y)); r1Y = ((tMat.col1.y * r1X) + (tMat.col2.y * r1Y)); r1X = tX; tMat = b2.m_xf.R; var r2X:Number = (m_localAnchor2.x - b2.m_sweep.localCenter.x); var r2Y:Number = (m_localAnchor2.y - b2.m_sweep.localCenter.y); tX = ((tMat.col1.x * r2X) + (tMat.col2.x * r2Y)); r2Y = ((tMat.col1.y * r2X) + (tMat.col2.y * r2Y)); r2X = tX; var dX:Number = (((b2.m_sweep.c.x + r2X) - b1.m_sweep.c.x) - r1X); var dY:Number = (((b2.m_sweep.c.y + r2Y) - b1.m_sweep.c.y) - r1Y); var length:Number = Math.sqrt(((dX * dX) + (dY * dY))); dX = (dX / length); dY = (dY / length); var C:Number = (length - m_length); C = b2Math.b2Clamp(C, -(b2Settings.b2_maxLinearCorrection), b2Settings.b2_maxLinearCorrection); var impulse:Number = (-(m_mass) * C); m_u.Set(dX, dY); var PX:Number = (impulse * m_u.x); var PY:Number = (impulse * m_u.y); b1.m_sweep.c.x = (b1.m_sweep.c.x - (b1.m_invMass * PX)); b1.m_sweep.c.y = (b1.m_sweep.c.y - (b1.m_invMass * PY)); b1.m_sweep.a = (b1.m_sweep.a - (b1.m_invI * ((r1X * PY) - (r1Y * PX)))); b2.m_sweep.c.x = (b2.m_sweep.c.x + (b2.m_invMass * PX)); b2.m_sweep.c.y = (b2.m_sweep.c.y + (b2.m_invMass * PY)); b2.m_sweep.a = (b2.m_sweep.a + (b2.m_invI * ((r2X * PY) - (r2Y * PX)))); b1.SynchronizeTransform(); b2.SynchronizeTransform(); return ((b2Math.b2Abs(C) < b2Settings.b2_linearSlop)); } override b2internal function SolveVelocityConstraints(step:b2TimeStep):void{ var tMat:b2Mat22; var b1:b2Body = m_body1; var b2:b2Body = m_body2; tMat = b1.m_xf.R; var r1X:Number = (m_localAnchor1.x - b1.m_sweep.localCenter.x); var r1Y:Number = (m_localAnchor1.y - b1.m_sweep.localCenter.y); var tX:Number = ((tMat.col1.x * r1X) + (tMat.col2.x * r1Y)); r1Y = ((tMat.col1.y * r1X) + (tMat.col2.y * r1Y)); r1X = tX; tMat = b2.m_xf.R; var r2X:Number = (m_localAnchor2.x - b2.m_sweep.localCenter.x); var r2Y:Number = (m_localAnchor2.y - b2.m_sweep.localCenter.y); tX = ((tMat.col1.x * r2X) + (tMat.col2.x * r2Y)); r2Y = ((tMat.col1.y * r2X) + (tMat.col2.y * r2Y)); r2X = tX; var v1X:Number = (b1.m_linearVelocity.x + (-(b1.m_angularVelocity) * r1Y)); var v1Y:Number = (b1.m_linearVelocity.y + (b1.m_angularVelocity * r1X)); var v2X:Number = (b2.m_linearVelocity.x + (-(b2.m_angularVelocity) * r2Y)); var v2Y:Number = (b2.m_linearVelocity.y + (b2.m_angularVelocity * r2X)); var Cdot:Number = ((m_u.x * (v2X - v1X)) + (m_u.y * (v2Y - v1Y))); var impulse:Number = (-(m_mass) * ((Cdot + m_bias) + (m_gamma * m_impulse))); m_impulse = (m_impulse + impulse); var PX:Number = (impulse * m_u.x); var PY:Number = (impulse * m_u.y); b1.m_linearVelocity.x = (b1.m_linearVelocity.x - (b1.m_invMass * PX)); b1.m_linearVelocity.y = (b1.m_linearVelocity.y - (b1.m_invMass * PY)); b1.m_angularVelocity = (b1.m_angularVelocity - (b1.m_invI * ((r1X * PY) - (r1Y * PX)))); b2.m_linearVelocity.x = (b2.m_linearVelocity.x + (b2.m_invMass * PX)); b2.m_linearVelocity.y = (b2.m_linearVelocity.y + (b2.m_invMass * PY)); b2.m_angularVelocity = (b2.m_angularVelocity + (b2.m_invI * ((r2X * PY) - (r2Y * PX)))); } } }//package Box2D.Dynamics.Joints
Section 55
//b2DistanceJointDef (Box2D.Dynamics.Joints.b2DistanceJointDef) package Box2D.Dynamics.Joints { import Box2D.Dynamics.*; import Box2D.Common.Math.*; public class b2DistanceJointDef extends b2JointDef { public var localAnchor1:b2Vec2; public var length:Number; public var dampingRatio:Number; public var localAnchor2:b2Vec2; public var frequencyHz:Number; public function b2DistanceJointDef(){ localAnchor1 = new b2Vec2(); localAnchor2 = new b2Vec2(); super(); type = b2Joint.e_distanceJoint; length = 1; frequencyHz = 0; dampingRatio = 0; } public function Initialize(b1:b2Body, b2:b2Body, anchor1:b2Vec2, anchor2:b2Vec2):void{ body1 = b1; body2 = b2; localAnchor1.SetV(body1.GetLocalPoint(anchor1)); localAnchor2.SetV(body2.GetLocalPoint(anchor2)); var dX:Number = (anchor2.x - anchor1.x); var dY:Number = (anchor2.y - anchor1.y); length = Math.sqrt(((dX * dX) + (dY * dY))); frequencyHz = 0; dampingRatio = 0; } } }//package Box2D.Dynamics.Joints
Section 56
//b2GearJoint (Box2D.Dynamics.Joints.b2GearJoint) package Box2D.Dynamics.Joints { import Box2D.Dynamics.*; import Box2D.Common.Math.*; import Box2D.Common.*; public class b2GearJoint extends b2Joint { private var m_ground2:b2Body; private var m_groundAnchor1:b2Vec2; private var m_groundAnchor2:b2Vec2; private var m_localAnchor1:b2Vec2; private var m_localAnchor2:b2Vec2; private var m_ratio:Number; private var m_revolute2:b2RevoluteJoint; private var m_mass:Number; private var m_impulse:Number; private var m_prismatic2:b2PrismaticJoint; private var m_ground1:b2Body; private var m_revolute1:b2RevoluteJoint; private var m_prismatic1:b2PrismaticJoint; private var m_constant:Number; private var m_J:b2Jacobian; public function b2GearJoint(def:b2GearJointDef){ var coordinate1:Number; var coordinate2:Number; m_groundAnchor1 = new b2Vec2(); m_groundAnchor2 = new b2Vec2(); m_localAnchor1 = new b2Vec2(); m_localAnchor2 = new b2Vec2(); m_J = new b2Jacobian(); super(def); var type1:int = def.joint1.m_type; var type2:int = def.joint2.m_type; m_revolute1 = null; m_prismatic1 = null; m_revolute2 = null; m_prismatic2 = null; m_ground1 = def.joint1.m_body1; m_body1 = def.joint1.m_body2; if (type1 == b2Joint.e_revoluteJoint){ m_revolute1 = (def.joint1 as b2RevoluteJoint); m_groundAnchor1.SetV(m_revolute1.m_localAnchor1); m_localAnchor1.SetV(m_revolute1.m_localAnchor2); coordinate1 = m_revolute1.GetJointAngle(); } else { m_prismatic1 = (def.joint1 as b2PrismaticJoint); m_groundAnchor1.SetV(m_prismatic1.m_localAnchor1); m_localAnchor1.SetV(m_prismatic1.m_localAnchor2); coordinate1 = m_prismatic1.GetJointTranslation(); }; m_ground2 = def.joint2.m_body1; m_body2 = def.joint2.m_body2; if (type2 == b2Joint.e_revoluteJoint){ m_revolute2 = (def.joint2 as b2RevoluteJoint); m_groundAnchor2.SetV(m_revolute2.m_localAnchor1); m_localAnchor2.SetV(m_revolute2.m_localAnchor2); coordinate2 = m_revolute2.GetJointAngle(); } else { m_prismatic2 = (def.joint2 as b2PrismaticJoint); m_groundAnchor2.SetV(m_prismatic2.m_localAnchor1); m_localAnchor2.SetV(m_prismatic2.m_localAnchor2); coordinate2 = m_prismatic2.GetJointTranslation(); }; m_ratio = def.ratio; m_constant = (coordinate1 + (m_ratio * coordinate2)); m_impulse = 0; } override public function GetAnchor1():b2Vec2{ return (m_body1.GetWorldPoint(m_localAnchor1)); } override public function GetAnchor2():b2Vec2{ return (m_body2.GetWorldPoint(m_localAnchor2)); } override b2internal function InitVelocityConstraints(step:b2TimeStep):void{ var ugX:Number; var ugY:Number; var rX:Number; var rY:Number; var tMat:b2Mat22; var tVec:b2Vec2; var crug:Number; var tX:Number; var g1:b2Body = m_ground1; var g2:b2Body = m_ground2; var b1:b2Body = m_body1; var b2:b2Body = m_body2; var K:Number = 0; m_J.SetZero(); if (m_revolute1){ m_J.angular1 = -1; K = (K + b1.m_invI); } else { tMat = g1.m_xf.R; tVec = m_prismatic1.m_localXAxis1; ugX = ((tMat.col1.x * tVec.x) + (tMat.col2.x * tVec.y)); ugY = ((tMat.col1.y * tVec.x) + (tMat.col2.y * tVec.y)); tMat = b1.m_xf.R; rX = (m_localAnchor1.x - b1.m_sweep.localCenter.x); rY = (m_localAnchor1.y - b1.m_sweep.localCenter.y); tX = ((tMat.col1.x * rX) + (tMat.col2.x * rY)); rY = ((tMat.col1.y * rX) + (tMat.col2.y * rY)); rX = tX; crug = ((rX * ugY) - (rY * ugX)); m_J.linear1.Set(-(ugX), -(ugY)); m_J.angular1 = -(crug); K = (K + (b1.m_invMass + ((b1.m_invI * crug) * crug))); }; if (m_revolute2){ m_J.angular2 = -(m_ratio); K = (K + ((m_ratio * m_ratio) * b2.m_invI)); } else { tMat = g2.m_xf.R; tVec = m_prismatic2.m_localXAxis1; ugX = ((tMat.col1.x * tVec.x) + (tMat.col2.x * tVec.y)); ugY = ((tMat.col1.y * tVec.x) + (tMat.col2.y * tVec.y)); tMat = b2.m_xf.R; rX = (m_localAnchor2.x - b2.m_sweep.localCenter.x); rY = (m_localAnchor2.y - b2.m_sweep.localCenter.y); tX = ((tMat.col1.x * rX) + (tMat.col2.x * rY)); rY = ((tMat.col1.y * rX) + (tMat.col2.y * rY)); rX = tX; crug = ((rX * ugY) - (rY * ugX)); m_J.linear2.Set((-(m_ratio) * ugX), (-(m_ratio) * ugY)); m_J.angular2 = (-(m_ratio) * crug); K = (K + ((m_ratio * m_ratio) * (b2.m_invMass + ((b2.m_invI * crug) * crug)))); }; m_mass = (1 / K); if (step.warmStarting){ b1.m_linearVelocity.x = (b1.m_linearVelocity.x + ((b1.m_invMass * m_impulse) * m_J.linear1.x)); b1.m_linearVelocity.y = (b1.m_linearVelocity.y + ((b1.m_invMass * m_impulse) * m_J.linear1.y)); b1.m_angularVelocity = (b1.m_angularVelocity + ((b1.m_invI * m_impulse) * m_J.angular1)); b2.m_linearVelocity.x = (b2.m_linearVelocity.x + ((b2.m_invMass * m_impulse) * m_J.linear2.x)); b2.m_linearVelocity.y = (b2.m_linearVelocity.y + ((b2.m_invMass * m_impulse) * m_J.linear2.y)); b2.m_angularVelocity = (b2.m_angularVelocity + ((b2.m_invI * m_impulse) * m_J.angular2)); } else { m_impulse = 0; }; } override public function GetReactionTorque(inv_dt:Number):Number{ var tMat:b2Mat22 = m_body2.m_xf.R; var rX:Number = (m_localAnchor1.x - m_body2.m_sweep.localCenter.x); var rY:Number = (m_localAnchor1.y - m_body2.m_sweep.localCenter.y); var tX:Number = ((tMat.col1.x * rX) + (tMat.col2.x * rY)); rY = ((tMat.col1.y * rX) + (tMat.col2.y * rY)); rX = tX; var PX:Number = (m_impulse * m_J.linear2.x); var PY:Number = (m_impulse * m_J.linear2.y); return ((inv_dt * (((m_impulse * m_J.angular2) - (rX * PY)) + (rY * PX)))); } override public function GetReactionForce(inv_dt:Number):b2Vec2{ return (new b2Vec2(((inv_dt * m_impulse) * m_J.linear2.x), ((inv_dt * m_impulse) * m_J.linear2.y))); } override b2internal function SolvePositionConstraints(baumgarte:Number):Boolean{ var coordinate1:Number; var coordinate2:Number; var linearError:Number = 0; var b1:b2Body = m_body1; var b2:b2Body = m_body2; if (m_revolute1){ coordinate1 = m_revolute1.GetJointAngle(); } else { coordinate1 = m_prismatic1.GetJointTranslation(); }; if (m_revolute2){ coordinate2 = m_revolute2.GetJointAngle(); } else { coordinate2 = m_prismatic2.GetJointTranslation(); }; var C:Number = (m_constant - (coordinate1 + (m_ratio * coordinate2))); var impulse:Number = (-(m_mass) * C); b1.m_sweep.c.x = (b1.m_sweep.c.x + ((b1.m_invMass * impulse) * m_J.linear1.x)); b1.m_sweep.c.y = (b1.m_sweep.c.y + ((b1.m_invMass * impulse) * m_J.linear1.y)); b1.m_sweep.a = (b1.m_sweep.a + ((b1.m_invI * impulse) * m_J.angular1)); b2.m_sweep.c.x = (b2.m_sweep.c.x + ((b2.m_invMass * impulse) * m_J.linear2.x)); b2.m_sweep.c.y = (b2.m_sweep.c.y + ((b2.m_invMass * impulse) * m_J.linear2.y)); b2.m_sweep.a = (b2.m_sweep.a + ((b2.m_invI * impulse) * m_J.angular2)); b1.SynchronizeTransform(); b2.SynchronizeTransform(); return ((linearError < b2Settings.b2_linearSlop)); } public function GetRatio():Number{ return (m_ratio); } override b2internal function SolveVelocityConstraints(step:b2TimeStep):void{ var b1:b2Body = m_body1; var b2:b2Body = m_body2; var Cdot:Number = m_J.Compute(b1.m_linearVelocity, b1.m_angularVelocity, b2.m_linearVelocity, b2.m_angularVelocity); var impulse:Number = (-(m_mass) * Cdot); m_impulse = (m_impulse + impulse); b1.m_linearVelocity.x = (b1.m_linearVelocity.x + ((b1.m_invMass * impulse) * m_J.linear1.x)); b1.m_linearVelocity.y = (b1.m_linearVelocity.y + ((b1.m_invMass * impulse) * m_J.linear1.y)); b1.m_angularVelocity = (b1.m_angularVelocity + ((b1.m_invI * impulse) * m_J.angular1)); b2.m_linearVelocity.x = (b2.m_linearVelocity.x + ((b2.m_invMass * impulse) * m_J.linear2.x)); b2.m_linearVelocity.y = (b2.m_linearVelocity.y + ((b2.m_invMass * impulse) * m_J.linear2.y)); b2.m_angularVelocity = (b2.m_angularVelocity + ((b2.m_invI * impulse) * m_J.angular2)); } } }//package Box2D.Dynamics.Joints
Section 57
//b2GearJointDef (Box2D.Dynamics.Joints.b2GearJointDef) package Box2D.Dynamics.Joints { public class b2GearJointDef extends b2JointDef { public var joint1:b2Joint; public var joint2:b2Joint; public var ratio:Number; public function b2GearJointDef(){ super(); type = b2Joint.e_gearJoint; joint1 = null; joint2 = null; ratio = 1; } } }//package Box2D.Dynamics.Joints
Section 58
//b2Jacobian (Box2D.Dynamics.Joints.b2Jacobian) package Box2D.Dynamics.Joints { import Box2D.Common.Math.*; public class b2Jacobian { public var linear1:b2Vec2; public var linear2:b2Vec2; public var angular1:Number; public var angular2:Number; public function b2Jacobian(){ linear1 = new b2Vec2(); linear2 = new b2Vec2(); super(); } public function Set(x1:b2Vec2, a1:Number, x2:b2Vec2, a2:Number):void{ linear1.SetV(x1); angular1 = a1; linear2.SetV(x2); angular2 = a2; } public function SetZero():void{ linear1.SetZero(); angular1 = 0; linear2.SetZero(); angular2 = 0; } public function Compute(x1:b2Vec2, a1:Number, x2:b2Vec2, a2:Number):Number{ return ((((((linear1.x * x1.x) + (linear1.y * x1.y)) + (angular1 * a1)) + ((linear2.x * x2.x) + (linear2.y * x2.y))) + (angular2 * a2))); } } }//package Box2D.Dynamics.Joints
Section 59
//b2Joint (Box2D.Dynamics.Joints.b2Joint) package Box2D.Dynamics.Joints { import Box2D.Dynamics.*; import Box2D.Common.Math.*; import Box2D.Common.*; public class b2Joint { b2internal var m_islandFlag:Boolean; b2internal var m_collideConnected:Boolean; b2internal var m_prev:b2Joint; b2internal var m_type:int; b2internal var m_next:b2Joint; b2internal var m_node1:b2JointEdge; b2internal var m_node2:b2JointEdge; b2internal var m_localCenter1:b2Vec2; b2internal var m_localCenter2:b2Vec2; b2internal var m_invMass1:Number; b2internal var m_invI2:Number; b2internal var m_invMass2:Number; private var m_userData; b2internal var m_body1:b2Body; b2internal var m_body2:b2Body; b2internal var m_invI1:Number; b2internal static const e_prismaticJoint:int = 2; b2internal static const e_equalLimits:int = 3; b2internal static const e_lineJoint:int = 7; b2internal static const e_gearJoint:int = 6; b2internal static const e_atUpperLimit:int = 2; b2internal static const e_atLowerLimit:int = 1; b2internal static const e_revoluteJoint:int = 1; b2internal static const e_inactiveLimit:int = 0; b2internal static const e_pulleyJoint:int = 4; b2internal static const e_unknownJoint:int = 0; b2internal static const e_distanceJoint:int = 3; b2internal static const e_mouseJoint:int = 5; public function b2Joint(def:b2JointDef){ m_node1 = new b2JointEdge(); m_node2 = new b2JointEdge(); m_localCenter1 = new b2Vec2(); m_localCenter2 = new b2Vec2(); super(); m_type = def.type; m_prev = null; m_next = null; m_body1 = def.body1; m_body2 = def.body2; m_collideConnected = def.collideConnected; m_islandFlag = false; m_userData = def.userData; } public function GetBody2():b2Body{ return (m_body2); } b2internal function ComputeXForm(xf:b2XForm, center:b2Vec2, localCenter:b2Vec2, angle:Number):void{ xf.R.Set(angle); xf.position.SetV(b2Math.SubtractVV(center, b2Math.b2MulMV(xf.R, localCenter))); } public function GetAnchor1():b2Vec2{ return (null); } public function GetAnchor2():b2Vec2{ return (null); } public function GetNext():b2Joint{ return (m_next); } public function GetType():int{ return (m_type); } b2internal function InitVelocityConstraints(step:b2TimeStep):void{ } public function GetReactionTorque(inv_dt:Number):Number{ return (0); } public function GetUserData(){ return (m_userData); } public function GetReactionForce(inv_dt:Number):b2Vec2{ return (null); } b2internal function SolvePositionConstraints(baumgarte:Number):Boolean{ return (false); } public function SetUserData(data):void{ m_userData = data; } public function GetBody1():b2Body{ return (m_body1); } b2internal function SolveVelocityConstraints(step:b2TimeStep):void{ } b2internal static function Destroy(joint:b2Joint, allocator):void{ } b2internal static function Create(def:b2JointDef, allocator):b2Joint{ var joint:b2Joint; switch (def.type){ case e_distanceJoint: joint = new b2DistanceJoint((def as b2DistanceJointDef)); break; case e_mouseJoint: joint = new b2MouseJoint((def as b2MouseJointDef)); break; case e_prismaticJoint: joint = new b2PrismaticJoint((def as b2PrismaticJointDef)); break; case e_revoluteJoint: joint = new b2RevoluteJoint((def as b2RevoluteJointDef)); break; case e_pulleyJoint: joint = new b2PulleyJoint((def as b2PulleyJointDef)); break; case e_gearJoint: joint = new b2GearJoint((def as b2GearJointDef)); break; case e_lineJoint: joint = new b2LineJoint((def as b2LineJointDef)); break; default: break; }; return (joint); } } }//package Box2D.Dynamics.Joints
Section 60
//b2JointDef (Box2D.Dynamics.Joints.b2JointDef) package Box2D.Dynamics.Joints { import Box2D.Dynamics.*; public class b2JointDef { public var body2:b2Body; public var type:int; public var userData; public var collideConnected:Boolean; public var body1:b2Body; public function b2JointDef(){ super(); type = b2Joint.e_unknownJoint; userData = null; body1 = null; body2 = null; collideConnected = false; } } }//package Box2D.Dynamics.Joints
Section 61
//b2JointEdge (Box2D.Dynamics.Joints.b2JointEdge) package Box2D.Dynamics.Joints { import Box2D.Dynamics.*; public class b2JointEdge { public var other:b2Body; public var next:b2JointEdge; public var prev:b2JointEdge; public var joint:b2Joint; public function b2JointEdge(){ super(); } } }//package Box2D.Dynamics.Joints
Section 62
//b2LineJoint (Box2D.Dynamics.Joints.b2LineJoint) package Box2D.Dynamics.Joints { import Box2D.Dynamics.*; import Box2D.Common.Math.*; import Box2D.Common.*; public class b2LineJoint extends b2Joint { private var m_a1:Number; private var m_a2:Number; private var m_perp:b2Vec2; private var m_lowerTranslation:Number; b2internal var m_localXAxis1:b2Vec2; private var m_impulse:b2Vec2; private var m_enableLimit:Boolean; private var m_maxMotorForce:Number; private var m_localYAxis1:b2Vec2; private var m_s2:Number; private var m_axis:b2Vec2; private var m_motorMass:Number; private var m_s1:Number; private var m_upperTranslation:Number; b2internal var m_localAnchor1:b2Vec2; b2internal var m_localAnchor2:b2Vec2; private var m_limitState:int; private var m_motorImpulse:Number; private var m_motorSpeed:Number; private var m_enableMotor:Boolean; private var m_K:b2Mat22; public function b2LineJoint(def:b2LineJointDef){ var tMat:b2Mat22; var tX:Number; var tY:Number; m_localAnchor1 = new b2Vec2(); m_localAnchor2 = new b2Vec2(); m_localXAxis1 = new b2Vec2(); m_localYAxis1 = new b2Vec2(); m_axis = new b2Vec2(); m_perp = new b2Vec2(); m_K = new b2Mat22(); m_impulse = new b2Vec2(); super(def); m_localAnchor1.SetV(def.localAnchor1); m_localAnchor2.SetV(def.localAnchor2); m_localXAxis1.SetV(def.localAxis1); m_localYAxis1.x = -(m_localXAxis1.y); m_localYAxis1.y = m_localXAxis1.x; m_impulse.SetZero(); m_motorMass = 0; m_motorImpulse = 0; m_lowerTranslation = def.lowerTranslation; m_upperTranslation = def.upperTranslation; m_maxMotorForce = def.maxMotorForce; m_motorSpeed = def.motorSpeed; m_enableLimit = def.enableLimit; m_enableMotor = def.enableMotor; m_limitState = e_inactiveLimit; m_axis.SetZero(); m_perp.SetZero(); } override b2internal function SolveVelocityConstraints(step:b2TimeStep):void{ var PX:Number; var PY:Number; var L1:Number; var L2:Number; var Cdot:Number; var impulse:Number; var oldImpulse:Number; var maxImpulse:Number; var Cdot2:Number; var f1:b2Vec2; var df:b2Vec2; var b:Number; var f2r:Number; var df2:Number; var b1:b2Body = m_body1; var b2:b2Body = m_body2; var v1:b2Vec2 = b1.m_linearVelocity; var w1:Number = b1.m_angularVelocity; var v2:b2Vec2 = b2.m_linearVelocity; var w2:Number = b2.m_angularVelocity; if (((m_enableMotor) && (!((m_limitState == e_equalLimits))))){ Cdot = ((((m_axis.x * (v2.x - v1.x)) + (m_axis.y * (v2.y - v1.y))) + (m_a2 * w2)) - (m_a1 * w1)); impulse = (m_motorMass * (m_motorSpeed - Cdot)); oldImpulse = m_motorImpulse; maxImpulse = (step.dt * m_maxMotorForce); m_motorImpulse = b2Math.b2Clamp((m_motorImpulse + impulse), -(maxImpulse), maxImpulse); impulse = (m_motorImpulse - oldImpulse); PX = (impulse * m_axis.x); PY = (impulse * m_axis.y); L1 = (impulse * m_a1); L2 = (impulse * m_a2); v1.x = (v1.x - (m_invMass1 * PX)); v1.y = (v1.y - (m_invMass1 * PY)); w1 = (w1 - (m_invI1 * L1)); v2.x = (v2.x + (m_invMass2 * PX)); v2.y = (v2.y + (m_invMass2 * PY)); w2 = (w2 + (m_invI2 * L2)); }; var Cdot1:Number = ((((m_perp.x * (v2.x - v1.x)) + (m_perp.y * (v2.y - v1.y))) + (m_s2 * w2)) - (m_s1 * w1)); if (((m_enableLimit) && (!((m_limitState == e_inactiveLimit))))){ Cdot2 = ((((m_axis.x * (v2.x - v1.x)) + (m_axis.y * (v2.y - v1.y))) + (m_a2 * w2)) - (m_a1 * w1)); f1 = m_impulse.Copy(); df = m_K.Solve(new b2Vec2(), -(Cdot1), -(Cdot2)); m_impulse.Add(df); if (m_limitState == e_atLowerLimit){ m_impulse.y = b2Math.b2Max(m_impulse.y, 0); } else { if (m_limitState == e_atUpperLimit){ m_impulse.y = b2Math.b2Min(m_impulse.y, 0); }; }; b = (-(Cdot1) - ((m_impulse.y - f1.y) * m_K.col2.x)); f2r = ((b / m_K.col1.x) + f1.x); m_impulse.x = f2r; df.x = (m_impulse.x - f1.x); df.y = (m_impulse.y - f1.y); PX = ((df.x * m_perp.x) + (df.y * m_axis.x)); PY = ((df.x * m_perp.y) + (df.y * m_axis.y)); L1 = ((df.x * m_s1) + (df.y * m_a1)); L2 = ((df.x * m_s2) + (df.y * m_a2)); v1.x = (v1.x - (m_invMass1 * PX)); v1.y = (v1.y - (m_invMass1 * PY)); w1 = (w1 - (m_invI1 * L1)); v2.x = (v2.x + (m_invMass2 * PX)); v2.y = (v2.y + (m_invMass2 * PY)); w2 = (w2 + (m_invI2 * L2)); } else { df2 = (-(Cdot1) / m_K.col1.x); m_impulse.x = (m_impulse.x + df2); PX = (df2 * m_perp.x); PY = (df2 * m_perp.y); L1 = (df2 * m_s1); L2 = (df2 * m_s2); v1.x = (v1.x - (m_invMass1 * PX)); v1.y = (v1.y - (m_invMass1 * PY)); w1 = (w1 - (m_invI1 * L1)); v2.x = (v2.x + (m_invMass2 * PX)); v2.y = (v2.y + (m_invMass2 * PY)); w2 = (w2 + (m_invI2 * L2)); }; b1.m_linearVelocity.SetV(v1); b1.m_angularVelocity = w1; b2.m_linearVelocity.SetV(v2); b2.m_angularVelocity = w2; } override public function GetAnchor1():b2Vec2{ return (m_body1.GetWorldPoint(m_localAnchor1)); } override public function GetAnchor2():b2Vec2{ return (m_body2.GetWorldPoint(m_localAnchor2)); } public function GetUpperLimit():Number{ return (m_upperTranslation); } public function GetLowerLimit():Number{ return (m_lowerTranslation); } public function EnableMotor(flag:Boolean):void{ m_body1.WakeUp(); m_body2.WakeUp(); m_enableMotor = flag; } public function GetJointTranslation():Number{ var tMat:b2Mat22; var b1:b2Body = m_body1; var b2:b2Body = m_body2; var p1:b2Vec2 = b1.GetWorldPoint(m_localAnchor1); var p2:b2Vec2 = b2.GetWorldPoint(m_localAnchor2); var dX:Number = (p2.x - p1.x); var dY:Number = (p2.y - p1.y); var axis:b2Vec2 = b1.GetWorldVector(m_localXAxis1); var translation:Number = ((axis.x * dX) + (axis.y * dY)); return (translation); } public function GetMotorSpeed():Number{ return (m_motorSpeed); } override public function GetReactionForce(inv_dt:Number):b2Vec2{ return (new b2Vec2((inv_dt * ((m_impulse.x * m_perp.x) + ((m_motorImpulse + m_impulse.y) * m_axis.x))), (inv_dt * ((m_impulse.x * m_perp.y) + ((m_motorImpulse + m_impulse.y) * m_axis.y))))); } override b2internal function SolvePositionConstraints(baumgarte:Number):Boolean{ var limitC:Number; var oldLimitImpulse:Number; var tMat:b2Mat22; var tX:Number; var m1:Number; var m2:Number; var i1:Number; var i2:Number; var translation:Number; var k11:Number; var impulse1:Number; var b1:b2Body = m_body1; var b2:b2Body = m_body2; var c1:b2Vec2 = b1.m_sweep.c; var a1:Number = b1.m_sweep.a; var c2:b2Vec2 = b2.m_sweep.c; var a2:Number = b2.m_sweep.a; var linearError:Number = 0; var angularError:Number = 0; var active:Boolean; var C2:Number = 0; var R1:b2Mat22 = new b2Mat22(a1); var R2:b2Mat22 = new b2Mat22(a2); tMat = R1; var r1X:Number = (m_localAnchor1.x - m_localCenter1.x); var r1Y:Number = (m_localAnchor1.y - m_localCenter1.y); tX = ((tMat.col1.x * r1X) + (tMat.col2.x * r1Y)); r1Y = ((tMat.col1.y * r1X) + (tMat.col2.y * r1Y)); r1X = tX; tMat = R2; var r2X:Number = (m_localAnchor2.x - m_localCenter2.x); var r2Y:Number = (m_localAnchor2.y - m_localCenter2.y); tX = ((tMat.col1.x * r2X) + (tMat.col2.x * r2Y)); r2Y = ((tMat.col1.y * r2X) + (tMat.col2.y * r2Y)); r2X = tX; var dX:Number = (((c2.x + r2X) - c1.x) - r1X); var dY:Number = (((c2.y + r2Y) - c1.y) - r1Y); if (m_enableLimit){ m_axis = b2Math.b2MulMV(R1, m_localXAxis1); m_a1 = (((dX + r1X) * m_axis.y) - ((dY + r1Y) * m_axis.x)); m_a2 = ((r2X * m_axis.y) - (r2Y * m_axis.x)); translation = ((m_axis.x * dX) + (m_axis.y * dY)); if (b2Math.b2Abs((m_upperTranslation - m_lowerTranslation)) < (2 * b2Settings.b2_linearSlop)){ C2 = b2Math.b2Clamp(translation, -(b2Settings.b2_maxLinearCorrection), b2Settings.b2_maxLinearCorrection); linearError = b2Math.b2Abs(translation); active = true; } else { if (translation <= m_lowerTranslation){ C2 = b2Math.b2Clamp(((translation - m_lowerTranslation) + b2Settings.b2_linearSlop), -(b2Settings.b2_maxLinearCorrection), 0); linearError = (m_lowerTranslation - translation); active = true; } else { if (translation >= m_upperTranslation){ C2 = b2Math.b2Clamp(((translation - m_upperTranslation) + b2Settings.b2_linearSlop), 0, b2Settings.b2_maxLinearCorrection); linearError = (translation - m_upperTranslation); active = true; }; }; }; }; m_perp = b2Math.b2MulMV(R1, m_localYAxis1); m_s1 = (((dX + r1X) * m_perp.y) - ((dY + r1Y) * m_perp.x)); m_s2 = ((r2X * m_perp.y) - (r2Y * m_perp.x)); var impulse:b2Vec2 = new b2Vec2(); var C1:Number = ((m_perp.x * dX) + (m_perp.y * dY)); linearError = b2Math.b2Max(linearError, b2Math.b2Abs(C1)); angularError = 0; if (active){ m1 = m_invMass1; m2 = m_invMass2; i1 = m_invI1; i2 = m_invI2; m_K.col1.x = (((m1 + m2) + ((i1 * m_s1) * m_s1)) + ((i2 * m_s2) * m_s2)); m_K.col1.y = (((i1 * m_s1) * m_a1) + ((i2 * m_s2) * m_a2)); m_K.col2.x = m_K.col1.y; m_K.col2.y = (((m1 + m2) + ((i1 * m_a1) * m_a1)) + ((i2 * m_a2) * m_a2)); m_K.Solve(impulse, -(C1), -(C2)); } else { m1 = m_invMass1; m2 = m_invMass2; i1 = m_invI1; i2 = m_invI2; k11 = (((m1 + m2) + ((i1 * m_s1) * m_s1)) + ((i2 * m_s2) * m_s2)); impulse1 = (-(C1) / k11); impulse.x = impulse1; impulse.y = 0; }; var PX:Number = ((impulse.x * m_perp.x) + (impulse.y * m_axis.x)); var PY:Number = ((impulse.x * m_perp.y) + (impulse.y * m_axis.y)); var L1:Number = ((impulse.x * m_s1) + (impulse.y * m_a1)); var L2:Number = ((impulse.x * m_s2) + (impulse.y * m_a2)); c1.x = (c1.x - (m_invMass1 * PX)); c1.y = (c1.y - (m_invMass1 * PY)); a1 = (a1 - (m_invI1 * L1)); c2.x = (c2.x + (m_invMass2 * PX)); c2.y = (c2.y + (m_invMass2 * PY)); a2 = (a2 + (m_invI2 * L2)); b1.m_sweep.a = a1; b2.m_sweep.a = a2; b1.SynchronizeTransform(); b2.SynchronizeTransform(); return ((((linearError <= b2Settings.b2_linearSlop)) && ((angularError <= b2Settings.b2_angularSlop)))); } public function SetMotorSpeed(speed:Number):void{ m_body1.WakeUp(); m_body2.WakeUp(); m_motorSpeed = speed; } public function GetJointSpeed():Number{ var tMat:b2Mat22; var b1:b2Body = m_body1; var b2:b2Body = m_body2; tMat = b1.m_xf.R; var r1X:Number = (m_localAnchor1.x - b1.m_sweep.localCenter.x); var r1Y:Number = (m_localAnchor1.y - b1.m_sweep.localCenter.y); var tX:Number = ((tMat.col1.x * r1X) + (tMat.col2.x * r1Y)); r1Y = ((tMat.col1.y * r1X) + (tMat.col2.y * r1Y)); r1X = tX; tMat = b2.m_xf.R; var r2X:Number = (m_localAnchor2.x - b2.m_sweep.localCenter.x); var r2Y:Number = (m_localAnchor2.y - b2.m_sweep.localCenter.y); tX = ((tMat.col1.x * r2X) + (tMat.col2.x * r2Y)); r2Y = ((tMat.col1.y * r2X) + (tMat.col2.y * r2Y)); r2X = tX; var p1X:Number = (b1.m_sweep.c.x + r1X); var p1Y:Number = (b1.m_sweep.c.y + r1Y); var p2X:Number = (b2.m_sweep.c.x + r2X); var p2Y:Number = (b2.m_sweep.c.y + r2Y); var dX:Number = (p2X - p1X); var dY:Number = (p2Y - p1Y); var axis:b2Vec2 = b1.GetWorldVector(m_localXAxis1); var v1:b2Vec2 = b1.m_linearVelocity; var v2:b2Vec2 = b2.m_linearVelocity; var w1:Number = b1.m_angularVelocity; var w2:Number = b2.m_angularVelocity; var speed:Number = (((dX * (-(w1) * axis.y)) + (dY * (w1 * axis.x))) + ((axis.x * (((v2.x + (-(w2) * r2Y)) - v1.x) - (-(w1) * r1Y))) + (axis.y * (((v2.y + (w2 * r2X)) - v1.y) - (w1 * r1X))))); return (speed); } override b2internal function InitVelocityConstraints(step:b2TimeStep):void{ var tMat:b2Mat22; var tX:Number; var jointTransition:Number; var PX:Number; var PY:Number; var L1:Number; var L2:Number; var b1:b2Body = m_body1; var b2:b2Body = m_body2; m_localCenter1.SetV(b1.GetLocalCenter()); m_localCenter2.SetV(b2.GetLocalCenter()); var xf1:b2XForm = b1.GetXForm(); var xf2:b2XForm = b2.GetXForm(); tMat = b1.m_xf.R; var r1X:Number = (m_localAnchor1.x - b1.m_sweep.localCenter.x); var r1Y:Number = (m_localAnchor1.y - b1.m_sweep.localCenter.y); tX = ((tMat.col1.x * r1X) + (tMat.col2.x * r1Y)); r1Y = ((tMat.col1.y * r1X) + (tMat.col2.y * r1Y)); r1X = tX; tMat = b2.m_xf.R; var r2X:Number = (m_localAnchor2.x - b2.m_sweep.localCenter.x); var r2Y:Number = (m_localAnchor2.y - b2.m_sweep.localCenter.y); tX = ((tMat.col1.x * r2X) + (tMat.col2.x * r2Y)); r2Y = ((tMat.col1.y * r2X) + (tMat.col2.y * r2Y)); r2X = tX; var dX:Number = (((b2.m_sweep.c.x + r2X) - b1.m_sweep.c.x) - r1X); var dY:Number = (((b2.m_sweep.c.y + r2Y) - b1.m_sweep.c.y) - r1Y); m_invMass1 = b1.m_invMass; m_invMass2 = b2.m_invMass; m_invI1 = b1.m_invI; m_invI2 = b2.m_invI; m_axis.SetV(b2Math.b2MulMV(xf1.R, m_localXAxis1)); m_a1 = (((dX + r1X) * m_axis.y) - ((dY + r1Y) * m_axis.x)); m_a2 = ((r2X * m_axis.y) - (r2Y * m_axis.x)); m_motorMass = (((m_invMass1 + m_invMass2) + ((m_invI1 * m_a1) * m_a1)) + ((m_invI2 * m_a2) * m_a2)); m_motorMass = (1 / m_motorMass); m_perp.SetV(b2Math.b2MulMV(xf1.R, m_localYAxis1)); m_s1 = (((dX + r1X) * m_perp.y) - ((dY + r1Y) * m_perp.x)); m_s2 = ((r2X * m_perp.y) - (r2Y * m_perp.x)); var m1:Number = m_invMass1; var m2:Number = m_invMass2; var i1:Number = m_invI1; var i2:Number = m_invI2; m_K.col1.x = (((m1 + m2) + ((i1 * m_s1) * m_s1)) + ((i2 * m_s2) * m_s2)); m_K.col1.y = (((i1 * m_s1) * m_a1) + ((i2 * m_s2) * m_a2)); m_K.col2.x = m_K.col1.y; m_K.col2.y = (((m1 + m2) + ((i1 * m_a1) * m_a1)) + ((i2 * m_a2) * m_a2)); if (m_enableLimit){ jointTransition = ((m_axis.x * dX) + (m_axis.y * dY)); if (b2Math.b2Abs((m_upperTranslation - m_lowerTranslation)) < (2 * b2Settings.b2_linearSlop)){ m_limitState = e_equalLimits; } else { if (jointTransition <= m_lowerTranslation){ if (m_limitState != e_atLowerLimit){ m_limitState = e_atLowerLimit; m_impulse.y = 0; }; } else { if (jointTransition >= m_upperTranslation){ if (m_limitState != e_atUpperLimit){ m_limitState = e_atUpperLimit; m_impulse.y = 0; }; } else { m_limitState = e_inactiveLimit; m_impulse.y = 0; }; }; }; } else { m_limitState = e_inactiveLimit; }; if (m_enableMotor == false){ m_motorImpulse = 0; }; if (step.warmStarting){ m_impulse.x = (m_impulse.x * step.dtRatio); m_impulse.y = (m_impulse.y * step.dtRatio); m_motorImpulse = (m_motorImpulse * step.dtRatio); PX = ((m_impulse.x * m_perp.x) + ((m_motorImpulse + m_impulse.y) * m_axis.x)); PY = ((m_impulse.x * m_perp.y) + ((m_motorImpulse + m_impulse.y) * m_axis.y)); L1 = ((m_impulse.x * m_s1) + ((m_motorImpulse + m_impulse.y) * m_a1)); L2 = ((m_impulse.x * m_s2) + ((m_motorImpulse + m_impulse.y) * m_a2)); b1.m_linearVelocity.x = (b1.m_linearVelocity.x - (m_invMass1 * PX)); b1.m_linearVelocity.y = (b1.m_linearVelocity.y - (m_invMass1 * PY)); b1.m_angularVelocity = (b1.m_angularVelocity - (m_invI1 * L1)); b2.m_linearVelocity.x = (b2.m_linearVelocity.x + (m_invMass2 * PX)); b2.m_linearVelocity.y = (b2.m_linearVelocity.y + (m_invMass2 * PY)); b2.m_angularVelocity = (b2.m_angularVelocity + (m_invI2 * L2)); } else { m_impulse.SetZero(); m_motorImpulse = 0; }; } public function GetMotorForce():Number{ return (m_motorImpulse); } public function EnableLimit(flag:Boolean):void{ m_body1.WakeUp(); m_body2.WakeUp(); m_enableLimit = flag; } public function SetMaxMotorForce(force:Number):void{ m_body1.WakeUp(); m_body2.WakeUp(); m_maxMotorForce = force; } override public function GetReactionTorque(inv_dt:Number):Number{ return ((inv_dt * m_impulse.y)); } public function IsLimitEnabled():Boolean{ return (m_enableLimit); } public function IsMotorEnabled():Boolean{ return (m_enableMotor); } public function SetLimits(lower:Number, upper:Number):void{ m_body1.WakeUp(); m_body2.WakeUp(); m_lowerTranslation = lower; m_upperTranslation = upper; } } }//package Box2D.Dynamics.Joints
Section 63
//b2LineJointDef (Box2D.Dynamics.Joints.b2LineJointDef) package Box2D.Dynamics.Joints { import Box2D.Dynamics.*; import Box2D.Common.Math.*; public class b2LineJointDef extends b2JointDef { public var motorSpeed:Number; public var localAxis1:b2Vec2; public var upperTranslation:Number; public var localAnchor1:b2Vec2; public var localAnchor2:b2Vec2; public var enableLimit:Boolean; public var enableMotor:Boolean; public var maxMotorForce:Number; public var lowerTranslation:Number; public function b2LineJointDef(){ localAnchor1 = new b2Vec2(); localAnchor2 = new b2Vec2(); localAxis1 = new b2Vec2(); super(); type = b2Joint.e_lineJoint; localAxis1.Set(1, 0); enableLimit = false; lowerTranslation = 0; upperTranslation = 0; enableMotor = false; maxMotorForce = 0; motorSpeed = 0; } public function Initialize(b1:b2Body, b2:b2Body, anchor:b2Vec2, axis:b2Vec2):void{ body1 = b1; body2 = b2; localAnchor1 = body1.GetLocalPoint(anchor); localAnchor2 = body2.GetLocalPoint(anchor); localAxis1 = body1.GetLocalVector(axis); } } }//package Box2D.Dynamics.Joints
Section 64
//b2MouseJoint (Box2D.Dynamics.Joints.b2MouseJoint) package Box2D.Dynamics.Joints { import Box2D.Dynamics.*; import Box2D.Common.Math.*; import Box2D.Common.*; public class b2MouseJoint extends b2Joint { private var K1:b2Mat22; private var K:b2Mat22; private var m_beta:Number; private var m_mass:b2Mat22; private var K2:b2Mat22; private var m_target:b2Vec2; private var m_gamma:Number; private var m_impulse:b2Vec2; private var m_C:b2Vec2; private var m_localAnchor:b2Vec2; private var m_maxForce:Number; private var m_dampingRatio:Number; private var m_frequencyHz:Number; public function b2MouseJoint(def:b2MouseJointDef){ var tY:Number; K = new b2Mat22(); K1 = new b2Mat22(); K2 = new b2Mat22(); m_localAnchor = new b2Vec2(); m_target = new b2Vec2(); m_impulse = new b2Vec2(); m_mass = new b2Mat22(); m_C = new b2Vec2(); super(def); m_target.SetV(def.target); var tX:Number = (m_target.x - m_body2.m_xf.position.x); tY = (m_target.y - m_body2.m_xf.position.y); var tMat:b2Mat22 = m_body2.m_xf.R; m_localAnchor.x = ((tX * tMat.col1.x) + (tY * tMat.col1.y)); m_localAnchor.y = ((tX * tMat.col2.x) + (tY * tMat.col2.y)); m_maxForce = def.maxForce; m_impulse.SetZero(); m_frequencyHz = def.frequencyHz; m_dampingRatio = def.dampingRatio; m_beta = 0; m_gamma = 0; } public function SetTarget(target:b2Vec2):void{ if (m_body2.IsSleeping()){ m_body2.WakeUp(); }; m_target = target; } override public function GetAnchor2():b2Vec2{ return (m_body2.GetWorldPoint(m_localAnchor)); } override b2internal function InitVelocityConstraints(step:b2TimeStep):void{ var b:b2Body; var tMat:b2Mat22; var rX:Number; var rY:Number; b = m_body2; var mass:Number = b.GetMass(); var omega:Number = ((2 * Math.PI) * m_frequencyHz); var d:Number = (((2 * mass) * m_dampingRatio) * omega); var k:Number = ((mass * omega) * omega); m_gamma = (1 / (step.dt * (d + (step.dt * k)))); m_beta = ((step.dt * k) * m_gamma); tMat = b.m_xf.R; rX = (m_localAnchor.x - b.m_sweep.localCenter.x); rY = (m_localAnchor.y - b.m_sweep.localCenter.y); var tX:Number = ((tMat.col1.x * rX) + (tMat.col2.x * rY)); rY = ((tMat.col1.y * rX) + (tMat.col2.y * rY)); rX = tX; var invMass:Number = b.m_invMass; var invI:Number = b.m_invI; K1.col1.x = invMass; K1.col2.x = 0; K1.col1.y = 0; K1.col2.y = invMass; K2.col1.x = ((invI * rY) * rY); K2.col2.x = ((-(invI) * rX) * rY); K2.col1.y = ((-(invI) * rX) * rY); K2.col2.y = ((invI * rX) * rX); K.SetM(K1); K.AddM(K2); K.col1.x = (K.col1.x + m_gamma); K.col2.y = (K.col2.y + m_gamma); K.GetInverse(m_mass); m_C.x = ((b.m_sweep.c.x + rX) - m_target.x); m_C.y = ((b.m_sweep.c.y + rY) - m_target.y); b.m_angularVelocity = (b.m_angularVelocity * 0.98); m_impulse.x = (m_impulse.x * step.dtRatio); m_impulse.y = (m_impulse.y * step.dtRatio); b.m_linearVelocity.x = (b.m_linearVelocity.x + (invMass * m_impulse.x)); b.m_linearVelocity.y = (b.m_linearVelocity.y + (invMass * m_impulse.y)); b.m_angularVelocity = (b.m_angularVelocity + (invI * ((rX * m_impulse.y) - (rY * m_impulse.x)))); } override public function GetAnchor1():b2Vec2{ return (m_target); } override public function GetReactionTorque(inv_dt:Number):Number{ return (0); } override public function GetReactionForce(inv_dt:Number):b2Vec2{ return (new b2Vec2((inv_dt * m_impulse.x), (inv_dt * m_impulse.y))); } override b2internal function SolvePositionConstraints(baumgarte:Number):Boolean{ return (true); } override b2internal function SolveVelocityConstraints(step:b2TimeStep):void{ var tMat:b2Mat22; var tX:Number; var tY:Number; var b:b2Body = m_body2; tMat = b.m_xf.R; var rX:Number = (m_localAnchor.x - b.m_sweep.localCenter.x); var rY:Number = (m_localAnchor.y - b.m_sweep.localCenter.y); tX = ((tMat.col1.x * rX) + (tMat.col2.x * rY)); rY = ((tMat.col1.y * rX) + (tMat.col2.y * rY)); rX = tX; var CdotX:Number = (b.m_linearVelocity.x + (-(b.m_angularVelocity) * rY)); var CdotY:Number = (b.m_linearVelocity.y + (b.m_angularVelocity * rX)); tMat = m_mass; tX = ((CdotX + (m_beta * m_C.x)) + (m_gamma * m_impulse.x)); tY = ((CdotY + (m_beta * m_C.y)) + (m_gamma * m_impulse.y)); var impulseX:Number = -(((tMat.col1.x * tX) + (tMat.col2.x * tY))); var impulseY:Number = -(((tMat.col1.y * tX) + (tMat.col2.y * tY))); var oldImpulseX:Number = m_impulse.x; var oldImpulseY:Number = m_impulse.y; m_impulse.x = (m_impulse.x + impulseX); m_impulse.y = (m_impulse.y + impulseY); var maxImpulse:Number = (step.dt * m_maxForce); if (m_impulse.LengthSquared() > (maxImpulse * maxImpulse)){ m_impulse.Multiply((maxImpulse / m_impulse.Length())); }; impulseX = (m_impulse.x - oldImpulseX); impulseY = (m_impulse.y - oldImpulseY); b.m_linearVelocity.x = (b.m_linearVelocity.x + (b.m_invMass * impulseX)); b.m_linearVelocity.y = (b.m_linearVelocity.y + (b.m_invMass * impulseY)); b.m_angularVelocity = (b.m_angularVelocity + (b.m_invI * ((rX * impulseY) - (rY * impulseX)))); } } }//package Box2D.Dynamics.Joints
Section 65
//b2MouseJointDef (Box2D.Dynamics.Joints.b2MouseJointDef) package Box2D.Dynamics.Joints { import Box2D.Common.Math.*; public class b2MouseJointDef extends b2JointDef { public var target:b2Vec2; public var maxForce:Number; public var dampingRatio:Number; public var frequencyHz:Number; public function b2MouseJointDef(){ target = new b2Vec2(); super(); type = b2Joint.e_mouseJoint; maxForce = 0; frequencyHz = 5; dampingRatio = 0.7; } } }//package Box2D.Dynamics.Joints
Section 66
//b2PrismaticJoint (Box2D.Dynamics.Joints.b2PrismaticJoint) package Box2D.Dynamics.Joints { import Box2D.Dynamics.*; import Box2D.Common.Math.*; import Box2D.Common.*; public class b2PrismaticJoint extends b2Joint { private var m_a1:Number; private var m_a2:Number; private var m_perp:b2Vec2; private var m_lowerTranslation:Number; b2internal var m_localXAxis1:b2Vec2; private var m_refAngle:Number; private var m_impulse:b2Vec3; private var m_enableLimit:Boolean; private var m_maxMotorForce:Number; private var m_localYAxis1:b2Vec2; private var m_s2:Number; private var m_axis:b2Vec2; private var m_motorMass:Number; private var m_s1:Number; private var m_upperTranslation:Number; b2internal var m_localAnchor1:b2Vec2; b2internal var m_localAnchor2:b2Vec2; private var m_limitState:int; private var m_motorImpulse:Number; private var m_motorSpeed:Number; private var m_enableMotor:Boolean; private var m_K:b2Mat33; public function b2PrismaticJoint(def:b2PrismaticJointDef){ var tMat:b2Mat22; var tX:Number; var tY:Number; m_localAnchor1 = new b2Vec2(); m_localAnchor2 = new b2Vec2(); m_localXAxis1 = new b2Vec2(); m_localYAxis1 = new b2Vec2(); m_axis = new b2Vec2(); m_perp = new b2Vec2(); m_K = new b2Mat33(); m_impulse = new b2Vec3(); super(def); m_localAnchor1.SetV(def.localAnchor1); m_localAnchor2.SetV(def.localAnchor2); m_localXAxis1.SetV(def.localAxis1); m_localYAxis1.x = -(m_localXAxis1.y); m_localYAxis1.y = m_localXAxis1.x; m_refAngle = def.referenceAngle; m_impulse.SetZero(); m_motorMass = 0; m_motorImpulse = 0; m_lowerTranslation = def.lowerTranslation; m_upperTranslation = def.upperTranslation; m_maxMotorForce = def.maxMotorForce; m_motorSpeed = def.motorSpeed; m_enableLimit = def.enableLimit; m_enableMotor = def.enableMotor; m_limitState = e_inactiveLimit; m_axis.SetZero(); m_perp.SetZero(); } override b2internal function SolveVelocityConstraints(step:b2TimeStep):void{ var PX:Number; var PY:Number; var L1:Number; var L2:Number; var Cdot:Number; var impulse:Number; var oldImpulse:Number; var maxImpulse:Number; var Cdot2:Number; var f1:b2Vec3; var df:b2Vec3; var bX:Number; var bY:Number; var f2r:b2Vec2; var df2:b2Vec2; var b1:b2Body = m_body1; var b2:b2Body = m_body2; var v1:b2Vec2 = b1.m_linearVelocity; var w1:Number = b1.m_angularVelocity; var v2:b2Vec2 = b2.m_linearVelocity; var w2:Number = b2.m_angularVelocity; if (((m_enableMotor) && (!((m_limitState == e_equalLimits))))){ Cdot = ((((m_axis.x * (v2.x - v1.x)) + (m_axis.y * (v2.y - v1.y))) + (m_a2 * w2)) - (m_a1 * w1)); impulse = (m_motorMass * (m_motorSpeed - Cdot)); oldImpulse = m_motorImpulse; maxImpulse = (step.dt * m_maxMotorForce); m_motorImpulse = b2Math.b2Clamp((m_motorImpulse + impulse), -(maxImpulse), maxImpulse); impulse = (m_motorImpulse - oldImpulse); PX = (impulse * m_axis.x); PY = (impulse * m_axis.y); L1 = (impulse * m_a1); L2 = (impulse * m_a2); v1.x = (v1.x - (m_invMass1 * PX)); v1.y = (v1.y - (m_invMass1 * PY)); w1 = (w1 - (m_invI1 * L1)); v2.x = (v2.x + (m_invMass2 * PX)); v2.y = (v2.y + (m_invMass2 * PY)); w2 = (w2 + (m_invI2 * L2)); }; var Cdot1X:Number = ((((m_perp.x * (v2.x - v1.x)) + (m_perp.y * (v2.y - v1.y))) + (m_s2 * w2)) - (m_s1 * w1)); var Cdot1Y:Number = (w2 - w1); if (((m_enableLimit) && (!((m_limitState == e_inactiveLimit))))){ Cdot2 = ((((m_axis.x * (v2.x - v1.x)) + (m_axis.y * (v2.y - v1.y))) + (m_a2 * w2)) - (m_a1 * w1)); f1 = m_impulse.Copy(); df = m_K.Solve33(new b2Vec3(), -(Cdot1X), -(Cdot1Y), -(Cdot2)); m_impulse.Add(df); if (m_limitState == e_atLowerLimit){ m_impulse.z = b2Math.b2Max(m_impulse.z, 0); } else { if (m_limitState == e_atUpperLimit){ m_impulse.z = b2Math.b2Min(m_impulse.z, 0); }; }; bX = (-(Cdot1X) - ((m_impulse.z - f1.z) * m_K.col3.x)); bY = (-(Cdot1Y) - ((m_impulse.z - f1.z) * m_K.col3.y)); f2r = m_K.Solve22(new b2Vec2(), bX, bY); f2r.x = (f2r.x + f1.x); f2r.y = (f2r.y + f1.y); m_impulse.x = f2r.x; m_impulse.y = f2r.y; df.x = (m_impulse.x - f1.x); df.y = (m_impulse.y - f1.y); df.z = (m_impulse.z - f1.z); PX = ((df.x * m_perp.x) + (df.z * m_axis.x)); PY = ((df.x * m_perp.y) + (df.z * m_axis.y)); L1 = (((df.x * m_s1) + df.y) + (df.z * m_a1)); L2 = (((df.x * m_s2) + df.y) + (df.z * m_a2)); v1.x = (v1.x - (m_invMass1 * PX)); v1.y = (v1.y - (m_invMass1 * PY)); w1 = (w1 - (m_invI1 * L1)); v2.x = (v2.x + (m_invMass2 * PX)); v2.y = (v2.y + (m_invMass2 * PY)); w2 = (w2 + (m_invI2 * L2)); } else { df2 = m_K.Solve22(new b2Vec2(), -(Cdot1X), -(Cdot1Y)); m_impulse.x = (m_impulse.x + df2.x); m_impulse.y = (m_impulse.y + df2.y); PX = (df2.x * m_perp.x); PY = (df2.x * m_perp.y); L1 = ((df2.x * m_s1) + df2.y); L2 = ((df2.x * m_s2) + df2.y); v1.x = (v1.x - (m_invMass1 * PX)); v1.y = (v1.y - (m_invMass1 * PY)); w1 = (w1 - (m_invI1 * L1)); v2.x = (v2.x + (m_invMass2 * PX)); v2.y = (v2.y + (m_invMass2 * PY)); w2 = (w2 + (m_invI2 * L2)); }; b1.m_linearVelocity.SetV(v1); b1.m_angularVelocity = w1; b2.m_linearVelocity.SetV(v2); b2.m_angularVelocity = w2; } override public function GetAnchor1():b2Vec2{ return (m_body1.GetWorldPoint(m_localAnchor1)); } override public function GetAnchor2():b2Vec2{ return (m_body2.GetWorldPoint(m_localAnchor2)); } public function GetUpperLimit():Number{ return (m_upperTranslation); } public function GetLowerLimit():Number{ return (m_lowerTranslation); } public function EnableMotor(flag:Boolean):void{ m_body1.WakeUp(); m_body2.WakeUp(); m_enableMotor = flag; } public function GetJointTranslation():Number{ var tMat:b2Mat22; var b1:b2Body = m_body1; var b2:b2Body = m_body2; var p1:b2Vec2 = b1.GetWorldPoint(m_localAnchor1); var p2:b2Vec2 = b2.GetWorldPoint(m_localAnchor2); var dX:Number = (p2.x - p1.x); var dY:Number = (p2.y - p1.y); var axis:b2Vec2 = b1.GetWorldVector(m_localXAxis1); var translation:Number = ((axis.x * dX) + (axis.y * dY)); return (translation); } public function GetMotorSpeed():Number{ return (m_motorSpeed); } override public function GetReactionForce(inv_dt:Number):b2Vec2{ return (new b2Vec2((inv_dt * ((m_impulse.x * m_perp.x) + ((m_motorImpulse + m_impulse.z) * m_axis.x))), (inv_dt * ((m_impulse.x * m_perp.y) + ((m_motorImpulse + m_impulse.z) * m_axis.y))))); } override b2internal function SolvePositionConstraints(baumgarte:Number):Boolean{ var limitC:Number; var oldLimitImpulse:Number; var tMat:b2Mat22; var tX:Number; var m1:Number; var m2:Number; var i1:Number; var i2:Number; var translation:Number; var k11:Number; var k12:Number; var k22:Number; var impulse1:b2Vec2; var b1:b2Body = m_body1; var b2:b2Body = m_body2; var c1:b2Vec2 = b1.m_sweep.c; var a1:Number = b1.m_sweep.a; var c2:b2Vec2 = b2.m_sweep.c; var a2:Number = b2.m_sweep.a; var linearError:Number = 0; var angularError:Number = 0; var active:Boolean; var C2:Number = 0; var R1:b2Mat22 = new b2Mat22(a1); var R2:b2Mat22 = new b2Mat22(a2); tMat = R1; var r1X:Number = (m_localAnchor1.x - m_localCenter1.x); var r1Y:Number = (m_localAnchor1.y - m_localCenter1.y); tX = ((tMat.col1.x * r1X) + (tMat.col2.x * r1Y)); r1Y = ((tMat.col1.y * r1X) + (tMat.col2.y * r1Y)); r1X = tX; tMat = R2; var r2X:Number = (m_localAnchor2.x - m_localCenter2.x); var r2Y:Number = (m_localAnchor2.y - m_localCenter2.y); tX = ((tMat.col1.x * r2X) + (tMat.col2.x * r2Y)); r2Y = ((tMat.col1.y * r2X) + (tMat.col2.y * r2Y)); r2X = tX; var dX:Number = (((c2.x + r2X) - c1.x) - r1X); var dY:Number = (((c2.y + r2Y) - c1.y) - r1Y); if (m_enableLimit){ m_axis = b2Math.b2MulMV(R1, m_localXAxis1); m_a1 = (((dX + r1X) * m_axis.y) - ((dY + r1Y) * m_axis.x)); m_a2 = ((r2X * m_axis.y) - (r2Y * m_axis.x)); translation = ((m_axis.x * dX) + (m_axis.y * dY)); if (b2Math.b2Abs((m_upperTranslation - m_lowerTranslation)) < (2 * b2Settings.b2_linearSlop)){ C2 = b2Math.b2Clamp(translation, -(b2Settings.b2_maxLinearCorrection), b2Settings.b2_maxLinearCorrection); linearError = b2Math.b2Abs(translation); active = true; } else { if (translation <= m_lowerTranslation){ C2 = b2Math.b2Clamp(((translation - m_lowerTranslation) + b2Settings.b2_linearSlop), -(b2Settings.b2_maxLinearCorrection), 0); linearError = (m_lowerTranslation - translation); active = true; } else { if (translation >= m_upperTranslation){ C2 = b2Math.b2Clamp(((translation - m_upperTranslation) + b2Settings.b2_linearSlop), 0, b2Settings.b2_maxLinearCorrection); linearError = (translation - m_upperTranslation); active = true; }; }; }; }; m_perp = b2Math.b2MulMV(R1, m_localYAxis1); m_s1 = (((dX + r1X) * m_perp.y) - ((dY + r1Y) * m_perp.x)); m_s2 = ((r2X * m_perp.y) - (r2Y * m_perp.x)); var impulse:b2Vec3 = new b2Vec3(); var C1X:Number = ((m_perp.x * dX) + (m_perp.y * dY)); var C1Y:Number = ((a2 - a1) - m_refAngle); linearError = b2Math.b2Max(linearError, b2Math.b2Abs(C1X)); angularError = b2Math.b2Abs(C1Y); if (active){ m1 = m_invMass1; m2 = m_invMass2; i1 = m_invI1; i2 = m_invI2; m_K.col1.x = (((m1 + m2) + ((i1 * m_s1) * m_s1)) + ((i2 * m_s2) * m_s2)); m_K.col1.y = ((i1 * m_s1) + (i2 * m_s2)); m_K.col1.z = (((i1 * m_s1) * m_a1) + ((i2 * m_s2) * m_a2)); m_K.col2.x = m_K.col1.y; m_K.col2.y = (i1 + i2); m_K.col2.z = ((i1 * m_a1) + (i2 * m_a2)); m_K.col3.x = m_K.col1.z; m_K.col3.y = m_K.col2.z; m_K.col3.z = (((m1 + m2) + ((i1 * m_a1) * m_a1)) + ((i2 * m_a2) * m_a2)); m_K.Solve33(impulse, -(C1X), -(C1Y), -(C2)); } else { m1 = m_invMass1; m2 = m_invMass2; i1 = m_invI1; i2 = m_invI2; k11 = (((m1 + m2) + ((i1 * m_s1) * m_s1)) + ((i2 * m_s2) * m_s2)); k12 = ((i1 * m_s1) + (i2 * m_s2)); k22 = (i1 + i2); m_K.col1.Set(k11, k12, 0); m_K.col2.Set(k12, k22, 0); impulse1 = m_K.Solve22(new b2Vec2(), -(C1X), -(C1Y)); impulse.x = impulse1.x; impulse.y = impulse1.y; impulse.z = 0; }; var PX:Number = ((impulse.x * m_perp.x) + (impulse.z * m_axis.x)); var PY:Number = ((impulse.x * m_perp.y) + (impulse.z * m_axis.y)); var L1:Number = (((impulse.x * m_s1) + impulse.y) + (impulse.z * m_a1)); var L2:Number = (((impulse.x * m_s2) + impulse.y) + (impulse.z * m_a2)); c1.x = (c1.x - (m_invMass1 * PX)); c1.y = (c1.y - (m_invMass1 * PY)); a1 = (a1 - (m_invI1 * L1)); c2.x = (c2.x + (m_invMass2 * PX)); c2.y = (c2.y + (m_invMass2 * PY)); a2 = (a2 + (m_invI2 * L2)); b1.m_sweep.a = a1; b2.m_sweep.a = a2; b1.SynchronizeTransform(); b2.SynchronizeTransform(); return ((((linearError <= b2Settings.b2_linearSlop)) && ((angularError <= b2Settings.b2_angularSlop)))); } public function SetMotorSpeed(speed:Number):void{ m_body1.WakeUp(); m_body2.WakeUp(); m_motorSpeed = speed; } public function GetJointSpeed():Number{ var tMat:b2Mat22; var b1:b2Body = m_body1; var b2:b2Body = m_body2; tMat = b1.m_xf.R; var r1X:Number = (m_localAnchor1.x - b1.m_sweep.localCenter.x); var r1Y:Number = (m_localAnchor1.y - b1.m_sweep.localCenter.y); var tX:Number = ((tMat.col1.x * r1X) + (tMat.col2.x * r1Y)); r1Y = ((tMat.col1.y * r1X) + (tMat.col2.y * r1Y)); r1X = tX; tMat = b2.m_xf.R; var r2X:Number = (m_localAnchor2.x - b2.m_sweep.localCenter.x); var r2Y:Number = (m_localAnchor2.y - b2.m_sweep.localCenter.y); tX = ((tMat.col1.x * r2X) + (tMat.col2.x * r2Y)); r2Y = ((tMat.col1.y * r2X) + (tMat.col2.y * r2Y)); r2X = tX; var p1X:Number = (b1.m_sweep.c.x + r1X); var p1Y:Number = (b1.m_sweep.c.y + r1Y); var p2X:Number = (b2.m_sweep.c.x + r2X); var p2Y:Number = (b2.m_sweep.c.y + r2Y); var dX:Number = (p2X - p1X); var dY:Number = (p2Y - p1Y); var axis:b2Vec2 = b1.GetWorldVector(m_localXAxis1); var v1:b2Vec2 = b1.m_linearVelocity; var v2:b2Vec2 = b2.m_linearVelocity; var w1:Number = b1.m_angularVelocity; var w2:Number = b2.m_angularVelocity; var speed:Number = (((dX * (-(w1) * axis.y)) + (dY * (w1 * axis.x))) + ((axis.x * (((v2.x + (-(w2) * r2Y)) - v1.x) - (-(w1) * r1Y))) + (axis.y * (((v2.y + (w2 * r2X)) - v1.y) - (w1 * r1X))))); return (speed); } override b2internal function InitVelocityConstraints(step:b2TimeStep):void{ var tMat:b2Mat22; var tX:Number; var jointTransition:Number; var PX:Number; var PY:Number; var L1:Number; var L2:Number; var b1:b2Body = m_body1; var b2:b2Body = m_body2; m_localCenter1.SetV(b1.GetLocalCenter()); m_localCenter2.SetV(b2.GetLocalCenter()); var xf1:b2XForm = b1.GetXForm(); var xf2:b2XForm = b2.GetXForm(); tMat = b1.m_xf.R; var r1X:Number = (m_localAnchor1.x - b1.m_sweep.localCenter.x); var r1Y:Number = (m_localAnchor1.y - b1.m_sweep.localCenter.y); tX = ((tMat.col1.x * r1X) + (tMat.col2.x * r1Y)); r1Y = ((tMat.col1.y * r1X) + (tMat.col2.y * r1Y)); r1X = tX; tMat = b2.m_xf.R; var r2X:Number = (m_localAnchor2.x - b2.m_sweep.localCenter.x); var r2Y:Number = (m_localAnchor2.y - b2.m_sweep.localCenter.y); tX = ((tMat.col1.x * r2X) + (tMat.col2.x * r2Y)); r2Y = ((tMat.col1.y * r2X) + (tMat.col2.y * r2Y)); r2X = tX; var dX:Number = (((b2.m_sweep.c.x + r2X) - b1.m_sweep.c.x) - r1X); var dY:Number = (((b2.m_sweep.c.y + r2Y) - b1.m_sweep.c.y) - r1Y); m_invMass1 = b1.m_invMass; m_invMass2 = b2.m_invMass; m_invI1 = b1.m_invI; m_invI2 = b2.m_invI; m_axis.SetV(b2Math.b2MulMV(xf1.R, m_localXAxis1)); m_a1 = (((dX + r1X) * m_axis.y) - ((dY + r1Y) * m_axis.x)); m_a2 = ((r2X * m_axis.y) - (r2Y * m_axis.x)); m_motorMass = (((m_invMass1 + m_invMass2) + ((m_invI1 * m_a1) * m_a1)) + ((m_invI2 * m_a2) * m_a2)); m_motorMass = (1 / m_motorMass); m_perp.SetV(b2Math.b2MulMV(xf1.R, m_localYAxis1)); m_s1 = (((dX + r1X) * m_perp.y) - ((dY + r1Y) * m_perp.x)); m_s2 = ((r2X * m_perp.y) - (r2Y * m_perp.x)); var m1:Number = m_invMass1; var m2:Number = m_invMass2; var i1:Number = m_invI1; var i2:Number = m_invI2; m_K.col1.x = (((m1 + m2) + ((i1 * m_s1) * m_s1)) + ((i2 * m_s2) * m_s2)); m_K.col1.y = ((i1 * m_s1) + (i2 * m_s2)); m_K.col1.z = (((i1 * m_s1) * m_a1) + ((i2 * m_s2) * m_a2)); m_K.col2.x = m_K.col1.y; m_K.col2.y = (i1 + i2); m_K.col2.z = ((i1 * m_a1) + (i2 * m_a2)); m_K.col3.x = m_K.col1.z; m_K.col3.y = m_K.col2.z; m_K.col3.z = (((m1 + m2) + ((i1 * m_a1) * m_a1)) + ((i2 * m_a2) * m_a2)); if (m_enableLimit){ jointTransition = ((m_axis.x * dX) + (m_axis.y * dY)); if (b2Math.b2Abs((m_upperTranslation - m_lowerTranslation)) < (2 * b2Settings.b2_linearSlop)){ m_limitState = e_equalLimits; } else { if (jointTransition <= m_lowerTranslation){ if (m_limitState != e_atLowerLimit){ m_limitState = e_atLowerLimit; m_impulse.z = 0; }; } else { if (jointTransition >= m_upperTranslation){ if (m_limitState != e_atUpperLimit){ m_limitState = e_atUpperLimit; m_impulse.z = 0; }; } else { m_limitState = e_inactiveLimit; m_impulse.z = 0; }; }; }; } else { m_limitState = e_inactiveLimit; }; if (m_enableMotor == false){ m_motorImpulse = 0; }; if (step.warmStarting){ m_impulse.x = (m_impulse.x * step.dtRatio); m_impulse.y = (m_impulse.y * step.dtRatio); m_motorImpulse = (m_motorImpulse * step.dtRatio); PX = ((m_impulse.x * m_perp.x) + ((m_motorImpulse + m_impulse.z) * m_axis.x)); PY = ((m_impulse.x * m_perp.y) + ((m_motorImpulse + m_impulse.z) * m_axis.y)); L1 = (((m_impulse.x * m_s1) + m_impulse.y) + ((m_motorImpulse + m_impulse.z) * m_a1)); L2 = (((m_impulse.x * m_s2) + m_impulse.y) + ((m_motorImpulse + m_impulse.z) * m_a2)); b1.m_linearVelocity.x = (b1.m_linearVelocity.x - (m_invMass1 * PX)); b1.m_linearVelocity.y = (b1.m_linearVelocity.y - (m_invMass1 * PY)); b1.m_angularVelocity = (b1.m_angularVelocity - (m_invI1 * L1)); b2.m_linearVelocity.x = (b2.m_linearVelocity.x + (m_invMass2 * PX)); b2.m_linearVelocity.y = (b2.m_linearVelocity.y + (m_invMass2 * PY)); b2.m_angularVelocity = (b2.m_angularVelocity + (m_invI2 * L2)); } else { m_impulse.SetZero(); m_motorImpulse = 0; }; } public function GetMotorForce():Number{ return (m_motorImpulse); } public function EnableLimit(flag:Boolean):void{ m_body1.WakeUp(); m_body2.WakeUp(); m_enableLimit = flag; } public function SetMaxMotorForce(force:Number):void{ m_body1.WakeUp(); m_body2.WakeUp(); m_maxMotorForce = force; } override public function GetReactionTorque(inv_dt:Number):Number{ return ((inv_dt * m_impulse.y)); } public function IsLimitEnabled():Boolean{ return (m_enableLimit); } public function IsMotorEnabled():Boolean{ return (m_enableMotor); } public function SetLimits(lower:Number, upper:Number):void{ m_body1.WakeUp(); m_body2.WakeUp(); m_lowerTranslation = lower; m_upperTranslation = upper; } } }//package Box2D.Dynamics.Joints
Section 67
//b2PrismaticJointDef (Box2D.Dynamics.Joints.b2PrismaticJointDef) package Box2D.Dynamics.Joints { import Box2D.Dynamics.*; import Box2D.Common.Math.*; public class b2PrismaticJointDef extends b2JointDef { public var motorSpeed:Number; public var localAxis1:b2Vec2; public var referenceAngle:Number; public var upperTranslation:Number; public var localAnchor1:b2Vec2; public var localAnchor2:b2Vec2; public var enableLimit:Boolean; public var enableMotor:Boolean; public var maxMotorForce:Number; public var lowerTranslation:Number; public function b2PrismaticJointDef(){ localAnchor1 = new b2Vec2(); localAnchor2 = new b2Vec2(); localAxis1 = new b2Vec2(); super(); type = b2Joint.e_prismaticJoint; localAxis1.Set(1, 0); referenceAngle = 0; enableLimit = false; lowerTranslation = 0; upperTranslation = 0; enableMotor = false; maxMotorForce = 0; motorSpeed = 0; } public function Initialize(b1:b2Body, b2:b2Body, anchor:b2Vec2, axis:b2Vec2):void{ body1 = b1; body2 = b2; localAnchor1 = body1.GetLocalPoint(anchor); localAnchor2 = body2.GetLocalPoint(anchor); localAxis1 = body1.GetLocalVector(axis); referenceAngle = (body2.GetAngle() - body1.GetAngle()); } } }//package Box2D.Dynamics.Joints
Section 68
//b2PulleyJoint (Box2D.Dynamics.Joints.b2PulleyJoint) package Box2D.Dynamics.Joints { import Box2D.Dynamics.*; import Box2D.Common.Math.*; import Box2D.Common.*; public class b2PulleyJoint extends b2Joint { private var m_limitState1:int; private var m_limitState2:int; private var m_ground:b2Body; private var m_maxLength2:Number; private var m_maxLength1:Number; private var m_impulse:Number; private var m_constant:Number; private var m_state:int; private var m_ratio:Number; private var m_groundAnchor1:b2Vec2; private var m_groundAnchor2:b2Vec2; private var m_localAnchor1:b2Vec2; private var m_localAnchor2:b2Vec2; private var m_limitMass1:Number; private var m_limitMass2:Number; private var m_pulleyMass:Number; private var m_limitImpulse1:Number; private var m_limitImpulse2:Number; private var m_u1:b2Vec2; private var m_u2:b2Vec2; b2internal static const b2_minPulleyLength:Number = 2; public function b2PulleyJoint(def:b2PulleyJointDef){ var tMat:b2Mat22; var tX:Number; var tY:Number; m_groundAnchor1 = new b2Vec2(); m_groundAnchor2 = new b2Vec2(); m_localAnchor1 = new b2Vec2(); m_localAnchor2 = new b2Vec2(); m_u1 = new b2Vec2(); m_u2 = new b2Vec2(); super(def); m_ground = m_body1.m_world.m_groundBody; m_groundAnchor1.x = (def.groundAnchor1.x - m_ground.m_xf.position.x); m_groundAnchor1.y = (def.groundAnchor1.y - m_ground.m_xf.position.y); m_groundAnchor2.x = (def.groundAnchor2.x - m_ground.m_xf.position.x); m_groundAnchor2.y = (def.groundAnchor2.y - m_ground.m_xf.position.y); m_localAnchor1.SetV(def.localAnchor1); m_localAnchor2.SetV(def.localAnchor2); m_ratio = def.ratio; m_constant = (def.length1 + (m_ratio * def.length2)); m_maxLength1 = b2Math.b2Min(def.maxLength1, (m_constant - (m_ratio * b2_minPulleyLength))); m_maxLength2 = b2Math.b2Min(def.maxLength2, ((m_constant - b2_minPulleyLength) / m_ratio)); m_impulse = 0; m_limitImpulse1 = 0; m_limitImpulse2 = 0; } public function GetGroundAnchor2():b2Vec2{ var a:b2Vec2 = m_ground.m_xf.position.Copy(); a.Add(m_groundAnchor2); return (a); } override public function GetAnchor1():b2Vec2{ return (m_body1.GetWorldPoint(m_localAnchor1)); } override public function GetAnchor2():b2Vec2{ return (m_body2.GetWorldPoint(m_localAnchor2)); } override public function GetReactionForce(inv_dt:Number):b2Vec2{ return (new b2Vec2(((inv_dt * m_impulse) * m_u2.x), ((inv_dt * m_impulse) * m_u2.y))); } override b2internal function SolvePositionConstraints(baumgarte:Number):Boolean{ var tMat:b2Mat22; var r1X:Number; var r1Y:Number; var r2X:Number; var r2Y:Number; var p1X:Number; var p1Y:Number; var p2X:Number; var p2Y:Number; var length1:Number; var length2:Number; var C:Number; var impulse:Number; var oldImpulse:Number; var oldLimitPositionImpulse:Number; var tX:Number; var b1:b2Body = m_body1; var b2:b2Body = m_body2; var s1X:Number = (m_ground.m_xf.position.x + m_groundAnchor1.x); var s1Y:Number = (m_ground.m_xf.position.y + m_groundAnchor1.y); var s2X:Number = (m_ground.m_xf.position.x + m_groundAnchor2.x); var s2Y:Number = (m_ground.m_xf.position.y + m_groundAnchor2.y); var linearError:Number = 0; if (m_state == e_atUpperLimit){ tMat = b1.m_xf.R; r1X = (m_localAnchor1.x - b1.m_sweep.localCenter.x); r1Y = (m_localAnchor1.y - b1.m_sweep.localCenter.y); tX = ((tMat.col1.x * r1X) + (tMat.col2.x * r1Y)); r1Y = ((tMat.col1.y * r1X) + (tMat.col2.y * r1Y)); r1X = tX; tMat = b2.m_xf.R; r2X = (m_localAnchor2.x - b2.m_sweep.localCenter.x); r2Y = (m_localAnchor2.y - b2.m_sweep.localCenter.y); tX = ((tMat.col1.x * r2X) + (tMat.col2.x * r2Y)); r2Y = ((tMat.col1.y * r2X) + (tMat.col2.y * r2Y)); r2X = tX; p1X = (b1.m_sweep.c.x + r1X); p1Y = (b1.m_sweep.c.y + r1Y); p2X = (b2.m_sweep.c.x + r2X); p2Y = (b2.m_sweep.c.y + r2Y); m_u1.Set((p1X - s1X), (p1Y - s1Y)); m_u2.Set((p2X - s2X), (p2Y - s2Y)); length1 = m_u1.Length(); length2 = m_u2.Length(); if (length1 > b2Settings.b2_linearSlop){ m_u1.Multiply((1 / length1)); } else { m_u1.SetZero(); }; if (length2 > b2Settings.b2_linearSlop){ m_u2.Multiply((1 / length2)); } else { m_u2.SetZero(); }; C = ((m_constant - length1) - (m_ratio * length2)); linearError = b2Math.b2Max(linearError, -(C)); C = b2Math.b2Clamp((C + b2Settings.b2_linearSlop), -(b2Settings.b2_maxLinearCorrection), 0); impulse = (-(m_pulleyMass) * C); p1X = (-(impulse) * m_u1.x); p1Y = (-(impulse) * m_u1.y); p2X = ((-(m_ratio) * impulse) * m_u2.x); p2Y = ((-(m_ratio) * impulse) * m_u2.y); b1.m_sweep.c.x = (b1.m_sweep.c.x + (b1.m_invMass * p1X)); b1.m_sweep.c.y = (b1.m_sweep.c.y + (b1.m_invMass * p1Y)); b1.m_sweep.a = (b1.m_sweep.a + (b1.m_invI * ((r1X * p1Y) - (r1Y * p1X)))); b2.m_sweep.c.x = (b2.m_sweep.c.x + (b2.m_invMass * p2X)); b2.m_sweep.c.y = (b2.m_sweep.c.y + (b2.m_invMass * p2Y)); b2.m_sweep.a = (b2.m_sweep.a + (b2.m_invI * ((r2X * p2Y) - (r2Y * p2X)))); b1.SynchronizeTransform(); b2.SynchronizeTransform(); }; if (m_limitState1 == e_atUpperLimit){ tMat = b1.m_xf.R; r1X = (m_localAnchor1.x - b1.m_sweep.localCenter.x); r1Y = (m_localAnchor1.y - b1.m_sweep.localCenter.y); tX = ((tMat.col1.x * r1X) + (tMat.col2.x * r1Y)); r1Y = ((tMat.col1.y * r1X) + (tMat.col2.y * r1Y)); r1X = tX; p1X = (b1.m_sweep.c.x + r1X); p1Y = (b1.m_sweep.c.y + r1Y); m_u1.Set((p1X - s1X), (p1Y - s1Y)); length1 = m_u1.Length(); if (length1 > b2Settings.b2_linearSlop){ m_u1.x = (m_u1.x * (1 / length1)); m_u1.y = (m_u1.y * (1 / length1)); } else { m_u1.SetZero(); }; C = (m_maxLength1 - length1); linearError = b2Math.b2Max(linearError, -(C)); C = b2Math.b2Clamp((C + b2Settings.b2_linearSlop), -(b2Settings.b2_maxLinearCorrection), 0); impulse = (-(m_limitMass1) * C); p1X = (-(impulse) * m_u1.x); p1Y = (-(impulse) * m_u1.y); b1.m_sweep.c.x = (b1.m_sweep.c.x + (b1.m_invMass * p1X)); b1.m_sweep.c.y = (b1.m_sweep.c.y + (b1.m_invMass * p1Y)); b1.m_sweep.a = (b1.m_sweep.a + (b1.m_invI * ((r1X * p1Y) - (r1Y * p1X)))); b1.SynchronizeTransform(); }; if (m_limitState2 == e_atUpperLimit){ tMat = b2.m_xf.R; r2X = (m_localAnchor2.x - b2.m_sweep.localCenter.x); r2Y = (m_localAnchor2.y - b2.m_sweep.localCenter.y); tX = ((tMat.col1.x * r2X) + (tMat.col2.x * r2Y)); r2Y = ((tMat.col1.y * r2X) + (tMat.col2.y * r2Y)); r2X = tX; p2X = (b2.m_sweep.c.x + r2X); p2Y = (b2.m_sweep.c.y + r2Y); m_u2.Set((p2X - s2X), (p2Y - s2Y)); length2 = m_u2.Length(); if (length2 > b2Settings.b2_linearSlop){ m_u2.x = (m_u2.x * (1 / length2)); m_u2.y = (m_u2.y * (1 / length2)); } else { m_u2.SetZero(); }; C = (m_maxLength2 - length2); linearError = b2Math.b2Max(linearError, -(C)); C = b2Math.b2Clamp((C + b2Settings.b2_linearSlop), -(b2Settings.b2_maxLinearCorrection), 0); impulse = (-(m_limitMass2) * C); p2X = (-(impulse) * m_u2.x); p2Y = (-(impulse) * m_u2.y); b2.m_sweep.c.x = (b2.m_sweep.c.x + (b2.m_invMass * p2X)); b2.m_sweep.c.y = (b2.m_sweep.c.y + (b2.m_invMass * p2Y)); b2.m_sweep.a = (b2.m_sweep.a + (b2.m_invI * ((r2X * p2Y) - (r2Y * p2X)))); b2.SynchronizeTransform(); }; return ((linearError < b2Settings.b2_linearSlop)); } override b2internal function InitVelocityConstraints(step:b2TimeStep):void{ var b1:b2Body; var tMat:b2Mat22; var P1X:Number; var P1Y:Number; var P2X:Number; var P2Y:Number; b1 = m_body1; var b2:b2Body = m_body2; tMat = b1.m_xf.R; var r1X:Number = (m_localAnchor1.x - b1.m_sweep.localCenter.x); var r1Y:Number = (m_localAnchor1.y - b1.m_sweep.localCenter.y); var tX:Number = ((tMat.col1.x * r1X) + (tMat.col2.x * r1Y)); r1Y = ((tMat.col1.y * r1X) + (tMat.col2.y * r1Y)); r1X = tX; tMat = b2.m_xf.R; var r2X:Number = (m_localAnchor2.x - b2.m_sweep.localCenter.x); var r2Y:Number = (m_localAnchor2.y - b2.m_sweep.localCenter.y); tX = ((tMat.col1.x * r2X) + (tMat.col2.x * r2Y)); r2Y = ((tMat.col1.y * r2X) + (tMat.col2.y * r2Y)); r2X = tX; var p1X:Number = (b1.m_sweep.c.x + r1X); var p1Y:Number = (b1.m_sweep.c.y + r1Y); var p2X:Number = (b2.m_sweep.c.x + r2X); var p2Y:Number = (b2.m_sweep.c.y + r2Y); var s1X:Number = (m_ground.m_xf.position.x + m_groundAnchor1.x); var s1Y:Number = (m_ground.m_xf.position.y + m_groundAnchor1.y); var s2X:Number = (m_ground.m_xf.position.x + m_groundAnchor2.x); var s2Y:Number = (m_ground.m_xf.position.y + m_groundAnchor2.y); m_u1.Set((p1X - s1X), (p1Y - s1Y)); m_u2.Set((p2X - s2X), (p2Y - s2Y)); var length1:Number = m_u1.Length(); var length2:Number = m_u2.Length(); if (length1 > b2Settings.b2_linearSlop){ m_u1.Multiply((1 / length1)); } else { m_u1.SetZero(); }; if (length2 > b2Settings.b2_linearSlop){ m_u2.Multiply((1 / length2)); } else { m_u2.SetZero(); }; var C:Number = ((m_constant - length1) - (m_ratio * length2)); if (C > 0){ m_state = e_inactiveLimit; m_impulse = 0; } else { m_state = e_atUpperLimit; }; if (length1 < m_maxLength1){ m_limitState1 = e_inactiveLimit; m_limitImpulse1 = 0; } else { m_limitState1 = e_atUpperLimit; }; if (length2 < m_maxLength2){ m_limitState2 = e_inactiveLimit; m_limitImpulse2 = 0; } else { m_limitState2 = e_atUpperLimit; }; var cr1u1:Number = ((r1X * m_u1.y) - (r1Y * m_u1.x)); var cr2u2:Number = ((r2X * m_u2.y) - (r2Y * m_u2.x)); m_limitMass1 = (b1.m_invMass + ((b1.m_invI * cr1u1) * cr1u1)); m_limitMass2 = (b2.m_invMass + ((b2.m_invI * cr2u2) * cr2u2)); m_pulleyMass = (m_limitMass1 + ((m_ratio * m_ratio) * m_limitMass2)); m_limitMass1 = (1 / m_limitMass1); m_limitMass2 = (1 / m_limitMass2); m_pulleyMass = (1 / m_pulleyMass); if (step.warmStarting){ m_impulse = (m_impulse * step.dtRatio); m_limitImpulse1 = (m_limitImpulse1 * step.dtRatio); m_limitImpulse2 = (m_limitImpulse2 * step.dtRatio); P1X = ((-(m_impulse) - m_limitImpulse1) * m_u1.x); P1Y = ((-(m_impulse) - m_limitImpulse1) * m_u1.y); P2X = (((-(m_ratio) * m_impulse) - m_limitImpulse2) * m_u2.x); P2Y = (((-(m_ratio) * m_impulse) - m_limitImpulse2) * m_u2.y); b1.m_linearVelocity.x = (b1.m_linearVelocity.x + (b1.m_invMass * P1X)); b1.m_linearVelocity.y = (b1.m_linearVelocity.y + (b1.m_invMass * P1Y)); b1.m_angularVelocity = (b1.m_angularVelocity + (b1.m_invI * ((r1X * P1Y) - (r1Y * P1X)))); b2.m_linearVelocity.x = (b2.m_linearVelocity.x + (b2.m_invMass * P2X)); b2.m_linearVelocity.y = (b2.m_linearVelocity.y + (b2.m_invMass * P2Y)); b2.m_angularVelocity = (b2.m_angularVelocity + (b2.m_invI * ((r2X * P2Y) - (r2Y * P2X)))); } else { m_impulse = 0; m_limitImpulse1 = 0; m_limitImpulse2 = 0; }; } override public function GetReactionTorque(inv_dt:Number):Number{ return (0); } public function GetRatio():Number{ return (m_ratio); } public function GetLength2():Number{ var p:b2Vec2 = m_body2.GetWorldPoint(m_localAnchor2); var sX:Number = (m_ground.m_xf.position.x + m_groundAnchor2.x); var sY:Number = (m_ground.m_xf.position.y + m_groundAnchor2.y); var dX:Number = (p.x - sX); var dY:Number = (p.y - sY); return (Math.sqrt(((dX * dX) + (dY * dY)))); } override b2internal function SolveVelocityConstraints(step:b2TimeStep):void{ var tMat:b2Mat22; var v1X:Number; var v1Y:Number; var v2X:Number; var v2Y:Number; var P1X:Number; var P1Y:Number; var P2X:Number; var P2Y:Number; var Cdot:Number; var impulse:Number; var oldImpulse:Number; var b1:b2Body = m_body1; var b2:b2Body = m_body2; tMat = b1.m_xf.R; var r1X:Number = (m_localAnchor1.x - b1.m_sweep.localCenter.x); var r1Y:Number = (m_localAnchor1.y - b1.m_sweep.localCenter.y); var tX:Number = ((tMat.col1.x * r1X) + (tMat.col2.x * r1Y)); r1Y = ((tMat.col1.y * r1X) + (tMat.col2.y * r1Y)); r1X = tX; tMat = b2.m_xf.R; var r2X:Number = (m_localAnchor2.x - b2.m_sweep.localCenter.x); var r2Y:Number = (m_localAnchor2.y - b2.m_sweep.localCenter.y); tX = ((tMat.col1.x * r2X) + (tMat.col2.x * r2Y)); r2Y = ((tMat.col1.y * r2X) + (tMat.col2.y * r2Y)); r2X = tX; if (m_state == e_atUpperLimit){ v1X = (b1.m_linearVelocity.x + (-(b1.m_angularVelocity) * r1Y)); v1Y = (b1.m_linearVelocity.y + (b1.m_angularVelocity * r1X)); v2X = (b2.m_linearVelocity.x + (-(b2.m_angularVelocity) * r2Y)); v2Y = (b2.m_linearVelocity.y + (b2.m_angularVelocity * r2X)); Cdot = (-(((m_u1.x * v1X) + (m_u1.y * v1Y))) - (m_ratio * ((m_u2.x * v2X) + (m_u2.y * v2Y)))); impulse = (m_pulleyMass * -(Cdot)); oldImpulse = m_impulse; m_impulse = b2Math.b2Max(0, (m_impulse + impulse)); impulse = (m_impulse - oldImpulse); P1X = (-(impulse) * m_u1.x); P1Y = (-(impulse) * m_u1.y); P2X = ((-(m_ratio) * impulse) * m_u2.x); P2Y = ((-(m_ratio) * impulse) * m_u2.y); b1.m_linearVelocity.x = (b1.m_linearVelocity.x + (b1.m_invMass * P1X)); b1.m_linearVelocity.y = (b1.m_linearVelocity.y + (b1.m_invMass * P1Y)); b1.m_angularVelocity = (b1.m_angularVelocity + (b1.m_invI * ((r1X * P1Y) - (r1Y * P1X)))); b2.m_linearVelocity.x = (b2.m_linearVelocity.x + (b2.m_invMass * P2X)); b2.m_linearVelocity.y = (b2.m_linearVelocity.y + (b2.m_invMass * P2Y)); b2.m_angularVelocity = (b2.m_angularVelocity + (b2.m_invI * ((r2X * P2Y) - (r2Y * P2X)))); }; if (m_limitState1 == e_atUpperLimit){ v1X = (b1.m_linearVelocity.x + (-(b1.m_angularVelocity) * r1Y)); v1Y = (b1.m_linearVelocity.y + (b1.m_angularVelocity * r1X)); Cdot = -(((m_u1.x * v1X) + (m_u1.y * v1Y))); impulse = (-(m_limitMass1) * Cdot); oldImpulse = m_limitImpulse1; m_limitImpulse1 = b2Math.b2Max(0, (m_limitImpulse1 + impulse)); impulse = (m_limitImpulse1 - oldImpulse); P1X = (-(impulse) * m_u1.x); P1Y = (-(impulse) * m_u1.y); b1.m_linearVelocity.x = (b1.m_linearVelocity.x + (b1.m_invMass * P1X)); b1.m_linearVelocity.y = (b1.m_linearVelocity.y + (b1.m_invMass * P1Y)); b1.m_angularVelocity = (b1.m_angularVelocity + (b1.m_invI * ((r1X * P1Y) - (r1Y * P1X)))); }; if (m_limitState2 == e_atUpperLimit){ v2X = (b2.m_linearVelocity.x + (-(b2.m_angularVelocity) * r2Y)); v2Y = (b2.m_linearVelocity.y + (b2.m_angularVelocity * r2X)); Cdot = -(((m_u2.x * v2X) + (m_u2.y * v2Y))); impulse = (-(m_limitMass2) * Cdot); oldImpulse = m_limitImpulse2; m_limitImpulse2 = b2Math.b2Max(0, (m_limitImpulse2 + impulse)); impulse = (m_limitImpulse2 - oldImpulse); P2X = (-(impulse) * m_u2.x); P2Y = (-(impulse) * m_u2.y); b2.m_linearVelocity.x = (b2.m_linearVelocity.x + (b2.m_invMass * P2X)); b2.m_linearVelocity.y = (b2.m_linearVelocity.y + (b2.m_invMass * P2Y)); b2.m_angularVelocity = (b2.m_angularVelocity + (b2.m_invI * ((r2X * P2Y) - (r2Y * P2X)))); }; } public function GetLength1():Number{ var p:b2Vec2 = m_body1.GetWorldPoint(m_localAnchor1); var sX:Number = (m_ground.m_xf.position.x + m_groundAnchor1.x); var sY:Number = (m_ground.m_xf.position.y + m_groundAnchor1.y); var dX:Number = (p.x - sX); var dY:Number = (p.y - sY); return (Math.sqrt(((dX * dX) + (dY * dY)))); } public function GetGroundAnchor1():b2Vec2{ var a:b2Vec2 = m_ground.m_xf.position.Copy(); a.Add(m_groundAnchor1); return (a); } } }//package Box2D.Dynamics.Joints
Section 69
//b2PulleyJointDef (Box2D.Dynamics.Joints.b2PulleyJointDef) package Box2D.Dynamics.Joints { import Box2D.Dynamics.*; import Box2D.Common.Math.*; public class b2PulleyJointDef extends b2JointDef { public var maxLength1:Number; public var maxLength2:Number; public var length1:Number; public var localAnchor1:b2Vec2; public var localAnchor2:b2Vec2; public var groundAnchor1:b2Vec2; public var groundAnchor2:b2Vec2; public var ratio:Number; public var length2:Number; public function b2PulleyJointDef(){ groundAnchor1 = new b2Vec2(); groundAnchor2 = new b2Vec2(); localAnchor1 = new b2Vec2(); localAnchor2 = new b2Vec2(); super(); type = b2Joint.e_pulleyJoint; groundAnchor1.Set(-1, 1); groundAnchor2.Set(1, 1); localAnchor1.Set(-1, 0); localAnchor2.Set(1, 0); length1 = 0; maxLength1 = 0; length2 = 0; maxLength2 = 0; ratio = 1; collideConnected = true; } public function Initialize(b1:b2Body, b2:b2Body, ga1:b2Vec2, ga2:b2Vec2, anchor1:b2Vec2, anchor2:b2Vec2, r:Number):void{ body1 = b1; body2 = b2; groundAnchor1.SetV(ga1); groundAnchor2.SetV(ga2); localAnchor1 = body1.GetLocalPoint(anchor1); localAnchor2 = body2.GetLocalPoint(anchor2); var d1X:Number = (anchor1.x - ga1.x); var d1Y:Number = (anchor1.y - ga1.y); length1 = Math.sqrt(((d1X * d1X) + (d1Y * d1Y))); var d2X:Number = (anchor2.x - ga2.x); var d2Y:Number = (anchor2.y - ga2.y); length2 = Math.sqrt(((d2X * d2X) + (d2Y * d2Y))); ratio = r; var C:Number = (length1 + (ratio * length2)); maxLength1 = (C - (ratio * b2PulleyJoint.b2_minPulleyLength)); maxLength2 = ((C - b2PulleyJoint.b2_minPulleyLength) / ratio); } } }//package Box2D.Dynamics.Joints
Section 70
//b2RevoluteJoint (Box2D.Dynamics.Joints.b2RevoluteJoint) package Box2D.Dynamics.Joints { import Box2D.Dynamics.*; import Box2D.Common.Math.*; import Box2D.Common.*; public class b2RevoluteJoint extends b2Joint { private var m_mass:b2Mat33; private var m_impulse:b2Vec3; private var m_enableLimit:Boolean; private var m_limitState:int; private var m_motorMass:Number; b2internal var m_localAnchor1:b2Vec2; b2internal var m_localAnchor2:b2Vec2; private var K1:b2Mat22; private var K2:b2Mat22; private var K3:b2Mat22; private var K:b2Mat22; private var m_motorImpulse:Number; private var m_enableMotor:Boolean; private var m_referenceAngle:Number; private var m_upperAngle:Number; private var m_motorSpeed:Number; private var m_lowerAngle:Number; private var m_maxMotorTorque:Number; private static var tImpulse:b2Vec2 = new b2Vec2(); public function b2RevoluteJoint(def:b2RevoluteJointDef){ K = new b2Mat22(); K1 = new b2Mat22(); K2 = new b2Mat22(); K3 = new b2Mat22(); m_localAnchor1 = new b2Vec2(); m_localAnchor2 = new b2Vec2(); m_impulse = new b2Vec3(); m_mass = new b2Mat33(); super(def); m_localAnchor1.SetV(def.localAnchor1); m_localAnchor2.SetV(def.localAnchor2); m_referenceAngle = def.referenceAngle; m_impulse.SetZero(); m_motorImpulse = 0; m_lowerAngle = def.lowerAngle; m_upperAngle = def.upperAngle; m_maxMotorTorque = def.maxMotorTorque; m_motorSpeed = def.motorSpeed; m_enableLimit = def.enableLimit; m_enableMotor = def.enableMotor; m_limitState = e_inactiveLimit; } override b2internal function SolveVelocityConstraints(step:b2TimeStep):void{ var tMat:b2Mat22; var tX:Number; var newImpulse:Number; var reduced:b2Vec2; var r1X:Number; var r1Y:Number; var r2X:Number; var r2Y:Number; var Cdot:Number; var impulse:Number; var oldImpulse:Number; var maxImpulse:Number; var Cdot1X:Number; var Cdot1Y:Number; var Cdot2:Number; var impulse3:b2Vec3; var CdotX:Number; var CdotY:Number; var impulse2:b2Vec2; var b1:b2Body = m_body1; var b2:b2Body = m_body2; var v1:b2Vec2 = b1.m_linearVelocity; var w1:Number = b1.m_angularVelocity; var v2:b2Vec2 = b2.m_linearVelocity; var w2:Number = b2.m_angularVelocity; var m1:Number = b1.m_invMass; var m2:Number = b2.m_invMass; var i1:Number = b1.m_invI; var i2:Number = b2.m_invI; if (((m_enableMotor) && (!((m_limitState == e_equalLimits))))){ Cdot = ((w2 - w1) - m_motorSpeed); impulse = (m_motorMass * -(Cdot)); oldImpulse = m_motorImpulse; maxImpulse = (step.dt * m_maxMotorTorque); m_motorImpulse = b2Math.b2Clamp((m_motorImpulse + impulse), -(maxImpulse), maxImpulse); impulse = (m_motorImpulse - oldImpulse); w1 = (w1 - (i1 * impulse)); w2 = (w2 + (i2 * impulse)); }; if (((m_enableLimit) && (!((m_limitState == e_inactiveLimit))))){ tMat = b1.m_xf.R; r1X = (m_localAnchor1.x - b1.m_sweep.localCenter.x); r1Y = (m_localAnchor1.y - b1.m_sweep.localCenter.y); tX = ((tMat.col1.x * r1X) + (tMat.col2.x * r1Y)); r1Y = ((tMat.col1.y * r1X) + (tMat.col2.y * r1Y)); r1X = tX; tMat = b2.m_xf.R; r2X = (m_localAnchor2.x - b2.m_sweep.localCenter.x); r2Y = (m_localAnchor2.y - b2.m_sweep.localCenter.y); tX = ((tMat.col1.x * r2X) + (tMat.col2.x * r2Y)); r2Y = ((tMat.col1.y * r2X) + (tMat.col2.y * r2Y)); r2X = tX; Cdot1X = (((v2.x + (-(w2) * r2Y)) - v1.x) - (-(w1) * r1Y)); Cdot1Y = (((v2.y + (w2 * r2X)) - v1.y) - (w1 * r1X)); Cdot2 = (w2 - w1); impulse3 = m_mass.Solve33(new b2Vec3(), -(Cdot1X), -(Cdot1Y), -(Cdot2)); if (m_limitState == e_equalLimits){ m_impulse.Add(impulse3); } else { if (m_limitState == e_atLowerLimit){ newImpulse = (m_impulse.z + impulse3.z); if (newImpulse < 0){ reduced = m_mass.Solve22(new b2Vec2(), -(Cdot1X), -(Cdot1Y)); impulse3.x = reduced.x; impulse3.y = reduced.y; impulse3.z = -(m_impulse.z); m_impulse.x = (m_impulse.x + reduced.x); m_impulse.y = (m_impulse.y + reduced.y); m_impulse.z = 0; }; } else { if (m_limitState == e_atUpperLimit){ newImpulse = (m_impulse.z + impulse3.z); if (newImpulse > 0){ reduced = m_mass.Solve22(new b2Vec2(), -(Cdot1X), -(Cdot1Y)); impulse3.x = reduced.x; impulse3.y = reduced.y; impulse3.z = -(m_impulse.z); m_impulse.x = (m_impulse.x + reduced.x); m_impulse.y = (m_impulse.y + reduced.y); m_impulse.z = 0; }; }; }; }; v1.x = (v1.x - (m1 * impulse3.x)); v1.y = (v1.y - (m1 * impulse3.y)); w1 = (w1 - (i1 * (((r1X * impulse3.y) - (r1Y * impulse3.x)) + impulse3.z))); v2.x = (v2.x + (m2 * impulse3.x)); v2.y = (v2.y + (m2 * impulse3.y)); w2 = (w2 + (i2 * (((r2X * impulse3.y) - (r2Y * impulse3.x)) + impulse3.z))); } else { tMat = b1.m_xf.R; r1X = (m_localAnchor1.x - b1.m_sweep.localCenter.x); r1Y = (m_localAnchor1.y - b1.m_sweep.localCenter.y); tX = ((tMat.col1.x * r1X) + (tMat.col2.x * r1Y)); r1Y = ((tMat.col1.y * r1X) + (tMat.col2.y * r1Y)); r1X = tX; tMat = b2.m_xf.R; r2X = (m_localAnchor2.x - b2.m_sweep.localCenter.x); r2Y = (m_localAnchor2.y - b2.m_sweep.localCenter.y); tX = ((tMat.col1.x * r2X) + (tMat.col2.x * r2Y)); r2Y = ((tMat.col1.y * r2X) + (tMat.col2.y * r2Y)); r2X = tX; CdotX = (((v2.x + (-(w2) * r2Y)) - v1.x) - (-(w1) * r1Y)); CdotY = (((v2.y + (w2 * r2X)) - v1.y) - (w1 * r1X)); impulse2 = m_mass.Solve22(new b2Vec2(), -(CdotX), -(CdotY)); m_impulse.x = (m_impulse.x + impulse2.x); m_impulse.y = (m_impulse.y + impulse2.y); v1.x = (v1.x - (m1 * impulse2.x)); v1.y = (v1.y - (m1 * impulse2.y)); w1 = (w1 - (i1 * ((r1X * impulse2.y) - (r1Y * impulse2.x)))); v2.x = (v2.x + (m2 * impulse2.x)); v2.y = (v2.y + (m2 * impulse2.y)); w2 = (w2 + (i2 * ((r2X * impulse2.y) - (r2Y * impulse2.x)))); }; b1.m_linearVelocity.SetV(v1); b1.m_angularVelocity = w1; b2.m_linearVelocity.SetV(v2); b2.m_angularVelocity = w2; } override public function GetAnchor1():b2Vec2{ return (m_body1.GetWorldPoint(m_localAnchor1)); } override public function GetAnchor2():b2Vec2{ return (m_body2.GetWorldPoint(m_localAnchor2)); } public function GetUpperLimit():Number{ return (m_upperAngle); } public function GetLowerLimit():Number{ return (m_lowerAngle); } public function EnableMotor(flag:Boolean):void{ m_enableMotor = flag; } public function GetMotorSpeed():Number{ return (m_motorSpeed); } override public function GetReactionForce(inv_dt:Number):b2Vec2{ return (new b2Vec2((inv_dt * m_impulse.x), (inv_dt * m_impulse.y))); } override b2internal function SolvePositionConstraints(baumgarte:Number):Boolean{ var oldLimitImpulse:Number; var C:Number; var tMat:b2Mat22; var tX:Number; var impulseX:Number; var impulseY:Number; var angle:Number; var limitImpulse:Number; var uX:Number; var uY:Number; var k:Number; var m:Number; var k_beta:Number; var b1:b2Body = m_body1; var b2:b2Body = m_body2; var angularError:Number = 0; var positionError:Number = 0; if (((m_enableLimit) && (!((m_limitState == e_inactiveLimit))))){ angle = ((b2.m_sweep.a - b1.m_sweep.a) - m_referenceAngle); limitImpulse = 0; if (m_limitState == e_equalLimits){ C = b2Math.b2Clamp(angle, -(b2Settings.b2_maxAngularCorrection), b2Settings.b2_maxAngularCorrection); limitImpulse = (-(m_motorMass) * C); angularError = b2Math.b2Abs(C); } else { if (m_limitState == e_atLowerLimit){ C = (angle - m_lowerAngle); angularError = -(C); C = b2Math.b2Clamp((C + b2Settings.b2_angularSlop), -(b2Settings.b2_maxAngularCorrection), 0); limitImpulse = (-(m_motorMass) * C); } else { if (m_limitState == e_atUpperLimit){ C = (angle - m_upperAngle); angularError = C; C = b2Math.b2Clamp((C - b2Settings.b2_angularSlop), 0, b2Settings.b2_maxAngularCorrection); limitImpulse = (-(m_motorMass) * C); }; }; }; b1.m_sweep.a = (b1.m_sweep.a - (b1.m_invI * limitImpulse)); b2.m_sweep.a = (b2.m_sweep.a + (b2.m_invI * limitImpulse)); b1.SynchronizeTransform(); b2.SynchronizeTransform(); }; tMat = b1.m_xf.R; var r1X:Number = (m_localAnchor1.x - b1.m_sweep.localCenter.x); var r1Y:Number = (m_localAnchor1.y - b1.m_sweep.localCenter.y); tX = ((tMat.col1.x * r1X) + (tMat.col2.x * r1Y)); r1Y = ((tMat.col1.y * r1X) + (tMat.col2.y * r1Y)); r1X = tX; tMat = b2.m_xf.R; var r2X:Number = (m_localAnchor2.x - b2.m_sweep.localCenter.x); var r2Y:Number = (m_localAnchor2.y - b2.m_sweep.localCenter.y); tX = ((tMat.col1.x * r2X) + (tMat.col2.x * r2Y)); r2Y = ((tMat.col1.y * r2X) + (tMat.col2.y * r2Y)); r2X = tX; var CX:Number = (((b2.m_sweep.c.x + r2X) - b1.m_sweep.c.x) - r1X); var CY:Number = (((b2.m_sweep.c.y + r2Y) - b1.m_sweep.c.y) - r1Y); var CLengthSquared:Number = ((CX * CX) + (CY * CY)); var CLength:Number = Math.sqrt(CLengthSquared); positionError = CLength; var invMass1:Number = b1.m_invMass; var invMass2:Number = b2.m_invMass; var invI1:Number = b1.m_invI; var invI2:Number = b2.m_invI; var k_allowedStretch:Number = (10 * b2Settings.b2_linearSlop); if (CLengthSquared > (k_allowedStretch * k_allowedStretch)){ uX = (CX / CLength); uY = (CY / CLength); k = (invMass1 + invMass2); m = (1 / k); impulseX = (m * -(CX)); impulseY = (m * -(CY)); k_beta = 0.5; b1.m_sweep.c.x = (b1.m_sweep.c.x - ((k_beta * invMass1) * impulseX)); b1.m_sweep.c.y = (b1.m_sweep.c.y - ((k_beta * invMass1) * impulseY)); b2.m_sweep.c.x = (b2.m_sweep.c.x + ((k_beta * invMass2) * impulseX)); b2.m_sweep.c.y = (b2.m_sweep.c.y + ((k_beta * invMass2) * impulseY)); CX = (((b2.m_sweep.c.x + r2X) - b1.m_sweep.c.x) - r1X); CY = (((b2.m_sweep.c.y + r2Y) - b1.m_sweep.c.y) - r1Y); }; K1.col1.x = (invMass1 + invMass2); K1.col2.x = 0; K1.col1.y = 0; K1.col2.y = (invMass1 + invMass2); K2.col1.x = ((invI1 * r1Y) * r1Y); K2.col2.x = ((-(invI1) * r1X) * r1Y); K2.col1.y = ((-(invI1) * r1X) * r1Y); K2.col2.y = ((invI1 * r1X) * r1X); K3.col1.x = ((invI2 * r2Y) * r2Y); K3.col2.x = ((-(invI2) * r2X) * r2Y); K3.col1.y = ((-(invI2) * r2X) * r2Y); K3.col2.y = ((invI2 * r2X) * r2X); K.SetM(K1); K.AddM(K2); K.AddM(K3); K.Solve(tImpulse, -(CX), -(CY)); impulseX = tImpulse.x; impulseY = tImpulse.y; b1.m_sweep.c.x = (b1.m_sweep.c.x - (b1.m_invMass * impulseX)); b1.m_sweep.c.y = (b1.m_sweep.c.y - (b1.m_invMass * impulseY)); b1.m_sweep.a = (b1.m_sweep.a - (b1.m_invI * ((r1X * impulseY) - (r1Y * impulseX)))); b2.m_sweep.c.x = (b2.m_sweep.c.x + (b2.m_invMass * impulseX)); b2.m_sweep.c.y = (b2.m_sweep.c.y + (b2.m_invMass * impulseY)); b2.m_sweep.a = (b2.m_sweep.a + (b2.m_invI * ((r2X * impulseY) - (r2Y * impulseX)))); b1.SynchronizeTransform(); b2.SynchronizeTransform(); return ((((positionError <= b2Settings.b2_linearSlop)) && ((angularError <= b2Settings.b2_angularSlop)))); } public function SetMotorSpeed(speed:Number):void{ m_body1.WakeUp(); m_body2.WakeUp(); m_motorSpeed = speed; } public function GetJointSpeed():Number{ return ((m_body2.m_angularVelocity - m_body1.m_angularVelocity)); } public function SetMaxMotorTorque(torque:Number):void{ m_maxMotorTorque = torque; } public function GetJointAngle():Number{ return (((m_body2.m_sweep.a - m_body1.m_sweep.a) - m_referenceAngle)); } public function GetMotorTorque():Number{ return (m_maxMotorTorque); } override b2internal function InitVelocityConstraints(step:b2TimeStep):void{ var b1:b2Body; var b2:b2Body; var tMat:b2Mat22; var tX:Number; var r1X:Number; var r1Y:Number; var jointAngle:Number; var PX:Number; var PY:Number; b1 = m_body1; b2 = m_body2; if (((m_enableMotor) || (m_enableLimit))){ }; tMat = b1.m_xf.R; r1X = (m_localAnchor1.x - b1.m_sweep.localCenter.x); r1Y = (m_localAnchor1.y - b1.m_sweep.localCenter.y); tX = ((tMat.col1.x * r1X) + (tMat.col2.x * r1Y)); r1Y = ((tMat.col1.y * r1X) + (tMat.col2.y * r1Y)); r1X = tX; tMat = b2.m_xf.R; var r2X:Number = (m_localAnchor2.x - b2.m_sweep.localCenter.x); var r2Y:Number = (m_localAnchor2.y - b2.m_sweep.localCenter.y); tX = ((tMat.col1.x * r2X) + (tMat.col2.x * r2Y)); r2Y = ((tMat.col1.y * r2X) + (tMat.col2.y * r2Y)); r2X = tX; var m1:Number = b1.m_invMass; var m2:Number = b2.m_invMass; var i1:Number = b1.m_invI; var i2:Number = b2.m_invI; m_mass.col1.x = (((m1 + m2) + ((r1Y * r1Y) * i1)) + ((r2Y * r2Y) * i2)); m_mass.col2.x = (((-(r1Y) * r1X) * i1) - ((r2Y * r2X) * i2)); m_mass.col3.x = ((-(r1Y) * i1) - (r2Y * i2)); m_mass.col1.y = m_mass.col2.x; m_mass.col2.y = (((m1 + m2) + ((r1X * r1X) * i1)) + ((r2X * r2X) * i2)); m_mass.col3.y = ((r1X * i1) + (r2X * i2)); m_mass.col1.z = m_mass.col3.x; m_mass.col2.z = m_mass.col3.y; m_mass.col3.z = (i1 + i2); m_motorMass = (1 / (i1 + i2)); if (m_enableMotor == false){ m_motorImpulse = 0; }; if (m_enableLimit){ jointAngle = ((b2.m_sweep.a - b1.m_sweep.a) - m_referenceAngle); if (b2Math.b2Abs((m_upperAngle - m_lowerAngle)) < (2 * b2Settings.b2_angularSlop)){ m_limitState = e_equalLimits; } else { if (jointAngle <= m_lowerAngle){ if (m_limitState != e_atLowerLimit){ m_impulse.z = 0; }; m_limitState = e_atLowerLimit; } else { if (jointAngle >= m_upperAngle){ if (m_limitState != e_atUpperLimit){ m_impulse.z = 0; }; m_limitState = e_atUpperLimit; } else { m_limitState = e_inactiveLimit; m_impulse.z = 0; }; }; }; } else { m_limitState = e_inactiveLimit; }; if (step.warmStarting){ m_impulse.x = (m_impulse.x * step.dtRatio); m_impulse.y = (m_impulse.y * step.dtRatio); m_motorImpulse = (m_motorImpulse * step.dtRatio); PX = m_impulse.x; PY = m_impulse.y; b1.m_linearVelocity.x = (b1.m_linearVelocity.x - (m1 * PX)); b1.m_linearVelocity.y = (b1.m_linearVelocity.y - (m1 * PY)); b1.m_angularVelocity = (b1.m_angularVelocity - (i1 * ((((r1X * PY) - (r1Y * PX)) + m_motorImpulse) + m_impulse.z))); b2.m_linearVelocity.x = (b2.m_linearVelocity.x + (m2 * PX)); b2.m_linearVelocity.y = (b2.m_linearVelocity.y + (m2 * PY)); b2.m_angularVelocity = (b2.m_angularVelocity + (i2 * ((((r2X * PY) - (r2Y * PX)) + m_motorImpulse) + m_impulse.z))); } else { m_impulse.SetZero(); m_motorImpulse = 0; }; } public function EnableLimit(flag:Boolean):void{ m_enableLimit = flag; } override public function GetReactionTorque(inv_dt:Number):Number{ return ((inv_dt * m_impulse.z)); } public function IsLimitEnabled():Boolean{ return (m_enableLimit); } public function IsMotorEnabled():Boolean{ m_body1.WakeUp(); m_body2.WakeUp(); return (m_enableMotor); } public function SetLimits(lower:Number, upper:Number):void{ m_lowerAngle = lower; m_upperAngle = upper; } } }//package Box2D.Dynamics.Joints
Section 71
//b2RevoluteJointDef (Box2D.Dynamics.Joints.b2RevoluteJointDef) package Box2D.Dynamics.Joints { import Box2D.Dynamics.*; import Box2D.Common.Math.*; public class b2RevoluteJointDef extends b2JointDef { public var upperAngle:Number; public var enableMotor:Boolean; public var referenceAngle:Number; public var motorSpeed:Number; public var localAnchor1:b2Vec2; public var localAnchor2:b2Vec2; public var enableLimit:Boolean; public var lowerAngle:Number; public var maxMotorTorque:Number; public function b2RevoluteJointDef(){ localAnchor1 = new b2Vec2(); localAnchor2 = new b2Vec2(); super(); type = b2Joint.e_revoluteJoint; localAnchor1.Set(0, 0); localAnchor2.Set(0, 0); referenceAngle = 0; lowerAngle = 0; upperAngle = 0; maxMotorTorque = 0; motorSpeed = 0; enableLimit = false; enableMotor = false; } public function Initialize(b1:b2Body, b2:b2Body, anchor:b2Vec2):void{ body1 = b1; body2 = b2; localAnchor1 = body1.GetLocalPoint(anchor); localAnchor2 = body2.GetLocalPoint(anchor); referenceAngle = (body2.GetAngle() - body1.GetAngle()); } } }//package Box2D.Dynamics.Joints
Section 72
//b2Body (Box2D.Dynamics.b2Body) package Box2D.Dynamics { import Box2D.Collision.Shapes.*; import Box2D.Dynamics.Contacts.*; import Box2D.Common.Math.*; import Box2D.Dynamics.Joints.*; import Box2D.Common.*; public class b2Body { b2internal var m_next:b2Body; b2internal var m_angularVelocity:Number; b2internal var m_xf:b2XForm; b2internal var m_contactList:b2ContactEdge; b2internal var m_shapeList:b2Shape; b2internal var m_force:b2Vec2; b2internal var m_sweep:b2Sweep; b2internal var m_mass:Number; b2internal var m_torque:Number; private var m_userData; b2internal var m_flags:uint; b2internal var m_world:b2World; b2internal var m_prev:b2Body; b2internal var m_invMass:Number; private var m_type:int; b2internal var m_linearDamping:Number; b2internal var m_angularDamping:Number; b2internal var m_invI:Number; b2internal var m_shapeCount:int; b2internal var m_linearVelocity:b2Vec2; b2internal var m_islandIndex:int; b2internal var m_jointList:b2JointEdge; b2internal var m_sleepTime:Number; b2internal var m_I:Number; b2internal static var e_fixedRotationFlag:uint = 64; b2internal static var e_frozenFlag:uint = 2; b2internal static var e_maxTypes:uint = 3; b2internal static var e_sleepFlag:uint = 8; private static var s_massData:b2MassData = new b2MassData(); b2internal static var e_bulletFlag:uint = 32; b2internal static var e_staticType:uint = 1; b2internal static var e_islandFlag:uint = 4; b2internal static var e_allowSleepFlag:uint = 16; private static var s_xf1:b2XForm = new b2XForm(); b2internal static var e_dynamicType:uint = 2; public function b2Body(bd:b2BodyDef, world:b2World){ m_xf = new b2XForm(); m_sweep = new b2Sweep(); m_linearVelocity = new b2Vec2(); m_force = new b2Vec2(); super(); m_flags = 0; if (bd.isBullet){ m_flags = (m_flags | e_bulletFlag); }; if (bd.fixedRotation){ m_flags = (m_flags | e_fixedRotationFlag); }; if (bd.allowSleep){ m_flags = (m_flags | e_allowSleepFlag); }; if (bd.isSleeping){ m_flags = (m_flags | e_sleepFlag); }; m_world = world; m_xf.position.SetV(bd.position); m_xf.R.Set(bd.angle); m_sweep.localCenter.SetV(bd.massData.center); m_sweep.t0 = 1; m_sweep.a0 = (m_sweep.a = bd.angle); var tMat:b2Mat22 = m_xf.R; var tVec:b2Vec2 = m_sweep.localCenter; m_sweep.c.x = ((tMat.col1.x * tVec.x) + (tMat.col2.x * tVec.y)); m_sweep.c.y = ((tMat.col1.y * tVec.x) + (tMat.col2.y * tVec.y)); m_sweep.c.x = (m_sweep.c.x + m_xf.position.x); m_sweep.c.y = (m_sweep.c.y + m_xf.position.y); m_sweep.c0.SetV(m_sweep.c); m_jointList = null; m_contactList = null; m_prev = null; m_next = null; m_linearDamping = bd.linearDamping; m_angularDamping = bd.angularDamping; m_force.Set(0, 0); m_torque = 0; m_linearVelocity.SetZero(); m_angularVelocity = 0; m_sleepTime = 0; m_invMass = 0; m_I = 0; m_invI = 0; m_mass = bd.massData.mass; if (m_mass > 0){ m_invMass = (1 / m_mass); }; if ((m_flags & b2Body.e_fixedRotationFlag) == 0){ m_I = bd.massData.I; }; if (m_I > 0){ m_invI = (1 / m_I); }; if ((((m_invMass == 0)) && ((m_invI == 0)))){ m_type = e_staticType; } else { m_type = e_dynamicType; }; m_userData = bd.userData; m_shapeList = null; m_shapeCount = 0; } public function GetLinearVelocityFromWorldPoint(worldPoint:b2Vec2):b2Vec2{ return (new b2Vec2((m_linearVelocity.x - (m_angularVelocity * (worldPoint.y - m_sweep.c.y))), (m_linearVelocity.y + (m_angularVelocity * (worldPoint.x - m_sweep.c.x))))); } public function SetLinearVelocity(v:b2Vec2):void{ m_linearVelocity.SetV(v); } public function WakeUp():void{ m_flags = (m_flags & ~(e_sleepFlag)); m_sleepTime = 0; } public function ApplyTorque(torque:Number):void{ if (IsSleeping()){ WakeUp(); }; m_torque = (m_torque + torque); } public function GetLocalCenter():b2Vec2{ return (m_sweep.localCenter); } private function connectEdges(s1:b2EdgeShape, s2:b2EdgeShape, angle1:Number):Number{ var angle2:Number = Math.atan2(s2.GetDirectionVector().y, s2.GetDirectionVector().x); var coreOffset:Number = Math.tan(((angle2 - angle1) * 0.5)); var core:b2Vec2 = b2Math.MulFV(coreOffset, s2.GetDirectionVector()); core = b2Math.SubtractVV(core, s2.GetNormalVector()); core = b2Math.MulFV(b2Settings.b2_toiSlop, core); core = b2Math.AddVV(core, s2.GetVertex1()); var cornerDir:b2Vec2 = b2Math.AddVV(s1.GetDirectionVector(), s2.GetDirectionVector()); cornerDir.Normalize(); var convex = (b2Math.b2Dot(s1.GetDirectionVector(), s2.GetNormalVector()) > 0); s1.SetNextEdge(s2, core, cornerDir, convex); s2.SetPrevEdge(s1, core, cornerDir, convex); return (angle2); } public function GetLinearVelocity():b2Vec2{ return (m_linearVelocity); } public function IsFrozen():Boolean{ return (((m_flags & e_frozenFlag) == e_frozenFlag)); } public function IsDynamic():Boolean{ return ((m_type == e_dynamicType)); } b2internal function SynchronizeTransform():void{ m_xf.R.Set(m_sweep.a); var tMat:b2Mat22 = m_xf.R; var tVec:b2Vec2 = m_sweep.localCenter; m_xf.position.x = (m_sweep.c.x - ((tMat.col1.x * tVec.x) + (tMat.col2.x * tVec.y))); m_xf.position.y = (m_sweep.c.y - ((tMat.col1.y * tVec.x) + (tMat.col2.y * tVec.y))); } public function GetInertia():Number{ return (m_I); } public function IsSleeping():Boolean{ return (((m_flags & e_sleepFlag) == e_sleepFlag)); } public function SetMassFromShapes():void{ var s:b2Shape; if (m_world.m_lock == true){ return; }; m_mass = 0; m_invMass = 0; m_I = 0; m_invI = 0; var centerX:Number = 0; var centerY:Number = 0; var massData:b2MassData = s_massData; s = m_shapeList; while (s) { s.ComputeMass(massData); m_mass = (m_mass + massData.mass); centerX = (centerX + (massData.mass * massData.center.x)); centerY = (centerY + (massData.mass * massData.center.y)); m_I = (m_I + massData.I); s = s.m_next; }; if (m_mass > 0){ m_invMass = (1 / m_mass); centerX = (centerX * m_invMass); centerY = (centerY * m_invMass); }; if ((((m_I > 0)) && (((m_flags & e_fixedRotationFlag) == 0)))){ m_I = (m_I - (m_mass * ((centerX * centerX) + (centerY * centerY)))); m_invI = (1 / m_I); } else { m_I = 0; m_invI = 0; }; m_sweep.localCenter.Set(centerX, centerY); var tMat:b2Mat22 = m_xf.R; var tVec:b2Vec2 = m_sweep.localCenter; m_sweep.c.x = ((tMat.col1.x * tVec.x) + (tMat.col2.x * tVec.y)); m_sweep.c.y = ((tMat.col1.y * tVec.x) + (tMat.col2.y * tVec.y)); m_sweep.c.x = (m_sweep.c.x + m_xf.position.x); m_sweep.c.y = (m_sweep.c.y + m_xf.position.y); m_sweep.c0.SetV(m_sweep.c); s = m_shapeList; while (s) { s.UpdateSweepRadius(m_sweep.localCenter); s = s.m_next; }; var oldType:int = m_type; if ((((m_invMass == 0)) && ((m_invI == 0)))){ m_type = e_staticType; } else { m_type = e_dynamicType; }; if (oldType != m_type){ s = m_shapeList; while (s) { s.RefilterProxy(m_world.m_broadPhase, m_xf); s = s.m_next; }; }; } public function PutToSleep():void{ m_flags = (m_flags | e_sleepFlag); m_sleepTime = 0; m_linearVelocity.SetZero(); m_angularVelocity = 0; m_force.SetZero(); m_torque = 0; } public function GetJointList():b2JointEdge{ return (m_jointList); } public function SetXForm(position:b2Vec2, angle:Number):Boolean{ var s:b2Shape; var inRange:Boolean; if (m_world.m_lock == true){ return (true); }; if (IsFrozen()){ return (false); }; m_xf.R.Set(angle); m_xf.position.SetV(position); var tMat:b2Mat22 = m_xf.R; var tVec:b2Vec2 = m_sweep.localCenter; m_sweep.c.x = ((tMat.col1.x * tVec.x) + (tMat.col2.x * tVec.y)); m_sweep.c.y = ((tMat.col1.y * tVec.x) + (tMat.col2.y * tVec.y)); m_sweep.c.x = (m_sweep.c.x + m_xf.position.x); m_sweep.c.y = (m_sweep.c.y + m_xf.position.y); m_sweep.c0.SetV(m_sweep.c); m_sweep.a0 = (m_sweep.a = angle); var freeze:Boolean; s = m_shapeList; while (s) { inRange = s.Synchronize(m_world.m_broadPhase, m_xf, m_xf); if (inRange == false){ freeze = true; break; }; s = s.m_next; }; if (freeze == true){ m_flags = (m_flags | e_frozenFlag); m_linearVelocity.SetZero(); m_angularVelocity = 0; s = m_shapeList; while (s) { s.DestroyProxy(m_world.m_broadPhase); s = s.m_next; }; return (false); }; m_world.m_broadPhase.Commit(); return (true); } public function GetLocalPoint(worldPoint:b2Vec2):b2Vec2{ return (b2Math.b2MulXT(m_xf, worldPoint)); } public function SetAngularVelocity(omega:Number):void{ m_angularVelocity = omega; } b2internal function SynchronizeShapes():Boolean{ var s:b2Shape; var xf1:b2XForm = s_xf1; xf1.R.Set(m_sweep.a0); var tMat:b2Mat22 = xf1.R; var tVec:b2Vec2 = m_sweep.localCenter; xf1.position.x = (m_sweep.c0.x - ((tMat.col1.x * tVec.x) + (tMat.col2.x * tVec.y))); xf1.position.y = (m_sweep.c0.y - ((tMat.col1.y * tVec.x) + (tMat.col2.y * tVec.y))); var inRange:Boolean; s = m_shapeList; while (s) { inRange = s.Synchronize(m_world.m_broadPhase, xf1, m_xf); if (inRange == false){ break; }; s = s.m_next; }; if (inRange == false){ m_flags = (m_flags | e_frozenFlag); m_linearVelocity.SetZero(); m_angularVelocity = 0; s = m_shapeList; while (s) { s.DestroyProxy(m_world.m_broadPhase); s = s.m_next; }; return (false); }; return (true); } public function GetAngle():Number{ return (m_sweep.a); } public function GetXForm():b2XForm{ return (m_xf); } public function ApplyImpulse(impulse:b2Vec2, point:b2Vec2):void{ if (IsSleeping()){ WakeUp(); }; m_linearVelocity.x = (m_linearVelocity.x + (m_invMass * impulse.x)); m_linearVelocity.y = (m_linearVelocity.y + (m_invMass * impulse.y)); m_angularVelocity = (m_angularVelocity + (m_invI * (((point.x - m_sweep.c.x) * impulse.y) - ((point.y - m_sweep.c.y) * impulse.x)))); } public function GetAngularVelocity():Number{ return (m_angularVelocity); } public function GetMass():Number{ return (m_mass); } public function GetLinearVelocityFromLocalPoint(localPoint:b2Vec2):b2Vec2{ var A:b2Mat22 = m_xf.R; var worldPoint:b2Vec2 = new b2Vec2(((A.col1.x * localPoint.x) + (A.col2.x * localPoint.y)), ((A.col1.y * localPoint.x) + (A.col2.y * localPoint.y))); worldPoint.x = (worldPoint.x + m_xf.position.x); worldPoint.y = (worldPoint.y + m_xf.position.y); return (new b2Vec2((m_linearVelocity.x - (m_angularVelocity * (worldPoint.y - m_sweep.c.y))), (m_linearVelocity.y + (m_angularVelocity * (worldPoint.x - m_sweep.c.x))))); } public function GetShapeList():b2Shape{ return (m_shapeList); } public function ApplyForce(force:b2Vec2, point:b2Vec2):void{ if (IsSleeping()){ WakeUp(); }; m_force.x = (m_force.x + force.x); m_force.y = (m_force.y + force.y); m_torque = (m_torque + (((point.x - m_sweep.c.x) * force.y) - ((point.y - m_sweep.c.y) * force.x))); } public function SetMass(massData:b2MassData):void{ var s:b2Shape; if (m_world.m_lock == true){ return; }; m_invMass = 0; m_I = 0; m_invI = 0; m_mass = massData.mass; if (m_mass > 0){ m_invMass = (1 / m_mass); }; if ((m_flags & b2Body.e_fixedRotationFlag) == 0){ m_I = massData.I; }; if (m_I > 0){ m_invI = (1 / m_I); }; m_sweep.localCenter.SetV(massData.center); var tMat:b2Mat22 = m_xf.R; var tVec:b2Vec2 = m_sweep.localCenter; m_sweep.c.x = ((tMat.col1.x * tVec.x) + (tMat.col2.x * tVec.y)); m_sweep.c.y = ((tMat.col1.y * tVec.x) + (tMat.col2.y * tVec.y)); m_sweep.c.x = (m_sweep.c.x + m_xf.position.x); m_sweep.c.y = (m_sweep.c.y + m_xf.position.y); m_sweep.c0.SetV(m_sweep.c); s = m_shapeList; while (s) { s.UpdateSweepRadius(m_sweep.localCenter); s = s.m_next; }; var oldType:int = m_type; if ((((m_invMass == 0)) && ((m_invI == 0)))){ m_type = e_staticType; } else { m_type = e_dynamicType; }; if (oldType != m_type){ s = m_shapeList; while (s) { s.RefilterProxy(m_world.m_broadPhase, m_xf); s = s.m_next; }; }; } public function IsStatic():Boolean{ return ((m_type == e_staticType)); } public function GetWorldVector(localVector:b2Vec2):b2Vec2{ return (b2Math.b2MulMV(m_xf.R, localVector)); } public function GetNext():b2Body{ return (m_next); } b2internal function Advance(t:Number):void{ m_sweep.Advance(t); m_sweep.c.SetV(m_sweep.c0); m_sweep.a = m_sweep.a0; SynchronizeTransform(); } public function SetBullet(flag:Boolean):void{ if (flag){ m_flags = (m_flags | e_bulletFlag); } else { m_flags = (m_flags & ~(e_bulletFlag)); }; } public function CreateShape(def:b2ShapeDef):b2Shape{ var edgeDef:b2EdgeChainDef; var v1:b2Vec2; var v2:b2Vec2; var i:int; var s0:b2EdgeShape; var s1:b2EdgeShape; var s2:b2EdgeShape; var angle:Number; if (m_world.m_lock == true){ return (null); }; if (def.type == b2Shape.e_edgeShape){ edgeDef = (def as b2EdgeChainDef); if (edgeDef.isALoop){ v1 = edgeDef.vertices[(edgeDef.vertexCount - 1)]; i = 0; } else { v1 = edgeDef.vertices[0]; i = 1; }; s0 = null; s1 = null; s2 = null; angle = 0; while (i < edgeDef.vertexCount) { v2 = edgeDef.vertices[i]; s2 = new b2EdgeShape(v1, v2, def); s2.m_next = m_shapeList; m_shapeList = s2; m_shapeCount++; s2.m_body = this; s2.CreateProxy(m_world.m_broadPhase, m_xf); s2.UpdateSweepRadius(m_sweep.localCenter); if (s1 == null){ s0 = s2; angle = Math.atan2(s2.GetDirectionVector().y, s2.GetDirectionVector().x); } else { angle = connectEdges(s1, s2, angle); }; s1 = s2; v1 = v2; i++; }; if (edgeDef.isALoop){ connectEdges(s1, s0, angle); }; return (s0); }; var s:b2Shape = b2Shape.Create(def, m_world.m_blockAllocator); s.m_next = m_shapeList; m_shapeList = s; m_shapeCount++; s.m_body = this; s.CreateProxy(m_world.m_broadPhase, m_xf); s.UpdateSweepRadius(m_sweep.localCenter); return (s); } b2internal function IsConnected(other:b2Body):Boolean{ var jn:b2JointEdge = m_jointList; while (jn) { if (jn.other == other){ return ((jn.joint.m_collideConnected == false)); }; jn = jn.next; }; return (false); } public function DestroyShape(s:b2Shape):void{ if (m_world.m_lock == true){ return; }; s.DestroyProxy(m_world.m_broadPhase); var node:b2Shape = m_shapeList; var ppS:b2Shape; var found:Boolean; while (node != null) { if (node == s){ if (ppS){ ppS.m_next = s.m_next; } else { m_shapeList = s.m_next; }; found = true; break; }; ppS = node; node = node.m_next; }; s.m_body = null; s.m_next = null; m_shapeCount--; b2Shape.Destroy(s, m_world.m_blockAllocator); } public function GetUserData(){ return (m_userData); } public function IsBullet():Boolean{ return (((m_flags & e_bulletFlag) == e_bulletFlag)); } public function GetWorldCenter():b2Vec2{ return (m_sweep.c); } public function AllowSleeping(flag:Boolean):void{ if (flag){ m_flags = (m_flags | e_allowSleepFlag); } else { m_flags = (m_flags & ~(e_allowSleepFlag)); WakeUp(); }; } public function SetUserData(data):void{ m_userData = data; } public function GetLocalVector(worldVector:b2Vec2):b2Vec2{ return (b2Math.b2MulTMV(m_xf.R, worldVector)); } public function GetWorldPoint(localPoint:b2Vec2):b2Vec2{ var A:b2Mat22 = m_xf.R; var u:b2Vec2 = new b2Vec2(((A.col1.x * localPoint.x) + (A.col2.x * localPoint.y)), ((A.col1.y * localPoint.x) + (A.col2.y * localPoint.y))); u.x = (u.x + m_xf.position.x); u.y = (u.y + m_xf.position.y); return (u); } public function GetWorld():b2World{ return (m_world); } public function GetPosition():b2Vec2{ return (m_xf.position); } } }//package Box2D.Dynamics
Section 73
//b2BodyDef (Box2D.Dynamics.b2BodyDef) package Box2D.Dynamics { import Box2D.Collision.Shapes.*; import Box2D.Common.Math.*; public class b2BodyDef { public var angularDamping:Number; public var angle:Number; public var isSleeping:Boolean; public var position:b2Vec2; public var isBullet:Boolean; public var allowSleep:Boolean; public var userData; public var fixedRotation:Boolean; public var linearDamping:Number; public var massData:b2MassData; public function b2BodyDef(){ massData = new b2MassData(); position = new b2Vec2(); super(); massData.center.SetZero(); massData.mass = 0; massData.I = 0; userData = null; position.Set(0, 0); angle = 0; linearDamping = 0; angularDamping = 0; allowSleep = true; isSleeping = false; fixedRotation = false; isBullet = false; } } }//package Box2D.Dynamics
Section 74
//b2BoundaryListener (Box2D.Dynamics.b2BoundaryListener) package Box2D.Dynamics { public class b2BoundaryListener { public function b2BoundaryListener(){ super(); } public function Violation(body:b2Body):void{ } } }//package Box2D.Dynamics
Section 75
//b2ContactFilter (Box2D.Dynamics.b2ContactFilter) package Box2D.Dynamics { import Box2D.Collision.Shapes.*; import Box2D.Common.*; public class b2ContactFilter { b2internal static var b2_defaultFilter:b2ContactFilter = new (b2ContactFilter); ; public function b2ContactFilter(){ super(); } public function ShouldCollide(shape1:b2Shape, shape2:b2Shape):Boolean{ var filter1:b2FilterData = shape1.GetFilterData(); var filter2:b2FilterData = shape2.GetFilterData(); if ((((filter1.groupIndex == filter2.groupIndex)) && (!((filter1.groupIndex == 0))))){ return ((filter1.groupIndex > 0)); }; var collide:Boolean = ((!(((filter1.maskBits & filter2.categoryBits) == 0))) && (!(((filter1.categoryBits & filter2.maskBits) == 0)))); return (collide); } public function RayCollide(userData, shape:b2Shape):Boolean{ if (!userData){ return (true); }; return (ShouldCollide((userData as b2Shape), shape)); } } }//package Box2D.Dynamics
Section 76
//b2ContactListener (Box2D.Dynamics.b2ContactListener) package Box2D.Dynamics { import Box2D.Collision.*; import Box2D.Dynamics.Contacts.*; public class b2ContactListener { public function b2ContactListener(){ super(); } public function Add(point:b2ContactPoint):void{ } public function Remove(point:b2ContactPoint):void{ } public function Persist(point:b2ContactPoint):void{ } public function Result(point:b2ContactResult):void{ } } }//package Box2D.Dynamics
Section 77
//b2ContactManager (Box2D.Dynamics.b2ContactManager) package Box2D.Dynamics { import Box2D.Collision.Shapes.*; import Box2D.Collision.*; import Box2D.Dynamics.Contacts.*; import Box2D.Common.Math.*; import Box2D.Common.*; public class b2ContactManager extends b2PairCallback { b2internal var m_world:b2World; private var m_destroyImmediate:Boolean; private var m_nullContact:b2NullContact; private static const s_evalCP:b2ContactPoint = new b2ContactPoint(); public function b2ContactManager(){ m_nullContact = new b2NullContact(); super(); m_world = null; m_destroyImmediate = false; } override public function PairRemoved(proxyUserData1, proxyUserData2, pairUserData):void{ if (pairUserData == null){ return; }; var c:b2Contact = (pairUserData as b2Contact); if (c == m_nullContact){ return; }; Destroy(c); } public function Destroy(c:b2Contact):void{ var manifolds:Array; var i:int; var manifold:b2Manifold; var j:int; var mp:b2ManifoldPoint; var v1:b2Vec2; var v2:b2Vec2; var shape1:b2Shape = c.m_shape1; var shape2:b2Shape = c.m_shape2; var body1:b2Body = shape1.m_body; var body2:b2Body = shape2.m_body; var cp:b2ContactPoint = s_evalCP; cp.shape1 = c.m_shape1; cp.shape2 = c.m_shape2; cp.friction = b2Settings.b2MixFriction(shape1.GetFriction(), shape2.GetFriction()); cp.restitution = b2Settings.b2MixRestitution(shape1.GetRestitution(), shape2.GetRestitution()); var manifoldCount:int = c.m_manifoldCount; if ((((manifoldCount > 0)) && (m_world.m_contactListener))){ manifolds = c.GetManifolds(); i = 0; while (i < manifoldCount) { manifold = manifolds[i]; cp.normal.SetV(manifold.normal); j = 0; while (j < manifold.pointCount) { mp = manifold.points[j]; cp.position = body1.GetWorldPoint(mp.localPoint1); v1 = body1.GetLinearVelocityFromLocalPoint(mp.localPoint1); v2 = body2.GetLinearVelocityFromLocalPoint(mp.localPoint2); cp.velocity.Set((v2.x - v1.x), (v2.y - v1.y)); cp.separation = mp.separation; cp.id.key = mp.id._key; m_world.m_contactListener.Remove(cp); j++; }; i++; }; }; if (c.m_prev){ c.m_prev.m_next = c.m_next; }; if (c.m_next){ c.m_next.m_prev = c.m_prev; }; if (c == m_world.m_contactList){ m_world.m_contactList = c.m_next; }; if (c.m_node1.prev){ c.m_node1.prev.next = c.m_node1.next; }; if (c.m_node1.next){ c.m_node1.next.prev = c.m_node1.prev; }; if (c.m_node1 == body1.m_contactList){ body1.m_contactList = c.m_node1.next; }; if (c.m_node2.prev){ c.m_node2.prev.next = c.m_node2.next; }; if (c.m_node2.next){ c.m_node2.next.prev = c.m_node2.prev; }; if (c.m_node2 == body2.m_contactList){ body2.m_contactList = c.m_node2.next; }; b2Contact.Destroy(c, m_world.m_blockAllocator); m_world.m_contactCount--; } override public function PairAdded(proxyUserData1, proxyUserData2){ var shape1:b2Shape = (proxyUserData1 as b2Shape); var shape2:b2Shape = (proxyUserData2 as b2Shape); var body1:b2Body = shape1.m_body; var body2:b2Body = shape2.m_body; if (((body1.IsStatic()) && (body2.IsStatic()))){ return (m_nullContact); }; if (shape1.m_body == shape2.m_body){ return (m_nullContact); }; if (body2.IsConnected(body1)){ return (m_nullContact); }; if (((!((m_world.m_contactFilter == null))) && ((m_world.m_contactFilter.ShouldCollide(shape1, shape2) == false)))){ return (m_nullContact); }; var c:b2Contact = b2Contact.Create(shape1, shape2, m_world.m_blockAllocator); if (c == null){ return (m_nullContact); }; shape1 = c.m_shape1; shape2 = c.m_shape2; body1 = shape1.m_body; body2 = shape2.m_body; c.m_prev = null; c.m_next = m_world.m_contactList; if (m_world.m_contactList != null){ m_world.m_contactList.m_prev = c; }; m_world.m_contactList = c; c.m_node1.contact = c; c.m_node1.other = body2; c.m_node1.prev = null; c.m_node1.next = body1.m_contactList; if (body1.m_contactList != null){ body1.m_contactList.prev = c.m_node1; }; body1.m_contactList = c.m_node1; c.m_node2.contact = c; c.m_node2.other = body1; c.m_node2.prev = null; c.m_node2.next = body2.m_contactList; if (body2.m_contactList != null){ body2.m_contactList.prev = c.m_node2; }; body2.m_contactList = c.m_node2; m_world.m_contactCount++; return (c); } public function Collide():void{ var body1:b2Body; var body2:b2Body; var c:b2Contact = m_world.m_contactList; while (c) { body1 = c.m_shape1.m_body; body2 = c.m_shape2.m_body; if (((body1.IsSleeping()) && (body2.IsSleeping()))){ } else { c.Update(m_world.m_contactListener); }; c = c.m_next; }; } } }//package Box2D.Dynamics
Section 78
//b2DebugDraw (Box2D.Dynamics.b2DebugDraw) package Box2D.Dynamics { import flash.display.*; import Box2D.Collision.Shapes.*; import Box2D.Collision.*; import Box2D.Dynamics.Contacts.*; import Box2D.Common.Math.*; import Box2D.Common.*; public class b2DebugDraw { private var m_xformScale:Number;// = 1 private var m_fillAlpha:Number;// = 1 private var m_alpha:Number;// = 1 private var m_lineThickness:Number;// = 1 private var m_drawFlags:uint; b2internal var m_sprite:Sprite; private var m_drawScale:Number;// = 1 public static var e_coreShapeBit:uint = 4; public static var e_shapeBit:uint = 1; public static var e_centerOfMassBit:uint = 64; public static var e_aabbBit:uint = 8; public static var e_obbBit:uint = 16; public static var e_pairBit:uint = 32; public static var e_jointBit:uint = 2; public function b2DebugDraw(){ super(); m_drawFlags = 0; } public function SetDrawScale(drawScale:Number):void{ m_drawScale = drawScale; } public function GetFillAlpha():Number{ return (m_fillAlpha); } public function GetAlpha():Number{ return (m_alpha); } public function GetLineThickness():Number{ return (m_lineThickness); } public function GetDrawScale():Number{ return (m_drawScale); } public function DrawSolidPolygon(vertices:Array, vertexCount:int, color:b2Color):void{ m_sprite.graphics.lineStyle(m_lineThickness, color.color, m_alpha); m_sprite.graphics.moveTo((vertices[0].x * m_drawScale), (vertices[0].y * m_drawScale)); m_sprite.graphics.beginFill(color.color, m_fillAlpha); var i = 1; while (i < vertexCount) { m_sprite.graphics.lineTo((vertices[i].x * m_drawScale), (vertices[i].y * m_drawScale)); i++; }; m_sprite.graphics.lineTo((vertices[0].x * m_drawScale), (vertices[0].y * m_drawScale)); m_sprite.graphics.endFill(); } public function DrawCircle(center:b2Vec2, radius:Number, color:b2Color):void{ m_sprite.graphics.lineStyle(m_lineThickness, color.color, m_alpha); m_sprite.graphics.drawCircle((center.x * m_drawScale), (center.y * m_drawScale), (radius * m_drawScale)); } public function DrawSolidCircle(center:b2Vec2, radius:Number, axis:b2Vec2, color:b2Color):void{ m_sprite.graphics.lineStyle(m_lineThickness, color.color, m_alpha); m_sprite.graphics.moveTo(0, 0); m_sprite.graphics.beginFill(color.color, m_fillAlpha); m_sprite.graphics.drawCircle((center.x * m_drawScale), (center.y * m_drawScale), (radius * m_drawScale)); m_sprite.graphics.endFill(); m_sprite.graphics.moveTo((center.x * m_drawScale), (center.y * m_drawScale)); m_sprite.graphics.lineTo(((center.x + (axis.x * radius)) * m_drawScale), ((center.y + (axis.y * radius)) * m_drawScale)); } public function DrawXForm(xf:b2XForm):void{ m_sprite.graphics.lineStyle(m_lineThickness, 0xFF0000, m_alpha); m_sprite.graphics.moveTo((xf.position.x * m_drawScale), (xf.position.y * m_drawScale)); m_sprite.graphics.lineTo(((xf.position.x + (m_xformScale * xf.R.col1.x)) * m_drawScale), ((xf.position.y + (m_xformScale * xf.R.col1.y)) * m_drawScale)); m_sprite.graphics.lineStyle(m_lineThickness, 0xFF00, m_alpha); m_sprite.graphics.moveTo((xf.position.x * m_drawScale), (xf.position.y * m_drawScale)); m_sprite.graphics.lineTo(((xf.position.x + (m_xformScale * xf.R.col2.x)) * m_drawScale), ((xf.position.y + (m_xformScale * xf.R.col2.y)) * m_drawScale)); } public function ClearFlags(flags:uint):void{ m_drawFlags = (m_drawFlags & ~(flags)); } public function GetSprite():Sprite{ return (m_sprite); } public function GetXFormScale():Number{ return (m_xformScale); } public function SetFlags(flags:uint):void{ m_drawFlags = flags; } public function SetSprite(sprite:Sprite):void{ m_sprite = sprite; } public function AppendFlags(flags:uint):void{ m_drawFlags = (m_drawFlags | flags); } public function DrawSegment(p1:b2Vec2, p2:b2Vec2, color:b2Color):void{ m_sprite.graphics.lineStyle(m_lineThickness, color.color, m_alpha); m_sprite.graphics.moveTo((p1.x * m_drawScale), (p1.y * m_drawScale)); m_sprite.graphics.lineTo((p2.x * m_drawScale), (p2.y * m_drawScale)); } public function SetXFormScale(xformScale:Number):void{ m_xformScale = xformScale; } public function GetFlags():uint{ return (m_drawFlags); } public function DrawPolygon(vertices:Array, vertexCount:int, color:b2Color):void{ m_sprite.graphics.lineStyle(m_lineThickness, color.color, m_alpha); m_sprite.graphics.moveTo((vertices[0].x * m_drawScale), (vertices[0].y * m_drawScale)); var i = 1; while (i < vertexCount) { m_sprite.graphics.lineTo((vertices[i].x * m_drawScale), (vertices[i].y * m_drawScale)); i++; }; m_sprite.graphics.lineTo((vertices[0].x * m_drawScale), (vertices[0].y * m_drawScale)); } public function SetFillAlpha(alpha:Number):void{ m_fillAlpha = alpha; } public function SetAlpha(alpha:Number):void{ m_alpha = alpha; } public function SetLineThickness(lineThickness:Number):void{ m_lineThickness = lineThickness; } } }//package Box2D.Dynamics
Section 79
//b2DestructionListener (Box2D.Dynamics.b2DestructionListener) package Box2D.Dynamics { import Box2D.Collision.Shapes.*; import Box2D.Dynamics.Joints.*; public class b2DestructionListener { public function b2DestructionListener(){ super(); } public function SayGoodbyeShape(shape:b2Shape):void{ } public function SayGoodbyeJoint(joint:b2Joint):void{ } } }//package Box2D.Dynamics
Section 80
//b2Island (Box2D.Dynamics.b2Island) package Box2D.Dynamics { import Box2D.Collision.*; import Box2D.Dynamics.Contacts.*; import Box2D.Common.Math.*; import Box2D.Dynamics.Joints.*; import Box2D.Common.*; public class b2Island { private var m_listener:b2ContactListener; private var m_bodyCapacity:int; b2internal var m_bodies:Array; b2internal var m_joints:Array; b2internal var m_jointCapacity:int; b2internal var m_contactCount:int; b2internal var m_contacts:Array; b2internal var m_contactCapacity:int; b2internal var m_jointCount:int; private var m_allocator; b2internal var m_bodyCount:int; private static var s_reportCR:b2ContactResult = new b2ContactResult(); public function b2Island(bodyCapacity:int, contactCapacity:int, jointCapacity:int, allocator, listener:b2ContactListener){ var i:int; super(); m_bodyCapacity = bodyCapacity; m_contactCapacity = contactCapacity; m_jointCapacity = jointCapacity; m_bodyCount = 0; m_contactCount = 0; m_jointCount = 0; m_allocator = allocator; m_listener = listener; m_bodies = new Array(bodyCapacity); i = 0; while (i < bodyCapacity) { m_bodies[i] = null; i++; }; m_contacts = new Array(contactCapacity); i = 0; while (i < contactCapacity) { m_contacts[i] = null; i++; }; m_joints = new Array(jointCapacity); i = 0; while (i < jointCapacity) { m_joints[i] = null; i++; }; } public function AddBody(body:b2Body):void{ body.m_islandIndex = m_bodyCount; var _local2 = m_bodyCount++; m_bodies[_local2] = body; } public function AddJoint(joint:b2Joint):void{ var _local2 = m_jointCount++; m_joints[_local2] = joint; } public function Report(constraints:Array):void{ var tMat:b2Mat22; var tVec:b2Vec2; var c:b2Contact; var cc:b2ContactConstraint; var cr:b2ContactResult; var b1:b2Body; var manifoldCount:int; var manifolds:Array; var j:int; var manifold:b2Manifold; var k:int; var point:b2ManifoldPoint; var ccp:b2ContactConstraintPoint; if (m_listener == null){ return; }; var i:int; while (i < m_contactCount) { c = m_contacts[i]; cc = constraints[i]; cr = s_reportCR; cr.shape1 = c.m_shape1; cr.shape2 = c.m_shape2; b1 = cr.shape1.m_body; manifoldCount = c.m_manifoldCount; manifolds = c.GetManifolds(); j = 0; while (j < manifoldCount) { manifold = manifolds[j]; cr.normal.SetV(manifold.normal); k = 0; while (k < manifold.pointCount) { point = manifold.points[k]; ccp = cc.points[k]; cr.position = b1.GetWorldPoint(point.localPoint1); cr.normalImpulse = ccp.normalImpulse; cr.tangentImpulse = ccp.tangentImpulse; cr.id.key = point.id.key; m_listener.Result(cr); k++; }; j++; }; i++; }; } public function AddContact(contact:b2Contact):void{ var _local2 = m_contactCount++; m_contacts[_local2] = contact; } public function Solve(step:b2TimeStep, gravity:b2Vec2, allowSleep:Boolean):void{ var i:int; var j:int; var b:b2Body; var joint:b2Joint; var contactsOkay:Boolean; var jointsOkay:Boolean; var jointOkay:Boolean; var minSleepTime:Number; var linTolSqr:Number; var angTolSqr:Number; i = 0; while (i < m_bodyCount) { b = m_bodies[i]; if (b.IsStatic()){ } else { b.m_linearVelocity.x = (b.m_linearVelocity.x + (step.dt * (gravity.x + (b.m_invMass * b.m_force.x)))); b.m_linearVelocity.y = (b.m_linearVelocity.y + (step.dt * (gravity.y + (b.m_invMass * b.m_force.y)))); b.m_angularVelocity = (b.m_angularVelocity + ((step.dt * b.m_invI) * b.m_torque)); b.m_force.SetZero(); b.m_torque = 0; b.m_linearVelocity.Multiply(b2Math.b2Clamp((1 - (step.dt * b.m_linearDamping)), 0, 1)); b.m_angularVelocity = (b.m_angularVelocity * b2Math.b2Clamp((1 - (step.dt * b.m_angularDamping)), 0, 1)); if (b.m_linearVelocity.LengthSquared() > b2Settings.b2_maxLinearVelocitySquared){ b.m_linearVelocity.Normalize(); b.m_linearVelocity.x = (b.m_linearVelocity.x * b2Settings.b2_maxLinearVelocity); b.m_linearVelocity.y = (b.m_linearVelocity.y * b2Settings.b2_maxLinearVelocity); }; if ((b.m_angularVelocity * b.m_angularVelocity) > b2Settings.b2_maxAngularVelocitySquared){ if (b.m_angularVelocity < 0){ b.m_angularVelocity = -(b2Settings.b2_maxAngularVelocity); } else { b.m_angularVelocity = b2Settings.b2_maxAngularVelocity; }; }; }; i++; }; var contactSolver:b2ContactSolver = new b2ContactSolver(step, m_contacts, m_contactCount, m_allocator); contactSolver.InitVelocityConstraints(step); i = 0; while (i < m_jointCount) { joint = m_joints[i]; joint.InitVelocityConstraints(step); i++; }; i = 0; while (i < step.velocityIterations) { j = 0; while (j < m_jointCount) { joint = m_joints[j]; joint.SolveVelocityConstraints(step); j++; }; contactSolver.SolveVelocityConstraints(); i++; }; contactSolver.FinalizeVelocityConstraints(); i = 0; while (i < m_bodyCount) { b = m_bodies[i]; if (b.IsStatic()){ } else { b.m_sweep.c0.SetV(b.m_sweep.c); b.m_sweep.a0 = b.m_sweep.a; b.m_sweep.c.x = (b.m_sweep.c.x + (step.dt * b.m_linearVelocity.x)); b.m_sweep.c.y = (b.m_sweep.c.y + (step.dt * b.m_linearVelocity.y)); b.m_sweep.a = (b.m_sweep.a + (step.dt * b.m_angularVelocity)); b.SynchronizeTransform(); }; i++; }; i = 0; while (i < step.positionIterations) { contactsOkay = contactSolver.SolvePositionConstraints(b2Settings.b2_contactBaumgarte); jointsOkay = true; j = 0; while (j < m_jointCount) { joint = m_joints[j]; jointOkay = joint.SolvePositionConstraints(b2Settings.b2_contactBaumgarte); jointsOkay = ((jointsOkay) && (jointOkay)); j++; }; if (((contactsOkay) && (jointsOkay))){ break; }; i++; }; Report(contactSolver.m_constraints); if (allowSleep){ minSleepTime = Number.MAX_VALUE; linTolSqr = (b2Settings.b2_linearSleepTolerance * b2Settings.b2_linearSleepTolerance); angTolSqr = (b2Settings.b2_angularSleepTolerance * b2Settings.b2_angularSleepTolerance); i = 0; while (i < m_bodyCount) { b = m_bodies[i]; if (b.m_invMass == 0){ } else { if ((b.m_flags & b2Body.e_allowSleepFlag) == 0){ b.m_sleepTime = 0; minSleepTime = 0; }; if (((((((b.m_flags & b2Body.e_allowSleepFlag) == 0)) || (((b.m_angularVelocity * b.m_angularVelocity) > angTolSqr)))) || ((b2Math.b2Dot(b.m_linearVelocity, b.m_linearVelocity) > linTolSqr)))){ b.m_sleepTime = 0; minSleepTime = 0; } else { b.m_sleepTime = (b.m_sleepTime + step.dt); minSleepTime = b2Math.b2Min(minSleepTime, b.m_sleepTime); }; }; i++; }; if (minSleepTime >= b2Settings.b2_timeToSleep){ i = 0; while (i < m_bodyCount) { b = m_bodies[i]; b.m_flags = (b.m_flags | b2Body.e_sleepFlag); b.m_linearVelocity.SetZero(); b.m_angularVelocity = 0; i++; }; }; }; } public function Clear():void{ m_bodyCount = 0; m_contactCount = 0; m_jointCount = 0; } public function SolveTOI(subStep:b2TimeStep):void{ var i:int; var j:int; var b:b2Body; var contactsOkay:Boolean; var jointsOkay:Boolean; var jointOkay:Boolean; var contactSolver:b2ContactSolver = new b2ContactSolver(subStep, m_contacts, m_contactCount, m_allocator); subStep.warmStarting = true; i = 0; while (i < m_jointCount) { m_joints[i].InitVelocityConstraints(subStep); i++; }; i = 0; while (i < subStep.velocityIterations) { contactSolver.SolveVelocityConstraints(); j = 0; while (j < m_jointCount) { m_joints[j].InitVelocityConstraints(subStep); j++; }; i++; }; i = 0; while (i < m_bodyCount) { b = m_bodies[i]; if (b.IsStatic()){ } else { b.m_sweep.c0.SetV(b.m_sweep.c); b.m_sweep.a0 = b.m_sweep.a; b.m_sweep.c.x = (b.m_sweep.c.x + (subStep.dt * b.m_linearVelocity.x)); b.m_sweep.c.y = (b.m_sweep.c.y + (subStep.dt * b.m_linearVelocity.y)); b.m_sweep.a = (b.m_sweep.a + (subStep.dt * b.m_angularVelocity)); b.SynchronizeTransform(); }; i++; }; var k_toiBaumgarte:Number = 0.75; i = 0; while (i < subStep.positionIterations) { contactsOkay = contactSolver.SolvePositionConstraints(k_toiBaumgarte); jointsOkay = true; j = 0; while (j < m_jointCount) { jointOkay = m_joints[j].SolvePositionConstraints(b2Settings.b2_contactBaumgarte); jointsOkay = ((jointsOkay) && (jointOkay)); j++; }; if (((contactsOkay) && (jointsOkay))){ break; }; i++; }; Report(contactSolver.m_constraints); } } }//package Box2D.Dynamics
Section 81
//b2TimeStep (Box2D.Dynamics.b2TimeStep) package Box2D.Dynamics { public class b2TimeStep { public var warmStarting:Boolean; public var inv_dt:Number; public var dt:Number; public var velocityIterations:int; public var dtRatio:Number; public var positionIterations:int; public function b2TimeStep(){ super(); } } }//package Box2D.Dynamics
Section 82
//b2World (Box2D.Dynamics.b2World) package Box2D.Dynamics { import Box2D.Collision.Shapes.*; import Box2D.Collision.*; import Box2D.Dynamics.Contacts.*; import Box2D.Common.Math.*; import Box2D.Dynamics.Joints.*; import Box2D.Common.*; public class b2World { private var m_inv_dt0:Number; private var m_boundaryListener:b2BoundaryListener; b2internal var m_contactList:b2Contact; b2internal var m_blockAllocator; b2internal var m_contactListener:b2ContactListener; b2internal var m_raycastSegment:b2Segment; b2internal var m_broadPhase:b2BroadPhase; private var m_destructionListener:b2DestructionListener; private var m_jointCount:int; b2internal var m_lock:Boolean; private var m_bodyCount:int; b2internal var m_raycastUserData; private var m_allowSleep:Boolean; b2internal var m_groundBody:b2Body; b2internal var m_contactCount:int; b2internal var m_raycastNormal:b2Vec2; b2internal var m_contactFilter:b2ContactFilter; b2internal var m_bodyList:b2Body; private var m_debugDraw:b2DebugDraw; b2internal var m_stackAllocator; private var m_jointList:b2Joint; private var m_gravity:b2Vec2; private var m_contactManager:b2ContactManager; private static var s_jointColor:b2Color = new b2Color(0.5, 0.8, 0.8); private static var m_continuousPhysics:Boolean; private static var s_blackColor:b2Color = new b2Color(0, 0, 0); private static var s_coreColor:b2Color = new b2Color(0.9, 0.6, 0.6); private static var s_xf:b2XForm = new b2XForm(); private static var m_warmStarting:Boolean; public function b2World(worldAABB:b2AABB, gravity:b2Vec2, doSleep:Boolean){ m_raycastNormal = new b2Vec2(); m_contactManager = new b2ContactManager(); super(); m_destructionListener = null; m_boundaryListener = null; m_contactFilter = b2ContactFilter.b2_defaultFilter; m_contactListener = null; m_debugDraw = null; m_bodyList = null; m_contactList = null; m_jointList = null; m_bodyCount = 0; m_contactCount = 0; m_jointCount = 0; m_warmStarting = true; m_continuousPhysics = true; m_allowSleep = doSleep; m_gravity = gravity; m_lock = false; m_inv_dt0 = 0; m_contactManager.m_world = this; m_broadPhase = new b2BroadPhase(worldAABB, m_contactManager); var bd:b2BodyDef = new b2BodyDef(); m_groundBody = CreateBody(bd); } b2internal function DrawJoint(joint:b2Joint):void{ var pulley:b2PulleyJoint; var s1:b2Vec2; var s2:b2Vec2; var b1:b2Body = joint.m_body1; var b2:b2Body = joint.m_body2; var xf1:b2XForm = b1.m_xf; var xf2:b2XForm = b2.m_xf; var x1:b2Vec2 = xf1.position; var x2:b2Vec2 = xf2.position; var p1:b2Vec2 = joint.GetAnchor1(); var p2:b2Vec2 = joint.GetAnchor2(); var color:b2Color = s_jointColor; switch (joint.m_type){ case b2Joint.e_distanceJoint: m_debugDraw.DrawSegment(p1, p2, color); break; case b2Joint.e_pulleyJoint: pulley = (joint as b2PulleyJoint); s1 = pulley.GetGroundAnchor1(); s2 = pulley.GetGroundAnchor2(); m_debugDraw.DrawSegment(s1, p1, color); m_debugDraw.DrawSegment(s2, p2, color); m_debugDraw.DrawSegment(s1, s2, color); break; case b2Joint.e_mouseJoint: m_debugDraw.DrawSegment(p1, p2, color); break; default: if (b1 != m_groundBody){ m_debugDraw.DrawSegment(x1, p1, color); }; m_debugDraw.DrawSegment(p1, p2, color); if (b2 != m_groundBody){ m_debugDraw.DrawSegment(x2, p2, color); }; }; } public function Refilter(shape:b2Shape):void{ shape.RefilterProxy(m_broadPhase, shape.m_body.m_xf); } public function SetDebugDraw(debugDraw:b2DebugDraw):void{ m_debugDraw = debugDraw; } public function SetContinuousPhysics(flag:Boolean):void{ m_continuousPhysics = flag; } public function GetProxyCount():int{ return (m_broadPhase.m_proxyCount); } b2internal function DrawDebugData():void{ var i:int; var b:b2Body; var s:b2Shape; var j:b2Joint; var bp:b2BroadPhase; var xf:b2XForm; var core:Boolean; var pair:b2Pair; var p1:b2Proxy; var p2:b2Proxy; var worldLower:b2Vec2; var worldUpper:b2Vec2; var p:b2Proxy; var poly:b2PolygonShape; var obb:b2OBB; var h:b2Vec2; var tMat:b2Mat22; var tVec:b2Vec2; var tX:Number; if (m_debugDraw == null){ return; }; m_debugDraw.m_sprite.graphics.clear(); var flags:uint = m_debugDraw.GetFlags(); var invQ:b2Vec2 = new b2Vec2(); var x1:b2Vec2 = new b2Vec2(); var x2:b2Vec2 = new b2Vec2(); var color:b2Color = new b2Color(0, 0, 0); var b1:b2AABB = new b2AABB(); var b2:b2AABB = new b2AABB(); var vs:Array = [new b2Vec2(), new b2Vec2(), new b2Vec2(), new b2Vec2()]; if ((flags & b2DebugDraw.e_shapeBit)){ core = ((flags & b2DebugDraw.e_coreShapeBit) == b2DebugDraw.e_coreShapeBit); b = m_bodyList; while (b) { xf = b.m_xf; s = b.GetShapeList(); while (s) { if (b.IsStatic()){ DrawShape(s, xf, new b2Color(0.5, 0.9, 0.5), core); } else { if (b.IsSleeping()){ DrawShape(s, xf, new b2Color(0.5, 0.5, 0.9), core); } else { DrawShape(s, xf, new b2Color(0.9, 0.9, 0.9), core); }; }; s = s.m_next; }; b = b.m_next; }; }; if ((flags & b2DebugDraw.e_jointBit)){ j = m_jointList; while (j) { DrawJoint(j); j = j.m_next; }; }; if ((flags & b2DebugDraw.e_pairBit)){ bp = m_broadPhase; invQ.Set((1 / bp.m_quantizationFactor.x), (1 / bp.m_quantizationFactor.y)); color.Set(0.9, 0.9, 0.3); for each (pair in bp.m_pairManager.m_pairs) { p1 = pair.proxy1; p2 = pair.proxy2; if (((!(p1)) || (!(p2)))){ } else { b1.lowerBound.x = (bp.m_worldAABB.lowerBound.x + (invQ.x * bp.m_bounds[0][p1.lowerBounds[0]].value)); b1.lowerBound.y = (bp.m_worldAABB.lowerBound.y + (invQ.y * bp.m_bounds[1][p1.lowerBounds[1]].value)); b1.upperBound.x = (bp.m_worldAABB.lowerBound.x + (invQ.x * bp.m_bounds[0][p1.upperBounds[0]].value)); b1.upperBound.y = (bp.m_worldAABB.lowerBound.y + (invQ.y * bp.m_bounds[1][p1.upperBounds[1]].value)); b2.lowerBound.x = (bp.m_worldAABB.lowerBound.x + (invQ.x * bp.m_bounds[0][p2.lowerBounds[0]].value)); b2.lowerBound.y = (bp.m_worldAABB.lowerBound.y + (invQ.y * bp.m_bounds[1][p2.lowerBounds[1]].value)); b2.upperBound.x = (bp.m_worldAABB.lowerBound.x + (invQ.x * bp.m_bounds[0][p2.upperBounds[0]].value)); b2.upperBound.y = (bp.m_worldAABB.lowerBound.y + (invQ.y * bp.m_bounds[1][p2.upperBounds[1]].value)); x1.x = (0.5 * (b1.lowerBound.x + b1.upperBound.x)); x1.y = (0.5 * (b1.lowerBound.y + b1.upperBound.y)); x2.x = (0.5 * (b2.lowerBound.x + b2.upperBound.x)); x2.y = (0.5 * (b2.lowerBound.y + b2.upperBound.y)); m_debugDraw.DrawSegment(x1, x2, color); }; }; }; if ((flags & b2DebugDraw.e_aabbBit)){ bp = m_broadPhase; worldLower = bp.m_worldAABB.lowerBound; worldUpper = bp.m_worldAABB.upperBound; invQ.Set((1 / bp.m_quantizationFactor.x), (1 / bp.m_quantizationFactor.y)); color.Set(0.9, 0.3, 0.9); i = 0; while (i < bp.m_proxyPool.length) { p = bp.m_proxyPool[i]; if (p.IsValid() == false){ } else { b1.lowerBound.x = (worldLower.x + (invQ.x * bp.m_bounds[0][p.lowerBounds[0]].value)); b1.lowerBound.y = (worldLower.y + (invQ.y * bp.m_bounds[1][p.lowerBounds[1]].value)); b1.upperBound.x = (worldLower.x + (invQ.x * bp.m_bounds[0][p.upperBounds[0]].value)); b1.upperBound.y = (worldLower.y + (invQ.y * bp.m_bounds[1][p.upperBounds[1]].value)); vs[0].Set(b1.lowerBound.x, b1.lowerBound.y); vs[1].Set(b1.upperBound.x, b1.lowerBound.y); vs[2].Set(b1.upperBound.x, b1.upperBound.y); vs[3].Set(b1.lowerBound.x, b1.upperBound.y); m_debugDraw.DrawPolygon(vs, 4, color); }; i++; }; vs[0].Set(worldLower.x, worldLower.y); vs[1].Set(worldUpper.x, worldLower.y); vs[2].Set(worldUpper.x, worldUpper.y); vs[3].Set(worldLower.x, worldUpper.y); m_debugDraw.DrawPolygon(vs, 4, new b2Color(0.3, 0.9, 0.9)); }; if ((flags & b2DebugDraw.e_obbBit)){ color.Set(0.5, 0.3, 0.5); b = m_bodyList; while (b) { xf = b.m_xf; s = b.GetShapeList(); while (s) { if (s.m_type != b2Shape.e_polygonShape){ } else { poly = (s as b2PolygonShape); obb = poly.GetOBB(); h = obb.extents; vs[0].Set(-(h.x), -(h.y)); vs[1].Set(h.x, -(h.y)); vs[2].Set(h.x, h.y); vs[3].Set(-(h.x), h.y); i = 0; while (i < 4) { tMat = obb.R; tVec = vs[i]; tX = (obb.center.x + ((tMat.col1.x * tVec.x) + (tMat.col2.x * tVec.y))); vs[i].y = (obb.center.y + ((tMat.col1.y * tVec.x) + (tMat.col2.y * tVec.y))); vs[i].x = tX; tMat = xf.R; tX = (xf.position.x + ((tMat.col1.x * tVec.x) + (tMat.col2.x * tVec.y))); vs[i].y = (xf.position.y + ((tMat.col1.y * tVec.x) + (tMat.col2.y * tVec.y))); vs[i].x = tX; i++; }; m_debugDraw.DrawPolygon(vs, 4, color); }; s = s.m_next; }; b = b.m_next; }; }; if ((flags & b2DebugDraw.e_centerOfMassBit)){ b = m_bodyList; while (b) { xf = s_xf; xf.R = b.m_xf.R; xf.position = b.GetWorldCenter(); m_debugDraw.DrawXForm(xf); b = b.m_next; }; }; } public function DestroyBody(b:b2Body):void{ var jn0:b2JointEdge; var s0:b2Shape; if (m_lock == true){ return; }; var jn:b2JointEdge = b.m_jointList; while (jn) { jn0 = jn; jn = jn.next; if (m_destructionListener){ m_destructionListener.SayGoodbyeJoint(jn0.joint); }; DestroyJoint(jn0.joint); }; var s:b2Shape = b.m_shapeList; while (s) { s0 = s; s = s.m_next; if (m_destructionListener){ m_destructionListener.SayGoodbyeShape(s0); }; s0.DestroyProxy(m_broadPhase); b2Shape.Destroy(s0, m_blockAllocator); }; if (b.m_prev){ b.m_prev.m_next = b.m_next; }; if (b.m_next){ b.m_next.m_prev = b.m_prev; }; if (b == m_bodyList){ m_bodyList = b.m_next; }; m_bodyCount--; } b2internal function DrawShape(shape:b2Shape, xf:b2XForm, color:b2Color, core:Boolean):void{ var circle:b2CircleShape; var center:b2Vec2; var radius:Number; var axis:b2Vec2; var i:int; var poly:b2PolygonShape; var vertexCount:int; var localVertices:Array; var vertices:Array; var localCoreVertices:Array; var edge:b2EdgeShape; var coreColor:b2Color = s_coreColor; switch (shape.m_type){ case b2Shape.e_circleShape: circle = (shape as b2CircleShape); center = b2Math.b2MulX(xf, circle.m_localPosition); radius = circle.m_radius; axis = xf.R.col1; m_debugDraw.DrawSolidCircle(center, radius, axis, color); if (core){ m_debugDraw.DrawCircle(center, (radius - b2Settings.b2_toiSlop), coreColor); }; break; case b2Shape.e_polygonShape: poly = (shape as b2PolygonShape); vertexCount = poly.GetVertexCount(); localVertices = poly.GetVertices(); vertices = new Array(b2Settings.b2_maxPolygonVertices); i = 0; while (i < vertexCount) { vertices[i] = b2Math.b2MulX(xf, localVertices[i]); i++; }; m_debugDraw.DrawSolidPolygon(vertices, vertexCount, color); if (core){ localCoreVertices = poly.GetCoreVertices(); i = 0; while (i < vertexCount) { vertices[i] = b2Math.b2MulX(xf, localCoreVertices[i]); i++; }; }; break; case b2Shape.e_edgeShape: edge = (shape as b2EdgeShape); m_debugDraw.DrawSegment(b2Math.b2MulX(xf, edge.GetVertex1()), b2Math.b2MulX(xf, edge.GetVertex2()), s_blackColor); if (core){ m_debugDraw.DrawSegment(b2Math.b2MulX(xf, edge.GetCoreVertex1()), b2Math.b2MulX(xf, edge.GetCoreVertex2()), coreColor); }; break; }; } public function GetGroundBody():b2Body{ return (m_groundBody); } public function SetContactFilter(filter:b2ContactFilter):void{ m_contactFilter = filter; } b2internal function Solve(step:b2TimeStep):void{ var b:b2Body; var stackCount:int; var i:int; var other:b2Body; var cn:b2ContactEdge; var jn:b2JointEdge; var inRange:Boolean; var island:b2Island = new b2Island(m_bodyCount, m_contactCount, m_jointCount, m_stackAllocator, m_contactListener); b = m_bodyList; while (b) { b.m_flags = (b.m_flags & ~(b2Body.e_islandFlag)); b = b.m_next; }; var c:b2Contact = m_contactList; while (c) { c.m_flags = (c.m_flags & ~(b2Contact.e_islandFlag)); c = c.m_next; }; var j:b2Joint = m_jointList; while (j) { j.m_islandFlag = false; j = j.m_next; }; var stackSize:int = m_bodyCount; var stack:Array = new Array(stackSize); var seed:b2Body = m_bodyList; while (seed) { if ((seed.m_flags & ((b2Body.e_islandFlag | b2Body.e_sleepFlag) | b2Body.e_frozenFlag))){ } else { if (seed.IsStatic()){ } else { island.Clear(); stackCount = 0; var _temp1 = stackCount; stackCount = (stackCount + 1); var _local15 = _temp1; stack[_local15] = seed; seed.m_flags = (seed.m_flags | b2Body.e_islandFlag); while (stackCount > 0) { --stackCount; b = stack[stackCount]; island.AddBody(b); b.m_flags = (b.m_flags & ~(b2Body.e_sleepFlag)); if (b.IsStatic()){ } else { cn = b.m_contactList; while (cn) { if ((cn.contact.m_flags & (b2Contact.e_islandFlag | b2Contact.e_nonSolidFlag))){ } else { if (cn.contact.m_manifoldCount == 0){ } else { island.AddContact(cn.contact); cn.contact.m_flags = (cn.contact.m_flags | b2Contact.e_islandFlag); other = cn.other; if ((other.m_flags & b2Body.e_islandFlag)){ } else { var _temp2 = stackCount; stackCount = (stackCount + 1); var _local16 = _temp2; stack[_local16] = other; other.m_flags = (other.m_flags | b2Body.e_islandFlag); }; }; }; cn = cn.next; }; jn = b.m_jointList; while (jn) { if (jn.joint.m_islandFlag == true){ } else { island.AddJoint(jn.joint); jn.joint.m_islandFlag = true; other = jn.other; if ((other.m_flags & b2Body.e_islandFlag)){ } else { var _temp3 = stackCount; stackCount = (stackCount + 1); _local16 = _temp3; stack[_local16] = other; other.m_flags = (other.m_flags | b2Body.e_islandFlag); }; }; jn = jn.next; }; }; }; island.Solve(step, m_gravity, m_allowSleep); i = 0; while (i < island.m_bodyCount) { b = island.m_bodies[i]; if (b.IsStatic()){ b.m_flags = (b.m_flags & ~(b2Body.e_islandFlag)); }; i++; }; }; }; seed = seed.m_next; }; b = m_bodyList; while (b) { if ((b.m_flags & (b2Body.e_sleepFlag | b2Body.e_frozenFlag))){ } else { if (b.IsStatic()){ } else { inRange = b.SynchronizeShapes(); if ((((inRange == false)) && (!((m_boundaryListener == null))))){ m_boundaryListener.Violation(b); }; }; }; b = b.m_next; }; m_broadPhase.Commit(); } public function Query(aabb:b2AABB, shapes:Array, maxCount:int):int{ var results:Array = new Array(maxCount); var count:int = m_broadPhase.QueryAABB(aabb, results, maxCount); var i:int; while (i < count) { shapes[i] = results[i]; i++; }; return (count); } public function GetContactCount():int{ return (m_contactCount); } b2internal function SolveTOI(step:b2TimeStep):void{ var b:b2Body; var s1:b2Shape; var s2:b2Shape; var b1:b2Body; var b2:b2Body; var cEdge:b2ContactEdge; var j:b2Joint; var c:b2Contact; var minContact:b2Contact; var minTOI:Number; var seed:b2Body; var queueStart:int; var queueSize:int; var jEdge:b2JointEdge; var subStep:b2TimeStep; var i:int; var toi:Number; var t0:Number; var other:b2Body; var inRange:Boolean; var island:b2Island = new b2Island(m_bodyCount, b2Settings.b2_maxTOIContactsPerIsland, b2Settings.b2_maxTOIJointsPerIsland, m_stackAllocator, m_contactListener); var queueCapacity:int = m_bodyCount; var queue:Array = new Array(queueCapacity); b = m_bodyList; while (b) { b.m_flags = (b.m_flags & ~(b2Body.e_islandFlag)); b.m_sweep.t0 = 0; b = b.m_next; }; c = m_contactList; while (c) { c.m_flags = (c.m_flags & ~((b2Contact.e_toiFlag | b2Contact.e_islandFlag))); c = c.m_next; }; j = m_jointList; while (j) { j.m_islandFlag = false; j = j.m_next; }; while (true) { minContact = null; minTOI = 1; c = m_contactList; for (;c;(c = c.m_next)) { if ((c.m_flags & (b2Contact.e_slowFlag | b2Contact.e_nonSolidFlag))){ } else { toi = 1; if ((c.m_flags & b2Contact.e_toiFlag)){ toi = c.m_toi; } else { s1 = c.m_shape1; s2 = c.m_shape2; b1 = s1.m_body; b2 = s2.m_body; if (((((b1.IsStatic()) || (b1.IsSleeping()))) && (((b2.IsStatic()) || (b2.IsSleeping()))))){ continue; }; t0 = b1.m_sweep.t0; if (b1.m_sweep.t0 < b2.m_sweep.t0){ t0 = b2.m_sweep.t0; b1.m_sweep.Advance(t0); } else { if (b2.m_sweep.t0 < b1.m_sweep.t0){ t0 = b1.m_sweep.t0; b2.m_sweep.Advance(t0); }; }; toi = b2TimeOfImpact.TimeOfImpact(c.m_shape1, b1.m_sweep, c.m_shape2, b2.m_sweep); if ((((toi > 0)) && ((toi < 1)))){ toi = (((1 - toi) * t0) + toi); if (toi > 1){ toi = 1; }; }; c.m_toi = toi; c.m_flags = (c.m_flags | b2Contact.e_toiFlag); }; if ((((Number.MIN_VALUE < toi)) && ((toi < minTOI)))){ minContact = c; minTOI = toi; }; }; }; if ((((minContact == null)) || (((1 - (100 * Number.MIN_VALUE)) < minTOI)))){ break; }; s1 = minContact.m_shape1; s2 = minContact.m_shape2; b1 = s1.m_body; b2 = s2.m_body; b1.Advance(minTOI); b2.Advance(minTOI); minContact.Update(m_contactListener); minContact.m_flags = (minContact.m_flags & ~(b2Contact.e_toiFlag)); if (minContact.m_manifoldCount == 0){ } else { seed = b1; if (seed.IsStatic()){ seed = b2; }; island.Clear(); queueStart = 0; queueSize = 0; var _temp1 = queueSize; queueSize = (queueSize + 1); queue[(queueStart + _temp1)] = seed; seed.m_flags = (seed.m_flags | b2Body.e_islandFlag); while (queueSize > 0) { var _temp2 = queueStart; queueStart = (queueStart + 1); b = queue[_temp2]; queueSize--; island.AddBody(b); b.m_flags = (b.m_flags & ~(b2Body.e_sleepFlag)); if (b.IsStatic()){ } else { cEdge = b.m_contactList; while (cEdge) { if (island.m_contactCount == island.m_contactCapacity){ } else { if ((cEdge.contact.m_flags & ((b2Contact.e_islandFlag | b2Contact.e_slowFlag) | b2Contact.e_nonSolidFlag))){ } else { if (cEdge.contact.m_manifoldCount == 0){ } else { island.AddContact(cEdge.contact); cEdge.contact.m_flags = (cEdge.contact.m_flags | b2Contact.e_islandFlag); other = cEdge.other; if ((other.m_flags & b2Body.e_islandFlag)){ } else { if (other.IsStatic() == false){ other.Advance(minTOI); other.WakeUp(); }; queue[(queueStart + queueSize)] = other; queueSize++; other.m_flags = (other.m_flags | b2Body.e_islandFlag); }; }; }; }; cEdge = cEdge.next; }; }; }; jEdge = b.m_jointList; while (jEdge) { if (island.m_jointCount == island.m_jointCapacity){ } else { if (jEdge.joint.m_islandFlag == true){ } else { island.AddJoint(jEdge.joint); jEdge.joint.m_islandFlag = true; other = jEdge.other; if ((other.m_flags & b2Body.e_islandFlag)){ } else { if (!other.IsStatic()){ other.Advance(minTOI); other.WakeUp(); }; queue[(queueStart + queueSize)] = other; queueSize++; other.m_flags = (other.m_flags | b2Body.e_islandFlag); }; }; }; jEdge = jEdge.next; }; subStep = new b2TimeStep(); subStep.warmStarting = false; subStep.dt = ((1 - minTOI) * step.dt); subStep.inv_dt = (1 / subStep.dt); subStep.dtRatio = 0; subStep.velocityIterations = step.velocityIterations; subStep.positionIterations = step.positionIterations; island.SolveTOI(subStep); i = 0; while (i < island.m_bodyCount) { b = island.m_bodies[i]; b.m_flags = (b.m_flags & ~(b2Body.e_islandFlag)); if ((b.m_flags & (b2Body.e_sleepFlag | b2Body.e_frozenFlag))){ } else { if (b.IsStatic()){ } else { inRange = b.SynchronizeShapes(); if ((((inRange == false)) && (!((m_boundaryListener == null))))){ m_boundaryListener.Violation(b); }; cEdge = b.m_contactList; while (cEdge) { cEdge.contact.m_flags = (cEdge.contact.m_flags & ~(b2Contact.e_toiFlag)); cEdge = cEdge.next; }; }; }; i++; }; i = 0; while (i < island.m_contactCount) { c = island.m_contacts[i]; c.m_flags = (c.m_flags & ~((b2Contact.e_toiFlag | b2Contact.e_islandFlag))); i++; }; i = 0; while (i < island.m_jointCount) { j = island.m_joints[i]; j.m_islandFlag = false; i++; }; m_broadPhase.Commit(); }; }; } public function GetJointList():b2Joint{ return (m_jointList); } public function Validate():void{ m_broadPhase.Validate(); } public function SetGravity(gravity:b2Vec2):void{ m_gravity = gravity; } public function GetPairCount():int{ return (m_broadPhase.m_pairManager.m_pairCount); } public function GetBodyList():b2Body{ return (m_bodyList); } public function SetWarmStarting(flag:Boolean):void{ m_warmStarting = flag; } public function Raycast(segment:b2Segment, shapes:Array, maxCount:int, solidShapes:Boolean, userData):int{ var count:int; var results:Array = new Array(maxCount); m_raycastSegment = segment; m_raycastUserData = userData; if (solidShapes){ count = m_broadPhase.QuerySegment(segment, results, maxCount, RaycastSortKey); } else { count = m_broadPhase.QuerySegment(segment, results, maxCount, RaycastSortKey2); }; var i:int; while (i < count) { shapes[i] = results[i]; i++; }; return (count); } public function CreateJoint(def:b2JointDef):b2Joint{ var b:b2Body; var s:b2Shape; var j:b2Joint = b2Joint.Create(def, m_blockAllocator); j.m_prev = null; j.m_next = m_jointList; if (m_jointList){ m_jointList.m_prev = j; }; m_jointList = j; m_jointCount++; j.m_node1.joint = j; j.m_node1.other = j.m_body2; j.m_node1.prev = null; j.m_node1.next = j.m_body1.m_jointList; if (j.m_body1.m_jointList){ j.m_body1.m_jointList.prev = j.m_node1; }; j.m_body1.m_jointList = j.m_node1; j.m_node2.joint = j; j.m_node2.other = j.m_body1; j.m_node2.prev = null; j.m_node2.next = j.m_body2.m_jointList; if (j.m_body2.m_jointList){ j.m_body2.m_jointList.prev = j.m_node2; }; j.m_body2.m_jointList = j.m_node2; if (def.collideConnected == false){ b = ((def.body1.m_shapeCount < def.body2.m_shapeCount)) ? def.body1 : def.body2; s = b.m_shapeList; while (s) { s.RefilterProxy(m_broadPhase, b.m_xf); s = s.m_next; }; }; return (j); } public function DestroyJoint(j:b2Joint):void{ var b:b2Body; var s:b2Shape; var collideConnected:Boolean = j.m_collideConnected; if (j.m_prev){ j.m_prev.m_next = j.m_next; }; if (j.m_next){ j.m_next.m_prev = j.m_prev; }; if (j == m_jointList){ m_jointList = j.m_next; }; var body1:b2Body = j.m_body1; var body2:b2Body = j.m_body2; body1.WakeUp(); body2.WakeUp(); if (j.m_node1.prev){ j.m_node1.prev.next = j.m_node1.next; }; if (j.m_node1.next){ j.m_node1.next.prev = j.m_node1.prev; }; if (j.m_node1 == body1.m_jointList){ body1.m_jointList = j.m_node1.next; }; j.m_node1.prev = null; j.m_node1.next = null; if (j.m_node2.prev){ j.m_node2.prev.next = j.m_node2.next; }; if (j.m_node2.next){ j.m_node2.next.prev = j.m_node2.prev; }; if (j.m_node2 == body2.m_jointList){ body2.m_jointList = j.m_node2.next; }; j.m_node2.prev = null; j.m_node2.next = null; b2Joint.Destroy(j, m_blockAllocator); m_jointCount--; if (collideConnected == false){ b = ((body1.m_shapeCount < body2.m_shapeCount)) ? body1 : body2; s = b.m_shapeList; while (s) { s.RefilterProxy(m_broadPhase, b.m_xf); s = s.m_next; }; }; } public function SetContactListener(listener:b2ContactListener):void{ m_contactListener = listener; } b2internal function RaycastSortKey(shape:b2Shape):Number{ if (((m_contactFilter) && (!(m_contactFilter.RayCollide(m_raycastUserData, shape))))){ return (-1); }; var body:b2Body = shape.GetBody(); var xf:b2XForm = body.GetXForm(); var lambda:Array = [0]; if (shape.TestSegment(xf, lambda, m_raycastNormal, m_raycastSegment, 1) == b2Shape.e_missCollide){ return (-1); }; return (lambda[0]); } b2internal function RaycastSortKey2(shape:b2Shape):Number{ if (((m_contactFilter) && (!(m_contactFilter.RayCollide(m_raycastUserData, shape))))){ return (-1); }; var body:b2Body = shape.GetBody(); var xf:b2XForm = body.GetXForm(); var lambda:Array = [0]; if (shape.TestSegment(xf, lambda, m_raycastNormal, m_raycastSegment, 1) != b2Shape.e_hitCollide){ return (-1); }; return (lambda[0]); } public function RaycastOne(segment:b2Segment, lambda:Array, normal:b2Vec2, solidShapes:Boolean, userData):b2Shape{ var shapes:Array = new Array(1); var count:Number = Raycast(segment, shapes, 1, solidShapes, userData); if (count == 0){ return (null); }; if (count > 1){ trace(count); }; var shape:b2Shape = shapes[0]; var xf:b2XForm = shape.GetBody().GetXForm(); shape.TestSegment(xf, lambda, normal, segment, 1); return (shape); } public function CreateBody(def:b2BodyDef):b2Body{ if (m_lock == true){ return (null); }; var b:b2Body = new b2Body(def, this); b.m_prev = null; b.m_next = m_bodyList; if (m_bodyList){ m_bodyList.m_prev = b; }; m_bodyList = b; m_bodyCount++; return (b); } public function SetBoundaryListener(listener:b2BoundaryListener):void{ m_boundaryListener = listener; } public function SetDestructionListener(listener:b2DestructionListener):void{ m_destructionListener = listener; } public function Step(dt:Number, velocityIterations:int, positionIterations:int):void{ m_lock = true; var step:b2TimeStep = new b2TimeStep(); step.dt = dt; step.velocityIterations = velocityIterations; step.positionIterations = positionIterations; if (dt > 0){ step.inv_dt = (1 / dt); } else { step.inv_dt = 0; }; step.dtRatio = (m_inv_dt0 * dt); step.warmStarting = m_warmStarting; m_contactManager.Collide(); if (step.dt > 0){ Solve(step); }; if (((m_continuousPhysics) && ((step.dt > 0)))){ SolveTOI(step); }; DrawDebugData(); m_inv_dt0 = step.inv_dt; m_lock = false; } public function GetGravity():b2Vec2{ return (m_gravity); } public function GetBodyCount():int{ return (m_bodyCount); } public function InRange(aabb:b2AABB):Boolean{ return (m_broadPhase.InRange(aabb)); } public function GetJointCount():int{ return (m_jointCount); } } }//package Box2D.Dynamics
Section 83
//CalcButton (Core.Button.CalcButton) package Core.Button { import flash.events.*; import flash.display.*; import Core.*; import flash.text.*; public class CalcButton extends Sprite { private var _txt:TextField; private var _bitmap:Bitmap; public var _num:int;// = 0 public function CalcButton(n:int, active:Boolean, onClick:Function){ _txt = new TextField(); super(); _num = n; if (active){ _bitmap = new Resourcen.instance.BUTTON_LEVEL_ACTIVE(); } else { _bitmap = new Resourcen.instance.BUTTON_LEVEL_INACTIVE(); }; _txt.text = n.toString(); _txt.mouseEnabled = true; _txt.selectable = false; _txt.height = 17; _txt.setTextFormat(Resourcen.instance.textFmt); if (n < 10){ _txt.x = 18; } else { _txt.x = 13; }; _txt.y = 12; addChild(_bitmap); var bd:BitmapData = new BitmapData(_txt.width, _txt.height, true, 0); bd.draw(_txt); var bmp:Bitmap = new Bitmap(bd); if (n < 10){ bmp.x = 18; } else { bmp.x = 13; }; bmp.y = 12; addChild(bmp); this.addEventListener(MouseEvent.MOUSE_UP, onClick); _txt.addEventListener(MouseEvent.MOUSE_UP, onClick); this.buttonMode = true; } private function onMouseUp(e:Event):void{ } private function onMouseDown(e:Event):void{ } } }//package Core.Button
Section 84
//CircleFill (Core.Components.CircleFill) package Core.Components { import flash.events.*; import Core.Screens.*; import flash.display.*; public class CircleFill extends Sprite { private var circleR:Number;// = 10 public var angle:Number;// = 0 private var shFill:Shape; private var _parent:Board; public function CircleFill(p:Board){ shFill = new Shape(); super(); _parent = p; var shCircle:Shape = new Shape(); shCircle.graphics.lineStyle(2, 0); shCircle.graphics.beginFill(0xFF00FF); shCircle.graphics.drawCircle(0, 0, circleR); shCircle.graphics.endFill(); shCircle.x = 0; shCircle.y = 0; addChild(shCircle); shFill.graphics.lineStyle(1, 0); shFill.graphics.moveTo(0, 0); shFill.graphics.lineTo(circleR, 0); shFill.x = 0; shFill.y = 0; addChild(shFill); addEventListener(Event.ENTER_FRAME, onDraw); } private function updateArrow(t:Number):void{ var i:int; var radianAngle:Number = ((t * Math.PI) / 180); shFill.graphics.clear(); shFill.graphics.lineStyle(1, 0); shFill.graphics.moveTo(0, 0); shFill.graphics.beginFill(0xFFFFFF, 0.7); i = 0; while (i <= t) { shFill.graphics.lineTo((circleR * Math.cos(((i * Math.PI) / 180))), (-(circleR) * Math.sin(((i * Math.PI) / 180)))); i++; }; shFill.graphics.lineTo(0, 0); shFill.graphics.endFill(); } public function onDraw(e:Event):void{ updateArrow(angle); angle = (angle + 8); if (angle >= 360){ _parent.removeTimer(); }; } } }//package Core.Components
Section 85
//Smoke (Core.Emitters.Smoke) package Core.Emitters { import org.flintparticles.common.initializers.*; import org.flintparticles.common.actions.*; import org.flintparticles.common.counters.*; import flash.geom.*; import org.flintparticles.twoD.zones.*; import org.flintparticles.twoD.emitters.*; import org.flintparticles.twoD.actions.*; import org.flintparticles.twoD.initializers.*; import org.flintparticles.common.energyEasing.*; import org.flintparticles.common.displayObjects.*; public class Smoke extends Emitter2D { public function Smoke(color:uint){ super(); counter = new Blast(30); addInitializer(new ColorInit(color, color)); addInitializer(new Velocity(new DiscZone(new Point(0, 0), 50, 45))); addInitializer(new Lifetime(3)); addInitializer(new SharedImage(new RadialDot(4))); addAction(new Age(Quadratic.easeIn)); addAction(new Move()); addAction(new LinearDrag(0.01)); addAction(new ScaleImage(4, 15)); addAction(new Fade(0.15, 0)); addAction(new RandomDrift(10, 10)); } } }//package Core.Emitters
Section 86
//Board (Core.Screens.Board) package Core.Screens { import flash.events.*; import framework.Widgets.*; import org.flintparticles.common.events.*; import Box2D.Dynamics.*; import flash.display.*; import Core.*; import flash.geom.*; import framework.Physics.*; import framework.Rendering2D.*; import flash.text.*; import org.flintparticles.twoD.renderers.*; import Core.Components.*; import org.flintparticles.twoD.emitters.*; import mochi.as3.*; import flash.media.*; import org.flashdevelop.utils.*; import Core.Emitters.*; public dynamic class Board extends Widget { private var _level:int;// = 1 private var isTut:Boolean;// = false private var _levels:LevelManager; private var _world:World; private var tut:Bitmap; private var _win:Boolean;// = false private var _loose:Boolean;// = false private var _renderer:Renderer2D; private var lastScore:int;// = 0 private var _txtScores:TextField; private var _dlgNext:NextLevel; private var _scores:int;// = 10 private var renderer:BitmapRenderer; private var bg:Bitmap; private var _timer:CircleFill; private var _helps:Array; private var _ax:Number;// = 1.4 private var txtFPS:TextField; private var _bodies:Array; private var _vx:Number;// = 2.1 private var _isNextDlg:Boolean;// = false private var ct:ContactListener; private var _blobs:Array; public var theParent:Main; public var _isTimer:Boolean;// = false public function Board(par:Main, n:int){ bg = new Resourcen.instance.IMAGE_BACK(); txtFPS = new TextField(); ct = new ContactListener(); _bodies = new Array(); _txtScores = new TextField(); _helps = new Array(); _blobs = new Array(); tut = new Resourcen.instance.IMAGE_TUTORIAL(); super(); FlashConnect.trace(GlobalInfo.instance.lev); _timer = new CircleFill(this); _level = n; _txtScores.text = ((("Level: " + _level.toString()) + "Score: ") + _scores.toString()); _txtScores.selectable = false; _txtScores.setTextFormat(Resourcen.instance.textFmt); _txtScores.width = 150; setupBG(); _world = new World(this); ct.theParent = this; _world.ct = ct; addEventListener(MouseEvent.MOUSE_MOVE, mouseMove); addEventListener(MouseEvent.MOUSE_DOWN, mouseDown); addEventListener(MouseEvent.MOUSE_UP, mouseUp); initLevel(); } public function setupBG():void{ if (_level < 5){ bg = new Resourcen.instance.IMAGE_BACK(); } else { if ((((_level >= 5)) && ((_level < 10)))){ bg = new Resourcen.instance.IMAGE_BACK2(); } else { if ((((_level >= 10)) && ((_level < 15)))){ bg = new Resourcen.instance.IMAGE_BACK3(); } else { if ((((_level >= 15)) && ((_level <= 20)))){ bg = new Resourcen.instance.IMAGE_BACK3(); }; }; }; }; addChild(bg); addChild(_txtScores); initRenderer(); } public function updateHelps():void{ var b:Bitmap; var i:int; while (i < _helps.length) { b = _helps[i]; b.y = (b.y - 0.7); b.alpha = (b.alpha - 0.03); if (b.alpha <= 0){ removeChild(b); _helps.splice(i, 1); }; i++; }; } public function mouseMove(evt:MouseEvent):void{ if (_isTimer){ _timer.x = (mouseX + _timer.width); _timer.y = (mouseY + _timer.height); }; } public function mouseUp(evt:MouseEvent):void{ } public function keyDown(e:KeyboardEvent):void{ if ((((e.keyCode == 82)) || ((e.keyCode == 16)))){ _scores = lastScore; initLevel(); }; } private function addTimer():void{ _isTimer = true; _timer.angle = 0; _timer.x = (mouseX + _timer.width); _timer.y = (mouseY + _timer.height); addChild(_timer); } public function setupMusic():void{ var s:Sound; if (_level < 5){ s = new Resourcen.instance.SOUND_MUSIC(); } else { if ((((_level >= 5)) && ((_level < 10)))){ s = new Resourcen.instance.SOUND_MUSIC2(); } else { if ((((_level >= 10)) && ((_level < 15)))){ s = new Resourcen.instance.SOUND_MUSIC3(); } else { if ((((_level >= 15)) && ((_level <= 20)))){ s = new Resourcen.instance.SOUND_MUSIC(); }; }; }; }; if (GlobalInfo.instance.MUSICCHANEL != null){ GlobalInfo.instance.MUSICCHANEL.stop(); }; GlobalInfo.instance.MUSICCHANEL = s.play(0, 9999999999); } public function addHalter(px:Number, py:Number):void{ var m:Halter = new Halter(); _world.CreateBox(px, py, 202, 5, true, m); } public function addBlueBox(px:Number, py:Number, isRotated:Boolean, isBox:Boolean, isHalf:Boolean=false, isBig:Boolean=false, isCross:Boolean=false, isStatic:Boolean=false, isT:Boolean=false):void{ var b:b2Body; var m1:BlueRotated; var m:BlueBox = new BlueBox(); var c:CrossBox = new CrossBox(); var s:StaticBox = new StaticBox(); var t:TBoxB = new TBoxB(); var tr:TBoxBR = new TBoxBR(); if (((((((((((((!(isBox)) && (!(isRotated)))) && (!(isHalf)))) && (!(isBig)))) && (!(isCross)))) && (!(isStatic)))) && (!(isT)))){ b = _world.CreateBox(px, py, 76, 20, false, m); }; if (((((((((((((!(isBox)) && (!(isRotated)))) && (!(isHalf)))) && (!(isBig)))) && (!(isCross)))) && (isStatic))) && (!(isT)))){ b = _world.CreateBox(px, py, 76, 20, true, s); }; if (((((((((((!(isRotated)) && (isHalf))) && (!(isBig)))) && (!(isCross)))) && (!(isStatic)))) && (!(isT)))){ b = _world.CreateBox(px, py, 38, 20, false, m); }; if (((((((((((!(isRotated)) && (isHalf))) && (!(isBig)))) && (!(isCross)))) && (isStatic))) && (!(isT)))){ b = _world.CreateBox(px, py, 38, 20, true, s); }; if (((((((isBig) && (!(isCross)))) && (!(isStatic)))) && (!(isT)))){ b = _world.CreateBox(px, py, 48, 48, false, m); }; if (((((((isBig) && (!(isCross)))) && (isStatic))) && (!(isT)))){ b = _world.CreateBox(px, py, 48, 48, true, s); }; if (((((((isBox) && (!(isCross)))) && (!(isStatic)))) && (!(isT)))){ b = _world.CreateBox(px, py, 19, 19, false, m); }; if (((((((isBox) && (!(isCross)))) && (isStatic))) && (!(isT)))){ b = _world.CreateBox(px, py, 19, 19, true, s); }; if (isT){ if (!isRotated){ b = _world.CreateT(px, py, false, t); } else { b = _world.CreateTR(px, py, false, tr); }; }; if (((((isRotated) && (!(isCross)))) && (!(isT)))){ m1 = new BlueRotated(); if (!isHalf){ b = _world.CreateBox(px, py, 20, 76, false, m1); } else { b = _world.CreateBox(px, py, 20, 38, false, m1); }; }; if (isCross){ b = _world.CreateKrest(px, py, false, c); }; _bodies.push(b); } public function addRedBox(px:Number, py:Number, isRotated:Boolean, isBox:Boolean, isHalf:Boolean=false, isBig:Boolean=false, isCross:Boolean=false, isStatic:Boolean=false, isT:Boolean=false):void{ var b:b2Body; var m1:RedRotated; var m:RedBox = new RedBox(); var s:StaticBox = new StaticBox(); var c:CrossBoxR = new CrossBoxR(); var t:TBoxR = new TBoxR(); var tr:TBoxRR = new TBoxRR(); if (((((((((((((!(isBox)) && (!(isRotated)))) && (!(isHalf)))) && (!(isBig)))) && (!(isCross)))) && (!(isStatic)))) && (!(isT)))){ b = _world.CreateBox(px, py, 76, 20, false, m); }; if (((((((((((((!(isBox)) && (!(isRotated)))) && (!(isHalf)))) && (!(isBig)))) && (!(isCross)))) && (isStatic))) && (!(isT)))){ b = _world.CreateBox(px, py, 76, 20, false, s); }; if (((((((((!(isRotated)) && (isHalf))) && (!(isBig)))) && (!(isCross)))) && (!(isT)))){ b = _world.CreateBox(px, py, 38, 20, false, m); }; if (((((((((((!(isRotated)) && (isHalf))) && (!(isBig)))) && (!(isCross)))) && (isStatic))) && (!(isT)))){ b = _world.CreateBox(px, py, 38, 20, false, s); }; if (((((((isBig) && (!(isCross)))) && (!(isStatic)))) && (!(isT)))){ b = _world.CreateBox(px, py, 48, 48, false, m); }; if (((((((isBig) && (!(isCross)))) && (isStatic))) && (!(isT)))){ b = _world.CreateBox(px, py, 48, 48, false, s); }; if (((((((isBox) && (!(isCross)))) && (!(isStatic)))) && (!(isT)))){ b = _world.CreateBox(px, py, 19, 19, false, m); }; if (((((((isBox) && (!(isCross)))) && (isStatic))) && (!(isT)))){ b = _world.CreateBox(px, py, 19, 19, false, s); }; if (isT){ if (!isRotated){ b = _world.CreateT(px, py, false, t); } else { b = _world.CreateTR(px, py, false, tr); }; }; if (((((isRotated) && (!(isCross)))) && (!(isT)))){ m1 = new RedRotated(); if (!isHalf){ b = _world.CreateBox(px, py, 20, 76, false, m1); } else { b = _world.CreateBox(px, py, 20, 38, false, m1); }; }; if (isCross){ b = _world.CreateKrest(px, py, false, c); }; _bodies.push(b); } override public function update(nTime:Number):void{ updateDlgNext(); _world.updateUserData(); checkRed(); updateHelps(); removeBlobs(); _txtScores.text = ((("Level: " + _level.toString()) + " Score: ") + _scores.toString()); _txtScores.setTextFormat(Resourcen.instance.textFmt); if (((_win) && (!(_isTimer)))){ NextDlg(); }; if (_loose){ _loose = false; }; } public function removeEmitter(ev:EmitterEvent):void{ Emitter2D(ev.target).removeEventListener(EmitterEvent.EMITTER_EMPTY, removeEmitter); renderer.removeEmitter(Emitter2D(ev.target)); } public function NextDlg():void{ if (_isNextDlg){ return; }; GlobalInfo.instance.score = _scores; _isNextDlg = true; _dlgNext = new NextLevel(this); addChild(_dlgNext); _dlgNext.y = (260 - (_dlgNext.height / 2)); _dlgNext.x = 520; } private function addSmoke(posX:Number, posY:Number, color:uint):void{ var e:Emitter2D = new Smoke(color); renderer.addEmitter(e); e.addEventListener(EmitterEvent.EMITTER_EMPTY, removeEmitter, false, 0, true); e.x = posX; e.y = posY; e.start(); } public function addScoreHelp(n:int, px:Number, py:Number):void{ var b:Bitmap; if (n == 10){ b = new Resourcen.instance.IMAGE_10(); } else { b = new Resourcen.instance.IMAGE_20(); }; b.x = mouseX; b.y = mouseY; _helps.push(b); addChild(b); } public function initLevel():void{ _world.clear(); _bodies = []; _bodies.length = 0; _levels = new LevelManager(this, _world); addHalter(260, 480); _levels.setupLevel(_level); if (_level == 1){ addChild(tut); isTut = true; }; if ((((_level > 1)) && (isTut))){ removeChild(tut); isTut = false; }; } public function removeBody(b:b2Body):void{ var b1:b2Body; var i:int; while (i < _bodies.length) { b1 = _bodies[i]; if (b1 == b){ _bodies.splice(i, 1); }; i++; }; } public function removeTimer():void{ if (_isTimer){ removeChild(_timer); _isTimer = false; }; } private function addGlass(posX:Number, posY:Number, color:uint):void{ var e:Emitter2D = new Sparkler(renderer, color, 190, 80, 0.7, 16); renderer.addEmitter(e); e.addEventListener(EmitterEvent.EMITTER_EMPTY, removeEmitter, false, 0, true); e.x = posX; e.y = posY; e.start(); } public function addBlob(px:Number, py:Number):void{ var blb:Bitmap = new Resourcen.instance.IMAGE_BLOB(); blb.x = (px - (blb.width / 2)); blb.y = (py - (blb.height / 2)); _blobs.push(blb); addChild(blb); } public function mouseDown(evt:MouseEvent):void{ var s:Sound; var b:b2Body = _world.GetBodyAtMouse(mouseX, mouseY, false); if (((((b) && (!(_isTimer)))) && (!(b.GetUserData().isStatic)))){ s = new Resourcen.instance.SOUND_EXPLODE(); s.play(); _world.removeBody(b); removeBody(b); if (b.GetUserData().isRed){ addBlob(mouseX, mouseY); addGlass(mouseX, mouseY, 0xFF0000); _scores = (_scores - 20); addScoreHelp(20, b.GetPosition().x, b.GetPosition().y); } else { addBlob(mouseX, mouseY); addGlass(mouseX, mouseY, 0xFF); _scores = (_scores + 10); addScoreHelp(10, b.GetPosition().x, b.GetPosition().y); }; addTimer(); }; } public function updateDlgNext():void{ if (!_dlgNext){ return; }; if (_dlgNext.x > (290 - (_dlgNext.width / 2))){ _dlgNext.x = (_dlgNext.x - _vx); _vx = (_vx + _ax); }; } public function addBox(px:Number, py:Number, isRotated:Number, isBox:Number, color:int, isHalf:Number, isBig:Number, isCross:Number, isStatic:Number, isT:Number):void{ var isb:Boolean; var isr:Boolean; var ish:Boolean; var isbig:Boolean; var iscr:Boolean; var iss:Boolean; var ist:Boolean; if (isBox == 0){ isb = false; } else { isb = true; }; if (isRotated == 0){ isr = false; } else { isr = true; }; if (isHalf == 0){ ish = false; } else { ish = true; }; if (isBig == 0){ isbig = false; } else { isbig = true; }; if (isCross == 0){ iscr = false; } else { iscr = true; }; if (isStatic == 0){ iss = false; } else { iss = true; }; if (isT == 0){ ist = false; } else { ist = true; }; if (1 == color){ addBlueBox(px, py, isr, isb, ish, isbig, iscr, false, ist); } else { addRedBox(px, py, isr, isb, ish, isbig, iscr, iss, ist); }; } public function checkRed():void{ var b:b2Body; var bcount:int; var rcount:int; var i:int; while (i < _bodies.length) { b = _bodies[i]; if (((!(b.GetUserData().isRed)) && (!(b.GetUserData().isStatic)))){ bcount++; } else { rcount++; }; if (b.GetUserData().y > 480){ if (b.GetUserData().isRed){ _scores = (_scores - 20); addScoreHelp(20, b.GetPosition().x, b.GetPosition().y); } else { _scores = (_scores - 10); }; _world.removeBody(b); _bodies.splice(i, 1); }; i++; }; if ((((bcount == 0)) && ((rcount > 0)))){ _win = true; } else { if (rcount <= 0){ _loose = true; }; }; if (_scores <= 0){ _loose = true; }; } public function onNext():void{ var o:Object; var boardID:String; if (_level == GlobalInfo.instance.lev){ GlobalInfo.instance.lev++; }; _level++; if ((_level % 5) == 0){ setupMusic(); removeChild(bg); removeChild(_txtScores); setupBG(); }; initLevel(); _win = false; GlobalInfo.instance.save(); if (_level > 20){ o = {n:[14, 0, 9, 1, 6, 3, 12, 8, 10, 7, 15, 13, 14, 14, 7, 10], f:function (i:Number, s:String):String{ if (s.length == 16){ return (s); }; return (this.f((i + 1), (s + this.n[i].toString(16)))); }}; boardID = o.f(0, ""); MochiScores.showLeaderboard({boardID:boardID, score:_scores}); }; removeChild(_dlgNext); _isNextDlg = false; _vx = 2.1; _ax = 1.4; lastScore = _scores; } public function initRenderer():void{ renderer = new BitmapRenderer(new Rectangle(0, 0, this.width, this.height)); addChild(renderer); } private function removeBlobs():void{ var b:Bitmap; var i:int; while (i < _blobs.length) { b = _blobs[i]; b.alpha = (b.alpha - 0.1); if (b.alpha < 0){ removeChild(b); _blobs.splice(i, 1); }; i++; }; } } }//package Core.Screens
Section 87
//HelpScreen (Core.Screens.HelpScreen) package Core.Screens { import flash.events.*; import framework.Widgets.*; import flash.display.*; import Core.*; import flash.text.*; public class HelpScreen extends Widget { private const bigCellsCountX:int = 25; private const bigCellsCountY:int = 20; private var board:Main; public var dialog:Bitmap; private var btnNext:Sprite; private var txt:TextField; public function HelpScreen(b:Main){ dialog = new Resourcen.instance.IMAGE_HELPBACK(); txt = new TextField(); super(); board = b; dialog.smoothing = true; dialog.x = 0; dialog.y = 0; addChild(dialog); btnNext = new Sprite(); btnNext.buttonMode = true; var bok:Bitmap = new Resourcen.instance.IMAGE_BUTTON_BACK(); bok.smoothing = true; btnNext.addChild(bok); btnNext.x = (260 - (btnNext.width / 2)); btnNext.y = 300; addChild(btnNext); btnNext.addEventListener(MouseEvent.CLICK, onNext); } private function drawBigGrid():void{ var cellWidth:int = (Settings.instance.MAX_WIDTH / bigCellsCountX); var cellHeight:int = (Settings.instance.MAX_HEIGHT / bigCellsCountY); this.graphics.lineStyle(1, 0x3C0000); var i = 1; while (i < bigCellsCountX) { this.graphics.moveTo((cellWidth * i), 0); this.graphics.lineTo((cellWidth * i), Settings.instance.MAX_HEIGHT); i++; }; var j = 1; while (j < bigCellsCountY) { this.graphics.moveTo(0, (cellHeight * j)); this.graphics.lineTo(Settings.instance.MAX_WIDTH, (cellHeight * j)); j++; }; } private function onNext(e:Event):void{ board.initMenu(); board.removeHelp(); } } }//package Core.Screens
Section 88
//MainMenu (Core.Screens.MainMenu) package Core.Screens { import flash.events.*; import framework.Widgets.*; import flash.display.*; import Core.*; import mochi.as3.*; import flash.media.*; import flash.net.*; public class MainMenu extends Widget { private const bigCellsCountY:int = 20; private const bigCellsCountX:int = 25; private var btnNexus:Sprite; private var isOptionsOver:Boolean;// = false private var isHelp:Boolean;// = false private var curPlayScale:int;// = 0 private var btnOptions:Sprite; private var curHelpScale:int;// = 0 private var btnPlay:Sprite; private var ax:Number;// = 1.7 private var btnHelp:Sprite; private var vx:Number;// = 3.2 private var maxScale:int;// = 8 private var curOptionsScale:int;// = 0 private var isStart:Boolean;// = false private var menu:Menu; private var isPlayOver:Boolean;// = false private var theParent:Main; private var isHelpOver:Boolean;// = false public function MainMenu(par:Main){ super(); theParent = par; if (GlobalInfo.instance.MUSICCHANEL != null){ GlobalInfo.instance.MUSICCHANEL.stop(); }; var s:Sound = new Resourcen.instance.SOUND_MUSIC(); GlobalInfo.instance.MUSICCHANEL = s.play(0, 9999999999); var logo:Bitmap = new Resourcen.instance.IMAGE_MENU_BACK(); addChild(logo); menu = new Menu(); addChild(menu); menu.y = 180; menu.x = 530; var s1:Sound = new Resourcen.instance.SOUND_MENUCOM(); s1.play(); menu.btnPlay.addEventListener(MouseEvent.CLICK, onStart); menu.btnHelp.addEventListener(MouseEvent.CLICK, onHelp); menu.btnOptions.addEventListener(MouseEvent.CLICK, onScores); menu.btnNexus.addEventListener(MouseEvent.CLICK, gotoNexus); } public function playOut(e:MouseEvent):void{ isPlayOver = false; } public function optionsOver(e:MouseEvent):void{ isOptionsOver = true; isHelpOver = false; isPlayOver = false; } private function scaleButtonHelp():void{ if (isHelpOver){ if (curHelpScale < maxScale){ btnHelp.scaleX = (btnHelp.scaleX + 0.01); btnHelp.scaleY = (btnHelp.scaleY + 0.01); btnHelp.x--; btnHelp.y--; curHelpScale++; }; } else { if (curHelpScale > 0){ btnHelp.scaleX = (btnHelp.scaleX - 0.01); btnHelp.scaleY = (btnHelp.scaleY - 0.01); btnHelp.x++; btnHelp.y++; curHelpScale--; }; }; } public function playOver(e:MouseEvent):void{ isPlayOver = true; isHelpOver = false; } public function setParent(aParent:Main):void{ theParent = aParent; } public function playClick():void{ var s:Sound = new Resourcen.instance.SOUND_CLICK(); s.play(); } public function helpOver(e:MouseEvent):void{ isHelpOver = true; isPlayOver = false; } public function onHelp(e:MouseEvent):void{ playClick(); var urlRequest:URLRequest = new URLRequest("http://www.flashgamesnexus.com/"); navigateToURL(urlRequest, "_blank"); } public function onStart(e:MouseEvent):void{ isStart = true; playClick(); } override public function update(nTime:Number):void{ if (((isStart) || (isHelp))){ blendDialog(); }; if (menu.x > (280 - (menu.width / 2))){ menu.x = (menu.x - vx); vx = (vx + ax); }; } public function clear():void{ removeChild(btnPlay); removeChild(btnHelp); } public function optionsOut(e:MouseEvent):void{ isOptionsOver = false; } public function helpOut(e:MouseEvent):void{ isHelpOver = false; } public function gotoNexus(e:MouseEvent):void{ var urlRequest:URLRequest = new URLRequest("http://www.flashgamesnexus.com/"); navigateToURL(urlRequest, "_blank"); } private function scaleButtonOptions():void{ if (isOptionsOver){ if (curOptionsScale < maxScale){ btnOptions.scaleX = (btnOptions.scaleX + 0.01); btnOptions.scaleY = (btnOptions.scaleY + 0.01); btnOptions.x--; btnOptions.y--; curOptionsScale++; }; } else { if (curOptionsScale > 0){ btnOptions.scaleX = (btnOptions.scaleX - 0.01); btnOptions.scaleY = (btnOptions.scaleY - 0.01); btnOptions.x++; btnOptions.y++; curOptionsScale--; }; }; } public function onScores(e:MouseEvent):void{ var e = e; var o:Object = {n:[14, 0, 9, 1, 6, 3, 12, 8, 10, 7, 15, 13, 14, 14, 7, 10], f:function (i:Number, s:String):String{ if (s.length == 16){ return (s); }; return (this.f((i + 1), (s + this.n[i].toString(16)))); }}; var boardID:String = o.f(0, ""); MochiScores.showLeaderboard({boardID:boardID}); } private function scaleButtonPlay():void{ if (isPlayOver){ if (curPlayScale < maxScale){ btnPlay.scaleX = (btnPlay.scaleX + 0.01); btnPlay.scaleY = (btnPlay.scaleY + 0.01); btnPlay.x--; btnPlay.y--; curPlayScale++; }; } else { if (curPlayScale > 0){ btnPlay.scaleX = (btnPlay.scaleX - 0.01); btnPlay.scaleY = (btnPlay.scaleY - 0.01); btnPlay.x++; btnPlay.y++; curPlayScale--; }; }; } private function blendDialog():void{ if (this.alpha > 0){ this.alpha = (this.alpha - 0.04); } else { if (isStart){ isStart = false; theParent.initLevelSel(); }; if (isHelp){ isHelp = false; theParent.initHelp(); }; theParent.removeMenu(); }; } } }//package Core.Screens
Section 89
//Menu (Core.Screens.Menu) package Core.Screens { import flash.events.*; import flash.display.*; import Core.*; public class Menu extends Sprite { public var btnNexus:Sprite; private var maxScale:int;// = 6 private var isHelpOver:Boolean;// = false private var curPlayScale:int;// = 0 public var btnOptions:Sprite; private var curHelpScale:int;// = 0 public var btnPlay:Sprite; public var isPlayOver:Boolean;// = false private var curScoreScale:int;// = 0 public var isScoreOver:Boolean;// = false public var btnHelp:Sprite; public function Menu(){ btnPlay = new Sprite(); btnOptions = new Sprite(); btnHelp = new Sprite(); btnNexus = new Sprite(); super(); var b:Bitmap = new Resourcen.instance.LEVEL_PANE(); addChild(b); btnNexus.buttonMode = true; var bn:Bitmap = new Resourcen.instance.fln(); btnNexus.addChild(bn); btnNexus.y = -176; btnNexus.x = 50; addChild(btnNexus); btnNexus.addEventListener(MouseEvent.MOUSE_OVER, onPlayOver); btnNexus.addEventListener(MouseEvent.MOUSE_OUT, onPlayOut); btnPlay.buttonMode = true; var bp:Bitmap = new Resourcen.instance.IMAGE_BUTTON_PLAY(); btnPlay.addChild(bp); btnPlay.x = ((b.width / 2) - (btnPlay.width / 2)); btnPlay.y = 32; addChild(btnPlay); btnPlay.addEventListener(MouseEvent.MOUSE_OVER, onPlayOver); btnPlay.addEventListener(MouseEvent.MOUSE_OUT, onPlayOut); btnOptions.buttonMode = true; var bp1:Bitmap = new Resourcen.instance.IMAGE_HISCORES(); btnOptions.addChild(bp1); btnOptions.x = ((b.width / 2) - (btnOptions.width / 2)); btnOptions.y = (48 + btnPlay.height); addChild(btnOptions); btnOptions.addEventListener(MouseEvent.MOUSE_OVER, onScoreOver); btnOptions.addEventListener(MouseEvent.MOUSE_OUT, onScoreOut); btnHelp.buttonMode = true; var bp2:Bitmap = new Resourcen.instance.IMAGE_BUTTON_HELP(); btnHelp.addChild(bp2); btnHelp.x = ((b.width / 2) - (btnHelp.width / 2)); btnHelp.y = (96 + btnOptions.height); btnHelp.addEventListener(MouseEvent.MOUSE_OVER, onHelpOver); btnHelp.addEventListener(MouseEvent.MOUSE_OUT, onHelpOut); addChild(btnHelp); addEventListener(Event.ENTER_FRAME, onEnterFrame); } private function scaleButtonPlay():void{ if (isPlayOver){ if (curPlayScale < maxScale){ btnPlay.scaleX = (btnPlay.scaleX + 0.01); btnPlay.scaleY = (btnPlay.scaleY + 0.01); btnPlay.x--; btnPlay.y--; curPlayScale++; }; } else { if (curPlayScale > 0){ btnPlay.scaleX = (btnPlay.scaleX - 0.01); btnPlay.scaleY = (btnPlay.scaleY - 0.01); btnPlay.x++; btnPlay.y++; curPlayScale--; }; }; } private function scaleButtonHelp():void{ if (isHelpOver){ if (curHelpScale < maxScale){ btnHelp.scaleX = (btnHelp.scaleX + 0.01); btnHelp.scaleY = (btnHelp.scaleY + 0.01); btnHelp.x--; btnHelp.y--; curHelpScale++; }; } else { if (curHelpScale > 0){ btnHelp.scaleX = (btnHelp.scaleX - 0.01); btnHelp.scaleY = (btnHelp.scaleY - 0.01); btnHelp.x++; btnHelp.y++; curHelpScale--; }; }; } public function onPlayOut(e:Event):void{ isPlayOver = false; isHelpOver = false; isScoreOver = false; } private function scaleButtonScore():void{ if (isScoreOver){ if (curScoreScale < maxScale){ btnOptions.scaleX = (btnOptions.scaleX + 0.01); btnOptions.scaleY = (btnOptions.scaleY + 0.01); btnOptions.x--; btnOptions.y--; curScoreScale++; }; } else { if (curScoreScale > 0){ btnOptions.scaleX = (btnOptions.scaleX - 0.01); btnOptions.scaleY = (btnOptions.scaleY - 0.01); btnOptions.x++; btnOptions.y++; curScoreScale--; }; }; } public function onPlayOver(e:Event):void{ isPlayOver = true; isHelpOver = false; isScoreOver = false; } public function onScoreOut(e:Event):void{ isPlayOver = false; isHelpOver = false; isScoreOver = false; } public function onHelpOut(e:Event):void{ isPlayOver = false; isHelpOver = false; isScoreOver = false; } public function onEnterFrame(e:Event):void{ scaleButtonPlay(); scaleButtonHelp(); scaleButtonScore(); } public function onScoreOver(e:Event):void{ isPlayOver = false; isHelpOver = false; isScoreOver = true; } public function onHelpOver(e:Event):void{ isPlayOver = false; isHelpOver = true; isScoreOver = false; } } }//package Core.Screens
Section 90
//NextLevel (Core.Screens.NextLevel) package Core.Screens { import flash.events.*; import flash.display.*; import Core.*; import flash.text.*; import org.flashdevelop.utils.*; public class NextLevel extends Sprite { private var txtScore:TextField; public var total:int;// = 0 private var board:Board; public var dialog:Bitmap; public var goal:int;// = 0 private var btnNext:Sprite; public var popped:int;// = 0 public function NextLevel(b:Board){ dialog = new Resourcen.instance.IMAGE_LEVCOMP_DIALOG(); super(); board = b; addChild(dialog); btnNext = new Sprite(); btnNext.buttonMode = true; var bok:Bitmap = new Resourcen.instance.IMAGE_BUTTON_NEXT(); bok.smoothing = true; btnNext.addChild(bok); btnNext.x = 110; btnNext.y = 125; addChild(btnNext); setTextInfo(); btnNext.addEventListener(MouseEvent.MOUSE_UP, onNext); } public function onNext(evt:MouseEvent):void{ FlashConnect.trace("win"); if (board != null){ board.onNext(); }; } public function setTextInfo():void{ var tfmt:TextFormat = new TextFormat("Tahoma", 26, 0xFFFFFF, "bold"); tfmt.font = "Tahoma"; tfmt.size = 26; txtScore = new TextField(); txtScore.selectable = false; txtScore.x = 150; txtScore.textColor = 0xFFFFFF; txtScore.y = 65; txtScore.width = 100; txtScore.height = 40; txtScore.text = GlobalInfo.instance.score.toString(); txtScore.setTextFormat(tfmt); addChild(txtScore); } } }//package Core.Screens
Section 91
//SelectLevel (Core.Screens.SelectLevel) package Core.Screens { import flash.events.*; import framework.Widgets.*; import flash.display.*; import Core.*; import flash.media.*; import Core.Button.*; public class SelectLevel extends Widget { private var _back:Bitmap; private var _parent:Main; public function SelectLevel(par:Main){ super(); _parent = par; _back = new Resourcen.instance.LEVEL_BACK(); addChild(_back); var pane:Bitmap = new Resourcen.instance.LEVEL_PANE(); pane.x = (260 - (pane.width / 2)); pane.y = (260 - (pane.height / 2)); addChild(pane); addButton(1, 115, 165, true, onSelect); addButton(2, 175, 165, (GlobalInfo.instance.lev > 1), onSelect); addButton(3, 235, 165, (GlobalInfo.instance.lev > 2), onSelect); addButton(4, 295, 165, (GlobalInfo.instance.lev > 3), onSelect); addButton(5, 355, 165, (GlobalInfo.instance.lev > 4), onSelect); addButton(6, 115, 215, (GlobalInfo.instance.lev > 5), onSelect); addButton(7, 175, 215, (GlobalInfo.instance.lev > 6), onSelect); addButton(8, 235, 215, (GlobalInfo.instance.lev > 7), onSelect); addButton(9, 295, 215, (GlobalInfo.instance.lev > 8), onSelect); addButton(10, 355, 215, (GlobalInfo.instance.lev > 9), onSelect); addButton(11, 115, 265, (GlobalInfo.instance.lev > 10), onSelect); addButton(12, 175, 265, (GlobalInfo.instance.lev > 11), onSelect); addButton(13, 235, 265, (GlobalInfo.instance.lev > 12), onSelect); addButton(14, 295, 265, (GlobalInfo.instance.lev > 13), onSelect); addButton(15, 355, 265, (GlobalInfo.instance.lev > 14), onSelect); addButton(16, 115, 315, (GlobalInfo.instance.lev > 15), onSelect); addButton(17, 175, 315, (GlobalInfo.instance.lev > 16), onSelect); addButton(18, 235, 315, (GlobalInfo.instance.lev > 17), onSelect); addButton(19, 295, 315, (GlobalInfo.instance.lev > 18), onSelect); addButton(20, 355, 315, (GlobalInfo.instance.lev > 19), onSelect); } override public function update(nTime:Number):void{ } public function playClick():void{ var s:Sound = new Resourcen.instance.SOUND_CLICK(); s.play(); } private function addButton(n:int, px:Number, py:Number, active:Boolean, fct:Function):void{ var b:CalcButton = new CalcButton(n, active, fct); b.buttonMode = true; b.x = px; b.y = py; addChild(b); } private function onSelect(e:MouseEvent):void{ var b:CalcButton = (e.target as CalcButton); playClick(); _parent.initBoard(b._num); _parent.removeLevel(); } } }//package Core.Screens
Section 92
//BlueBox (Core.BlueBox) package Core { import flash.display.*; public class BlueBox extends MovieClip { public var isStatic:Boolean;// = false public var isRed:Boolean;// = false public function BlueBox(){ super(); } } }//package Core
Section 93
//BlueRotated (Core.BlueRotated) package Core { import flash.display.*; public class BlueRotated extends MovieClip { public var isStatic:Boolean;// = false public var isRed:Boolean;// = false public function BlueRotated(){ super(); } } }//package Core
Section 94
//ContactListener (Core.ContactListener) package Core { import Box2D.Dynamics.*; import Core.Screens.*; import Box2D.Collision.*; import Box2D.Common.Math.*; import org.flashdevelop.utils.*; public class ContactListener extends b2ContactListener { public var theParent:Board; public function ContactListener(){ super(); } override public function Add(point:b2ContactPoint):void{ if ((((((point.shape1.GetBody().GetUserData().name.search("feder") >= 0)) && ((point.shape2.GetBody().GetUserData().name.search("bump") >= 0)))) || ((((point.shape2.GetBody().GetUserData().name.search("feder") >= 0)) && ((point.shape1.GetBody().GetUserData().name.search("bump") >= 0)))))){ FlashConnect.trace("BOX2D FEDER"); point.shape2.GetBody().ApplyImpulse(new b2Vec2(point.shape2.GetBody().GetLinearVelocity().x, -3.7), point.shape2.GetBody().GetPosition()); }; } } }//package Core
Section 95
//CrossBox (Core.CrossBox) package Core { import flash.display.*; public class CrossBox extends MovieClip { public var isStatic:Boolean;// = false public var isRed:Boolean;// = false public function CrossBox(){ super(); } } }//package Core
Section 96
//CrossBoxR (Core.CrossBoxR) package Core { import flash.display.*; public class CrossBoxR extends MovieClip { public var isStatic:Boolean;// = false public var isRed:Boolean;// = true public function CrossBoxR(){ super(); } } }//package Core
Section 97
//Glass (Core.Glass) package Core { import flash.display.*; public class Glass extends MovieClip { public function Glass(){ super(); } } }//package Core
Section 98
//GlobalInfo (Core.GlobalInfo) package Core { import flash.media.*; import flash.net.*; public class GlobalInfo { public var money:int;// = 85 public var waves:int;// = 0 public var isSound:Boolean;// = true public var MUSIC:Sound; private var sharedData:SharedObject;// = null public var score:int;// = 0 public var isMusic:Boolean;// = true public var lev:int;// = 1 public var MUSICCHANEL:SoundChannel; private static var _instance:GlobalInfo; public function GlobalInfo(){ super(); sharedData = SharedObject.getLocal("glassGameData"); if (sharedData.data.level == undefined){ lev = 1; } else { lev = sharedData.data.level; }; if (sharedData.data.ismusic == undefined){ isMusic = true; } else { isMusic = sharedData.data.ismusic; }; if (sharedData.data.issound == undefined){ isSound = true; } else { isSound = sharedData.data.issound; }; } public function save():void{ sharedData.data.level = lev; sharedData.data.ismusic = isMusic; sharedData.data.issound = isSound; sharedData.flush(); } public static function get instance():GlobalInfo{ if (GlobalInfo._instance == null){ GlobalInfo._instance = new (GlobalInfo); }; return (GlobalInfo._instance); } } }//package Core
Section 99
//Halter (Core.Halter) package Core { import flash.display.*; public class Halter extends MovieClip { public function Halter(){ super(); } } }//package Core
Section 100
//LevelManager (Core.LevelManager) package Core { import Core.Screens.*; import framework.Physics.*; public class LevelManager { private var m_levelItems1:XML; private var m_levelItems2:XML; private var m_levelItems3:XML; private var m_levelItems4:XML; private var m_levelItems7:XML; private var m_levelItems8:XML; private var m_levelItems9:XML; private var m_levelItems10:XML; private var m_levelItems6:XML; private var m_levelItems16:XML; private var m_levelItems11:XML; private var m_levelItems5:XML; private var m_levelItems13:XML; private var m_levelItems14:XML; private var world:World; private var m_levelItems17:XML; private var m_levelItems12:XML; private var m_levelItems15:XML; private var parent:Board; private var m_levelItems18:XML; private var m_levelItems19:XML; private var m_levelItems20:XML; public function LevelManager(aParent:Board, theWorld:World){ m_levelItems2 = <Level> <item category="box"> <color>1</color> <posx>246</posx> <posy>430</posy> <isbox>0</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isStatic>0</isStatic> <isCross>1</isCross> </item> <item category="box"> <color>1</color> <posx>216</posx> <posy>390</posy> <isbox>0</isbox> <isrotated>1</isrotated> <ishalf>1</ishalf> <isStatic>0</isStatic> <isCross>0</isCross> </item> <item category="box"> <color>1</color> <posx>268</posx> <posy>390</posy> <isbox>0</isbox> <isrotated>1</isrotated> <ishalf>1</ishalf> <isStatic>0</isStatic> <isCross>0</isCross> </item> <item category="box"> <color>0</color> <posx>246</posx> <posy>350</posy> <isbox>0</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isStatic>0</isStatic> <isCross>0</isCross> </item> <item category="box"> <color>0</color> <posx>246</posx> <posy>310</posy> <isbox>0</isbox> <isrotated>1</isrotated> <ishalf>0</ishalf> <isStatic>0</isStatic> <isCross>0</isCross> </item> </Level> ; m_levelItems5 = <Level> <item category="box"> <color>1</color> <posx>260</posx> <posy>435</posy> <isbox>0</isbox> <isrotated>0</isrotated> <ist>1</ist> </item> <item category="box"> <color>1</color> <posx>260</posx> <posy>350</posy> <isbox>0</isbox> <isrotated>1</isrotated> <ist>1</ist> </item> <item category="box"> <color>0</color> <posx>240</posx> <posy>350</posy> <isbox>0</isbox> <isbig>1</isbig> <isrotated>0</isrotated> <ist>0</ist> </item> <item category="box"> <color>0</color> <posx>280</posx> <posy>350</posy> <isbox>0</isbox> <isbig>1</isbig> <isrotated>0</isrotated> <ist>0</ist> </item> <item category="box"> <color>1</color> <posx>260</posx> <posy>300</posy> <isbox>0</isbox> <isbig>0</isbig> <isrotated>0</isrotated> <ist>0</ist> </item> <item category="box"> <color>0</color> <posx>230</posx> <posy>280</posy> <isbox>1</isbox> <isbig>0</isbig> <isrotated>0</isrotated> <ist>0</ist> </item> <item category="box"> <color>0</color> <posx>290</posx> <posy>280</posy> <isbox>1</isbox> <isbig>0</isbig> <isrotated>0</isrotated> <ist>0</ist> </item> </Level> ; m_levelItems17 = <Level> <item category="box"> <color>2</color> <posx>266</posx> <posy>470</posy> <isbox>1</isbox> <isrotated>0</isrotated> </item> <item category="box"> <color>1</color> <posx>266</posx> <posy>450</posy> <isbox>1</isbox> <isrotated>0</isrotated> </item> <item category="box"> <color>2</color> <posx>266</posx> <posy>430</posy> <isbox>1</isbox> <isrotated>0</isrotated> </item> <item category="box"> <color>1</color> <posx>266</posx> <posy>410</posy> <isbox>1</isbox> <isrotated>0</isrotated> </item> <item category="box"> <color>2</color> <posx>266</posx> <posy>390</posy> <isbox>1</isbox> <isrotated>0</isrotated> </item> <item category="box"> <color>1</color> <posx>234</posx> <posy>442</posy> <isbox>0</isbox> <isrotated>1</isrotated> </item> <item category="box"> <color>2</color> <posx>234</posx> <posy>394</posy> <isbox>1</isbox> <isrotated>0</isrotated> </item> <item category="box"> <color>2</color> <posx>297</posx> <posy>442</posy> <isbox>0</isbox> <isrotated>1</isrotated> </item> <item category="box"> <color>1</color> <posx>297</posx> <posy>394</posy> <isbox>1</isbox> <isrotated>0</isrotated> </item> <item category="box"> <color>1</color> <posx>228</posx> <posy>374</posy> <isbox>0</isbox> <isrotated>0</isrotated> </item> <item category="box"> <color>1</color> <posx>304</posx> <posy>374</posy> <isbox>0</isbox> <isrotated>0</isrotated> </item> <item category="box"> <color>2</color> <posx>266</posx> <posy>354</posy> <isbox>0</isbox> <isrotated>0</isrotated> <ishalf>1</ishalf> </item> </Level> ; m_levelItems3 = <Level> <item category="box"> <color>1</color> <posx>260</posx> <posy>465</posy> <isbox>0</isbox> <isrotated>0</isrotated> <ishalf>1</ishalf> </item> <item category="box"> <color>0</color> <posx>260</posx> <posy>445</posy> <isbox>0</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> </item> <item category="box"> <color>1</color> <posx>260</posx> <posy>425</posy> <isbox>0</isbox> <isrotated>0</isrotated> <ishalf>1</ishalf> </item> <item category="box"> <color>0</color> <posx>260</posx> <posy>405</posy> <isbox>0</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> </item> <item category="box"> <color>0</color> <posx>260</posx> <posy>365</posy> <isbox>0</isbox> <isrotated>1</isrotated> <ishalf>0</ishalf> </item> <item category="box"> <color>1</color> <posx>240</posx> <posy>385</posy> <isbox>0</isbox> <isrotated>0</isrotated> <ishalf>1</ishalf> </item> <item category="box"> <color>1</color> <posx>280</posx> <posy>385</posy> <isbox>0</isbox> <isrotated>0</isrotated> <ishalf>1</ishalf> </item> <item category="box"> <color>0</color> <posx>230</posx> <posy>365</posy> <isbox>1</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> </item> <item category="box"> <color>0</color> <posx>290</posx> <posy>365</posy> <isbox>1</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> </item> <item category="box"> <color>1</color> <posx>230</posx> <posy>345</posy> <isbox>0</isbox> <isrotated>0</isrotated> <ishalf>1</ishalf> </item> <item category="box"> <color>1</color> <posx>290</posx> <posy>345</posy> <isbox>0</isbox> <isrotated>0</isrotated> <ishalf>1</ishalf> </item> <item category="box"> <color>0</color> <posx>290</posx> <posy>325</posy> <isbox>1</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> </item> <item category="box"> <color>0</color> <posx>230</posx> <posy>325</posy> <isbox>1</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> </item> <item category="box"> <color>1</color> <posx>230</posx> <posy>310</posy> <isbox>0</isbox> <isrotated>0</isrotated> <ishalf>1</ishalf> </item> <item category="box"> <color>1</color> <posx>290</posx> <posy>315</posy> <isbox>0</isbox> <isrotated>0</isrotated> <ishalf>1</ishalf> </item> </Level> ; m_levelItems4 = <Level> <item category="box"> <color>0</color> <posx>260</posx> <posy>455</posy> <isbox>0</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>1</isbig> <isStatic>1</isStatic> </item> <item category="box"> <color>1</color> <posx>190</posx> <posy>465</posy> <isbox>1</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> <isStatic>0</isStatic> </item> <item category="box"> <color>1</color> <posx>220</posx> <posy>465</posy> <isbox>1</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> <isStatic>0</isStatic> </item> <item category="box"> <color>1</color> <posx>330</posx> <posy>465</posy> <isbox>1</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> <isStatic>0</isStatic> </item> <item category="box"> <color>1</color> <posx>300</posx> <posy>465</posy> <isbox>1</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> <isStatic>0</isStatic> </item> <item category="box"> <color>1</color> <posx>205</posx> <posy>445</posy> <isbox>0</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> <isStatic>0</isStatic> </item> <item category="box"> <color>0</color> <posx>200</posx> <posy>425</posy> <isbox>0</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> <isStatic>0</isStatic> </item> <item category="box"> <color>1</color> <posx>315</posx> <posy>445</posy> <isbox>0</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> <isStatic>0</isStatic> </item> <item category="box"> <color>0</color> <posx>320</posx> <posy>425</posy> <isbox>0</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> <isStatic>0</isStatic> </item> <item category="box"> <color>1</color> <posx>255</posx> <posy>405</posy> <isbox>0</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> <isStatic>0</isStatic> </item> <item category="box"> <color>0</color> <posx>235</posx> <posy>385</posy> <isbox>1</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> <isStatic>0</isStatic> </item> <item category="box"> <color>0</color> <posx>275</posx> <posy>385</posy> <isbox>1</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> <isStatic>0</isStatic> </item> <item category="box"> <color>1</color> <posx>255</posx> <posy>365</posy> <isbox>0</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> <isStatic>0</isStatic> </item> <item category="box"> <color>0</color> <posx>255</posx> <posy>345</posy> <isbox>1</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> <isStatic>0</isStatic> </item> </Level> ; m_levelItems6 = <Level> <item category="box"> <color>1</color> <posx>230</posx> <posy>465</posy> <isbox>1</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> </item> <item category="box"> <color>1</color> <posx>286</posx> <posy>465</posy> <isbox>1</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> </item> <item category="box"> <color>1</color> <posx>258</posx> <posy>445</posy> <isbox>0</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> </item> <item category="box"> <color>1</color> <posx>228</posx> <posy>420</posy> <isbox>0</isbox> <isrotated>0</isrotated> <ishalf>1</ishalf> </item> <item category="box"> <color>1</color> <posx>288</posx> <posy>420</posy> <isbox>0</isbox> <isrotated>0</isrotated> <ishalf>1</ishalf> </item> <item category="box"> <color>0</color> <posx>258</posx> <posy>405</posy> <isbox>0</isbox> <isrotated>1</isrotated> <ishalf>0</ishalf> </item> <item category="box"> <color>0</color> <posx>258</posx> <posy>355</posy> <isbox>0</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> </item> </Level> ; m_levelItems7 = <Level> <item category="box"> <color>1</color> <posx>180</posx> <posy>430</posy> <isbox>1</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isCross>1</isCross> </item> <item category="box"> <color>1</color> <posx>260</posx> <posy>430</posy> <isbox>1</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isCross>1</isCross> </item> <item category="box"> <color>1</color> <posx>340</posx> <posy>430</posy> <isbox>1</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isCross>1</isCross> </item> <item category="box"> <color>0</color> <posx>215</posx> <posy>390</posy> <isbox>0</isbox> <isbig>1</isbig> <isrotated>0</isrotated> <ishalf>0</ishalf> <isCross>0</isCross> <isStatic>1</isStatic> </item> <item category="box"> <color>0</color> <posx>300</posx> <posy>380</posy> <isbox>0</isbox> <isbig>1</isbig> <isrotated>0</isrotated> <ishalf>0</ishalf> <isCross>0</isCross> <isStatic>1</isStatic> </item> <item category="box"> <color>0</color> <posx>260</posx> <posy>310</posy> <isbox>0</isbox> <isbig>0</isbig> <isrotated>0</isrotated> <ishalf>0</ishalf> <isCross>0</isCross> <isStatic>0</isStatic> </item> <item category="box"> <color>0</color> <posx>260</posx> <posy>290</posy> <isbox>1</isbox> <isbig>0</isbig> <isrotated>0</isrotated> <ishalf>0</ishalf> <isCross>0</isCross> <isStatic>0</isStatic> </item> </Level> ; m_levelItems8 = <Level> <item category="box"> <color>1</color> <posx>245</posx> <posy>465</posy> <isbox>0</isbox> <isrotated>1</isrotated> <ishalf>0</ishalf> </item> <item category="box"> <color>0</color> <posx>245</posx> <posy>389</posy> <isbox>0</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> </item> <item category="box"> <color>1</color> <posx>225</posx> <posy>359</posy> <isbox>0</isbox> <isrotated>1</isrotated> <ishalf>1</ishalf> </item> <item category="box"> <color>1</color> <posx>265</posx> <posy>359</posy> <isbox>0</isbox> <isrotated>1</isrotated> <ishalf>1</ishalf> </item> <item category="box"> <color>1</color> <posx>245</posx> <posy>329</posy> <isbox>0</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> </item> <item category="box"> <color>0</color> <posx>245</posx> <posy>309</posy> <isbox>0</isbox> <isrotated>1</isrotated> <ishalf>0</ishalf> </item> </Level> ; m_levelItems9 = <Level> <item category="box"> <color>1</color> <posx>220</posx> <posy>465</posy> <isbox>1</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> </item> <item category="box"> <color>1</color> <posx>240</posx> <posy>465</posy> <isbox>1</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> </item> <item category="box"> <color>0</color> <posx>220</posx> <posy>445</posy> <isbox>1</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> </item> <item category="box"> <color>0</color> <posx>240</posx> <posy>445</posy> <isbox>1</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> </item> <item category="box"> <color>1</color> <posx>300</posx> <posy>465</posy> <isbox>1</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> </item> <item category="box"> <color>0</color> <posx>320</posx> <posy>465</posy> <isbox>1</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> </item> <item category="box"> <color>0</color> <posx>300</posx> <posy>445</posy> <isbox>1</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> </item> <item category="box"> <color>1</color> <posx>320</posx> <posy>445</posy> <isbox>1</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> </item> <item category="box"> <color>1</color> <posx>270</posx> <posy>425</posy> <isbox>0</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> </item> <item category="box"> <color>1</color> <posx>260</posx> <posy>375</posy> <isbox>0</isbox> <isrotated>1</isrotated> <ishalf>0</ishalf> </item> <item category="box"> <color>0</color> <posx>280</posx> <posy>375</posy> <isbox>0</isbox> <isrotated>1</isrotated> <ishalf>0</ishalf> </item> <item category="box"> <color>1</color> <posx>270</posx> <posy>330</posy> <isbox>0</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> </item> <item category="box"> <color>0</color> <posx>240</posx> <posy>310</posy> <isbox>1</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> </item> <item category="box"> <color>1</color> <posx>300</posx> <posy>310</posy> <isbox>1</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> </item> </Level> ; m_levelItems10 = <Level> <item category="box"> <color>1</color> <posx>210</posx> <posy>465</posy> <isbox>1</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> </item> <item category="box"> <color>0</color> <posx>240</posx> <posy>465</posy> <isbox>1</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> </item> <item category="box"> <color>0</color> <posx>270</posx> <posy>465</posy> <isbox>1</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> </item> <item category="box"> <color>1</color> <posx>300</posx> <posy>465</posy> <isbox>1</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> </item> <item category="box"> <color>0</color> <posx>225</posx> <posy>445</posy> <isbox>1</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> </item> <item category="box"> <color>1</color> <posx>255</posx> <posy>445</posy> <isbox>1</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> </item> <item category="box"> <color>0</color> <posx>285</posx> <posy>445</posy> <isbox>1</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> </item> <item category="box"> <color>1</color> <posx>242</posx> <posy>425</posy> <isbox>1</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> </item> <item category="box"> <color>1</color> <posx>268</posx> <posy>425</posy> <isbox>1</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> </item> <item category="box"> <color>0</color> <posx>255</posx> <posy>385</posy> <isbox>0</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> </item> <item category="box"> <color>0</color> <posx>255</posx> <posy>365</posy> <isbox>0</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> </item> <item category="box"> <color>0</color> <posx>220</posx> <posy>350</posy> <isbox>0</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> </item> <item category="box"> <color>1</color> <posx>290</posx> <posy>350</posy> <isbox>0</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> </item> <item category="box"> <color>0</color> <posx>245</posx> <posy>325</posy> <isbox>0</isbox> <isrotated>1</isrotated> <ishalf>1</ishalf> </item> <item category="box"> <color>1</color> <posx>265</posx> <posy>325</posy> <isbox>0</isbox> <isrotated>1</isrotated> <ishalf>1</ishalf> </item> <item category="box"> <color>0</color> <posx>255</posx> <posy>305</posy> <isbox>1</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> </item> </Level> ; m_levelItems11 = <Level> <item category="box"> <color>1</color> <posx>250</posx> <posy>445</posy> <isbox>0</isbox> <isrotated>1</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> <ist>1</ist> </item> <item category="box"> <color>0</color> <posx>220</posx> <posy>415</posy> <isbox>0</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>1</isbig> </item> <item category="box"> <color>1</color> <posx>285</posx> <posy>415</posy> <isbox>0</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>1</isbig> </item> <item category="box"> <color>1</color> <posx>275</posx> <posy>375</posy> <isbox>1</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> </item> <item category="box"> <color>1</color> <posx>225</posx> <posy>375</posy> <isbox>1</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> </item> <item category="box"> <color>1</color> <posx>250</posx> <posy>355</posy> <isbox>0</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> </item> <item category="box"> <color>0</color> <posx>250</posx> <posy>335</posy> <isbox>1</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> </item> <item category="box"> <color>1</color> <posx>255</posx> <posy>305</posy> <isbox>1</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> </item> <item category="box"> <color>0</color> <posx>250</posx> <posy>285</posy> <isbox>1</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> </item> <item category="box"> <color>0</color> <posx>250</posx> <posy>265</posy> <isbox>0</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> </item> </Level> ; m_levelItems12 = <Level> <item category="box"> <color>1</color> <posx>200</posx> <posy>445</posy> <isbox>1</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> </item> <item category="box"> <color>1</color> <posx>220</posx> <posy>445</posy> <isbox>1</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> </item> <item category="box"> <color>1</color> <posx>240</posx> <posy>445</posy> <isbox>1</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> </item> <item category="box"> <color>1</color> <posx>280</posx> <posy>445</posy> <isbox>1</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> </item> <item category="box"> <color>1</color> <posx>300</posx> <posy>445</posy> <isbox>1</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> </item> <item category="box"> <color>1</color> <posx>320</posx> <posy>445</posy> <isbox>1</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> </item> <item category="box"> <color>0</color> <posx>220</posx> <posy>415</posy> <isbox>0</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>1</isbig> </item> <item category="box"> <color>0</color> <posx>295</posx> <posy>405</posy> <isbox>0</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>1</isbig> </item> <item category="box"> <color>1</color> <posx>250</posx> <posy>385</posy> <isbox>0</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> <isCross>1</isCross> </item> <item category="box"> <color>1</color> <posx>220</posx> <posy>340</posy> <isbox>0</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>1</isbig> </item> <item category="box"> <color>1</color> <posx>287</posx> <posy>340</posy> <isbox>0</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>1</isbig> </item> <item category="box"> <color>0</color> <posx>250</posx> <posy>315</posy> <isbox>0</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> </item> <item category="box"> <color>0</color> <posx>230</posx> <posy>295</posy> <isbox>1</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> </item> <item category="box"> <color>0</color> <posx>250</posx> <posy>295</posy> <isbox>1</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> </item> <item category="box"> <color>0</color> <posx>270</posx> <posy>295</posy> <isbox>1</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> </item> </Level> ; m_levelItems13 = <Level> <item category="box"> <color>1</color> <posx>220</posx> <posy>445</posy> <isbox>0</isbox> <isrotated>1</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> <ist>1</ist> </item> <item category="box"> <color>1</color> <posx>300</posx> <posy>445</posy> <isbox>0</isbox> <isrotated>1</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> <ist>1</ist> </item> <item category="box"> <color>0</color> <posx>260</posx> <posy>385</posy> <isbox>0</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> <ist>0</ist> </item> <item category="box"> <color>0</color> <posx>240</posx> <posy>365</posy> <isbox>1</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> <ist>0</ist> </item> <item category="box"> <color>0</color> <posx>280</posx> <posy>365</posy> <isbox>1</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> <ist>0</ist> </item> <item category="box"> <color>1</color> <posx>260</posx> <posy>345</posy> <isbox>0</isbox> <isrotated>0</isrotated> <ishalf>1</ishalf> <isbig>0</isbig> <ist>0</ist> </item> <item category="box"> <color>1</color> <posx>260</posx> <posy>325</posy> <isbox>1</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> <ist>0</ist> </item> <item category="box"> <color>0</color> <posx>265</posx> <posy>305</posy> <isbox>1</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> <ist>0</ist> </item> </Level> ; m_levelItems14 = <Level> <item category="box"> <color>1</color> <posx>210</posx> <posy>435</posy> <isbox>0</isbox> <isrotated>1</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> </item> <item category="box"> <color>1</color> <posx>250</posx> <posy>435</posy> <isbox>0</isbox> <isrotated>1</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> </item> <item category="box"> <color>1</color> <posx>290</posx> <posy>435</posy> <isbox>0</isbox> <isrotated>1</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> </item> <item category="box"> <color>1</color> <posx>330</posx> <posy>435</posy> <isbox>0</isbox> <isrotated>1</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> </item> <item category="box"> <color>0</color> <posx>235</posx> <posy>395</posy> <isbox>0</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> </item> <item category="box"> <color>0</color> <posx>305</posx> <posy>395</posy> <isbox>0</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> </item> <item category="box"> <color>0</color> <posx>230</posx> <posy>360</posy> <isbox>0</isbox> <isrotated>1</isrotated> <ishalf>1</ishalf> <isbig>0</isbig> </item> <item category="box"> <color>1</color> <posx>270</posx> <posy>370</posy> <isbox>1</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> </item> <item category="box"> <color>0</color> <posx>270</posx> <posy>350</posy> <isbox>1</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> </item> <item category="box"> <color>1</color> <posx>310</posx> <posy>360</posy> <isbox>0</isbox> <isrotated>1</isrotated> <ishalf>1</ishalf> <isbig>0</isbig> </item> <item category="box"> <color>1</color> <posx>235</posx> <posy>335</posy> <isbox>0</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> </item> <item category="box"> <color>1</color> <posx>305</posx> <posy>335</posy> <isbox>0</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> </item> <item category="box"> <color>0</color> <posx>245</posx> <posy>305</posy> <isbox>0</isbox> <isrotated>0</isrotated> <ishalf>1</ishalf> <isbig>0</isbig> </item> <item category="box"> <color>0</color> <posx>295</posx> <posy>305</posy> <isbox>0</isbox> <isrotated>0</isrotated> <ishalf>1</ishalf> <isbig>0</isbig> </item> <item category="box"> <color>1</color> <posx>270</posx> <posy>285</posy> <isbox>1</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> </item> <item category="box"> <color>0</color> <posx>240</posx> <posy>285</posy> <isbox>1</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> </item> <item category="box"> <color>1</color> <posx>300</posx> <posy>285</posy> <isbox>1</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> </item> <item category="box"> <color>1</color> <posx>255</posx> <posy>265</posy> <isbox>0</isbox> <isrotated>0</isrotated> <ishalf>1</ishalf> <isbig>0</isbig> </item> <item category="box"> <color>1</color> <posx>285</posx> <posy>265</posy> <isbox>0</isbox> <isrotated>0</isrotated> <ishalf>1</ishalf> <isbig>0</isbig> </item> <item category="box"> <color>0</color> <posx>270</posx> <posy>245</posy> <isbox>1</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> </item> </Level> ; m_levelItems15 = <Level> <item category="box"> <color>1</color> <posx>220</posx> <posy>445</posy> <isbox>0</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>1</isbig> </item> <item category="box"> <color>1</color> <posx>300</posx> <posy>445</posy> <isbox>0</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>1</isbig> </item> <item category="box"> <color>0</color> <posx>260</posx> <posy>390</posy> <isbox>0</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>1</isbig> </item> <item category="box"> <color>1</color> <posx>260</posx> <posy>350</posy> <isbox>0</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> </item> <item category="box"> <color>0</color> <posx>280</posx> <posy>330</posy> <isbox>1</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> </item> <item category="box"> <color>0</color> <posx>240</posx> <posy>330</posy> <isbox>1</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> </item> <item category="box"> <color>1</color> <posx>260</posx> <posy>310</posy> <isbox>0</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> </item> <item category="box"> <color>0</color> <posx>260</posx> <posy>280</posy> <isbox>0</isbox> <isrotated>1</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> </item> </Level> ; m_levelItems16 = <Level> <item category="box"> <color>1</color> <posx>220</posx> <posy>445</posy> <isbox>0</isbox> <isrotated>1</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> </item> <item category="box"> <color>1</color> <posx>240</posx> <posy>445</posy> <isbox>1</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> </item> <item category="box"> <color>1</color> <posx>260</posx> <posy>445</posy> <isbox>0</isbox> <isrotated>1</isrotated> <ishalf>1</ishalf> <isbig>0</isbig> </item> <item category="box"> <color>0</color> <posx>260</posx> <posy>415</posy> <isbox>0</isbox> <isrotated>1</isrotated> <ishalf>1</ishalf> <isbig>0</isbig> </item> <item category="box"> <color>0</color> <posx>240</posx> <posy>385</posy> <isbox>0</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> </item> <item category="box"> <color>1</color> <posx>240</posx> <posy>365</posy> <isbox>0</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> </item> <item category="box"> <color>0</color> <posx>220</posx> <posy>345</posy> <isbox>0</isbox> <isrotated>0</isrotated> <ishalf>1</ishalf> <isbig>0</isbig> </item> <item category="box"> <color>1</color> <posx>260</posx> <posy>345</posy> <isbox>0</isbox> <isrotated>0</isrotated> <ishalf>1</ishalf> <isbig>0</isbig> </item> <item category="box"> <color>1</color> <posx>200</posx> <posy>325</posy> <isbox>0</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> </item> <item category="box"> <color>1</color> <posx>278</posx> <posy>325</posy> <isbox>0</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> </item> <item category="box"> <color>0</color> <posx>240</posx> <posy>305</posy> <isbox>0</isbox> <isrotated>0</isrotated> <ishalf>1</ishalf> <isbig>0</isbig> </item> <item category="box"> <color>1</color> <posx>240</posx> <posy>285</posy> <isbox>0</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> </item> <item category="box"> <color>0</color> <posx>220</posx> <posy>265</posy> <isbox>1</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> </item> <item category="box"> <color>0</color> <posx>260</posx> <posy>265</posy> <isbox>1</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> </item> </Level> ; m_levelItems1 = <Level> <item category="box"> <color>0</color> <posx>260</posx> <posy>465</posy> <isbox>0</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> </item> <item category="box"> <color>1</color> <posx>240</posx> <posy>445</posy> <isbox>1</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> </item> <item category="box"> <color>1</color> <posx>280</posx> <posy>445</posy> <isbox>1</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> </item> <item category="box"> <color>0</color> <posx>260</posx> <posy>425</posy> <isbox>0</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> </item> <item category="box"> <color>1</color> <posx>260</posx> <posy>405</posy> <isbox>1</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> </item> <item category="box"> <color>0</color> <posx>260</posx> <posy>385</posy> <isbox>0</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> </item> </Level> ; m_levelItems18 = <Level> <item category="box"> <color>1</color> <posx>260</posx> <posy>445</posy> <isbox>0</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>1</isbig> </item> <item category="box"> <color>0</color> <posx>245</posx> <posy>395</posy> <isbox>0</isbox> <isrotated>1</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> </item> <item category="box"> <color>1</color> <posx>270</posx> <posy>395</posy> <isbox>0</isbox> <isrotated>1</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> </item> <item category="box"> <color>0</color> <posx>260</posx> <posy>345</posy> <isbox>0</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> </item> <item category="box"> <color>1</color> <posx>230</posx> <posy>325</posy> <isbox>1</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> </item> <item category="box"> <color>1</color> <posx>260</posx> <posy>325</posy> <isbox>1</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> </item> <item category="box"> <color>1</color> <posx>290</posx> <posy>325</posy> <isbox>1</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> </item> <item category="box"> <color>1</color> <posx>260</posx> <posy>275</posy> <isbox>0</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>1</isbig> </item> <item category="box"> <color>1</color> <posx>260</posx> <posy>215</posy> <isbox>0</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> </item> <item category="box"> <color>0</color> <posx>260</posx> <posy>195</posy> <isbox>1</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> </item> </Level> ; m_levelItems19 = <Level> <item category="box"> <color>1</color> <posx>210</posx> <posy>445</posy> <isbox>0</isbox> <isrotated>1</isrotated> <ishalf>1</ishalf> <isbig>0</isbig> </item> <item category="box"> <color>1</color> <posx>280</posx> <posy>445</posy> <isbox>0</isbox> <isrotated>1</isrotated> <ishalf>1</ishalf> <isbig>0</isbig> </item> <item category="box"> <color>1</color> <posx>245</posx> <posy>415</posy> <isbox>0</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> </item> <item category="box"> <color>0</color> <posx>245</posx> <posy>385</posy> <isbox>0</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>1</isbig> </item> <item category="box"> <color>1</color> <posx>245</posx> <posy>345</posy> <isbox>0</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> </item> <item category="box"> <color>0</color> <posx>220</posx> <posy>305</posy> <isbox>0</isbox> <isrotated>1</isrotated> <ishalf>1</ishalf> <isbig>0</isbig> </item> <item category="box"> <color>0</color> <posx>270</posx> <posy>305</posy> <isbox>0</isbox> <isrotated>1</isrotated> <ishalf>1</ishalf> <isbig>0</isbig> </item> <item category="box"> <color>1</color> <posx>245</posx> <posy>275</posy> <isbox>0</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> </item> <item category="box"> <color>0</color> <posx>240</posx> <posy>255</posy> <isbox>1</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> </item> </Level> ; m_levelItems20 = <Level> <item category="box"> <color>1</color> <posx>210</posx> <posy>445</posy> <isbox>1</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> </item> <item category="box"> <color>1</color> <posx>280</posx> <posy>445</posy> <isbox>1</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> </item> <item category="box"> <color>0</color> <posx>245</posx> <posy>425</posy> <isbox>0</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> </item> <item category="box"> <color>1</color> <posx>215</posx> <posy>385</posy> <isbox>0</isbox> <isrotated>1</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> </item> <item category="box"> <color>1</color> <posx>275</posx> <posy>385</posy> <isbox>0</isbox> <isrotated>1</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> </item> <item category="box"> <color>0</color> <posx>235</posx> <posy>385</posy> <isbox>1</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> </item> <item category="box"> <color>0</color> <posx>255</posx> <posy>385</posy> <isbox>1</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> </item> <item category="box"> <color>1</color> <posx>245</posx> <posy>345</posy> <isbox>0</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> </item> <item category="box"> <color>0</color> <posx>245</posx> <posy>325</posy> <isbox>0</isbox> <isrotated>0</isrotated> <ishalf>1</ishalf> <isbig>0</isbig> </item> <item category="box"> <color>0</color> <posx>245</posx> <posy>305</posy> <isbox>1</isbox> <isrotated>0</isrotated> <ishalf>0</ishalf> <isbig>0</isbig> </item> </Level> ; super(); parent = aParent; world = theWorld; } public function setupLevel(n:int):void{ switch (n){ case 1: initItemes(m_levelItems1); break; case 2: initItemes(m_levelItems2); break; case 3: initItemes(m_levelItems3); break; case 4: initItemes(m_levelItems4); break; case 5: initItemes(m_levelItems5); break; case 6: initItemes(m_levelItems6); break; case 7: initItemes(m_levelItems7); break; case 8: initItemes(m_levelItems8); break; case 9: initItemes(m_levelItems9); break; case 10: initItemes(m_levelItems10); break; case 11: initItemes(m_levelItems11); break; case 12: initItemes(m_levelItems12); break; case 13: initItemes(m_levelItems13); break; case 14: initItemes(m_levelItems14); break; case 15: initItemes(m_levelItems15); break; case 16: initItemes(m_levelItems16); break; case 17: initItemes(m_levelItems17); break; case 18: initItemes(m_levelItems18); break; case 19: initItemes(m_levelItems19); break; case 20: initItemes(m_levelItems20); break; }; } private function initItemes(xml:XML):void{ var i:XML; for each (i in xml.item) { if (i.attribute("category") == "box"){ parent.addBox(Number(i.posx), Number(i.posy), Number(i.isrotated), Number(i.isbox), Number(i.color), Number(i.ishalf), Number(i.isbig), Number(i.isCross), Number(i.isStatic), Number(i.ist)); }; }; } } }//package Core
Section 101
//RedBox (Core.RedBox) package Core { import flash.display.*; public class RedBox extends MovieClip { public var isStatic:Boolean;// = false public var isRed:Boolean;// = true public function RedBox(){ super(); } } }//package Core
Section 102
//RedRotated (Core.RedRotated) package Core { import flash.display.*; public class RedRotated extends MovieClip { public var isStatic:Boolean;// = false public var isRed:Boolean;// = true public function RedRotated(){ super(); } } }//package Core
Section 103
//Resourcen (Core.Resourcen) package Core { import flash.text.*; public class Resourcen { public var IMAGE_BUTTON_OK:Class; public var IMAGE_BUTTON_SETTINGS:Class; public var IMAGE_BULLET:Class; public var BUTTON_LEVEL_INACTIVE:Class; public var IMAGE_CLOSE_BUTTON:Class; public var SOUND_CLICK:Class; public var SOUND_MUSIC2:Class; public var SOUND_MUSIC4:Class; public var IMAGE_BLOB:Class; public var IMAGE_10:Class; public var SOUND_MUSIC3:Class; public var IMAGE_BACK2:Class; public var IMAGE_BACK3:Class; public var IMAGE_BACK4:Class; public var IMAGE_BUTTON_HELP:Class; public var IMAGE_HELPBACK:Class; public var BUTTON_LEVEL_ACTIVE:Class; public var IMAGE_LOGO:Class; public var SOUND_MUSIC:Class; public var IMAGE_BUTTON_PLAY:Class; public var IMAGE_MENU_BACK:Class; public var IMAGE_20:Class; public var MC_BLUE_BOX:Class; public var SOUND_MENUCOM:Class; public var IMAGE_BUTTON_NEXT:Class; public var IMAGE_LEVCOMP_DIALOG:Class; public var LEVEL_BACK:Class; public var IMAGE_HISCORES:Class; public var fln:Class; public var IMAGE_TUTORIAL:Class; public var LEVEL_PANE:Class; public var IMAGE_BACK:Class; public var SOUND_EXPLODE:Class; public var IMAGE_BUTTON_BACK:Class; public var textFmt:TextFormat; public var IMAGE_GAME_OVER:Class; private static var _instance:Resourcen; public function Resourcen(){ IMAGE_TUTORIAL = Resourcen_IMAGE_TUTORIAL; IMAGE_LEVCOMP_DIALOG = Resourcen_IMAGE_LEVCOMP_DIALOG; IMAGE_BUTTON_NEXT = Resourcen_IMAGE_BUTTON_NEXT; IMAGE_BLOB = Resourcen_IMAGE_BLOB; IMAGE_BACK = Resourcen_IMAGE_BACK; IMAGE_BACK2 = Resourcen_IMAGE_BACK2; IMAGE_BACK3 = Resourcen_IMAGE_BACK3; IMAGE_BACK4 = Resourcen_IMAGE_BACK4; MC_BLUE_BOX = Resourcen_MC_BLUE_BOX; SOUND_EXPLODE = Resourcen_SOUND_EXPLODE; SOUND_MENUCOM = Resourcen_SOUND_MENUCOM; SOUND_CLICK = Resourcen_SOUND_CLICK; BUTTON_LEVEL_ACTIVE = Resourcen_BUTTON_LEVEL_ACTIVE; BUTTON_LEVEL_INACTIVE = Resourcen_BUTTON_LEVEL_INACTIVE; LEVEL_BACK = Resourcen_LEVEL_BACK; LEVEL_PANE = Resourcen_LEVEL_PANE; IMAGE_MENU_BACK = Resourcen_IMAGE_MENU_BACK; IMAGE_HISCORES = Resourcen_IMAGE_HISCORES; IMAGE_HELPBACK = Resourcen_IMAGE_HELPBACK; IMAGE_10 = Resourcen_IMAGE_10; IMAGE_20 = Resourcen_IMAGE_20; SOUND_MUSIC = Resourcen_SOUND_MUSIC; SOUND_MUSIC2 = Resourcen_SOUND_MUSIC2; SOUND_MUSIC3 = Resourcen_SOUND_MUSIC3; SOUND_MUSIC4 = Resourcen_SOUND_MUSIC4; IMAGE_LOGO = Resourcen_IMAGE_LOGO; IMAGE_BUTTON_SETTINGS = Resourcen_IMAGE_BUTTON_SETTINGS; IMAGE_BUTTON_PLAY = Resourcen_IMAGE_BUTTON_PLAY; fln = Resourcen_fln; IMAGE_BUTTON_HELP = Resourcen_IMAGE_BUTTON_HELP; IMAGE_BUTTON_OK = Resourcen_IMAGE_BUTTON_OK; IMAGE_BUTTON_BACK = Resourcen_IMAGE_BUTTON_BACK; IMAGE_GAME_OVER = Resourcen_IMAGE_GAME_OVER; IMAGE_CLOSE_BUTTON = Resourcen_IMAGE_CLOSE_BUTTON; IMAGE_BULLET = Resourcen_IMAGE_BULLET; textFmt = new TextFormat("Tahoma", 13, 0xFFFFFF, "bold"); super(); } public static function get instance():Resourcen{ if (Resourcen._instance == null){ Resourcen._instance = new (Resourcen); }; return (Resourcen._instance); } } }//package Core
Section 104
//Resourcen_BUTTON_LEVEL_ACTIVE (Core.Resourcen_BUTTON_LEVEL_ACTIVE) package Core { import mx.core.*; public class Resourcen_BUTTON_LEVEL_ACTIVE extends BitmapAsset { } }//package Core
Section 105
//Resourcen_BUTTON_LEVEL_INACTIVE (Core.Resourcen_BUTTON_LEVEL_INACTIVE) package Core { import mx.core.*; public class Resourcen_BUTTON_LEVEL_INACTIVE extends BitmapAsset { } }//package Core
Section 106
//Resourcen_fln (Core.Resourcen_fln) package Core { import mx.core.*; public class Resourcen_fln extends BitmapAsset { } }//package Core
Section 107
//Resourcen_IMAGE_10 (Core.Resourcen_IMAGE_10) package Core { import mx.core.*; public class Resourcen_IMAGE_10 extends BitmapAsset { } }//package Core
Section 108
//Resourcen_IMAGE_20 (Core.Resourcen_IMAGE_20) package Core { import mx.core.*; public class Resourcen_IMAGE_20 extends BitmapAsset { } }//package Core
Section 109
//Resourcen_IMAGE_BACK (Core.Resourcen_IMAGE_BACK) package Core { import mx.core.*; public class Resourcen_IMAGE_BACK extends BitmapAsset { } }//package Core
Section 110
//Resourcen_IMAGE_BACK2 (Core.Resourcen_IMAGE_BACK2) package Core { import mx.core.*; public class Resourcen_IMAGE_BACK2 extends BitmapAsset { } }//package Core
Section 111
//Resourcen_IMAGE_BACK3 (Core.Resourcen_IMAGE_BACK3) package Core { import mx.core.*; public class Resourcen_IMAGE_BACK3 extends BitmapAsset { } }//package Core
Section 112
//Resourcen_IMAGE_BACK4 (Core.Resourcen_IMAGE_BACK4) package Core { import mx.core.*; public class Resourcen_IMAGE_BACK4 extends BitmapAsset { } }//package Core
Section 113
//Resourcen_IMAGE_BLOB (Core.Resourcen_IMAGE_BLOB) package Core { import mx.core.*; public class Resourcen_IMAGE_BLOB extends BitmapAsset { } }//package Core
Section 114
//Resourcen_IMAGE_BULLET (Core.Resourcen_IMAGE_BULLET) package Core { import mx.core.*; public class Resourcen_IMAGE_BULLET extends BitmapAsset { } }//package Core
Section 115
//Resourcen_IMAGE_BUTTON_BACK (Core.Resourcen_IMAGE_BUTTON_BACK) package Core { import mx.core.*; public class Resourcen_IMAGE_BUTTON_BACK extends BitmapAsset { } }//package Core
Section 116
//Resourcen_IMAGE_BUTTON_HELP (Core.Resourcen_IMAGE_BUTTON_HELP) package Core { import mx.core.*; public class Resourcen_IMAGE_BUTTON_HELP extends BitmapAsset { } }//package Core
Section 117
//Resourcen_IMAGE_BUTTON_NEXT (Core.Resourcen_IMAGE_BUTTON_NEXT) package Core { import mx.core.*; public class Resourcen_IMAGE_BUTTON_NEXT extends BitmapAsset { } }//package Core
Section 118
//Resourcen_IMAGE_BUTTON_OK (Core.Resourcen_IMAGE_BUTTON_OK) package Core { import mx.core.*; public class Resourcen_IMAGE_BUTTON_OK extends BitmapAsset { } }//package Core
Section 119
//Resourcen_IMAGE_BUTTON_PLAY (Core.Resourcen_IMAGE_BUTTON_PLAY) package Core { import mx.core.*; public class Resourcen_IMAGE_BUTTON_PLAY extends BitmapAsset { } }//package Core
Section 120
//Resourcen_IMAGE_BUTTON_SETTINGS (Core.Resourcen_IMAGE_BUTTON_SETTINGS) package Core { import mx.core.*; public class Resourcen_IMAGE_BUTTON_SETTINGS extends BitmapAsset { } }//package Core
Section 121
//Resourcen_IMAGE_CLOSE_BUTTON (Core.Resourcen_IMAGE_CLOSE_BUTTON) package Core { import mx.core.*; public class Resourcen_IMAGE_CLOSE_BUTTON extends BitmapAsset { } }//package Core
Section 122
//Resourcen_IMAGE_GAME_OVER (Core.Resourcen_IMAGE_GAME_OVER) package Core { import mx.core.*; public class Resourcen_IMAGE_GAME_OVER extends BitmapAsset { } }//package Core
Section 123
//Resourcen_IMAGE_HELPBACK (Core.Resourcen_IMAGE_HELPBACK) package Core { import mx.core.*; public class Resourcen_IMAGE_HELPBACK extends BitmapAsset { } }//package Core
Section 124
//Resourcen_IMAGE_HISCORES (Core.Resourcen_IMAGE_HISCORES) package Core { import mx.core.*; public class Resourcen_IMAGE_HISCORES extends BitmapAsset { } }//package Core
Section 125
//Resourcen_IMAGE_LEVCOMP_DIALOG (Core.Resourcen_IMAGE_LEVCOMP_DIALOG) package Core { import mx.core.*; public class Resourcen_IMAGE_LEVCOMP_DIALOG extends BitmapAsset { } }//package Core
Section 126
//Resourcen_IMAGE_LOGO (Core.Resourcen_IMAGE_LOGO) package Core { import mx.core.*; public class Resourcen_IMAGE_LOGO extends BitmapAsset { } }//package Core
Section 127
//Resourcen_IMAGE_MENU_BACK (Core.Resourcen_IMAGE_MENU_BACK) package Core { import mx.core.*; public class Resourcen_IMAGE_MENU_BACK extends BitmapAsset { } }//package Core
Section 128
//Resourcen_IMAGE_TUTORIAL (Core.Resourcen_IMAGE_TUTORIAL) package Core { import mx.core.*; public class Resourcen_IMAGE_TUTORIAL extends BitmapAsset { } }//package Core
Section 129
//Resourcen_LEVEL_BACK (Core.Resourcen_LEVEL_BACK) package Core { import mx.core.*; public class Resourcen_LEVEL_BACK extends BitmapAsset { } }//package Core
Section 130
//Resourcen_LEVEL_PANE (Core.Resourcen_LEVEL_PANE) package Core { import mx.core.*; public class Resourcen_LEVEL_PANE extends BitmapAsset { } }//package Core
Section 131
//Resourcen_MC_BLUE_BOX (Core.Resourcen_MC_BLUE_BOX) package Core { import mx.core.*; public class Resourcen_MC_BLUE_BOX extends SpriteAsset { } }//package Core
Section 132
//Resourcen_SOUND_CLICK (Core.Resourcen_SOUND_CLICK) package Core { import mx.core.*; public class Resourcen_SOUND_CLICK extends SoundAsset { } }//package Core
Section 133
//Resourcen_SOUND_EXPLODE (Core.Resourcen_SOUND_EXPLODE) package Core { import mx.core.*; public class Resourcen_SOUND_EXPLODE extends SoundAsset { } }//package Core
Section 134
//Resourcen_SOUND_MENUCOM (Core.Resourcen_SOUND_MENUCOM) package Core { import mx.core.*; public class Resourcen_SOUND_MENUCOM extends SoundAsset { } }//package Core
Section 135
//Resourcen_SOUND_MUSIC (Core.Resourcen_SOUND_MUSIC) package Core { import mx.core.*; public class Resourcen_SOUND_MUSIC extends SoundAsset { } }//package Core
Section 136
//Resourcen_SOUND_MUSIC2 (Core.Resourcen_SOUND_MUSIC2) package Core { import mx.core.*; public class Resourcen_SOUND_MUSIC2 extends SoundAsset { } }//package Core
Section 137
//Resourcen_SOUND_MUSIC3 (Core.Resourcen_SOUND_MUSIC3) package Core { import mx.core.*; public class Resourcen_SOUND_MUSIC3 extends SoundAsset { } }//package Core
Section 138
//Resourcen_SOUND_MUSIC4 (Core.Resourcen_SOUND_MUSIC4) package Core { import mx.core.*; public class Resourcen_SOUND_MUSIC4 extends SoundAsset { } }//package Core
Section 139
//Settings (Core.Settings) package Core { public class Settings { public const MAX_TOP:int = 400; public const MAX_WIDTH:int = 700; public const MAX_HEIGHT:int = 525; public const MIN_X:int = 0; public const MAX_X:int = 780; private static var _instance:Settings; public function Settings(){ super(); } public static function get instance():Settings{ if (Settings._instance == null){ Settings._instance = new (Settings); }; return (Settings._instance); } } }//package Core
Section 140
//Sparkler (Core.Sparkler) package Core { import flash.display.*; import org.flintparticles.common.initializers.*; import org.flintparticles.common.actions.*; import org.flintparticles.common.counters.*; import flash.geom.*; import org.flintparticles.twoD.zones.*; import org.flintparticles.twoD.emitters.*; import org.flintparticles.twoD.actions.*; import org.flintparticles.twoD.initializers.*; public class Sparkler extends Emitter2D { public function Sparkler(renderer:DisplayObject, color:uint, oradius:Number, iradius:Number, lifetime:Number, pcount:int=12){ super(); counter = new Blast(pcount); var bb:Glass = new Glass(); bb.width = (bb.height = 7); addInitializer(new SharedImage(bb)); addInitializer(new Velocity(new DiscZone(new Point(0, 0), 350, 200))); addInitializer(new Lifetime(0.3, 0.4)); addAction(new Age()); addAction(new Move()); addAction(new RotateToDirection()); addAction(new Fade()); } } }//package Core
Section 141
//StaticBox (Core.StaticBox) package Core { import flash.display.*; public class StaticBox extends MovieClip { public var isStatic:Boolean;// = true public var isRed:Boolean;// = false public function StaticBox(){ super(); } } }//package Core
Section 142
//TBoxB (Core.TBoxB) package Core { import flash.display.*; public class TBoxB extends MovieClip { public var isStatic:Boolean;// = false public var isRed:Boolean;// = false public function TBoxB(){ super(); } } }//package Core
Section 143
//TBoxBR (Core.TBoxBR) package Core { import flash.display.*; public class TBoxBR extends MovieClip { public var isStatic:Boolean;// = false public var isRed:Boolean;// = false public function TBoxBR(){ super(); } } }//package Core
Section 144
//TBoxR (Core.TBoxR) package Core { import flash.display.*; public class TBoxR extends MovieClip { public var isStatic:Boolean;// = false public var isRed:Boolean;// = true public function TBoxR(){ super(); } } }//package Core
Section 145
//TBoxRR (Core.TBoxRR) package Core { import flash.display.*; public class TBoxRR extends MovieClip { public var isStatic:Boolean;// = false public var isRed:Boolean;// = true public function TBoxRR(){ super(); } } }//package Core
Section 146
//World (framework.Physics.World) package framework.Physics { import framework.Widgets.*; import Box2D.Dynamics.*; import Core.Screens.*; import flash.display.*; import Box2D.Collision.Shapes.*; import Box2D.Collision.*; import Box2D.Common.Math.*; import Box2D.Dynamics.Joints.*; import org.flashdevelop.utils.*; public class World { public var bodyDef:b2BodyDef; public var circleDef:b2CircleDef; public var body:b2Body; public var movingBodies:Array; private var parent:Board; private var bodiesToRemove:Array; public var m_world:b2World; public var boxDef:b2PolygonDef; public var m_iterations:int;// = 15 private var mousePVec:b2Vec2; public var m_timeStep:Number; public var physScale:Number;// = 30 private var bodiesToRecreate:Array; public var ct:b2ContactListener;// = null public var m_items:Array; public var m_mouseJoint:b2MouseJoint; public var m_dbgSprite:Sprite; public function World(theParent:Board){ m_timeStep = (1 / physScale); bodiesToRecreate = new Array(); bodiesToRemove = new Array(); movingBodies = new Array(); m_items = new Array(); mousePVec = new b2Vec2(); super(); parent = theParent; initPhysics(); } public function createMouseJoint(body:b2Body, posx:Number, posy:Number):void{ var md:b2MouseJointDef; var mouseXWorldPhys:Number = (posx / physScale); var mouseYWorldPhys:Number = (posy / physScale); if (body){ md = new b2MouseJointDef(); md.body1 = m_world.GetGroundBody(); md.body2 = body; md.target.Set(mouseXWorldPhys, mouseYWorldPhys); md.maxForce = 1000; m_mouseJoint = (m_world.CreateJoint(md) as b2MouseJoint); body.WakeUp(); }; } public function GetParent():Widget{ return (parent); } public function GetBodyAtPos(posx:Number, posy:Number, includeStatic:Boolean=false):b2Body{ var tShape:b2Shape; var inside:Boolean; var real_x_mouse:Number = (posx / physScale); var real_y_mouse:Number = (posy / physScale); var mousePVec:b2Vec2 = new b2Vec2(); mousePVec.Set(real_x_mouse, real_y_mouse); var aabb:b2AABB = new b2AABB(); aabb.lowerBound.Set((real_x_mouse - 0.001), (real_y_mouse - 0.001)); aabb.upperBound.Set((real_x_mouse + 0.001), (real_y_mouse + 0.001)); var k_maxCount = 10; var shapes:Array = new Array(); var count:int = m_world.Query(aabb, shapes, k_maxCount); var body:b2Body; var i:int; while (i < count) { if ((((shapes[i].m_body.IsStatic() == false)) || (includeStatic))){ FlashConnect.trace(posx); tShape = (shapes[i] as b2Shape); inside = tShape.TestPoint(tShape.GetBody().GetXForm(), mousePVec); if (inside){ body = tShape.GetBody(); break; }; }; i++; }; return (body); } public function CreateKrest(px:Number, py:Number, isStatic:Boolean, mc:MovieClip):b2Body{ var bwidth:Number = 75; var bheight:Number = 75; bodyDef = new b2BodyDef(); bodyDef.position.x = (px / physScale); bodyDef.position.y = (py / physScale); if (mc){ bodyDef.userData = mc; bodyDef.userData.name = "krest"; bodyDef.userData.scaleX = -1; bodyDef.userData.width = ((physScale * 2) * GetRealWH(bwidth)); bodyDef.userData.height = ((physScale * 2) * GetRealWH(bheight)); }; body = m_world.CreateBody(bodyDef); body.CreateShape(getBoxDef(75, 20, isStatic, px, py)); body.CreateShape(getBoxDef(20, 75, isStatic, px, py)); body.SetMassFromShapes(); parent.addChild(bodyDef.userData); return (body); } public function CreateCircle(px:Number, py:Number, radius:Number, isStatic:Boolean, mc:MovieClip, contact:b2ContactListener=null):b2Body{ var b:b2Body; var cd:b2CircleDef = new b2CircleDef(); var bd:b2BodyDef = new b2BodyDef(); cd.radius = (radius / physScale); cd.density = 2; cd.restitution = 0.2; cd.friction = 0.5; bd.position.Set((px / physScale), (py / physScale)); bd.userData = mc; bd.userData.name = "bump"; bd.userData.width = 25; bd.userData.height = 33; b = m_world.CreateBody(bd); b.CreateShape(cd); b.SetMassFromShapes(); parent.addChild(mc); return (b); } public function recreateBoxAfterKanone(b:b2Body, bwidth:Number, bheight:Number, contact:b2ContactListener=null, isRotated:Boolean=false, deltaX:Number=64, deltaY:Number=64, isTramp:Boolean=false):b2Body{ bodyDef = new b2BodyDef(); if (!isRotated){ bodyDef.position.x = (b.GetPosition().x + (deltaX / physScale)); bodyDef.position.y = (b.GetPosition().y - (deltaY / physScale)); } else { bodyDef.position.x = (b.GetPosition().x + (4 / physScale)); bodyDef.position.y = (b.GetPosition().y - (deltaY / physScale)); }; boxDef = new b2PolygonDef(); boxDef.SetAsBox(GetRealWH(bwidth), GetRealWH(bheight)); if (contact != null){ m_world.SetContactListener(contact); }; boxDef.density = 1; boxDef.friction = 0.2; boxDef.restitution = 0.2; bodyDef.userData = b.GetUserData(); body = m_world.CreateBody(bodyDef); body.CreateShape(boxDef); body.SetMassFromShapes(); if (!isTramp){ if (bodyDef.userData.scaleX < 0){ bodyDef.userData.scaleX = -(bodyDef.userData.scaleX); }; if (isRotated){ bodyDef.userData.scaleX = (bodyDef.userData.scaleX * -1); }; }; parent.addChild(bodyDef.userData); return (body); } public function CreateBox(px:Number, py:Number, bwidth:Number, bheight:Number, isStatic:Boolean, mc:MovieClip, name:String="box", isRotated:Boolean=false):b2Body{ bodyDef = new b2BodyDef(); bodyDef.position.x = (px / physScale); bodyDef.position.y = (py / physScale); boxDef = new b2PolygonDef(); boxDef.SetAsBox(GetRealWH(bwidth), GetRealWH(bheight)); if (isStatic){ boxDef.density = 0; } else { boxDef.density = 1; boxDef.friction = 0.2; boxDef.restitution = 0.2; }; if (mc){ bodyDef.userData = mc; bodyDef.userData.name = name; bodyDef.userData.scaleX = -1; bodyDef.userData.width = ((physScale * 2) * GetRealWH(bwidth)); bodyDef.userData.height = ((physScale * 2) * GetRealWH(bheight)); }; body = m_world.CreateBody(bodyDef); body.CreateShape(boxDef); body.SetMassFromShapes(); if (((isRotated) && (mc))){ FlashConnect.trace("ROTATED"); }; parent.addChild(bodyDef.userData); return (body); } public function initPhysics():void{ var worldAABB:b2AABB = new b2AABB(); worldAABB.lowerBound.Set(-1000, -1500); worldAABB.upperBound.Set(1000, 1500); var gravity:b2Vec2 = new b2Vec2(0, 3); var doSleep:Boolean; m_world = new b2World(worldAABB, gravity, doSleep); m_dbgSprite = new Sprite(); } public function removeMouseJoint():void{ if (m_mouseJoint){ FlashConnect.trace("DESTROY MOUSE JOINT"); m_world.DestroyJoint(m_mouseJoint); m_mouseJoint = null; }; } public function CreateTR(px:Number, py:Number, isStatic:Boolean, mc:MovieClip):b2Body{ var bwidth:Number = 75; var bheight:Number = 75; bodyDef = new b2BodyDef(); bodyDef.position.x = (px / physScale); bodyDef.position.y = (py / physScale); if (mc){ bodyDef.userData = mc; bodyDef.userData.name = "t"; bodyDef.userData.scaleX = -1; bodyDef.userData.width = ((physScale * 2) * GetRealWH(bwidth)); bodyDef.userData.height = ((physScale * 2) * GetRealWH(bheight)); }; body = m_world.CreateBody(bodyDef); body.CreateShape(getBoxDefT(75, 20, isStatic, 0, ((75 / 2) - 10))); body.CreateShape(getBoxDefT(20, 75, isStatic, 0, 0)); body.SetMassFromShapes(); parent.addChild(bodyDef.userData); return (body); } public function SetDebugDraw():void{ parent.addChild(m_dbgSprite); var dbgDraw:b2DebugDraw = new b2DebugDraw(); dbgDraw.SetSprite(m_dbgSprite); dbgDraw.SetDrawScale(physScale); dbgDraw.SetFillAlpha(1); dbgDraw.SetLineThickness(13); dbgDraw.SetFlags((b2DebugDraw.e_shapeBit | b2DebugDraw.e_jointBit)); m_world.SetDebugDraw(dbgDraw); } public function updateMouseJoint():void{ var mouseXWorldPhys:Number; var mouseYWorldPhys:Number; var p2:b2Vec2; if (m_mouseJoint){ mouseXWorldPhys = (parent.mouseX / physScale); mouseYWorldPhys = (parent.mouseY / physScale); p2 = new b2Vec2(mouseXWorldPhys, mouseYWorldPhys); m_mouseJoint.SetTarget(p2); }; } private function recreateBodies():void{ var btd:b2Body; var newBody:b2Body; var i:int; while (i < bodiesToRecreate.length) { btd = bodiesToRecreate[i]; if (parent.getChildByName(btd.GetUserData().name) != null){ parent.removeChild(btd.GetUserData()); m_world.DestroyBody(btd); bodiesToRecreate.splice(i, 1); newBody = recreateBox(btd, 64, 64, ct); if (!newBody.IsStatic()){ if (newBody.GetUserData().direction == "Up"){ newBody.ApplyImpulse(new b2Vec2(0, -(newBody.GetUserData().pixelCount)), new b2Vec2(newBody.GetPosition().x, newBody.GetPosition().y)); } else { if (newBody.GetUserData().direction == "Down"){ newBody.ApplyImpulse(new b2Vec2(0, newBody.GetUserData().pixelCount), new b2Vec2(newBody.GetPosition().x, newBody.GetPosition().y)); } else { if (newBody.GetUserData().direction == "Left"){ newBody.ApplyImpulse(new b2Vec2(-(newBody.GetUserData().pixelCount), 0), new b2Vec2(newBody.GetPosition().x, newBody.GetPosition().y)); } else { if (newBody.GetUserData().direction == "Right"){ newBody.ApplyImpulse(new b2Vec2(newBody.GetUserData().pixelCount, 0), new b2Vec2(newBody.GetPosition().x, newBody.GetPosition().y)); }; }; }; }; movingBodies.push(newBody); }; }; i++; }; } public function GetBodyAtMouse(posx:Number, posy:Number, includeStatic:Boolean=false):b2Body{ var tShape:b2Shape; var inside:Boolean; var mouseXWorldPhys:Number = (posx / physScale); var mouseYWorldPhys:Number = (posy / physScale); mousePVec.Set(mouseXWorldPhys, mouseYWorldPhys); var aabb:b2AABB = new b2AABB(); aabb.lowerBound.Set((mouseXWorldPhys - 0.001), (mouseYWorldPhys - 0.001)); aabb.upperBound.Set((mouseXWorldPhys + 0.001), (mouseYWorldPhys + 0.001)); var k_maxCount = 10; var shapes:Array = new Array(); var count:int = m_world.Query(aabb, shapes, k_maxCount); var body:b2Body; var i:int; while (i < count) { if ((((shapes[i].GetBody().IsStatic() == false)) || (includeStatic))){ tShape = (shapes[i] as b2Shape); inside = tShape.TestPoint(tShape.GetBody().GetXForm(), mousePVec); if (inside){ body = tShape.GetBody(); break; }; }; i++; }; trace(body.GetUserData().name); return (body); } public function getBoxDefT(bwidth:Number, bheight:Number, isStatic:Boolean, px:Number, py:Number):b2PolygonDef{ var boxDef:b2PolygonDef = new b2PolygonDef(); boxDef.SetAsOrientedBox(GetRealWH(bwidth), GetRealWH(bheight), new b2Vec2(0, (py / physScale))); if (isStatic){ boxDef.density = 0; } else { boxDef.density = 1; boxDef.friction = 0.2; boxDef.restitution = 0.2; }; return (boxDef); } public function addVelocity(b:b2Body, velocityX:Number, velocityY:Number):void{ } public function getBoxDef(bwidth:Number, bheight:Number, isStatic:Boolean, px:Number, py:Number):b2PolygonDef{ var boxDef:b2PolygonDef = new b2PolygonDef(); boxDef.SetAsBox(GetRealWH(bwidth), GetRealWH(bheight)); if (isStatic){ boxDef.density = 0; } else { boxDef.density = 1; boxDef.friction = 0.2; boxDef.restitution = 0.2; }; return (boxDef); } public function recreateBody(b:b2Body):void{ if (isToRecreate(b)){ trace("recreate"); trace(b.GetUserData().name); bodiesToRecreate.push(b); }; } public function CreateT(px:Number, py:Number, isStatic:Boolean, mc:MovieClip):b2Body{ var bwidth:Number = 75; var bheight:Number = 75; bodyDef = new b2BodyDef(); bodyDef.position.x = (px / physScale); bodyDef.position.y = (py / physScale); if (mc){ bodyDef.userData = mc; bodyDef.userData.name = "t"; bodyDef.userData.scaleX = -1; bodyDef.userData.width = ((physScale * 2) * GetRealWH(bwidth)); bodyDef.userData.height = ((physScale * 2) * GetRealWH(bheight)); }; body = m_world.CreateBody(bodyDef); body.CreateShape(getBoxDefT(75, 20, isStatic, 0, ((-75 / 2) + 10))); body.CreateShape(getBoxDefT(20, 75, isStatic, 0, 0)); body.SetMassFromShapes(); parent.addChild(bodyDef.userData); return (body); } public function getBodyByName(name:String):b2Body{ var bb:b2Body = m_world.GetBodyList(); while (bb) { if ((((bb.GetUserData() is Sprite)) && ((bb.GetUserData().name == name)))){ return (bb); }; bb = bb.GetNext(); }; return (null); } public function GetRealWH(Num:Number):Number{ return (((Num / physScale) / 2)); } public function removeBody(b:b2Body):void{ trace("delet"); if (isToDelete(b)){ trace("delete"); bodiesToRemove.push(b); }; } public function clear():void{ var b:b2Body; var node:b2Body = m_world.GetBodyList(); while (node) { b = node; node = node.GetNext(); if ((b.GetUserData() is Sprite)){ parent.removeChild(b.GetUserData()); }; m_world.DestroyBody(b); }; m_dbgSprite.graphics.clear(); } public function isToDelete(b:b2Body):Boolean{ var btd:b2Body; trace("not to recreate"); var i:int; while (i < bodiesToRemove.length) { btd = bodiesToRemove[i]; trace(btd.GetUserData().name); if (btd.GetUserData().name == b.GetUserData().name){ return (false); }; i++; }; return (true); } private function removeBodies():void{ var btd:b2Body; var i:int; while (i < bodiesToRemove.length) { btd = bodiesToRemove[i]; if (parent.getChildByName(btd.GetUserData().name) != null){ parent.removeChild(btd.GetUserData()); m_world.DestroyBody(btd); bodiesToRemove.splice(i, 1); }; i++; }; } public function checkImpulse():void{ var b:b2Body; var i:int; while (i < movingBodies.length) { b = movingBodies[i]; if (b.GetLinearVelocity().y >= 0){ trace("STOP!!!!!!!!!!!!!!!!!"); recreateBody(b); movingBodies.splice(i, 1); }; i++; }; } public function recreateBox(b:b2Body, bwidth:Number, bheight:Number, contact:b2ContactListener=null, isRotated:Boolean=false):b2Body{ bodyDef = new b2BodyDef(); bodyDef.position = b.GetPosition(); boxDef = new b2PolygonDef(); boxDef.SetAsBox(GetRealWH(bwidth), GetRealWH(bheight)); if (contact != null){ m_world.SetContactListener(contact); }; if (b.IsStatic()){ boxDef.density = 1; boxDef.friction = 0.2; boxDef.restitution = 0.2; } else { boxDef.density = 0; }; bodyDef.userData = b.GetUserData(); body = m_world.CreateBody(bodyDef); body.CreateShape(boxDef); body.SetMassFromShapes(); if (isRotated){ bodyDef.userData.scaleX = (bodyDef.userData.scaleX * -1); }; parent.addChild(bodyDef.userData); return (body); } public function isToRecreate(b:b2Body):Boolean{ var btd:b2Body; var i:int; while (i < bodiesToRecreate.length) { btd = bodiesToRecreate[i]; if (btd.GetUserData().name == b.GetUserData().name){ return (false); }; i++; }; return (true); } private function drawUserData():void{ var bb:b2Body = m_world.GetBodyList(); while (bb) { if ((bb.GetUserData() is Sprite)){ bb.GetUserData().x = (bb.GetPosition().x * physScale); bb.GetUserData().y = (bb.GetPosition().y * physScale); bb.GetUserData().rotation = (bb.GetAngle() * (180 / Math.PI)); }; if ((((bb.GetPosition().y > (576 / physScale))) && ((bb.GetUserData() is Sprite)))){ parent.removeChild((bb.GetUserData() as Sprite)); m_world.DestroyBody(bb); }; bb = bb.GetNext(); }; } public function updateUserData():void{ m_world.Step((1 / physScale), m_iterations, 2); removeBodies(); drawUserData(); } } }//package framework.Physics
Section 147
//Renderer2D (framework.Rendering2D.Renderer2D) package framework.Rendering2D { import flash.display.*; import flash.geom.*; public class Renderer2D extends Sprite { private var _bitmaps:Array; private var _bitmap:Bitmap; private var _smoothing:Boolean; private var _canvas:Rectangle; private var _bitmapData:BitmapData; public function Renderer2D(canvas:Rectangle, smooting:Boolean){ super(); _canvas = canvas; createBitmap(); _smoothing = smooting; _bitmaps = new Array(); createBitmap(); } public function draw(object, sourceRect:Rectangle=null, destPoint:Point=null):void{ _bitmapData.copyPixels(object, sourceRect, destPoint); } public function get Bitmaps():Array{ return (_bitmaps); } public function set Bitmaps(bitmaps:Array):void{ _bitmaps = bitmaps; } private function createBitmap():void{ if (!_canvas){ return; }; if (_bitmap){ removeChild(_bitmap); }; _bitmap = new Bitmap(null, "auto", _smoothing); _bitmapData = new BitmapData(_canvas.width, _canvas.height, true, 0); _bitmap.bitmapData = _bitmapData; addChild(_bitmap); _bitmap.x = _canvas.x; _bitmap.y = _canvas.y; } public function render():void{ _bitmapData.lock(); var i:int; while (i < _bitmaps.length) { draw(_bitmaps[i]); i++; }; _bitmapData.unlock(); } public function addBitmap(bitmap:BitmapData):void{ _bitmaps.push(bitmap); } } }//package framework.Rendering2D
Section 148
//IWidget (framework.Widgets.IWidget) package framework.Widgets { import flash.events.*; public interface IWidget extends IEventDispatcher { function onCollideDetected(_arg1:int, _arg2:Number, _arg3:Number):void; function get currentScreen():IWidget; function get parentScreen():IWidget; function update(:Number):void; function setWidget(:Class):void; function dispose():void; function onCollide(_arg1:Number, _arg2:Number):void; } }//package framework.Widgets
Section 149
//Root (framework.Widgets.Root) package framework.Widgets { import flash.display.*; public class Root extends Sprite { public function Root(){ super(); } } }//package framework.Widgets
Section 150
//Widget (framework.Widgets.Widget) package framework.Widgets { import flash.display.*; public class Widget extends MovieClip implements IWidget { public function Widget(){ super(); } public function onCollideDetected(cType:int, x_:Number, y_:Number):void{ } public function update(nTime:Number):void{ } public function get currentScreen():IWidget{ return (null); } public function setWidget(widget:Class):void{ } public function dispose():void{ } public function get parentScreen():IWidget{ return (null); } public function onCollide(x_:Number, y_:Number):void{ } } }//package framework.Widgets
Section 151
//WidgetManager (framework.Widgets.WidgetManager) package framework.Widgets { public class WidgetManager { private var parent:Root; private var widgets:Array; private static var _instance:WidgetManager; public function WidgetManager(){ super(); widgets = new Array(); } public function addWidget(w:Widget):void{ widgets.push(w); parent.addChild(w); } public function removeWidget(w:Widget):void{ var w1:Widget; parent.removeChild(w); var i:int; while (i < widgets.length) { w1 = widgets[i]; if (w1 == w){ widgets.splice(i, 1); break; }; i++; }; } public function update(nTime:Number):void{ var w:Widget; var i:int; while (i < widgets.length) { w = widgets[i]; w.update(nTime); i++; }; } public function SetParent(r:Root):void{ parent = r; } public static function get instance():WidgetManager{ if (WidgetManager._instance == null){ WidgetManager._instance = new (WidgetManager); }; return (WidgetManager._instance); } } }//package framework.Widgets
Section 152
//MochiAd (mochi.as3.MochiAd) package mochi.as3 { import flash.events.*; import flash.display.*; import flash.net.*; import flash.utils.*; import flash.system.*; public class MochiAd { public function MochiAd(){ super(); } public static function getVersion():String{ return ("3.0 as3"); } public static function showClickAwayAd(options:Object):void{ var clip:Object; var mc:MovieClip; var chk:MovieClip; var options = options; var DEFAULTS:Object = {ad_timeout:2000, regpt:"o", method:"showClickAwayAd", res:"300x250", no_bg:true, ad_started:function ():void{ }, ad_finished:function ():void{ }, ad_loaded:function (width:Number, height:Number):void{ }, ad_failed:function ():void{ trace("[MochiAd] Couldn't load an ad, make sure your game's local security sandbox is configured for Access Network Only and that you are not using ad blocking software"); }, ad_skipped:function ():void{ }}; options = MochiAd._parseOptions(options, DEFAULTS); clip = options.clip; var ad_timeout:Number = options.ad_timeout; delete options.ad_timeout; if (!MochiAd.load(options)){ options.ad_failed(); options.ad_finished(); return; }; options.ad_started(); mc = clip._mochiad; mc["onUnload"] = function ():void{ MochiAd._cleanup(mc); options.ad_finished(); }; var wh:Array = MochiAd._getRes(options, clip); var w:Number = wh[0]; var h:Number = wh[1]; mc.x = (w * 0.5); mc.y = (h * 0.5); chk = createEmptyMovieClip(mc, "_mochiad_wait", 3); chk.ad_timeout = ad_timeout; chk.started = getTimer(); chk.showing = false; mc.unloadAd = function ():void{ MochiAd.unload(clip); }; mc.adLoaded = options.ad_loaded; mc.adSkipped = options.ad_skipped; mc.rpc = function (callbackID:Number, arg:Object):void{ MochiAd.rpc(clip, callbackID, arg); }; var sendHostProgress:Boolean; mc.regContLC = function (lc_name:String):void{ mc._containerLCName = lc_name; }; chk["onEnterFrame"] = function ():void{ var total:Number; if (!this.parent){ delete this.onEnterFrame; return; }; var ad_clip:Object = this.parent._mochiad_ctr; var elapsed:Number = (getTimer() - this.started); var finished:Boolean; if (!chk.showing){ total = this.parent._mochiad_ctr.contentLoaderInfo.bytesTotal; if (total > 0){ chk.showing = true; finished = true; chk.started = getTimer(); } else { if (elapsed > chk.ad_timeout){ options.ad_failed(); finished = true; }; }; }; if (this.root == null){ finished = true; }; if (finished){ delete this.onEnterFrame; }; }; doOnEnterFrame(chk); } public static function _isNetworkAvailable():Boolean{ return (!((Security.sandboxType == "localWithFile"))); } public static function _allowDomains(server:String):String{ var hostname:String = server.split("/")[2].split(":")[0]; if (Security.sandboxType == "application"){ return (hostname); }; Security.allowDomain("*"); Security.allowDomain(hostname); Security.allowInsecureDomain("*"); Security.allowInsecureDomain(hostname); return (hostname); } public static function unload(clip:Object):Boolean{ if (((clip.clip) && (clip.clip._mochiad))){ clip = clip.clip; }; if (clip.origFrameRate != undefined){ clip.stage.frameRate = clip.origFrameRate; }; if (!clip._mochiad){ return (false); }; if (clip._mochiad._containerLCName != undefined){ clip._mochiad.lc.send(clip._mochiad._containerLCName, "notify", {id:"unload"}); }; if (clip._mochiad.onUnload){ clip._mochiad.onUnload(); }; delete clip._mochiad_loaded; delete clip._mochiad; return (true); } public static function showInterLevelAd(options:Object):void{ var clip:Object; var mc:MovieClip; var chk:MovieClip; var options = options; var DEFAULTS:Object = {ad_timeout:2000, fadeout_time:250, regpt:"o", method:"showTimedAd", ad_started:function ():void{ if ((this.clip is MovieClip)){ this.clip.stop(); } else { throw (new Error("MochiAd.showInterLevelAd requires a clip that is a MovieClip or is an instance of a class that extends MovieClip. If your clip is a Sprite, then you must provide custom ad_started and ad_finished handlers.")); }; }, ad_finished:function ():void{ if ((this.clip is MovieClip)){ this.clip.play(); } else { throw (new Error("MochiAd.showInterLevelAd requires a clip that is a MovieClip or is an instance of a class that extends MovieClip. If your clip is a Sprite, then you must provide custom ad_started and ad_finished handlers.")); }; }, ad_loaded:function (width:Number, height:Number):void{ }, ad_failed:function ():void{ trace("[MochiAd] Couldn't load an ad, make sure your game's local security sandbox is configured for Access Network Only and that you are not using ad blocking software"); }, ad_skipped:function ():void{ }}; options = MochiAd._parseOptions(options, DEFAULTS); clip = options.clip; var ad_msec:Number = 11000; var ad_timeout:Number = options.ad_timeout; delete options.ad_timeout; var fadeout_time:Number = options.fadeout_time; delete options.fadeout_time; if (!MochiAd.load(options)){ options.ad_failed(); options.ad_finished(); return; }; options.ad_started(); mc = clip._mochiad; mc["onUnload"] = function ():void{ MochiAd._cleanup(mc); options.ad_finished(); }; var wh:Array = MochiAd._getRes(options, clip); var w:Number = wh[0]; var h:Number = wh[1]; mc.x = (w * 0.5); mc.y = (h * 0.5); chk = createEmptyMovieClip(mc, "_mochiad_wait", 3); chk.ad_msec = ad_msec; chk.ad_timeout = ad_timeout; chk.started = getTimer(); chk.showing = false; chk.fadeout_time = fadeout_time; chk.fadeFunction = function ():void{ if (!this.parent){ delete this.onEnterFrame; delete this.fadeFunction; return; }; var p:Number = (100 * (1 - ((getTimer() - this.fadeout_start) / this.fadeout_time))); if (p > 0){ this.parent.alpha = (p * 0.01); } else { MochiAd.unload(clip); delete this["onEnterFrame"]; }; }; mc.unloadAd = function ():void{ MochiAd.unload(clip); }; mc.adLoaded = options.ad_loaded; mc.adSkipped = options.ad_skipped; mc.adjustProgress = function (msec:Number):void{ var _chk:Object = mc._mochiad_wait; _chk.server_control = true; _chk.showing = true; _chk.started = getTimer(); _chk.ad_msec = (msec - 250); }; mc.rpc = function (callbackID:Number, arg:Object):void{ MochiAd.rpc(clip, callbackID, arg); }; chk["onEnterFrame"] = function ():void{ var total:Number; if (!this.parent){ delete this.onEnterFrame; delete this.fadeFunction; return; }; var ad_clip:Object = this.parent._mochiad_ctr; var elapsed:Number = (getTimer() - this.started); var finished:Boolean; if (!chk.showing){ total = this.parent._mochiad_ctr.contentLoaderInfo.bytesTotal; if (total > 0){ chk.showing = true; chk.started = getTimer(); MochiAd.adShowing(clip); } else { if (elapsed > chk.ad_timeout){ options.ad_failed(); finished = true; }; }; }; if (elapsed > chk.ad_msec){ finished = true; }; if (finished){ if (this.server_control){ delete this.onEnterFrame; } else { this.fadeout_start = getTimer(); this.onEnterFrame = this.fadeFunction; }; }; }; doOnEnterFrame(chk); } public static function _parseOptions(options:Object, defaults:Object):Object{ var k:String; var pairs:Array; var i:Number; var kv:Array; var optcopy:Object = {}; for (k in defaults) { optcopy[k] = defaults[k]; }; if (options){ for (k in options) { optcopy[k] = options[k]; }; }; if (optcopy.clip == undefined){ throw (new Error("MochiAd is missing the 'clip' parameter. This should be a MovieClip, Sprite or an instance of a class that extends MovieClip or Sprite.")); }; options = optcopy.clip.loaderInfo.parameters.mochiad_options; if (options){ pairs = options.split("&"); i = 0; while (i < pairs.length) { kv = pairs[i].split("="); optcopy[unescape(kv[0])] = unescape(kv[1]); i++; }; }; if (optcopy.id == "test"){ trace("[MochiAd] WARNING: Using the MochiAds test identifier, make sure to use the code from your dashboard, not this example!"); }; return (optcopy); } public static function _cleanup(mc:Object):void{ var k:String; var lc:LocalConnection; var f:Function; var mc = mc; if (("lc" in mc)){ lc = mc.lc; f = function ():void{ lc.client = null; lc.close(); //unresolved jump var _slot1 = e; }; setTimeout(f, 0); }; var idx:Number = DisplayObjectContainer(mc).numChildren; while (idx > 0) { idx = (idx - 1); DisplayObjectContainer(mc).removeChildAt(idx); }; for (k in mc) { delete mc[k]; }; } public static function load(options:Object):MovieClip{ var clip:Object; var k:String; var server:String; var hostname:String; var lc:LocalConnection; var name:String; var loader:Loader; var g:Function; var req:URLRequest; var v:Object; var options = options; var DEFAULTS:Object = {server:"http://x.mochiads.com/srv/1/", method:"load", depth:10333, id:"_UNKNOWN_"}; options = MochiAd._parseOptions(options, DEFAULTS); options.swfv = 9; options.mav = MochiAd.getVersion(); clip = options.clip; if (!MochiAd._isNetworkAvailable()){ return (null); }; if (clip._mochiad_loaded){ return (null); }; //unresolved jump var _slot1 = e; throw (new Error("MochiAd requires a clip that is an instance of a dynamic class. If your class extends Sprite or MovieClip, you must make it dynamic.")); var depth:Number = options.depth; delete options.depth; var mc:MovieClip = createEmptyMovieClip(clip, "_mochiad", depth); var wh:Array = MochiAd._getRes(options, clip); options.res = ((wh[0] + "x") + wh[1]); options.server = (options.server + options.id); delete options.id; clip._mochiad_loaded = true; if (clip.loaderInfo.loaderURL.indexOf("http") == 0){ options.as3_swf = clip.loaderInfo.loaderURL; } else { trace("[MochiAd] NOTE: Security Sandbox Violation errors below are normal"); }; var lv:URLVariables = new URLVariables(); for (k in options) { v = options[k]; if (!(v is Function)){ lv[k] = v; }; }; server = lv.server; delete lv.server; hostname = _allowDomains(server); lc = new LocalConnection(); lc.client = mc; name = ["", Math.floor(new Date().getTime()), Math.floor((Math.random() * 999999))].join("_"); lc.allowDomain("*", "localhost"); lc.allowInsecureDomain("*", "localhost"); lc.connect(name); mc.lc = lc; mc.lcName = name; lv.lc = name; lv.st = getTimer(); loader = new Loader(); g = function (ev:Object):void{ ev.target.removeEventListener(ev.type, arguments.callee); MochiAd.unload(clip); }; loader.contentLoaderInfo.addEventListener(Event.UNLOAD, g); req = new URLRequest(((server + ".swf?cacheBust=") + new Date().getTime())); req.contentType = "application/x-www-form-urlencoded"; req.method = URLRequestMethod.POST; req.data = lv; loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, function (io:IOErrorEvent):void{ trace("[MochiAds] Blocked URL"); }); loader.load(req); mc.addChild(loader); mc._mochiad_ctr = loader; return (mc); } public static function runMethod(base:Object, methodName:String, argsArray:Array):Object{ var nameArray:Array = methodName.split("."); var i:Number = 0; while (i < (nameArray.length - 1)) { if ((((base[nameArray[i]] == undefined)) || ((base[nameArray[i]] == null)))){ return (undefined); }; base = base[nameArray[i]]; i++; }; if (typeof(base[nameArray[i]]) == "function"){ return (base[nameArray[i]].apply(base, argsArray)); }; return (undefined); } public static function createEmptyMovieClip(parent:Object, name:String, depth:Number):MovieClip{ var mc:MovieClip = new MovieClip(); if (((false) && (depth))){ parent.addChildAt(mc, depth); } else { parent.addChild(mc); }; parent[name] = mc; mc["_name"] = name; return (mc); } public static function _getRes(options:Object, clip:Object):Array{ var xy:Array; var b:Object = clip.getBounds(clip.root); var w:Number = 0; var h:Number = 0; if (typeof(options.res) != "undefined"){ xy = options.res.split("x"); w = parseFloat(xy[0]); h = parseFloat(xy[1]); } else { w = (b.xMax - b.xMin); h = (b.yMax - b.yMin); }; if ((((w == 0)) || ((h == 0)))){ w = clip.stage.stageWidth; h = clip.stage.stageHeight; }; return ([w, h]); } public static function adShowing(mc:Object):void{ mc.origFrameRate = mc.stage.frameRate; mc.stage.frameRate = 30; } public static function getValue(base:Object, objectName:String):Object{ var nameArray:Array = objectName.split("."); var i:Number = 0; while (i < (nameArray.length - 1)) { if ((((base[nameArray[i]] == undefined)) || ((base[nameArray[i]] == null)))){ return (undefined); }; base = base[nameArray[i]]; i++; }; return (base[nameArray[i]]); } public static function rpc(clip:Object, callbackID:Number, arg:Object):void{ var _local4:Object; var _local5:Object; switch (arg.id){ case "setValue": MochiAd.setValue(clip, arg.objectName, arg.value); break; case "getValue": _local4 = MochiAd.getValue(clip, arg.objectName); clip._mochiad.lc.send(clip._mochiad._containerLCName, "rpcResult", callbackID, _local4); break; case "runMethod": _local5 = MochiAd.runMethod(clip, arg.method, arg.args); clip._mochiad.lc.send(clip._mochiad._containerLCName, "rpcResult", callbackID, _local5); break; default: trace(("[mochiads rpc] unknown rpc id: " + arg.id)); }; } public static function setValue(base:Object, objectName:String, value:Object):void{ var nameArray:Array = objectName.split("."); var i:Number = 0; while (i < (nameArray.length - 1)) { if ((((base[nameArray[i]] == undefined)) || ((base[nameArray[i]] == null)))){ return; }; base = base[nameArray[i]]; i++; }; base[nameArray[i]] = value; } public static function showPreGameAd(options:Object):void{ var clip:Object; var mc:MovieClip; var chk:MovieClip; var complete:Boolean; var unloaded:Boolean; var sendHostProgress:Boolean; var fn:Function; var r:MovieClip; var options = options; var DEFAULTS:Object = {ad_timeout:3000, fadeout_time:250, regpt:"o", method:"showPreloaderAd", color:0xFF8A00, background:16777161, outline:13994812, no_progress_bar:false, ad_started:function ():void{ if ((this.clip is MovieClip)){ this.clip.stop(); } else { throw (new Error("MochiAd.showPreGameAd requires a clip that is a MovieClip or is an instance of a class that extends MovieClip. If your clip is a Sprite, then you must provide custom ad_started and ad_finished handlers.")); }; }, ad_finished:function ():void{ if ((this.clip is MovieClip)){ this.clip.play(); } else { throw (new Error("MochiAd.showPreGameAd requires a clip that is a MovieClip or is an instance of a class that extends MovieClip. If your clip is a Sprite, then you must provide custom ad_started and ad_finished handlers.")); }; }, ad_loaded:function (width:Number, height:Number):void{ }, ad_failed:function ():void{ trace("[MochiAd] Couldn't load an ad, make sure your game's local security sandbox is configured for Access Network Only and that you are not using ad blocking software"); }, ad_skipped:function ():void{ }, ad_progress:function (percent:Number):void{ }}; options = MochiAd._parseOptions(options, DEFAULTS); if ("c862232051e0a94e1c3609b3916ddb17".substr(0) == "dfeada81ac97cde83665f81c12da7def"){ options.ad_started(); fn = function ():void{ options.ad_finished(); }; setTimeout(fn, 100); return; }; clip = options.clip; var ad_msec:Number = 11000; var ad_timeout:Number = options.ad_timeout; delete options.ad_timeout; var fadeout_time:Number = options.fadeout_time; delete options.fadeout_time; if (!MochiAd.load(options)){ options.ad_failed(); options.ad_finished(); return; }; options.ad_started(); mc = clip._mochiad; mc["onUnload"] = function ():void{ MochiAd._cleanup(mc); var fn:Function = function ():void{ options.ad_finished(); }; setTimeout(fn, 100); }; var wh:Array = MochiAd._getRes(options, clip); var w:Number = wh[0]; var h:Number = wh[1]; mc.x = (w * 0.5); mc.y = (h * 0.5); chk = createEmptyMovieClip(mc, "_mochiad_wait", 3); chk.x = (w * -0.5); chk.y = (h * -0.5); var bar:MovieClip = createEmptyMovieClip(chk, "_mochiad_bar", 4); if (options.no_progress_bar){ bar.visible = false; delete options.no_progress_bar; } else { bar.x = 10; bar.y = (h - 20); }; var bar_color:Number = options.color; delete options.color; var bar_background:Number = options.background; delete options.background; var bar_outline:Number = options.outline; delete options.outline; var backing_mc:MovieClip = createEmptyMovieClip(bar, "_outline", 1); var backing:Object = backing_mc.graphics; backing.beginFill(bar_background); backing.moveTo(0, 0); backing.lineTo((w - 20), 0); backing.lineTo((w - 20), 10); backing.lineTo(0, 10); backing.lineTo(0, 0); backing.endFill(); var inside_mc:MovieClip = createEmptyMovieClip(bar, "_inside", 2); var inside:Object = inside_mc.graphics; inside.beginFill(bar_color); inside.moveTo(0, 0); inside.lineTo((w - 20), 0); inside.lineTo((w - 20), 10); inside.lineTo(0, 10); inside.lineTo(0, 0); inside.endFill(); inside_mc.scaleX = 0; var outline_mc:MovieClip = createEmptyMovieClip(bar, "_outline", 3); var outline:Object = outline_mc.graphics; outline.lineStyle(0, bar_outline, 100); outline.moveTo(0, 0); outline.lineTo((w - 20), 0); outline.lineTo((w - 20), 10); outline.lineTo(0, 10); outline.lineTo(0, 0); chk.ad_msec = ad_msec; chk.ad_timeout = ad_timeout; chk.started = getTimer(); chk.showing = false; chk.last_pcnt = 0; chk.fadeout_time = fadeout_time; chk.fadeFunction = function ():void{ var p:Number = (100 * (1 - ((getTimer() - this.fadeout_start) / this.fadeout_time))); if (p > 0){ this.parent.alpha = (p * 0.01); } else { MochiAd.unload(clip); delete this["onEnterFrame"]; }; }; complete = false; unloaded = false; var f:Function = function (ev:Event):void{ ev.target.removeEventListener(ev.type, arguments.callee); complete = true; if (unloaded){ MochiAd.unload(clip); }; }; clip.loaderInfo.addEventListener(Event.COMPLETE, f); if ((clip.root is MovieClip)){ r = (clip.root as MovieClip); if (r.framesLoaded >= r.totalFrames){ complete = true; }; }; mc.unloadAd = function ():void{ unloaded = true; if (complete){ MochiAd.unload(clip); }; }; mc.adLoaded = options.ad_loaded; mc.adSkipped = options.ad_skipped; mc.adjustProgress = function (msec:Number):void{ var _chk:Object = mc._mochiad_wait; _chk.server_control = true; _chk.showing = true; _chk.started = getTimer(); _chk.ad_msec = msec; }; mc.rpc = function (callbackID:Number, arg:Object):void{ MochiAd.rpc(clip, callbackID, arg); }; mc.rpcTestFn = function (s:String):Object{ trace(("[MOCHIAD rpcTestFn] " + s)); return (s); }; mc.regContLC = function (lc_name:String):void{ mc._containerLCName = lc_name; }; sendHostProgress = false; mc.sendHostLoadProgress = function (lc_name:String):void{ sendHostProgress = true; }; chk["onEnterFrame"] = function ():void{ var total:Number; if (((!(this.parent)) || (!(this.parent.parent)))){ delete this["onEnterFrame"]; return; }; var _clip:Object = this.parent.parent.root; var ad_clip:Object = this.parent._mochiad_ctr; var elapsed:Number = (getTimer() - this.started); var finished:Boolean; var clip_total:Number = _clip.loaderInfo.bytesTotal; var clip_loaded:Number = _clip.loaderInfo.bytesLoaded; if (complete){ clip_loaded = Math.max(1, clip_loaded); clip_total = clip_loaded; }; var clip_pcnt:Number = ((100 * clip_loaded) / clip_total); var ad_pcnt:Number = ((100 * elapsed) / chk.ad_msec); var _inside:Object = this._mochiad_bar._inside; var pcnt:Number = Math.min(100, Math.min(((clip_pcnt) || (0)), ad_pcnt)); pcnt = Math.max(this.last_pcnt, pcnt); this.last_pcnt = pcnt; _inside.scaleX = (pcnt * 0.01); options.ad_progress(pcnt); if (sendHostProgress){ clip._mochiad.lc.send(clip._mochiad._containerLCName, "notify", {id:"hostLoadPcnt", pcnt:clip_pcnt}); if (clip_pcnt == 100){ sendHostProgress = false; }; }; if (!chk.showing){ total = this.parent._mochiad_ctr.contentLoaderInfo.bytesTotal; if (total > 0){ chk.showing = true; chk.started = getTimer(); MochiAd.adShowing(clip); } else { if ((((elapsed > chk.ad_timeout)) && ((clip_pcnt == 100)))){ options.ad_failed(); finished = true; }; }; }; if (elapsed > chk.ad_msec){ finished = true; }; if (((complete) && (finished))){ if (this.server_control){ delete this.onEnterFrame; } else { this.fadeout_start = getTimer(); this.onEnterFrame = chk.fadeFunction; }; }; }; doOnEnterFrame(chk); } public static function showPreloaderAd(options:Object):void{ trace("[MochiAd] DEPRECATED: showPreloaderAd was renamed to showPreGameAd in 2.0"); MochiAd.showPreGameAd(options); } public static function showTimedAd(options:Object):void{ trace("[MochiAd] DEPRECATED: showTimedAd was renamed to showInterLevelAd in 2.0"); MochiAd.showInterLevelAd(options); } public static function doOnEnterFrame(mc:MovieClip):void{ var mc = mc; var f:Function = function (ev:Object):void{ if (((("onEnterFrame" in mc)) && (mc.onEnterFrame))){ mc.onEnterFrame(); } else { ev.target.removeEventListener(ev.type, arguments.callee); }; }; mc.addEventListener(Event.ENTER_FRAME, f); } } }//package mochi.as3
Section 153
//MochiDigits (mochi.as3.MochiDigits) package mochi.as3 { public final class MochiDigits { private var Sibling:MochiDigits; private var Fragment:Number; private var Encoder:Number; public function MochiDigits(digit:Number=0, index:uint=0):void{ super(); Encoder = 0; setValue(digit, index); } public function reencode():void{ var newEncode:uint = int((2147483647 * Math.random())); Fragment = (Fragment ^ (newEncode ^ Encoder)); Encoder = newEncode; } public function set value(v:Number):void{ setValue(v); } public function toString():String{ var s:String = String.fromCharCode((Fragment ^ Encoder)); if (Sibling != null){ s = (s + Sibling.toString()); }; return (s); } public function setValue(digit:Number=0, index:uint=0):void{ var s:String = digit.toString(); var _temp1 = index; index = (index + 1); Fragment = (s.charCodeAt(_temp1) ^ Encoder); if (index < s.length){ Sibling = new MochiDigits(digit, index); } else { Sibling = null; }; reencode(); } public function get value():Number{ return (Number(this.toString())); } public function addValue(inc:Number):void{ value = (value + inc); } } }//package mochi.as3
Section 154
//MochiScores (mochi.as3.MochiScores) package mochi.as3 { import flash.display.*; import flash.text.*; public class MochiScores { private static var boardID:String; public static var onErrorHandler:Object; public static var onCloseHandler:Object; public function MochiScores(){ super(); } public static function showLeaderboard(options:Object=null):void{ var n:Number; var options = options; if (options != null){ if (options.clip != null){ if ((options.clip is Sprite)){ MochiServices.setContainer(options.clip); }; delete options.clip; } else { MochiServices.setContainer(); }; MochiServices.stayOnTop(); if (options.name != null){ if ((options.name is TextField)){ if (options.name.text.length > 0){ options.name = options.name.text; }; }; }; if (options.score != null){ if ((options.score is TextField)){ if (options.score.text.length > 0){ options.score = options.score.text; }; } else { if ((options.score is MochiDigits)){ options.score = options.score.value; }; }; n = Number(options.score); if (isNaN(n)){ trace((("ERROR: Submitted score '" + options.score) + "' will be rejected, score is 'Not a Number'")); } else { if ((((n == Number.NEGATIVE_INFINITY)) || ((n == Number.POSITIVE_INFINITY)))){ trace((("ERROR: Submitted score '" + options.score) + "' will be rejected, score is an infinite")); } else { if (Math.floor(n) != n){ trace((("WARNING: Submitted score '" + options.score) + "' will be truncated")); }; options.score = n; }; }; }; if (options.onDisplay != null){ options.onDisplay(); } else { if (MochiServices.clip != null){ if ((MochiServices.clip is MovieClip)){ MochiServices.clip.stop(); } else { trace("Warning: Container is not a MovieClip, cannot call default onDisplay."); }; }; }; } else { options = {}; if ((MochiServices.clip is MovieClip)){ MochiServices.clip.stop(); } else { trace("Warning: Container is not a MovieClip, cannot call default onDisplay."); }; }; if (options.onClose != null){ onCloseHandler = options.onClose; } else { onCloseHandler = function ():void{ if ((MochiServices.clip is MovieClip)){ MochiServices.clip.play(); } else { trace("Warning: Container is not a MovieClip, cannot call default onClose."); }; }; }; if (options.onError != null){ onErrorHandler = options.onError; } else { onErrorHandler = null; }; if (options.boardID == null){ if (MochiScores.boardID != null){ options.boardID = MochiScores.boardID; }; }; trace("[MochiScores] NOTE: Security Sandbox Violation errors below are normal"); MochiServices.send("scores_showLeaderboard", {options:options}, null, onClose); } public static function closeLeaderboard():void{ MochiServices.send("scores_closeLeaderboard"); } public static function getPlayerInfo(callbackObj:Object, callbackMethod:Object=null):void{ MochiServices.send("scores_getPlayerInfo", null, callbackObj, callbackMethod); } public static function requestList(callbackObj:Object, callbackMethod:Object=null):void{ MochiServices.send("scores_requestList", null, callbackObj, callbackMethod); } public static function scoresArrayToObjects(scores:Object):Object{ var i:Number; var j:Number; var o:Object; var row_obj:Object; var item:String; var param:String; var so:Object = {}; for (item in scores) { if (typeof(scores[item]) == "object"){ if (((!((scores[item].cols == null))) && (!((scores[item].rows == null))))){ so[item] = []; o = scores[item]; j = 0; while (j < o.rows.length) { row_obj = {}; i = 0; while (i < o.cols.length) { row_obj[o.cols[i]] = o.rows[j][i]; i++; }; so[item].push(row_obj); j++; }; } else { so[item] = {}; for (param in scores[item]) { so[item][param] = scores[item][param]; }; }; } else { so[item] = scores[item]; }; }; return (so); } public static function submit(score:Number, name:String, callbackObj:Object=null, callbackMethod:Object=null):void{ score = Number(score); if (isNaN(score)){ trace((("ERROR: Submitted score '" + String(score)) + "' will be rejected, score is 'Not a Number'")); } else { if ((((score == Number.NEGATIVE_INFINITY)) || ((score == Number.POSITIVE_INFINITY)))){ trace((("ERROR: Submitted score '" + String(score)) + "' will be rejected, score is an infinite")); } else { if (Math.floor(score) != score){ trace((("WARNING: Submitted score '" + String(score)) + "' will be truncated")); }; score = Number(score); }; }; MochiServices.send("scores_submit", {score:score, name:name}, callbackObj, callbackMethod); } public static function onClose(args:Object=null):void{ if (args != null){ if (args.error != null){ if (args.error == true){ if (onErrorHandler != null){ if (args.errorCode == null){ args.errorCode = "IOError"; }; onErrorHandler(args.errorCode); MochiServices.doClose(); return; }; }; }; }; onCloseHandler(); MochiServices.doClose(); } public static function setBoardID(boardID:String):void{ MochiScores.boardID = boardID; MochiServices.send("scores_setBoardID", {boardID:boardID}); } } }//package mochi.as3
Section 155
//MochiServices (mochi.as3.MochiServices) package mochi.as3 { import flash.events.*; import flash.display.*; import flash.net.*; import flash.utils.*; import flash.system.*; import flash.geom.*; public class MochiServices { private static var _container:Object; private static var _connected:Boolean = false; private static var _swfVersion:String; public static var netupAttempted:Boolean = false; private static var _sendChannel:LocalConnection; private static var _clip:MovieClip; private static var _loader:Loader; private static var _id:String; private static var _listenChannel:LocalConnection; public static var widget:Boolean = false; private static var _timer:Timer; private static var _sendChannelName:String; private static var _connecting:Boolean = false; public static var onError:Object; private static var _listenChannelName:String = "__ms_"; private static var _servicesURL:String = "http://www.mochiads.com/static/lib/services/services.swf"; public static var netup:Boolean = true; public function MochiServices(){ super(); } public static function isNetworkAvailable():Boolean{ return (!((Security.sandboxType == "localWithFile"))); } public static function get connected():Boolean{ return (_connected); } private static function flush(error:Boolean):void{ var request:Object; var callback:Object; if (_clip != null){ if (_clip._queue != null){ while (_clip._queue.length > 0) { request = _clip._queue.shift(); callback = null; if (request != null){ if (request.callbackID != null){ callback = _clip._callbacks[request.callbackID]; }; delete _clip._callbacks[request.callbackID]; if (((error) && (!((callback == null))))){ handleError(request.args, callback.callbackObject, callback.callbackMethod); }; }; }; }; }; } public static function send(methodName:String, args:Object=null, callbackObject:Object=null, callbackMethod:Object=null):void{ if (_connected){ _sendChannel.send(_sendChannelName, "onReceive", {methodName:methodName, args:args, callbackID:_clip._nextcallbackID}); } else { if ((((_clip == null)) || (!(_connecting)))){ onError("NotConnected"); handleError(args, callbackObject, callbackMethod); flush(true); return; }; _clip._queue.push({methodName:methodName, args:args, callbackID:_clip._nextcallbackID}); }; if (_clip != null){ if (((!((_clip._callbacks == null))) && (!((_clip._nextcallbackID == null))))){ _clip._callbacks[_clip._nextcallbackID] = {callbackObject:callbackObject, callbackMethod:callbackMethod}; _clip._nextcallbackID++; }; }; } private static function init(id:String, clip:Object):void{ _id = id; if (clip != null){ _container = clip; loadCommunicator(id, _container); }; } public static function get childClip():Object{ return (_clip); } private static function clickMovie(url:String, cb:Function):MovieClip{ var b:int; var loader:Loader; var avm1_bytecode:Array = [150, 21, 0, 7, 1, 0, 0, 0, 0, 98, 116, 110, 0, 7, 2, 0, 0, 0, 0, 116, 104, 105, 115, 0, 28, 150, 22, 0, 0, 99, 114, 101, 97, 116, 101, 69, 109, 112, 116, 121, 77, 111, 118, 105, 101, 67, 108, 105, 112, 0, 82, 135, 1, 0, 0, 23, 150, 13, 0, 4, 0, 0, 111, 110, 82, 101, 108, 101, 97, 115, 101, 0, 142, 8, 0, 0, 0, 0, 2, 42, 0, 114, 0, 150, 17, 0, 0, 32, 0, 7, 1, 0, 0, 0, 8, 0, 0, 115, 112, 108, 105, 116, 0, 82, 135, 1, 0, 1, 23, 150, 7, 0, 4, 1, 7, 0, 0, 0, 0, 78, 150, 8, 0, 0, 95, 98, 108, 97, 110, 107, 0, 154, 1, 0, 0, 150, 7, 0, 0, 99, 108, 105, 99, 107, 0, 150, 7, 0, 4, 1, 7, 1, 0, 0, 0, 78, 150, 27, 0, 7, 2, 0, 0, 0, 7, 0, 0, 0, 0, 0, 76, 111, 99, 97, 108, 67, 111, 110, 110, 101, 99, 116, 105, 111, 110, 0, 64, 150, 6, 0, 0, 115, 101, 110, 100, 0, 82, 79, 150, 15, 0, 4, 0, 0, 95, 97, 108, 112, 104, 97, 0, 7, 0, 0, 0, 0, 79, 150, 23, 0, 7, 0xFF, 0, 0xFF, 0, 7, 1, 0, 0, 0, 4, 0, 0, 98, 101, 103, 105, 110, 70, 105, 108, 108, 0, 82, 23, 150, 25, 0, 7, 0, 0, 0, 0, 7, 0, 0, 0, 0, 7, 2, 0, 0, 0, 4, 0, 0, 109, 111, 118, 101, 84, 111, 0, 82, 23, 150, 25, 0, 7, 100, 0, 0, 0, 7, 0, 0, 0, 0, 7, 2, 0, 0, 0, 4, 0, 0, 108, 105, 110, 101, 84, 111, 0, 82, 23, 150, 25, 0, 7, 100, 0, 0, 0, 7, 100, 0, 0, 0, 7, 2, 0, 0, 0, 4, 0, 0, 108, 105, 110, 101, 84, 111, 0, 82, 23, 150, 25, 0, 7, 0, 0, 0, 0, 7, 100, 0, 0, 0, 7, 2, 0, 0, 0, 4, 0, 0, 108, 105, 110, 101, 84, 111, 0, 82, 23, 150, 25, 0, 7, 0, 0, 0, 0, 7, 0, 0, 0, 0, 7, 2, 0, 0, 0, 4, 0, 0, 108, 105, 110, 101, 84, 111, 0, 82, 23, 150, 16, 0, 7, 0, 0, 0, 0, 4, 0, 0, 101, 110, 100, 70, 105, 108, 108, 0, 82, 23]; var header:Array = [104, 0, 31, 64, 0, 7, 208, 0, 0, 12, 1, 0, 67, 2, 0xFF, 0xFF, 0xFF, 63, 3]; var footer:Array = [0, 64, 0, 0, 0]; var mc:MovieClip = new MovieClip(); var lc:LocalConnection = new LocalConnection(); var lc_name:String = ((("_click_" + Math.floor((Math.random() * 999999))) + "_") + Math.floor(new Date().getTime())); lc = new LocalConnection(); mc.lc = lc; mc.click = cb; lc.client = mc; lc.connect(lc_name); var ba:ByteArray = new ByteArray(); var cpool:ByteArray = new ByteArray(); cpool.endian = Endian.LITTLE_ENDIAN; cpool.writeShort(1); cpool.writeUTFBytes(((url + " ") + lc_name)); cpool.writeByte(0); var actionLength:uint = ((avm1_bytecode.length + cpool.length) + 4); var fileLength:uint = (actionLength + 35); ba.endian = Endian.LITTLE_ENDIAN; ba.writeUTFBytes("FWS"); ba.writeByte(8); ba.writeUnsignedInt(fileLength); for each (b in header) { ba.writeByte(b); }; ba.writeUnsignedInt(actionLength); ba.writeByte(136); ba.writeShort(cpool.length); ba.writeBytes(cpool); for each (b in avm1_bytecode) { ba.writeByte(b); }; for each (b in footer) { ba.writeByte(b); }; loader = new Loader(); loader.loadBytes(ba); mc.addChild(loader); return (mc); } public static function stayOnTop():void{ _container.addEventListener(Event.ENTER_FRAME, MochiServices.bringToTop, false, 0, true); if (_clip != null){ _clip.visible = true; }; } public static function addLinkEvent(url:String, burl:String, btn:DisplayObjectContainer, onClick:Function=null):void{ var avm1Click:DisplayObject; var x:String; var req:URLRequest; var loader:Loader; var setURL:Function; var err:Function; var complete:Function; var url = url; var burl = burl; var btn = btn; var onClick = onClick; var vars:Object = new Object(); vars["mav"] = getVersion(); vars["swfv"] = "9"; vars["swfurl"] = btn.loaderInfo.loaderURL; vars["fv"] = Capabilities.version; vars["os"] = Capabilities.os; vars["lang"] = Capabilities.language; vars["scres"] = ((Capabilities.screenResolutionX + "x") + Capabilities.screenResolutionY); var s = "?"; var i:Number = 0; for (x in vars) { if (i != 0){ s = (s + "&"); }; i = (i + 1); s = (((s + x) + "=") + escape(vars[x])); }; req = new URLRequest("http://x.mochiads.com/linkping.swf"); loader = new Loader(); setURL = function (url:String):void{ if (avm1Click){ btn.removeChild(avm1Click); }; avm1Click = clickMovie(url, onClick); var rect:Rectangle = btn.getBounds(btn); btn.addChild(avm1Click); avm1Click.x = rect.x; avm1Click.y = rect.y; avm1Click.scaleX = (0.01 * rect.width); avm1Click.scaleY = (0.01 * rect.height); }; err = function (ev:Object):void{ netup = false; ev.target.removeEventListener(ev.type, arguments.callee); setURL(burl); }; complete = function (ev:Object):void{ ev.target.removeEventListener(ev.type, arguments.callee); }; if (netup){ setURL((url + s)); } else { setURL(burl); }; if (!((netupAttempted) || (_connected))){ netupAttempted = true; loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, err); loader.contentLoaderInfo.addEventListener(Event.COMPLETE, complete); loader.load(req); }; } public static function disconnect():void{ if (((_connected) || (_connecting))){ if (_clip != null){ if (_clip.parent != null){ if ((_clip.parent is Sprite)){ Sprite(_clip.parent).removeChild(_clip); _clip = null; }; }; }; _connecting = (_connected = false); flush(true); _listenChannel.close(); //unresolved jump var _slot1 = error; }; if (_timer != null){ _timer.stop(); //unresolved jump var _slot1 = error; }; } public static function allowDomains(server:String):String{ var hostname:String; if (Security.sandboxType != "application"){ Security.allowDomain("*"); Security.allowInsecureDomain("*"); }; if (server.indexOf("http://") != -1){ hostname = server.split("/")[2].split(":")[0]; if (Security.sandboxType != "application"){ Security.allowDomain(hostname); Security.allowInsecureDomain(hostname); }; }; return (hostname); } public static function getVersion():String{ return ("3.0"); } public static function doClose():void{ _container.removeEventListener(Event.ENTER_FRAME, MochiServices.bringToTop); if (_clip.parent != null){ Sprite(_clip.parent).removeChild(_clip); }; } private static function onStatus(event:StatusEvent):void{ switch (event.level){ case "error": _connected = false; _listenChannel.connect(_listenChannelName); break; }; } public static function get id():String{ return (_id); } private static function urlOptions(clip:Object):Object{ var pairs:Array; var i:Number; var kv:Array; var opts:Object = {}; var options:String = clip.loaderInfo.parameters.mochiad_options; if (options){ pairs = options.split("&"); i = 0; while (i < pairs.length) { kv = pairs[i].split("="); opts[unescape(kv[0])] = unescape(kv[1]); i++; }; }; return (opts); } public static function setContainer(container:Object=null, doAdd:Boolean=true):void{ if (container != null){ if ((container is Sprite)){ _container = container; }; }; if (doAdd){ if ((_container is Sprite)){ Sprite(_container).addChild(_clip); }; }; } private static function handleError(args:Object, callbackObject:Object, callbackMethod:Object):void{ var args = args; var callbackObject = callbackObject; var callbackMethod = callbackMethod; if (args != null){ if (args.onError != null){ args.onError.apply(null, ["NotConnected"]); }; if (((!((args.options == null))) && (!((args.options.onError == null))))){ args.options.onError.apply(null, ["NotConnected"]); }; }; if (callbackMethod != null){ args = {}; args.error = true; args.errorCode = "NotConnected"; if (((!((callbackObject == null))) && ((callbackMethod is String)))){ var _local5 = callbackObject; _local5[callbackMethod](args); //unresolved jump var _slot1 = error; } else { if (callbackMethod != null){ callbackMethod.apply(args); //unresolved jump var _slot1 = error; }; }; }; } private static function initComChannels():void{ if (!_connected){ _sendChannel.addEventListener(StatusEvent.STATUS, MochiServices.onStatus); _sendChannel.send(_sendChannelName, "onReceive", {methodName:"handshakeDone"}); _sendChannel.send(_sendChannelName, "onReceive", {methodName:"registerGame", id:_id, clip:_container, version:getVersion(), parentURL:_container.loaderInfo.loaderURL}); _listenChannel.addEventListener(StatusEvent.STATUS, MochiServices.onStatus); _clip.onReceive = function (pkg:Object):void{ var methodName:String; var pkg = pkg; var cb:String = pkg.callbackID; var cblst:Object = this.client._callbacks[cb]; if (!cblst){ return; }; var method:* = cblst.callbackMethod; methodName = ""; var obj:Object = cblst.callbackObject; if (((obj) && ((typeof(method) == "string")))){ methodName = method; if (obj[method] != null){ method = obj[method]; } else { trace((("Error: Method " + method) + " does not exist.")); }; }; if (method != undefined){ method.apply(obj, pkg.args); //unresolved jump var _slot1 = error; trace(((("Error invoking callback method '" + methodName) + "': ") + pkg.toString())); } else { if (obj != null){ obj(pkg.args); //unresolved jump var _slot1 = error; trace(("Error invoking method on object: " + pkg.toString())); }; }; delete this.client._callbacks[cb]; }; _clip.onError = function ():void{ MochiServices.onError("IOError"); }; trace("connected!"); _connecting = false; _connected = true; while (_clip._queue.length > 0) { _sendChannel.send(_sendChannelName, "onReceive", _clip._queue.shift()); }; }; } private static function listen():void{ _listenChannel = new LocalConnection(); _listenChannel.client = _clip; _clip.handshake = function (args:Object):void{ MochiServices.comChannelName = args.newChannel; }; _listenChannel.allowDomain("*", "localhost"); _listenChannel.allowInsecureDomain("*", "localhost"); _listenChannel.connect(_listenChannelName); trace("Waiting for MochiAds services to connect..."); } public static function set comChannelName(val:String):void{ if (val != null){ if (val.length > 3){ _sendChannelName = (val + "_fromgame"); initComChannels(); }; }; } private static function loadCommunicator(id:String, clip:Object):MovieClip{ var id = id; var clip = clip; var clipname:String = ("_mochiservices_com_" + id); if (_clip != null){ return (_clip); }; if (!MochiServices.isNetworkAvailable()){ return (null); }; if (urlOptions(clip).servicesURL != undefined){ _servicesURL = urlOptions(clip).servicesURL; }; MochiServices.allowDomains(_servicesURL); _clip = createEmptyMovieClip(clip, clipname, 10336, false); _loader = new Loader(); var f:Function = function (ev:Object):void{ _clip._mochiad_ctr_failed = true; trace("MochiServices could not load."); MochiServices.disconnect(); MochiServices.onError("IOError"); }; _listenChannelName = (_listenChannelName + ((Math.floor(new Date().getTime()) + "_") + Math.floor((Math.random() * 99999)))); _loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, f); var req:URLRequest = new URLRequest(_servicesURL); var vars:URLVariables = new URLVariables(); vars.listenLC = _listenChannelName; vars.mochiad_options = clip.loaderInfo.parameters.mochiad_options; if (widget){ vars.widget = true; }; req.data = vars; listen(); _loader.load(req); _clip.addChild(_loader); _clip._mochiservices_com = _loader; _sendChannel = new LocalConnection(); _clip._queue = []; _clip._nextcallbackID = 0; _clip._callbacks = {}; _timer = new Timer(10000, 1); _timer.addEventListener(TimerEvent.TIMER, connectWait); _timer.start(); return (_clip); } public static function get clip():Object{ return (_container); } public static function bringToTop(e:Event):void{ var e = e; if (MochiServices.clip != null){ if (MochiServices.childClip != null){ if (MochiServices.clip.numChildren > 1){ MochiServices.clip.setChildIndex(MochiServices.childClip, (MochiServices.clip.numChildren - 1)); }; //unresolved jump var _slot1 = errorObject; trace("Warning: Depth sort error."); _container.removeEventListener(Event.ENTER_FRAME, MochiServices.bringToTop); }; }; } public static function connect(id:String, clip:Object, onError:Object=null):void{ var id = id; var clip = clip; var onError = onError; if ((clip is DisplayObject)){ if (((!(_connected)) && ((_clip == null)))){ trace("MochiServices Connecting..."); _connecting = true; init(id, clip); }; } else { trace("Error, MochiServices requires a Sprite, Movieclip or instance of the stage."); }; if (onError != null){ MochiServices.onError = onError; } else { if (MochiServices.onError == null){ MochiServices.onError = function (errorCode:String):void{ trace(errorCode); }; }; }; } public static function createEmptyMovieClip(parent:Object, name:String, depth:Number, doAdd:Boolean=true):MovieClip{ var parent = parent; var name = name; var depth = depth; var doAdd = doAdd; var mc:MovieClip = new MovieClip(); if (doAdd){ if (((false) && (depth))){ parent.addChildAt(mc, depth); } else { parent.addChild(mc); }; }; parent[name] = mc; //unresolved jump var _slot1 = e; throw (new Error("MochiServices requires a clip that is an instance of a dynamic class. If your class extends Sprite or MovieClip, you must make it dynamic.")); mc["_name"] = name; return (mc); } public static function connectWait(e:TimerEvent):void{ if (!_connected){ _clip._mochiad_ctr_failed = true; trace("MochiServices could not load. (timeout)"); MochiServices.disconnect(); MochiServices.onError("IOError"); }; } } }//package mochi.as3
Section 156
//BitmapAsset (mx.core.BitmapAsset) package mx.core { import flash.display.*; public class BitmapAsset extends FlexBitmap implements IFlexAsset, IFlexDisplayObject { mx_internal static const VERSION:String = "3.3.0.4852"; public function BitmapAsset(bitmapData:BitmapData=null, pixelSnapping:String="auto", smoothing:Boolean=false){ super(bitmapData, pixelSnapping, smoothing); } public function get measuredWidth():Number{ if (bitmapData){ return (bitmapData.width); }; return (0); } public function get measuredHeight():Number{ if (bitmapData){ return (bitmapData.height); }; return (0); } public function setActualSize(newWidth:Number, newHeight:Number):void{ width = newWidth; height = newHeight; } public function move(x:Number, y:Number):void{ this.x = x; this.y = y; } } }//package mx.core
Section 157
//EdgeMetrics (mx.core.EdgeMetrics) package mx.core { public class EdgeMetrics { public var top:Number; public var left:Number; public var bottom:Number; public var right:Number; mx_internal static const VERSION:String = "3.3.0.4852"; public static const EMPTY:EdgeMetrics = new EdgeMetrics(0, 0, 0, 0); ; public function EdgeMetrics(left:Number=0, top:Number=0, right:Number=0, bottom:Number=0){ super(); this.left = left; this.top = top; this.right = right; this.bottom = bottom; } public function clone():EdgeMetrics{ return (new EdgeMetrics(left, top, right, bottom)); } } }//package mx.core
Section 158
//FlexBitmap (mx.core.FlexBitmap) package mx.core { import flash.display.*; import mx.utils.*; public class FlexBitmap extends Bitmap { mx_internal static const VERSION:String = "3.3.0.4852"; public function FlexBitmap(bitmapData:BitmapData=null, pixelSnapping:String="auto", smoothing:Boolean=false){ var bitmapData = bitmapData; var pixelSnapping = pixelSnapping; var smoothing = smoothing; super(bitmapData, pixelSnapping, smoothing); name = NameUtil.createUniqueName(this); //unresolved jump var _slot1 = e; } override public function toString():String{ return (NameUtil.displayObjectToString(this)); } } }//package mx.core
Section 159
//FlexSprite (mx.core.FlexSprite) package mx.core { import flash.display.*; import mx.utils.*; public class FlexSprite extends Sprite { mx_internal static const VERSION:String = "3.3.0.4852"; public function FlexSprite(){ super(); name = NameUtil.createUniqueName(this); //unresolved jump var _slot1 = e; } override public function toString():String{ return (NameUtil.displayObjectToString(this)); } } }//package mx.core
Section 160
//IBorder (mx.core.IBorder) package mx.core { public interface IBorder { function get borderMetrics():EdgeMetrics; } }//package mx.core
Section 161
//IFlexAsset (mx.core.IFlexAsset) package mx.core { public interface IFlexAsset { } }//package mx.core
Section 162
//IFlexDisplayObject (mx.core.IFlexDisplayObject) package mx.core { import flash.events.*; import flash.display.*; import flash.geom.*; import flash.accessibility.*; public interface IFlexDisplayObject extends IBitmapDrawable, IEventDispatcher { function get visible():Boolean; function get rotation():Number; function localToGlobal(void:Point):Point; function get name():String; function set width(flash.display:Number):void; function get measuredHeight():Number; function get blendMode():String; function get scale9Grid():Rectangle; function set name(flash.display:String):void; function set scaleX(flash.display:Number):void; function set scaleY(flash.display:Number):void; function get measuredWidth():Number; function get accessibilityProperties():AccessibilityProperties; function set scrollRect(flash.display:Rectangle):void; function get cacheAsBitmap():Boolean; function globalToLocal(void:Point):Point; function get height():Number; function set blendMode(flash.display:String):void; function get parent():DisplayObjectContainer; function getBounds(String:DisplayObject):Rectangle; function get opaqueBackground():Object; function set scale9Grid(flash.display:Rectangle):void; function setActualSize(_arg1:Number, _arg2:Number):void; function set alpha(flash.display:Number):void; function set accessibilityProperties(flash.display:AccessibilityProperties):void; function get width():Number; function hitTestPoint(_arg1:Number, _arg2:Number, _arg3:Boolean=false):Boolean; function set cacheAsBitmap(flash.display:Boolean):void; function get scaleX():Number; function get scaleY():Number; function get scrollRect():Rectangle; function get mouseX():Number; function get mouseY():Number; function set height(flash.display:Number):void; function set mask(flash.display:DisplayObject):void; function getRect(String:DisplayObject):Rectangle; function get alpha():Number; function set transform(flash.display:Transform):void; function move(_arg1:Number, _arg2:Number):void; function get loaderInfo():LoaderInfo; function get root():DisplayObject; function hitTestObject(mx.core:IFlexDisplayObject/mx.core:IFlexDisplayObject:stage/get:DisplayObject):Boolean; function set opaqueBackground(flash.display:Object):void; function set visible(flash.display:Boolean):void; function get mask():DisplayObject; function set x(flash.display:Number):void; function set y(flash.display:Number):void; function get transform():Transform; function set filters(flash.display:Array):void; function get x():Number; function get y():Number; function get filters():Array; function set rotation(flash.display:Number):void; function get stage():Stage; } }//package mx.core
Section 163
//IRepeaterClient (mx.core.IRepeaterClient) package mx.core { public interface IRepeaterClient { function get instanceIndices():Array; function set instanceIndices(C:\autobuild\3.3.0\frameworks\projects\framework\src;mx\core;IRepeaterClient.as:Array):void; function get isDocument():Boolean; function set repeaters(C:\autobuild\3.3.0\frameworks\projects\framework\src;mx\core;IRepeaterClient.as:Array):void; function initializeRepeaterArrays(C:\autobuild\3.3.0\frameworks\projects\framework\src;mx\core;IRepeaterClient.as:IRepeaterClient):void; function get repeaters():Array; function set repeaterIndices(C:\autobuild\3.3.0\frameworks\projects\framework\src;mx\core;IRepeaterClient.as:Array):void; function get repeaterIndices():Array; } }//package mx.core
Section 164
//mx_internal (mx.core.mx_internal) package mx.core { public namespace mx_internal = "http://www.adobe.com/2006/flex/mx/internal"; }//package mx.core
Section 165
//SoundAsset (mx.core.SoundAsset) package mx.core { import flash.media.*; public class SoundAsset extends Sound implements IFlexAsset { mx_internal static const VERSION:String = "3.3.0.4852"; public function SoundAsset(){ super(); } } }//package mx.core
Section 166
//SpriteAsset (mx.core.SpriteAsset) package mx.core { public class SpriteAsset extends FlexSprite implements IFlexAsset, IFlexDisplayObject, IBorder { private var _measuredHeight:Number; private var _measuredWidth:Number; mx_internal static const VERSION:String = "3.3.0.4852"; public function SpriteAsset(){ super(); _measuredWidth = width; _measuredHeight = height; } public function get measuredWidth():Number{ return (_measuredWidth); } public function get measuredHeight():Number{ return (_measuredHeight); } public function setActualSize(newWidth:Number, newHeight:Number):void{ width = newWidth; height = newHeight; } public function move(x:Number, y:Number):void{ this.x = x; this.y = y; } public function get borderMetrics():EdgeMetrics{ if (scale9Grid == null){ return (EdgeMetrics.EMPTY); }; return (new EdgeMetrics(scale9Grid.left, scale9Grid.top, Math.ceil((measuredWidth - scale9Grid.right)), Math.ceil((measuredHeight - scale9Grid.bottom)))); } } }//package mx.core
Section 167
//NameUtil (mx.utils.NameUtil) package mx.utils { import flash.display.*; import flash.utils.*; import mx.core.*; public class NameUtil { mx_internal static const VERSION:String = "3.3.0.4852"; private static var counter:int = 0; public function NameUtil(){ super(); } public static function displayObjectToString(displayObject:DisplayObject):String{ var result:String; var o:DisplayObject; var s:String; var indices:Array; var displayObject = displayObject; o = displayObject; while (o != null) { if (((((o.parent) && (o.stage))) && ((o.parent == o.stage)))){ break; }; s = o.name; if ((o is IRepeaterClient)){ indices = IRepeaterClient(o).instanceIndices; if (indices){ s = (s + (("[" + indices.join("][")) + "]")); }; }; result = ((result == null)) ? s : ((s + ".") + result); o = o.parent; }; //unresolved jump var _slot1 = e; return (result); } public static function createUniqueName(object:Object):String{ if (!object){ return (null); }; var name:String = getQualifiedClassName(object); var index:int = name.indexOf("::"); if (index != -1){ name = name.substr((index + 2)); }; var charCode:int = name.charCodeAt((name.length - 1)); if ((((charCode >= 48)) && ((charCode <= 57)))){ name = (name + "_"); }; return ((name + counter++)); } } }//package mx.utils
Section 168
//FlashConnect (org.flashdevelop.utils.FlashConnect) package org.flashdevelop.utils { import flash.events.*; import flash.xml.*; import flash.utils.*; import flash.net.*; public class FlashConnect { public static var onReturnData:Function; public static var port:Number = 1978; private static var interval:Number; private static var messages:Array; public static var onConnection:Function; public static var host:String = "localhost"; public static var status:Number = 0; private static var socket:XMLSocket; public static var limit:Number = 1000; private static var counter:Number; public function FlashConnect(){ super(); } private static function onIOError(event:IOErrorEvent):void{ FlashConnect.status = -1; if (FlashConnect.onConnection != null){ FlashConnect.onConnection(); }; } public static function atrace(... _args):void{ var result:String = _args.join(","); var message:XMLNode = createMsgNode(result, TraceLevel.DEBUG); FlashConnect.send(message); } private static function createMsgNode(message:String, level:Number):XMLNode{ if (isNaN(level)){ level = TraceLevel.DEBUG; }; var msgNode:XMLNode = new XMLNode(1, null); var txtNode:XMLNode = new XMLNode(3, encodeURI(message)); msgNode.attributes.state = level.toString(); msgNode.attributes.cmd = "trace"; msgNode.nodeName = "message"; msgNode.appendChild(txtNode); return (msgNode); } public static function send(message:XMLNode):void{ if (messages == null){ initialize(); }; messages.push(message); } private static function onSecurityError(event:SecurityErrorEvent):void{ FlashConnect.status = -1; if (FlashConnect.onConnection != null){ FlashConnect.onConnection(); }; } private static function onConnect(event:Event):void{ FlashConnect.status = 1; if (FlashConnect.onConnection != null){ FlashConnect.onConnection(); }; } public static function trace(value:Object, level:Number=1):void{ var msgNode:XMLNode = createMsgNode(value.toString(), level); FlashConnect.send(msgNode); } private static function initialize():void{ counter = 0; messages = new Array(); socket = new XMLSocket(); socket.addEventListener(DataEvent.DATA, onData); socket.addEventListener(Event.CONNECT, onConnect); socket.addEventListener(IOErrorEvent.IO_ERROR, onIOError); socket.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onSecurityError); interval = setInterval(sendStack, 50); socket.connect(host, port); } private static function sendStack():void{ var message:XMLDocument; var rootNode:XMLNode; var msg:String; var errorNode:XMLNode; var msgNode:XMLNode; if ((((messages.length > 0)) && ((status == 1)))){ message = new XMLDocument(); rootNode = message.createElement("flashconnect"); while (messages.length != 0) { counter++; if (counter > limit){ clearInterval(interval); msg = new String("FlashConnect aborted. You have reached the limit of maximum messages."); errorNode = createMsgNode(msg, TraceLevel.ERROR); rootNode.appendChild(errorNode); break; } else { msgNode = XMLNode(messages.shift()); rootNode.appendChild(msgNode); }; }; message.appendChild(rootNode); socket.send(message); }; } private static function onData(event:DataEvent):void{ FlashConnect.status = 1; if (FlashConnect.onReturnData != null){ FlashConnect.onReturnData(event.data); }; } public static function mtrace(value:Object, method:String, path:String, line:Number):void{ var fixed:String = path.split("/").join("\\"); var formatted:String = ((((fixed + ":") + line) + ":") + value); FlashConnect.trace(formatted, TraceLevel.DEBUG); } } }//package org.flashdevelop.utils
Section 169
//TraceLevel (org.flashdevelop.utils.TraceLevel) package org.flashdevelop.utils { public class TraceLevel { public static const DEBUG:Number = 1; public static const FATAL:Number = 4; public static const WARNING:Number = 2; public static const INFO:Number = 0; public static const ERROR:Number = 3; public function TraceLevel(){ super(); } } }//package org.flashdevelop.utils
Section 170
//Action (org.flintparticles.common.actions.Action) package org.flintparticles.common.actions { import org.flintparticles.common.particles.*; import org.flintparticles.common.emitters.*; public interface Action { function update(_arg1:Emitter, _arg2:Particle, _arg3:Number):void; function addedToEmitter(C:\flashninjaclan\games\glasstower\GlassTower\development\src;org\flintparticles\common\actions;Action.as:Emitter):void; function removedFromEmitter(C:\flashninjaclan\games\glasstower\GlassTower\development\src;org\flintparticles\common\actions;Action.as:Emitter):void; function getDefaultPriority():Number; } }//package org.flintparticles.common.actions
Section 171
//ActionBase (org.flintparticles.common.actions.ActionBase) package org.flintparticles.common.actions { import org.flintparticles.common.particles.*; import org.flintparticles.common.emitters.*; public class ActionBase implements Action { public function ActionBase(){ super(); } public function addedToEmitter(emitter:Emitter):void{ } public function removedFromEmitter(emitter:Emitter):void{ } public function getDefaultPriority():Number{ return (0); } public function update(emitter:Emitter, particle:Particle, time:Number):void{ } } }//package org.flintparticles.common.actions
Section 172
//Age (org.flintparticles.common.actions.Age) package org.flintparticles.common.actions { import org.flintparticles.common.particles.*; import org.flintparticles.common.emitters.*; import org.flintparticles.common.energyEasing.*; public class Age extends ActionBase { private var _easing:Function; public function Age(easing:Function=null){ super(); if (easing == null){ _easing = Linear.easeNone; } else { _easing = easing; }; } public function set easing(value:Function):void{ _easing = value; } override public function update(emitter:Emitter, particle:Particle, time:Number):void{ particle.age = (particle.age + time); if (particle.age >= particle.lifetime){ particle.energy = 0; particle.isDead = true; } else { particle.energy = _easing(particle.age, particle.lifetime); }; } public function get easing():Function{ return (_easing); } } }//package org.flintparticles.common.actions
Section 173
//Fade (org.flintparticles.common.actions.Fade) package org.flintparticles.common.actions { import org.flintparticles.common.particles.*; import org.flintparticles.common.emitters.*; public class Fade extends ActionBase { private var _endAlpha:Number; private var _diffAlpha:Number; public function Fade(startAlpha:Number=1, endAlpha:Number=0){ super(); _diffAlpha = (startAlpha - endAlpha); _endAlpha = endAlpha; } public function get endAlpha():Number{ return (_endAlpha); } public function set endAlpha(value:Number):void{ _diffAlpha = ((_endAlpha + _diffAlpha) - value); _endAlpha = value; } override public function update(emitter:Emitter, particle:Particle, time:Number):void{ var alpha:Number = (_endAlpha + (_diffAlpha * particle.energy)); particle.color = ((particle.color & 0xFFFFFF) | (Math.round((alpha * 0xFF)) << 24)); } override public function getDefaultPriority():Number{ return (-5); } public function set startAlpha(value:Number):void{ _diffAlpha = (value - _endAlpha); } public function get startAlpha():Number{ return ((_endAlpha + _diffAlpha)); } } }//package org.flintparticles.common.actions
Section 174
//ScaleImage (org.flintparticles.common.actions.ScaleImage) package org.flintparticles.common.actions { import org.flintparticles.common.particles.*; import org.flintparticles.common.emitters.*; public class ScaleImage extends ActionBase { private var _diffScale:Number; private var _endScale:Number; public function ScaleImage(startScale:Number=1, endScale:Number=1){ super(); _diffScale = (startScale - endScale); _endScale = endScale; } public function set startScale(value:Number):void{ _diffScale = (value - _endScale); } public function set endScale(value:Number):void{ _diffScale = ((_endScale + _diffScale) - value); _endScale = value; } public function get startScale():Number{ return ((_endScale + _diffScale)); } override public function update(emitter:Emitter, particle:Particle, time:Number):void{ particle.scale = (_endScale + (_diffScale * particle.energy)); } public function get endScale():Number{ return (_endScale); } } }//package org.flintparticles.common.actions
Section 175
//Activity (org.flintparticles.common.activities.Activity) package org.flintparticles.common.activities { import org.flintparticles.common.emitters.*; public interface Activity { function initialize(C:\flashninjaclan\games\glasstower\GlassTower\development\src;org\flintparticles\common\activities;Activity.as:Emitter):void; function removedFromEmitter(C:\flashninjaclan\games\glasstower\GlassTower\development\src;org\flintparticles\common\activities;Activity.as:Emitter):void; function update(_arg1:Emitter, _arg2:Number):void; function addedToEmitter(C:\flashninjaclan\games\glasstower\GlassTower\development\src;org\flintparticles\common\activities;Activity.as:Emitter):void; function getDefaultPriority():Number; } }//package org.flintparticles.common.activities
Section 176
//Blast (org.flintparticles.common.counters.Blast) package org.flintparticles.common.counters { import org.flintparticles.common.emitters.*; public class Blast implements Counter { private var _startCount:uint; public function Blast(startCount:uint){ super(); _startCount = startCount; } public function stop():void{ } public function updateEmitter(emitter:Emitter, time:Number):uint{ return (0); } public function startEmitter(emitter:Emitter):uint{ return (_startCount); } public function resume():void{ } public function set startCount(value:Number):void{ _startCount = value; } public function get startCount():Number{ return (_startCount); } } }//package org.flintparticles.common.counters
Section 177
//Counter (org.flintparticles.common.counters.Counter) package org.flintparticles.common.counters { import org.flintparticles.common.emitters.*; public interface Counter { function stop():void; function startEmitter(:Emitter):uint; function updateEmitter(_arg1:Emitter, _arg2:Number):uint; function resume():void; } }//package org.flintparticles.common.counters
Section 178
//ZeroCounter (org.flintparticles.common.counters.ZeroCounter) package org.flintparticles.common.counters { import org.flintparticles.common.emitters.*; public class ZeroCounter implements Counter { public function ZeroCounter(){ super(); } public function stop():void{ } public function updateEmitter(emitter:Emitter, time:Number):uint{ return (0); } public function startEmitter(emitter:Emitter):uint{ return (0); } public function resume():void{ } } }//package org.flintparticles.common.counters
Section 179
//RadialDot (org.flintparticles.common.displayObjects.RadialDot) package org.flintparticles.common.displayObjects { import flash.display.*; import flash.geom.*; public class RadialDot extends Shape { public function RadialDot(radius:Number, color:uint=0xFFFFFF, bm:String="normal"){ super(); var matrix:Matrix = new Matrix(); matrix.createGradientBox((radius * 2), (radius * 2), 0, -(radius), -(radius)); graphics.beginGradientFill(GradientType.RADIAL, [color, color], [1, 0], [0, 0xFF], matrix); graphics.drawCircle(0, 0, radius); graphics.endFill(); blendMode = bm; } } }//package org.flintparticles.common.displayObjects
Section 180
//Emitter (org.flintparticles.common.emitters.Emitter) package org.flintparticles.common.emitters { import flash.events.*; import org.flintparticles.common.events.*; import org.flintparticles.common.initializers.*; import org.flintparticles.common.actions.*; import org.flintparticles.common.activities.*; import org.flintparticles.common.counters.*; import org.flintparticles.common.particles.*; import org.flintparticles.common.utils.*; public class Emitter extends EventDispatcher { protected var _running:Boolean;// = false protected var _activities:PriorityArray; protected var _particles:Array; protected var _initializers:PriorityArray; protected var _counter:Counter; protected var _started:Boolean;// = false protected var _actions:PriorityArray; protected var _useInternalTick:Boolean;// = true protected var _particleFactory:ParticleFactory; protected var _fixedFrameTime:Number;// = 0 protected var _maximumFrameTime:Number;// = 0.1 public function Emitter(){ super(); _particles = new Array(); _actions = new PriorityArray(); _initializers = new PriorityArray(); _activities = new PriorityArray(); _counter = new ZeroCounter(); } public function addInitializer(initializer:Initializer, priority:Number=NaN):void{ if (isNaN(priority)){ priority = initializer.getDefaultPriority(); }; _initializers.add(initializer, priority); initializer.addedToEmitter(this); } public function stop():void{ if (_useInternalTick){ FrameUpdater.instance.removeEventListener(UpdateEvent.UPDATE, updateEventListener); }; _started = false; killAllParticles(); } public function killAllParticles():void{ var len:int = _particles.length; var i:int; while (i < len) { dispatchEvent(new ParticleEvent(ParticleEvent.PARTICLE_DEAD, _particles[i])); _particleFactory.disposeParticle(_particles[i]); i++; }; _particles.length = 0; } public function set fixedFrameTime(value:Number):void{ _fixedFrameTime = value; } public function get maximumFrameTime():Number{ return (_maximumFrameTime); } public function get useInternalTick():Boolean{ return (_useInternalTick); } protected function createParticle():Particle{ var particle:Particle = _particleFactory.createParticle(); var len:int = _initializers.length; initParticle(particle); var i:int; while (i < len) { _initializers[i].initialize(this, particle); i++; }; _particles.push(particle); dispatchEvent(new ParticleEvent(ParticleEvent.PARTICLE_CREATED, particle)); return (particle); } public function get particleFactory():ParticleFactory{ return (_particleFactory); } private function updateEventListener(ev:UpdateEvent):void{ if (_fixedFrameTime){ update(_fixedFrameTime); } else { update(ev.time); }; } public function get particles():Array{ return (_particles); } protected function sortParticles():void{ } public function removeActivity(activity:Activity):void{ if (_activities.remove(activity)){ activity.removedFromEmitter(this); }; } public function set maximumFrameTime(value:Number):void{ _maximumFrameTime = value; } protected function initParticle(particle:Particle):void{ } public function addAction(action:Action, priority:Number=NaN):void{ if (isNaN(priority)){ priority = action.getDefaultPriority(); }; _actions.add(action, priority); action.addedToEmitter(this); } public function hasInitializerOfType(initializerClass:Class):Boolean{ var len:uint = _initializers.length; var i:uint; while (i < len) { if ((_initializers[i] is initializerClass)){ return (true); }; i++; }; return (false); } public function resume():void{ _running = true; } public function removeInitializer(initializer:Initializer):void{ if (_initializers.remove(initializer)){ initializer.removedFromEmitter(this); }; } public function get running():Boolean{ return (_running); } public function hasActionOfType(actionClass:Class):Boolean{ var len:uint = _actions.length; var i:uint; while (i < len) { if ((_actions[i] is actionClass)){ return (true); }; i++; }; return (false); } public function get fixedFrameTime():Number{ return (_fixedFrameTime); } public function set particleFactory(value:ParticleFactory):void{ _particleFactory = value; } public function hasActivity(activity:Activity):Boolean{ return (_activities.contains(activity)); } public function addActivity(activity:Activity, priority:Number=NaN):void{ if (isNaN(priority)){ priority = activity.getDefaultPriority(); }; _activities.add(activity, priority); activity.addedToEmitter(this); } public function update(time:Number):void{ var i:int; var particle:Particle; var action:Action; var len2:int; var j:int; if (!_running){ return; }; if (time > _maximumFrameTime){ time = _maximumFrameTime; }; var len:int = _counter.updateEmitter(this, time); i = 0; while (i < len) { createParticle(); i++; }; sortParticles(); len = _activities.length; i = 0; while (i < len) { _activities[i].update(this, time); i++; }; if (_particles.length > 0){ len = _actions.length; len2 = _particles.length; j = 0; while (j < len) { action = _actions[j]; i = 0; while (i < len2) { particle = _particles[i]; action.update(this, particle, time); i++; }; j++; }; i = len2; while (i--) { particle = _particles[i]; if (particle.isDead){ dispatchEvent(new ParticleEvent(ParticleEvent.PARTICLE_DEAD, particle)); _particleFactory.disposeParticle(particle); _particles.splice(i, 1); }; }; } else { dispatchEvent(new EmitterEvent(EmitterEvent.EMITTER_EMPTY)); }; dispatchEvent(new EmitterEvent(EmitterEvent.EMITTER_UPDATED)); } public function addExistingParticles(particles:Array, applyInitializers:Boolean=false):void{ var i:int; var len2:int; var j:int; var len:int = particles.length; if (applyInitializers){ len2 = _initializers.length; j = 0; while (j < len2) { i = 0; while (i < len) { _initializers[j].initialize(this, particles[i]); i++; }; j++; }; }; i = 0; while (i < len) { _particles.push(particles[i]); dispatchEvent(new ParticleEvent(ParticleEvent.PARTICLE_ADDED, particles[i])); i++; }; } public function removeAction(action:Action):void{ if (_actions.remove(action)){ action.removedFromEmitter(this); }; } public function hasActivityOfType(activityClass:Class):Boolean{ var len:uint = _activities.length; var i:uint; while (i < len) { if ((_activities[i] is activityClass)){ return (true); }; i++; }; return (false); } public function set useInternalTick(value:Boolean):void{ if (_useInternalTick != value){ _useInternalTick = value; if (_started){ if (_useInternalTick){ FrameUpdater.instance.addEventListener(UpdateEvent.UPDATE, updateEventListener, false, 0, true); } else { FrameUpdater.instance.removeEventListener(UpdateEvent.UPDATE, updateEventListener); }; }; }; } public function hasInitializer(initializer:Initializer):Boolean{ return (_initializers.contains(initializer)); } public function start():void{ if (_useInternalTick){ FrameUpdater.instance.addEventListener(UpdateEvent.UPDATE, updateEventListener, false, 0, true); }; _started = true; _running = true; var len:int = _activities.length; var i:int; while (i < len) { _activities[i].initialize(this); i++; }; len = _counter.startEmitter(this); i = 0; while (i < len) { createParticle(); i++; }; } public function hasAction(action:Action):Boolean{ return (_actions.contains(action)); } public function pause():void{ _running = false; } public function set counter(value:Counter):void{ _counter = value; if (running){ _counter.startEmitter(this); }; } public function get counter():Counter{ return (_counter); } public function runAhead(time:Number, frameRate:Number=10):void{ var maxTime:Number = _maximumFrameTime; var step:Number = (1 / frameRate); _maximumFrameTime = step; while (time > 0) { time = (time - step); update(step); }; _maximumFrameTime = maxTime; } } }//package org.flintparticles.common.emitters
Section 181
//Linear (org.flintparticles.common.energyEasing.Linear) package org.flintparticles.common.energyEasing { public class Linear { public function Linear(){ super(); } public static function easeOut(age:Number, lifetime:Number):Number{ return ((1 - (age / lifetime))); } public static function easeIn(age:Number, lifetime:Number):Number{ return ((1 - (age / lifetime))); } public static function easeInOut(age:Number, lifetime:Number):Number{ return ((1 - (age / lifetime))); } public static function easeNone(age:Number, lifetime:Number):Number{ return ((1 - (age / lifetime))); } } }//package org.flintparticles.common.energyEasing
Section 182
//Quadratic (org.flintparticles.common.energyEasing.Quadratic) package org.flintparticles.common.energyEasing { public class Quadratic { public function Quadratic(){ super(); } public static function easeOut(age:Number, lifetime:Number):Number{ age = (1 - (age / lifetime)); return ((age * age)); } public static function easeIn(age:Number, lifetime:Number):Number{ age = (age / lifetime); return ((1 - (age * age))); } public static function easeInOut(age:Number, lifetime:Number):Number{ age = (age / (lifetime * 0.5)); if (age < 1){ return ((1 - ((age * age) * 0.5))); }; age = (age - 2); return (((age * age) * 0.5)); } } }//package org.flintparticles.common.energyEasing
Section 183
//EmitterEvent (org.flintparticles.common.events.EmitterEvent) package org.flintparticles.common.events { import flash.events.*; public class EmitterEvent extends Event { public static var EMITTER_UPDATED:String = "emitterUpdated"; public static var EMITTER_EMPTY:String = "emitterEmpty"; public function EmitterEvent(type:String, bubbles:Boolean=false, cancelable:Boolean=false){ super(type, bubbles, cancelable); } } }//package org.flintparticles.common.events
Section 184
//ParticleEvent (org.flintparticles.common.events.ParticleEvent) package org.flintparticles.common.events { import flash.events.*; import org.flintparticles.common.particles.*; public class ParticleEvent extends Event { public var particle:Particle; public var otherObject; public static var PARTICLES_COLLISION:String = "particlesCollision"; public static var PARTICLE_ADDED:String = "particleAdded"; public static var PARTICLE_DEAD:String = "particleDead"; public static var PARTICLE_CREATED:String = "particleCreated"; public function ParticleEvent(type:String, particle:Particle=null, bubbles:Boolean=false, cancelable:Boolean=false){ super(type, bubbles, cancelable); this.particle = particle; } } }//package org.flintparticles.common.events
Section 185
//UpdateEvent (org.flintparticles.common.events.UpdateEvent) package org.flintparticles.common.events { import flash.events.*; public class UpdateEvent extends Event { public var time:Number; public static var UPDATE:String = "update"; public function UpdateEvent(type:String, time:Number=NaN, bubbles:Boolean=false, cancelable:Boolean=false){ super(type, bubbles, cancelable); this.time = time; } } }//package org.flintparticles.common.events
Section 186
//ColorInit (org.flintparticles.common.initializers.ColorInit) package org.flintparticles.common.initializers { import org.flintparticles.common.particles.*; import org.flintparticles.common.emitters.*; import org.flintparticles.common.utils.*; public class ColorInit extends InitializerBase { private var _max:uint; private var _min:uint; public function ColorInit(color1:uint, color2:uint){ super(); _min = color1; _max = color2; } public function set minColor(value:uint):void{ _min = value; } public function get color():uint{ return (((_min == _max)) ? _min : interpolateColors(_max, _min, 0.5)); } public function set color(value:uint):void{ _max = (_min = value); } override public function initialize(emitter:Emitter, particle:Particle):void{ if (_max == _min){ particle.color = _min; } else { particle.color = interpolateColors(_min, _max, Math.random()); }; } public function get minColor():uint{ return (_min); } public function set maxColor(value:uint):void{ _max = value; } public function get maxColor():uint{ return (_max); } } }//package org.flintparticles.common.initializers
Section 187
//Initializer (org.flintparticles.common.initializers.Initializer) package org.flintparticles.common.initializers { import org.flintparticles.common.particles.*; import org.flintparticles.common.emitters.*; public interface Initializer { function initialize(_arg1:Emitter, _arg2:Particle):void; function addedToEmitter(C:\flashninjaclan\games\glasstower\GlassTower\development\src;org\flintparticles\common\initializers;Initializer.as:Emitter):void; function removedFromEmitter(C:\flashninjaclan\games\glasstower\GlassTower\development\src;org\flintparticles\common\initializers;Initializer.as:Emitter):void; function getDefaultPriority():Number; } }//package org.flintparticles.common.initializers
Section 188
//InitializerBase (org.flintparticles.common.initializers.InitializerBase) package org.flintparticles.common.initializers { import org.flintparticles.common.particles.*; import org.flintparticles.common.emitters.*; public class InitializerBase implements Initializer { public function InitializerBase(){ super(); } public function initialize(emitter:Emitter, particle:Particle):void{ } public function addedToEmitter(emitter:Emitter):void{ } public function removedFromEmitter(emitter:Emitter):void{ } public function getDefaultPriority():Number{ return (0); } } }//package org.flintparticles.common.initializers
Section 189
//Lifetime (org.flintparticles.common.initializers.Lifetime) package org.flintparticles.common.initializers { import org.flintparticles.common.particles.*; import org.flintparticles.common.emitters.*; public class Lifetime extends InitializerBase { private var _max:Number; private var _min:Number; public function Lifetime(minLifetime:Number, maxLifetime:Number=NaN){ super(); _max = maxLifetime; _min = minLifetime; } public function get lifetime():Number{ return (((_min == _max)) ? _min : ((_max + _min) * 0.5)); } public function get maxLifetime():Number{ return (_max); } override public function initialize(emitter:Emitter, particle:Particle):void{ if (isNaN(_max)){ particle.lifetime = _min; } else { particle.lifetime = (_min + (Math.random() * (_max - _min))); }; } public function set lifetime(value:Number):void{ _max = (_min = value); } public function set minLifetime(value:Number):void{ _min = value; } public function set maxLifetime(value:Number):void{ _max = value; } public function get minLifetime():Number{ return (_min); } } }//package org.flintparticles.common.initializers
Section 190
//SharedImage (org.flintparticles.common.initializers.SharedImage) package org.flintparticles.common.initializers { import flash.display.*; import org.flintparticles.common.particles.*; import org.flintparticles.common.emitters.*; public class SharedImage extends InitializerBase { private var _image:DisplayObject; public function SharedImage(image:DisplayObject){ super(); _image = image; } override public function initialize(emitter:Emitter, particle:Particle):void{ particle.image = _image; } public function set image(value:DisplayObject):void{ _image = value; } public function get image():DisplayObject{ return (_image); } } }//package org.flintparticles.common.initializers
Section 191
//Particle (org.flintparticles.common.particles.Particle) package org.flintparticles.common.particles { import flash.geom.*; import flash.utils.*; public class Particle { public var energy:Number;// = 1 public var lifetime:Number;// = 0 public var scale:Number;// = 1 public var image;// = null public var color:uint;// = 4294967295 public var collisionRadius:Number;// = 1 private var _colorTransform:ColorTransform;// = null private var _previousColor:uint; public var isDead:Boolean;// = false public var mass:Number;// = 1 private var _dictionary:Dictionary;// = null public var age:Number;// = 0 public function Particle(){ super(); } public function get dictionary():Dictionary{ if (_dictionary == null){ _dictionary = new Dictionary(true); }; return (_dictionary); } public function get colorTransform():ColorTransform{ if (((!(_colorTransform)) || (!((_previousColor == color))))){ _colorTransform = new ColorTransform((((color >>> 16) & 0xFF) / 0xFF), (((color >>> 8) & 0xFF) / 0xFF), ((color & 0xFF) / 0xFF), (((color >>> 24) & 0xFF) / 0xFF), 0, 0, 0, 0); _previousColor = color; }; return (_colorTransform); } protected function cloneInto(p:Particle):Particle{ var key:Object; p.color = color; p.scale = scale; p.mass = mass; p.collisionRadius = collisionRadius; p.lifetime = lifetime; p.age = age; p.energy = energy; p.isDead = isDead; p.image = image; if (_dictionary){ p._dictionary = new Dictionary(true); for (key in _dictionary) { p._dictionary[key] = _dictionary[key]; }; }; return (p); } public function get alpha():Number{ return ((((color & 4278190080) >>> 24) / 0xFF)); } public function initialize():void{ color = 4294967295; scale = 1; mass = 1; collisionRadius = 1; lifetime = 0; age = 0; energy = 1; isDead = false; image = null; _dictionary = null; _colorTransform = null; } public function clone(factory:ParticleFactory=null):Particle{ var p:Particle; if (factory){ p = factory.createParticle(); } else { p = new Particle(); }; return (cloneInto(p)); } } }//package org.flintparticles.common.particles
Section 192
//ParticleFactory (org.flintparticles.common.particles.ParticleFactory) package org.flintparticles.common.particles { public interface ParticleFactory { function createParticle():Particle; function disposeParticle(C:\flashninjaclan\games\glasstower\GlassTower\development\src;org\flintparticles\common\particles;ParticleFactory.as:Particle):void; } }//package org.flintparticles.common.particles
Section 193
//Renderer (org.flintparticles.common.renderers.Renderer) package org.flintparticles.common.renderers { import org.flintparticles.common.emitters.*; public interface Renderer { function removeEmitter(:Emitter):void; function addEmitter(:Emitter):void; } }//package org.flintparticles.common.renderers
Section 194
//SpriteRendererBase (org.flintparticles.common.renderers.SpriteRendererBase) package org.flintparticles.common.renderers { import flash.events.*; import org.flintparticles.common.events.*; import flash.display.*; import org.flintparticles.common.particles.*; import org.flintparticles.common.emitters.*; public class SpriteRendererBase extends Sprite implements Renderer { protected var _emitters:Array; public function SpriteRendererBase(){ super(); _emitters = new Array(); mouseEnabled = false; mouseChildren = false; addEventListener(Event.ADDED_TO_STAGE, addedToStage, false, 0, true); } private function particleAdded(ev:ParticleEvent):void{ addParticle(ev.particle); if (stage){ stage.invalidate(); }; } private function addedToStage(ev:Event):void{ if (stage){ stage.invalidate(); }; } public function get emitters():Array{ return (_emitters); } protected function addParticle(particle:Particle):void{ } private function updateParticles(ev:Event):void{ var particles:Array = new Array(); var i:int; while (i < _emitters.length) { particles = particles.concat(_emitters[i].particles); i++; }; renderParticles(particles); } private function emitterUpdated(ev:EmitterEvent):void{ if (stage){ stage.invalidate(); }; } public function removeEmitter(emitter:Emitter):void{ var p:Particle; var i:int; while (i < _emitters.length) { if (_emitters[i] == emitter){ _emitters.splice(i, 1); emitter.removeEventListener(EmitterEvent.EMITTER_UPDATED, emitterUpdated); emitter.removeEventListener(ParticleEvent.PARTICLE_CREATED, particleAdded); emitter.removeEventListener(ParticleEvent.PARTICLE_ADDED, particleAdded); emitter.removeEventListener(ParticleEvent.PARTICLE_DEAD, particleRemoved); for each (p in emitter.particles) { removeParticle(p); }; if (_emitters.length == 0){ removeEventListener(Event.RENDER, updateParticles); renderParticles([]); } else { stage.invalidate(); }; return; }; i++; }; } protected function renderParticles(particles:Array):void{ } protected function removeParticle(particle:Particle):void{ } private function particleRemoved(ev:ParticleEvent):void{ removeParticle(ev.particle); if (stage){ stage.invalidate(); }; } public function addEmitter(emitter:Emitter):void{ var p:Particle; _emitters.push(emitter); if (stage){ stage.invalidate(); }; emitter.addEventListener(EmitterEvent.EMITTER_UPDATED, emitterUpdated, false, 0, true); emitter.addEventListener(ParticleEvent.PARTICLE_CREATED, particleAdded, false, 0, true); emitter.addEventListener(ParticleEvent.PARTICLE_ADDED, particleAdded, false, 0, true); emitter.addEventListener(ParticleEvent.PARTICLE_DEAD, particleRemoved, false, 0, true); for each (p in emitter.particles) { addParticle(p); }; if (_emitters.length == 1){ addEventListener(Event.RENDER, updateParticles, false, 0, true); }; } } }//package org.flintparticles.common.renderers
Section 195
//FrameUpdater (org.flintparticles.common.utils.FrameUpdater) package org.flintparticles.common.utils { import flash.events.*; import org.flintparticles.common.events.*; import flash.display.*; import flash.utils.*; public class FrameUpdater extends EventDispatcher { private var _shape:Shape; private var _time:Number; private static var _instance:FrameUpdater; public function FrameUpdater(){ super(); _shape = new Shape(); _shape.addEventListener(Event.ENTER_FRAME, frameUpdate, false, 0, true); _time = getTimer(); } private function frameUpdate(ev:Event):void{ var oldTime:int = _time; _time = getTimer(); var frameTime:Number = ((_time - oldTime) * 0.001); dispatchEvent(new UpdateEvent(UpdateEvent.UPDATE, frameTime)); } public static function get instance():FrameUpdater{ if (_instance == null){ _instance = new (FrameUpdater); }; return (_instance); } } }//package org.flintparticles.common.utils
Section 196
//interpolateColors (org.flintparticles.common.utils.interpolateColors) package org.flintparticles.common.utils { public function interpolateColors(color1:uint, color2:uint, ratio:Number):uint{ var inv:Number = (1 - ratio); var red:uint = Math.round(((((color1 >>> 16) & 0xFF) * ratio) + (((color2 >>> 16) & 0xFF) * inv))); var green:uint = Math.round(((((color1 >>> 8) & 0xFF) * ratio) + (((color2 >>> 8) & 0xFF) * inv))); var blue:uint = Math.round((((color1 & 0xFF) * ratio) + ((color2 & 0xFF) * inv))); var alpha:uint = Math.round(((((color1 >>> 24) & 0xFF) * ratio) + (((color2 >>> 24) & 0xFF) * inv))); return (((((alpha << 24) | (red << 16)) | (green << 8)) | blue)); } }//package org.flintparticles.common.utils
Section 197
//Maths (org.flintparticles.common.utils.Maths) package org.flintparticles.common.utils { public class Maths { private static const DEGTORAD:Number = 0.0174532925199433; private static const RADTODEG:Number = 57.2957795130823; public function Maths(){ super(); } public static function asRadians(degrees:Number):Number{ return ((degrees * DEGTORAD)); } public static function asDegrees(radians:Number):Number{ return ((radians * RADTODEG)); } } }//package org.flintparticles.common.utils
Section 198
//PriorityArray (org.flintparticles.common.utils.PriorityArray) package org.flintparticles.common.utils { import flash.utils.*; public class PriorityArray extends Proxy { private var _values:Array; public function PriorityArray(){ super(); _values = new Array(); } public function remove(value):Boolean{ var i:uint = _values.length; while (i--) { if (_values[i].value == value){ _values.splice(i, 1); return (true); }; }; return (false); } override "http://www.adobe.com/2006/actionscript/flash/proxy"?? function nextName(index:int):String{ return ((index - 1).toString()); } override "http://www.adobe.com/2006/actionscript/flash/proxy"?? function setProperty(name, value):void{ var index:uint = uint(name); if ((((index == name)) && ((index < _values.length)))){ _values[index].value = value; }; } public function add(value, priority:Number):uint{ var len:uint = _values.length; var i:uint; while (i < len) { if (_values[i].priority < priority){ break; }; i++; }; _values.splice(i, 0, new Pair(priority, value)); return (_values.length); } override "http://www.adobe.com/2006/actionscript/flash/proxy"?? function getProperty(name){ var index:int = int(name); if ((((((index == name)) && ((index < _values.length)))) && (_values[index]))){ return (_values[index].value); }; return (undefined); } public function clear():void{ _values.length = 0; } override "http://www.adobe.com/2006/actionscript/flash/proxy"?? function nextNameIndex(index:int):int{ if (index < _values.length){ return ((index + 1)); }; return (0); } public function get length():uint{ return (_values.length); } public function removeAt(index:uint){ var temp:* = _values[index].value; _values.splice(index, 1); return (temp); } override "http://www.adobe.com/2006/actionscript/flash/proxy"?? function nextValue(index:int){ return (_values[(index - 1)].value); } public function contains(value):Boolean{ var i:uint = _values.length; while (i--) { if (_values[i].value == value){ return (true); }; }; return (false); } } }//package org.flintparticles.common.utils class Pair { private var value; private var priority:Number; private function Pair(priority:Number, value){ super(); this.priority = priority; this.value = value; } }
Section 199
//LinearDrag (org.flintparticles.twoD.actions.LinearDrag) package org.flintparticles.twoD.actions { import org.flintparticles.common.actions.*; import org.flintparticles.common.particles.*; import org.flintparticles.common.emitters.*; import org.flintparticles.twoD.particles.*; public class LinearDrag extends ActionBase { private var _drag:Number; public function LinearDrag(drag:Number){ super(); _drag = drag; } public function get drag():Number{ return (_drag); } public function set drag(value:Number):void{ _drag = value; } override public function update(emitter:Emitter, particle:Particle, time:Number):void{ var p:Particle2D; p = Particle2D(particle); var scale:Number = (1 - ((_drag * time) / p.mass)); if (scale < 0){ p.velX = 0; p.velY = 0; } else { p.velX = (p.velX * scale); p.velY = (p.velY * scale); }; } } }//package org.flintparticles.twoD.actions
Section 200
//Move (org.flintparticles.twoD.actions.Move) package org.flintparticles.twoD.actions { import org.flintparticles.common.actions.*; import org.flintparticles.common.particles.*; import org.flintparticles.common.emitters.*; import org.flintparticles.twoD.particles.*; public class Move extends ActionBase { private var p:Particle2D; public function Move(){ super(); } override public function getDefaultPriority():Number{ return (-10); } override public function update(emitter:Emitter, particle:Particle, time:Number):void{ p = Particle2D(particle); p.x = (p.x + (p.velX * time)); p.y = (p.y + (p.velY * time)); } } }//package org.flintparticles.twoD.actions
Section 201
//RandomDrift (org.flintparticles.twoD.actions.RandomDrift) package org.flintparticles.twoD.actions { import org.flintparticles.common.actions.*; import org.flintparticles.common.particles.*; import org.flintparticles.common.emitters.*; import org.flintparticles.twoD.particles.*; public class RandomDrift extends ActionBase { private var _sizeX:Number; private var _sizeY:Number; public function RandomDrift(sizeX:Number, sizeY:Number){ super(); _sizeX = (sizeX * 2); _sizeY = (sizeY * 2); } override public function update(emitter:Emitter, particle:Particle, time:Number):void{ var p:Particle2D = Particle2D(particle); p.velX = (p.velX + (((Math.random() - 0.5) * _sizeX) * time)); p.velY = (p.velY + (((Math.random() - 0.5) * _sizeY) * time)); } public function get driftY():Number{ return ((_sizeY / 2)); } public function set driftY(value:Number):void{ _sizeY = (value * 2); } public function set driftX(value:Number):void{ _sizeX = (value * 2); } public function get driftX():Number{ return ((_sizeX / 2)); } } }//package org.flintparticles.twoD.actions
Section 202
//RotateToDirection (org.flintparticles.twoD.actions.RotateToDirection) package org.flintparticles.twoD.actions { import org.flintparticles.common.actions.*; import org.flintparticles.common.particles.*; import org.flintparticles.common.emitters.*; import org.flintparticles.twoD.particles.*; public class RotateToDirection extends ActionBase { public function RotateToDirection(){ super(); } override public function update(emitter:Emitter, particle:Particle, time:Number):void{ var p:Particle2D = Particle2D(particle); p.rotation = Math.atan2(p.velY, p.velX); } } }//package org.flintparticles.twoD.actions
Section 203
//Emitter2D (org.flintparticles.twoD.emitters.Emitter2D) package org.flintparticles.twoD.emitters { import org.flintparticles.common.particles.*; import org.flintparticles.common.emitters.*; import org.flintparticles.twoD.particles.*; import org.flintparticles.common.utils.*; public class Emitter2D extends Emitter { protected var _y:Number;// = 0 public var spaceSort:Boolean;// = false public var spaceSortedX:Array; protected var _x:Number;// = 0 protected var _rotation:Number;// = 0 protected static var _creator:ParticleCreator2D = new ParticleCreator2D(); public function Emitter2D(){ super(); _particleFactory = _creator; } public function get y():Number{ return (_y); } override protected function initParticle(particle:Particle):void{ var p:Particle2D; p = Particle2D(particle); p.x = _x; p.y = _y; p.rotation = _rotation; } override protected function sortParticles():void{ var len:int; var i:int; if (spaceSort){ spaceSortedX = _particles.sortOn("x", (Array.NUMERIC | Array.RETURNINDEXEDARRAY)); len = _particles.length; i = 0; while (i < len) { _particles[spaceSortedX[i]].sortID = i; i++; }; }; } public function set x(value:Number):void{ _x = value; } public function set rotRadians(value:Number):void{ _rotation = value; } public function get x():Number{ return (_x); } public function get rotRadians():Number{ return (_rotation); } public function set rotation(value:Number):void{ _rotation = Maths.asRadians(value); } public function get rotation():Number{ return (Maths.asDegrees(_rotation)); } public function set y(value:Number):void{ _y = value; } public static function get defaultParticleFactory():ParticleFactory{ return (_creator); } } }//package org.flintparticles.twoD.emitters
Section 204
//Velocity (org.flintparticles.twoD.initializers.Velocity) package org.flintparticles.twoD.initializers { import org.flintparticles.common.initializers.*; import org.flintparticles.common.particles.*; import org.flintparticles.common.emitters.*; import flash.geom.*; import org.flintparticles.twoD.particles.*; import org.flintparticles.twoD.zones.*; public class Velocity extends InitializerBase { private var _zone:Zone2D; public function Velocity(zone:Zone2D){ super(); _zone = zone; } override public function initialize(emitter:Emitter, particle:Particle):void{ var p:Particle2D; var sin:Number; var cos:Number; p = Particle2D(particle); var loc:Point = _zone.getLocation(); if (p.rotation == 0){ p.velX = loc.x; p.velY = loc.y; } else { sin = Math.sin(p.rotation); cos = Math.cos(p.rotation); p.velX = ((cos * loc.x) - (sin * loc.y)); p.velY = ((cos * loc.y) + (sin * loc.x)); }; } public function set zone(value:Zone2D):void{ _zone = value; } public function get zone():Zone2D{ return (_zone); } } }//package org.flintparticles.twoD.initializers
Section 205
//Particle2D (org.flintparticles.twoD.particles.Particle2D) package org.flintparticles.twoD.particles { import org.flintparticles.common.particles.*; import flash.geom.*; public class Particle2D extends Particle { public var sortID:int;// = -1 private var _inertia:Number; public var velY:Number;// = 0 private var _previousRadius:Number; private var _previousMass:Number; public var angVelocity:Number;// = 0 public var x:Number;// = 0 public var y:Number;// = 0 public var velX:Number;// = 0 public var rotation:Number;// = 0 public function Particle2D(){ super(); } override public function clone(factory:ParticleFactory=null):Particle{ var p:Particle2D; if (factory){ p = (factory.createParticle() as Particle2D); } else { p = new Particle2D(); }; cloneInto(p); p.x = x; p.y = y; p.velX = velX; p.velY = velY; p.rotation = rotation; p.angVelocity = angVelocity; return (p); } override public function initialize():void{ super.initialize(); x = 0; y = 0; velX = 0; velY = 0; rotation = 0; angVelocity = 0; sortID = -1; } public function get matrixTransform():Matrix{ var cos:Number = (scale * Math.cos(rotation)); var sin:Number = (scale * Math.sin(rotation)); return (new Matrix(cos, sin, -(sin), cos, x, y)); } public function get inertia():Number{ if (((!((mass == _previousMass))) || (!((collisionRadius == _previousRadius))))){ _inertia = (((mass * collisionRadius) * collisionRadius) * 0.5); _previousMass = mass; _previousRadius = collisionRadius; }; return (_inertia); } } }//package org.flintparticles.twoD.particles
Section 206
//ParticleCreator2D (org.flintparticles.twoD.particles.ParticleCreator2D) package org.flintparticles.twoD.particles { import org.flintparticles.common.particles.*; public class ParticleCreator2D implements ParticleFactory { private var _particles:Array; public function ParticleCreator2D(){ super(); _particles = new Array(); } public function clearAllParticles():void{ _particles = new Array(); } public function disposeParticle(particle:Particle):void{ if ((particle is Particle2D)){ particle.initialize(); _particles.push(particle); }; } public function createParticle():Particle{ if (_particles.length){ return (_particles.pop()); }; return (new Particle2D()); } } }//package org.flintparticles.twoD.particles
Section 207
//BitmapRenderer (org.flintparticles.twoD.renderers.BitmapRenderer) package org.flintparticles.twoD.renderers { import flash.display.*; import flash.geom.*; import flash.filters.*; import org.flintparticles.twoD.particles.*; import org.flintparticles.common.renderers.*; public class BitmapRenderer extends SpriteRendererBase { protected var _preFilters:Array; protected var _bitmap:Bitmap; protected var _bitmapData:BitmapData; protected var _colorMap:Array; protected var _smoothing:Boolean; protected var _canvas:Rectangle; protected var _postFilters:Array; protected static var ZERO_POINT:Point = new Point(0, 0); public function BitmapRenderer(canvas:Rectangle, smoothing:Boolean=false){ super(); mouseEnabled = false; mouseChildren = false; _smoothing = smoothing; _preFilters = new Array(); _postFilters = new Array(); _canvas = canvas; createBitmap(); } public function addFilter(filter:BitmapFilter, postRender:Boolean=false):void{ if (postRender){ _postFilters.push(filter); } else { _preFilters.push(filter); }; } protected function createBitmap():void{ if (!_canvas){ return; }; if (((_bitmap) && (_bitmapData))){ _bitmapData.dispose(); _bitmapData = null; }; if (_bitmap){ removeChild(_bitmap); }; _bitmap = new Bitmap(null, "auto", _smoothing); _bitmapData = new BitmapData(_canvas.width, _canvas.height, true, 0); _bitmap.bitmapData = _bitmapData; addChild(_bitmap); _bitmap.x = _canvas.x; _bitmap.y = _canvas.y; } public function clearPaletteMap():void{ _colorMap = null; } public function get canvas():Rectangle{ return (_canvas); } public function removeFilter(filter:BitmapFilter):void{ var i:int; while (i < _preFilters.length) { if (_preFilters[i] == filter){ _preFilters.splice(i, 1); return; }; i++; }; i = 0; while (i < _postFilters.length) { if (_postFilters[i] == filter){ _postFilters.splice(i, 1); return; }; i++; }; } public function set canvas(value:Rectangle):void{ _canvas = value; createBitmap(); } protected function drawParticle(particle:Particle2D):void{ var matrix:Matrix; matrix = particle.matrixTransform; matrix.translate(-(_canvas.x), -(_canvas.y)); _bitmapData.draw(particle.image, matrix, particle.colorTransform, DisplayObject(particle.image).blendMode, null, _smoothing); } public function setPaletteMap(red:Array=null, green:Array=null, blue:Array=null, alpha:Array=null):void{ _colorMap = new Array(4); _colorMap[0] = alpha; _colorMap[1] = red; _colorMap[2] = green; _colorMap[3] = blue; } public function get bitmapData():BitmapData{ return (_bitmapData); } override protected function renderParticles(particles:Array):void{ var i:int; var len:int; if (!_bitmap){ return; }; _bitmapData.lock(); len = _preFilters.length; i = 0; while (i < len) { _bitmapData.applyFilter(_bitmapData, _bitmapData.rect, BitmapRenderer.ZERO_POINT, _preFilters[i]); i++; }; if ((((len == 0)) && ((_postFilters.length == 0)))){ _bitmapData.fillRect(_bitmap.bitmapData.rect, 0); }; len = particles.length; if (len){ i = len; while (i--) { drawParticle(particles[i]); }; }; len = _postFilters.length; i = 0; while (i < len) { _bitmapData.applyFilter(_bitmapData, _bitmapData.rect, BitmapRenderer.ZERO_POINT, _postFilters[i]); i++; }; if (_colorMap){ _bitmapData.paletteMap(_bitmapData, _bitmapData.rect, ZERO_POINT, _colorMap[1], _colorMap[2], _colorMap[3], _colorMap[0]); }; _bitmapData.unlock(); } } }//package org.flintparticles.twoD.renderers
Section 208
//DiscZone (org.flintparticles.twoD.zones.DiscZone) package org.flintparticles.twoD.zones { import flash.geom.*; public class DiscZone implements Zone2D { private var _innerRadius:Number; private var _outerRadius:Number; private var _center:Point; private var _innerSq:Number; private var _outerSq:Number; private static const TWOPI:Number = 6.28318530717959; public function DiscZone(center:Point, outerRadius:Number, innerRadius:Number=0){ super(); if (outerRadius < innerRadius){ throw (new Error((((("The outerRadius (" + outerRadius) + ") can't be smaller than the innerRadius (") + innerRadius) + ") in your DiscZone. N.B. the outerRadius is the second argument in the constructor and the innerRadius is the third argument."))); }; _center = center; _innerRadius = innerRadius; _outerRadius = outerRadius; _innerSq = (_innerRadius * _innerRadius); _outerSq = (_outerRadius * _outerRadius); } public function set outerRadius(value:Number):void{ _outerRadius = value; _outerSq = (_outerRadius * _outerRadius); } public function get center():Point{ return (_center); } public function getArea():Number{ return ((Math.PI * (_outerSq - _innerSq))); } public function getLocation():Point{ var rand:Number = Math.random(); var point:Point = Point.polar((_innerRadius + ((1 - (rand * rand)) * (_outerRadius - _innerRadius))), (Math.random() * TWOPI)); point.x = (point.x + _center.x); point.y = (point.y + _center.y); return (point); } public function get outerRadius():Number{ return (_outerRadius); } public function get innerRadius():Number{ return (_innerRadius); } public function set innerRadius(value:Number):void{ _innerRadius = value; _innerSq = (_innerRadius * _innerRadius); } public function set center(value:Point):void{ _center = value; } public function contains(x:Number, y:Number):Boolean{ x = (x - _center.x); y = (y - _center.y); var distSq:Number = ((x * x) + (y * y)); return ((((distSq <= _outerSq)) && ((distSq >= _innerSq)))); } } }//package org.flintparticles.twoD.zones
Section 209
//Zone2D (org.flintparticles.twoD.zones.Zone2D) package org.flintparticles.twoD.zones { import flash.geom.*; public interface Zone2D { function getArea():Number; function getLocation():Point; function contains(_arg1:Number, _arg2:Number):Boolean; } }//package org.flintparticles.twoD.zones
Section 210
//Main (Main) package { import flash.events.*; import framework.Widgets.*; import Core.Screens.*; import flash.utils.*; public dynamic class Main extends Root { private var helpScreen:HelpScreen; private var _levels:SelectLevel; private var time:Number; private var menu:MainMenu; private var prevTime:Number;// = 0 private var board:Board; private var fps:Number; private static var m_isUpdateOn:Boolean; public function Main():void{ super(); m_isUpdateOn = true; if (stage){ init(); } else { addEventListener(Event.ADDED_TO_STAGE, init); }; } public function removeBoard():void{ WidgetManager.instance.removeWidget(board); } public function removeMenu():void{ menu.clear(); WidgetManager.instance.removeWidget(menu); } private function update(nTime:Number):void{ WidgetManager.instance.update(nTime); } public function initMenu():void{ menu = new MainMenu(this); WidgetManager.instance.addWidget(menu); } private function init(e:Event=null):void{ removeEventListener(Event.ADDED_TO_STAGE, init); WidgetManager.instance.SetParent(this); stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMove); stage.addEventListener(MouseEvent.MOUSE_DOWN, mouseDown); stage.addEventListener(MouseEvent.MOUSE_UP, mouseUp); stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDown); this.addEventListener(Event.ENTER_FRAME, enterFrame); initMenu(); } public function mouseMove(evt:MouseEvent):void{ if (board != null){ }; } public function removeHelp():void{ removeChild(helpScreen); helpScreen = null; initMenu(); } public function removeLevel():void{ WidgetManager.instance.removeWidget(_levels); } public function keyDown(evt:KeyboardEvent):void{ if (board != null){ board.keyDown(evt); }; } public function initLevelSel():void{ _levels = new SelectLevel(this); WidgetManager.instance.addWidget(_levels); } public function mouseDown(evt:MouseEvent):void{ if (board != null){ }; } public function mouseUp(evt:MouseEvent):void{ if (board != null){ }; } public function initHelp():void{ helpScreen = new HelpScreen(this); addChild(helpScreen); } public function enterFrame(evt:Event):void{ time = getTimer(); fps = ((time - prevTime) / 100); prevTime = getTimer(); update(fps); } public function initBoard(n:int):void{ board = new Board(this, n); board.theParent = this; WidgetManager.instance.addWidget(board); } public function initBoard1(n:int):void{ board = new Board(this, n); board.theParent = this; WidgetManager.instance.addWidget(board); } } }//package
Section 211
//Preloader (Preloader) package { import flash.events.*; import flash.display.*; import flash.text.*; import mochi.as3.*; import flash.utils.*; public dynamic class Preloader extends MovieClip { private var txt:TextField; public function Preloader(){ super(); MochiServices.connect("955eda859fb59bde", root); MochiAd.showPreGameAd({clip:root, id:"955eda859fb59bde", res:"520x520"}); var fmt:TextFormat = new TextFormat("Tahoma", 9, 0xFFFFFF); txt = new TextField(); txt.text = "Loading..."; txt.setTextFormat(fmt); txt.textColor = 0xFFFFFF; txt.x = ((540 / 2) - (txt.width / 2)); txt.y = ((590 / 2) - (txt.height / 2)); addChild(txt); addEventListener(Event.ENTER_FRAME, checkFrame); } private function startup():void{ var mainClass:Class = (getDefinitionByName("Main") as Class); addChild((new (mainClass) as DisplayObject)); } private function checkFrame(e:Event):void{ if (currentFrame == totalFrames){ removeEventListener(Event.ENTER_FRAME, checkFrame); removeChild(txt); startup(); }; } } }//package

Library Items

Symbol 1 BitmapUsed by:2 32 38
Symbol 2 GraphicUses:1Used by:3
Symbol 3 MovieClip {Core.BlueRotated} [blue_rotated]Uses:2
Symbol 4 BitmapUsed by:5
Symbol 5 GraphicUses:4Used by:6
Symbol 6 MovieClip {Core.StaticBox} [static_box]Uses:5
Symbol 7 BitmapUsed by:8 13
Symbol 8 GraphicUses:7Used by:9
Symbol 9 MovieClip {Core.RedBox} [lila_box]Uses:8
Symbol 10 BitmapUsed by:11
Symbol 11 GraphicUses:10Used by:12
Symbol 12 MovieClip {Core.TBoxB} [blue_boxt]Uses:11Used by:23
Symbol 13 GraphicUses:7Used by:14
Symbol 14 MovieClip {Core.RedRotated} [lila_rotated]Uses:13
Symbol 15 BitmapUsed by:16
Symbol 16 GraphicUses:15Used by:17
Symbol 17 MovieClip {Core.CrossBox} [cross_box]Uses:16
Symbol 18 BitmapUsed by:19 24
Symbol 19 GraphicUses:18Used by:20
Symbol 20 MovieClip {Core.TBoxR} [red_boxt]Uses:19
Symbol 21 GraphicUsed by:22
Symbol 22 MovieClip {Core.Halter} [halter]Uses:21
Symbol 23 MovieClip {Core.TBoxBR} [blue_boxt_r]Uses:12
Symbol 24 GraphicUses:18Used by:25
Symbol 25 MovieClip {Core.TBoxRR} [red_boxt_r]Uses:24
Symbol 26 BitmapUsed by:27
Symbol 27 GraphicUses:26Used by:28
Symbol 28 MovieClip {Core.CrossBoxR} [cross_boxr]Uses:27
Symbol 29 Sound {Core.Resourcen_SOUND_MUSIC} [music5]
Symbol 30 Sound {Core.Resourcen_SOUND_MENUCOM} [menucom]
Symbol 31 Sound {Core.Resourcen_SOUND_EXPLODE} [SOUND_GLASS]
Symbol 32 GraphicUses:1Used by:33
Symbol 33 MovieClip {Core.Resourcen_MC_BLUE_BOX} [blue_box]Uses:32
Symbol 34 Sound {Core.Resourcen_SOUND_CLICK} [button_click]
Symbol 35 Sound {Core.Resourcen_SOUND_MUSIC3} [music3]
Symbol 36 Sound {Core.Resourcen_SOUND_MUSIC4} [music4]
Symbol 37 Sound {Core.Resourcen_SOUND_MUSIC2} [music2]
Symbol 38 GraphicUses:1Used by:39
Symbol 39 MovieClip {Core.Glass} [glass]Uses:38
Symbol 40 Bitmap {Core.Resourcen_IMAGE_TUTORIAL}
Symbol 41 Bitmap {Core.Resourcen_IMAGE_20}
Symbol 42 Bitmap {Core.Resourcen_IMAGE_BACK}
Symbol 43 Bitmap {Core.Resourcen_LEVEL_PANE}
Symbol 44 Bitmap {Core.Resourcen_IMAGE_BACK2}
Symbol 45 Bitmap {Core.Resourcen_fln}
Symbol 46 Bitmap {Core.Resourcen_IMAGE_BACK4}
Symbol 47 Bitmap {Core.Resourcen_IMAGE_BACK3}
Symbol 48 Bitmap {Core.Resourcen_LEVEL_BACK}
Symbol 49 Bitmap {Core.Resourcen_IMAGE_MENU_BACK}
Symbol 50 Bitmap {Core.Resourcen_IMAGE_BUTTON_OK}
Symbol 51 Bitmap {Core.Resourcen_IMAGE_BULLET}
Symbol 52 Bitmap {Core.Resourcen_IMAGE_LOGO}
Symbol 53 Bitmap {Core.Resourcen_IMAGE_GAME_OVER}
Symbol 54 Bitmap {Core.Resourcen_IMAGE_BUTTON_NEXT}
Symbol 55 Bitmap {Core.Resourcen_IMAGE_LEVCOMP_DIALOG}
Symbol 56 Bitmap {Core.Resourcen_IMAGE_BUTTON_HELP}
Symbol 57 Bitmap {Core.Resourcen_IMAGE_10}
Symbol 58 Bitmap {Core.Resourcen_IMAGE_BLOB}
Symbol 59 Bitmap {Core.Resourcen_BUTTON_LEVEL_INACTIVE}
Symbol 60 Bitmap {Core.Resourcen_BUTTON_LEVEL_ACTIVE}
Symbol 61 Bitmap {Core.Resourcen_IMAGE_BUTTON_SETTINGS}
Symbol 62 Bitmap {Core.Resourcen_IMAGE_BUTTON_PLAY}
Symbol 63 Bitmap {Core.Resourcen_IMAGE_HISCORES}
Symbol 64 Bitmap {Core.Resourcen_IMAGE_HELPBACK}
Symbol 65 Bitmap {Core.Resourcen_IMAGE_BUTTON_BACK}

Special Tags

FileAttributes (69)Timeline Frame 1Access network only, Metadata present, AS3.
SWFMetaData (77)Timeline Frame 1459 bytes "<rdf:RDF xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'><rdf:Description rdf:about='' xmlns ..."
ScriptLimits (65)Timeline Frame 1MaxRecursionDepth: 1000, ScriptTimeout: 60 seconds
ExportAssets (56)Timeline Frame 2Symbol 3 as "blue_rotated"
ExportAssets (56)Timeline Frame 2Symbol 6 as "static_box"
ExportAssets (56)Timeline Frame 2Symbol 9 as "lila_box"
ExportAssets (56)Timeline Frame 2Symbol 12 as "blue_boxt"
ExportAssets (56)Timeline Frame 2Symbol 14 as "lila_rotated"
ExportAssets (56)Timeline Frame 2Symbol 17 as "cross_box"
ExportAssets (56)Timeline Frame 2Symbol 20 as "red_boxt"
ExportAssets (56)Timeline Frame 2Symbol 22 as "halter"
ExportAssets (56)Timeline Frame 2Symbol 23 as "blue_boxt_r"
ExportAssets (56)Timeline Frame 2Symbol 25 as "red_boxt_r"
ExportAssets (56)Timeline Frame 2Symbol 28 as "cross_boxr"
ExportAssets (56)Timeline Frame 2Symbol 29 as "music5"
ExportAssets (56)Timeline Frame 2Symbol 30 as "menucom"
ExportAssets (56)Timeline Frame 2Symbol 31 as "SOUND_GLASS"
ExportAssets (56)Timeline Frame 2Symbol 33 as "blue_box"
ExportAssets (56)Timeline Frame 2Symbol 34 as "button_click"
ExportAssets (56)Timeline Frame 2Symbol 35 as "music3"
ExportAssets (56)Timeline Frame 2Symbol 36 as "music4"
ExportAssets (56)Timeline Frame 2Symbol 37 as "music2"
ExportAssets (56)Timeline Frame 2Symbol 39 as "glass"
EnableDebugger2 (64)Timeline Frame 131 bytes "u.$1$cE$H7fUvUhZB5.0W554NuYka0."
DebugMX1 (63)Timeline Frame 1
SerialNumber (41)Timeline Frame 1

Labels

"Preloader"Frame 1
"start"Frame 2




http://swfchan.com/19/92958/info.shtml
Created: 27/3 -2019 04:49:00 Last modified: 27/3 -2019 04:49:00 Server time: 14/11 -2024 23:49:43