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.Common.Math.*;
import Box2D.Collision.*;
import Box2D.Common.*;
public class b2CircleShape extends b2Shape {
public var m_localPosition:b2Vec2;
public 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):Boolean{
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.x + ((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){
return (false);
};
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 (false);
};
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 (true);
};
return (false);
}
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((Math.min(p1X, p2X) - m_radius), (Math.min(p1Y, p2Y) - m_radius));
aabb.upperBound.Set((Math.max(p1X, p2X) + m_radius), (Math.max(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 public 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
//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 4
//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 5
//b2PolygonShape (Box2D.Collision.Shapes.b2PolygonShape)
package Box2D.Collision.Shapes {
import Box2D.Dynamics.*;
import Box2D.Common.Math.*;
import Box2D.Collision.*;
import Box2D.Common.*;
public class b2PolygonShape extends b2Shape {
public var m_coreVertices:Array;
public var m_vertices:Array;
private var s_supportVec:b2Vec2;
public var m_centroid:b2Vec2;
public var m_normals:Array;
public var m_obb:b2OBB;
public 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++;
};
}
public function GetCoreVertices():Array{
return (m_coreVertices);
}
public function GetVertices():Array{
return (m_vertices);
}
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(Math.min(aabb1.lowerBound.x, aabb2.lowerBound.x), Math.min(aabb1.lowerBound.y, aabb2.lowerBound.y));
aabb.upperBound.Set(Math.max(aabb1.upperBound.x, aabb2.upperBound.x), Math.max(aabb1.upperBound.y, aabb2.upperBound.y));
}
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):Boolean{
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) {
tX = (m_vertices[i].x - p1X);
tY = (m_vertices[i].y - p1Y);
tVec = m_normals[i];
numerator = ((tVec.x * tX) + (tVec.y * tY));
denominator = ((tVec.x * dX) + (tVec.y * dY));
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 (false);
};
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 (true);
};
return (false);
}
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:*;
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[(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 Support(xf:b2XForm, dX:Number, dY:Number):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;
var bestValue:Number = ((m_coreVertices[0].x * dLocalX) + (m_coreVertices[0].y * dLocalY));
var i = 1;
while (i < m_vertexCount) {
value = ((m_coreVertices[i].x * dLocalX) + (m_coreVertices[i].y * dLocalY));
if (value > bestValue){
bestIndex = i;
bestValue = value;
};
i++;
};
tMat = xf.R;
var tVec:b2Vec2 = 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);
}
override public function UpdateSweepRadius(center:b2Vec2):void{
var dX:Number;
var dY:Number;
m_sweepRadius = 0;
var i:int;
while (i < m_vertexCount) {
dX = (m_coreVertices[i].x - center.x);
dY = (m_coreVertices[i].y - center.y);
dX = Math.sqrt(((dX * dX) + (dY * dY)));
m_sweepRadius = Math.max(m_sweepRadius, dX);
i++;
};
}
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));
}
public function GetVertexCount():int{
return (m_vertexCount);
}
override public function TestPoint(xf:b2XForm, p:b2Vec2):Boolean{
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) {
tX = (pLocalX - m_vertices[i].x);
tY = (pLocalY - m_vertices[i].y);
dot = ((m_normals[i].x * tX) + (m_normals[i].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[(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);
}
public 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[(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));
lowerX = Math.min(lowerX, rX);
lowerY = Math.min(lowerY, rY);
upperX = Math.max(upperX, rX);
upperY = Math.max(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 6
//b2Shape (Box2D.Collision.Shapes.b2Shape)
package Box2D.Collision.Shapes {
import Box2D.Dynamics.*;
import Box2D.Common.Math.*;
import Box2D.Collision.*;
public class b2Shape {
public var m_next:b2Shape;
public var m_type:int;
public var m_restitution:Number;
public var m_sweepRadius:Number;
public var m_userData;
public var m_density:Number;
public var m_proxyId:uint;
public var m_friction:Number;
public var m_isSensor:Boolean;
public var m_groupIndex:int;
public var m_categoryBits:uint;
public var m_body:b2Body;
public var m_maskBits:uint;
public static const e_polygonShape:int = 1;
public static const e_unknownShape:int = -1;
public static const e_circleShape:int = 0;
public static const e_shapeTypeCount:int = 2;
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_proxyId = b2Pair.b2_nullProxy;
m_categoryBits = def.categoryBits;
m_maskBits = def.maskBits;
m_groupIndex = def.groupIndex;
m_isSensor = def.isSensor;
}
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 GetType():int{
return (m_type);
}
public function TestSegment(xf:b2XForm, lambda:Array, normal:b2Vec2, segment:b2Segment, maxLambda:Number):Boolean{
return (false);
}
public function IsSensor():Boolean{
return (m_isSensor);
}
public function ComputeMass(massData:b2MassData):void{
}
public function Synchronize(broadPhase:b2BroadPhase, transform1:b2XForm, transform2:b2XForm):Boolean{
if (m_proxyId == b2Pair.b2_nullProxy){
return (false);
};
var aabb:b2AABB = s_syncAABB;
ComputeSweptAABB(aabb, transform1, transform2);
if (broadPhase.InRange(aabb)){
broadPhase.MoveProxy(m_proxyId, aabb);
return (true);
};
return (false);
}
public function CreateProxy(broadPhase:b2BroadPhase, transform:b2XForm):void{
var aabb:b2AABB = s_proxyAABB;
ComputeAABB(aabb, transform);
var inRange:Boolean = broadPhase.InRange(aabb);
if (inRange){
m_proxyId = broadPhase.CreateProxy(aabb, this);
} else {
m_proxyId = b2Pair.b2_nullProxy;
};
}
public function DestroyProxy(broadPhase:b2BroadPhase){
if (m_proxyId != b2Pair.b2_nullProxy){
broadPhase.DestroyProxy(m_proxyId);
m_proxyId = b2Pair.b2_nullProxy;
};
}
public function UpdateSweepRadius(center:b2Vec2):void{
}
public function ComputeAABB(aabb:b2AABB, xf:b2XForm):void{
}
public function GetBody():b2Body{
return (m_body);
}
public function GetUserData(){
return (m_userData);
}
public function TestPoint(xf:b2XForm, p:b2Vec2):Boolean{
return (false);
}
public function ResetProxy(broadPhase:b2BroadPhase, transform:b2XForm):void{
if (m_proxyId != b2Pair.b2_nullProxy){
broadPhase.DestroyProxy(m_proxyId);
};
var aabb:b2AABB = s_resetAABB;
ComputeAABB(aabb, transform);
var inRange:Boolean = broadPhase.InRange(aabb);
if (inRange){
m_proxyId = broadPhase.CreateProxy(aabb, this);
} else {
m_proxyId = b2Pair.b2_nullProxy;
};
}
public static function Destroy(shape:b2Shape, allocator){
}
public 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 7
//b2ShapeDef (Box2D.Collision.Shapes.b2ShapeDef)
package Box2D.Collision.Shapes {
public class b2ShapeDef {
public var friction:Number;
public var groupIndex:int;
public var categoryBits:int;
public var density:Number;
public var restitution:Number;
public var maskBits:int;
public var userData;// = null
public var type:int;
public var isSensor:Boolean;
public function b2ShapeDef(){
super();
type = b2Shape.e_unknownShape;
userData = null;
friction = 0.2;
restitution = 0;
density = 0;
categoryBits = 1;
maskBits = 0xFFFF;
groupIndex = 0;
isSensor = false;
}
}
}//package Box2D.Collision.Shapes
Section 8
//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 9
//b2Bound (Box2D.Collision.b2Bound)
package Box2D.Collision {
public class b2Bound {
public var value:uint;
public var proxyId:uint;
public var stabbingCount:uint;
public function b2Bound(){
super();
}
public function Swap(b:b2Bound):void{
var tempValue:uint = value;
var tempProxyId:uint = proxyId;
var tempStabbingCount:uint = stabbingCount;
value = b.value;
proxyId = b.proxyId;
stabbingCount = b.stabbingCount;
b.value = tempValue;
b.proxyId = tempProxyId;
b.stabbingCount = tempStabbingCount;
}
public function IsLower():Boolean{
return (((value & 1) == 0));
}
public function IsUpper():Boolean{
return (((value & 1) == 1));
}
}
}//package Box2D.Collision
Section 10
//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 11
//b2BroadPhase (Box2D.Collision.b2BroadPhase)
package Box2D.Collision {
import Box2D.Common.Math.*;
import Box2D.Common.*;
public class b2BroadPhase {
public var m_bounds:Array;
public var m_quantizationFactor:b2Vec2;
public var m_worldAABB:b2AABB;
public var m_freeProxy:uint;
public var m_proxyCount:int;
public var m_proxyPool:Array;
public var m_queryResultCount:int;
public var m_pairManager:b2PairManager;
public var m_timeStamp:uint;
public 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;
var tProxy:b2Proxy;
var j:int;
m_pairManager = new b2PairManager();
m_proxyPool = new Array(b2Settings.b2_maxPairs);
m_bounds = new Array((2 * b2Settings.b2_maxProxies));
m_queryResults = new Array(b2Settings.b2_maxProxies);
m_quantizationFactor = new b2Vec2();
super();
m_pairManager.Initialize(this, callback);
m_worldAABB = worldAABB;
m_proxyCount = 0;
i = 0;
while (i < b2Settings.b2_maxProxies) {
m_queryResults[i] = 0;
i++;
};
m_bounds = new Array(2);
i = 0;
while (i < 2) {
m_bounds[i] = new Array((2 * b2Settings.b2_maxProxies));
j = 0;
while (j < (2 * b2Settings.b2_maxProxies)) {
m_bounds[i][j] = new b2Bound();
j++;
};
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);
i = 0;
while (i < (b2Settings.b2_maxProxies - 1)) {
tProxy = new b2Proxy();
m_proxyPool[i] = tProxy;
tProxy.SetNext((i + 1));
tProxy.timeStamp = 0;
tProxy.overlapCount = b2_invalid;
tProxy.userData = null;
i++;
};
tProxy = new b2Proxy();
m_proxyPool[(b2Settings.b2_maxProxies - 1)] = tProxy;
tProxy.SetNext(b2Pair.b2_nullProxy);
tProxy.timeStamp = 0;
tProxy.overlapCount = b2_invalid;
tProxy.userData = null;
m_freeProxy = 0;
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_proxyPool[m_queryResults[i]];
userData[i] = proxy.userData;
i++;
count++;
};
m_queryResultCount = 0;
IncrementTimeStamp();
return (count);
}
public function Commit():void{
m_pairManager.Commit();
}
public function GetProxy(proxyId:int):b2Proxy{
if ((((proxyId == b2Pair.b2_nullProxy)) || ((m_proxyPool[proxyId].IsValid() == false)))){
return (null);
};
return (m_proxyPool[proxyId]);
}
private function IncrementTimeStamp():void{
var i:uint;
if (m_timeStamp == b2Settings.USHRT_MAX){
i = 0;
while (i < b2Settings.b2_maxProxies) {
m_proxyPool[i].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 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) {
if (bounds[j].IsLower()){
IncrementOverlapCount(bounds[j].proxyId);
};
j++;
};
if (lowerQuery > 0){
i = (lowerQuery - 1);
s = bounds[i].stabbingCount;
while (s) {
if (bounds[i].IsLower()){
proxy = m_proxyPool[bounds[i].proxyId];
if (lowerQuery <= proxy.upperBounds[axis]){
IncrementOverlapCount(bounds[i].proxyId);
s--;
};
};
i--;
};
};
lowerQueryOut[0] = lowerQuery;
upperQueryOut[0] = upperQuery;
}
private function TestOverlapValidate(p1:b2Proxy, p2:b2Proxy):Boolean{
var bounds:Array;
var axis:int;
while (axis < 2) {
bounds = m_bounds[axis];
if (bounds[p1.lowerBounds[axis]].value > bounds[p2.upperBounds[axis]].value){
return (false);
};
if (bounds[p1.upperBounds[axis]].value < bounds[p2.lowerBounds[axis]].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):uint{
var index:uint;
var proxy:b2Proxy;
var bounds:Array;
var lowerIndex:uint;
var upperIndex:uint;
var lowerIndexOut:Array;
var upperIndexOut:Array;
var tArr:Array;
var j:int;
var tEnd:int;
var tBound1:b2Bound;
var tBound2:b2Bound;
var tIndex:int;
var proxy2:b2Proxy;
var proxyId:uint = m_freeProxy;
proxy = m_proxyPool[proxyId];
m_freeProxy = proxy.GetNext();
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];
tArr = new Array();
tEnd = (boundCount - upperIndex);
j = 0;
while (j < tEnd) {
tArr[j] = new b2Bound();
tBound1 = tArr[j];
tBound2 = bounds[(upperIndex + j)];
tBound1.value = tBound2.value;
tBound1.proxyId = tBound2.proxyId;
tBound1.stabbingCount = tBound2.stabbingCount;
j++;
};
tEnd = tArr.length;
tIndex = (upperIndex + 2);
j = 0;
while (j < tEnd) {
tBound2 = tArr[j];
tBound1 = bounds[(tIndex + j)];
tBound1.value = tBound2.value;
tBound1.proxyId = tBound2.proxyId;
tBound1.stabbingCount = tBound2.stabbingCount;
j++;
};
tArr = new Array();
tEnd = (upperIndex - lowerIndex);
j = 0;
while (j < tEnd) {
tArr[j] = new b2Bound();
tBound1 = tArr[j];
tBound2 = bounds[(lowerIndex + j)];
tBound1.value = tBound2.value;
tBound1.proxyId = tBound2.proxyId;
tBound1.stabbingCount = tBound2.stabbingCount;
j++;
};
tEnd = tArr.length;
tIndex = (lowerIndex + 1);
j = 0;
while (j < tEnd) {
tBound2 = tArr[j];
tBound1 = bounds[(tIndex + j)];
tBound1.value = tBound2.value;
tBound1.proxyId = tBound2.proxyId;
tBound1.stabbingCount = tBound2.stabbingCount;
j++;
};
upperIndex++;
bounds[lowerIndex].value = lowerValues[axis];
bounds[lowerIndex].proxyId = proxyId;
bounds[upperIndex].value = upperValues[axis];
bounds[upperIndex].proxyId = proxyId;
bounds[lowerIndex].stabbingCount = ((lowerIndex == 0)) ? 0 : bounds[(lowerIndex - 1)].stabbingCount;
bounds[upperIndex].stabbingCount = bounds[(upperIndex - 1)].stabbingCount;
index = lowerIndex;
while (index < upperIndex) {
bounds[index].stabbingCount++;
index++;
};
index = lowerIndex;
while (index < (boundCount + 2)) {
proxy2 = m_proxyPool[bounds[index].proxyId];
if (bounds[index].IsLower()){
proxy2.lowerBounds[axis] = index;
} else {
proxy2.upperBounds[axis] = index;
};
index++;
};
axis++;
};
m_proxyCount++;
var i:int;
while (i < m_queryResultCount) {
m_pairManager.AddBufferedPair(proxyId, m_queryResults[i]);
i++;
};
m_pairManager.Commit();
m_queryResultCount = 0;
IncrementTimeStamp();
return (proxyId);
}
public function DestroyProxy(proxyId:uint):void{
var bounds:Array;
var lowerIndex:uint;
var upperIndex:uint;
var lowerValue:uint;
var upperValue:uint;
var tArr:Array;
var j:int;
var tEnd:int;
var tBound1:b2Bound;
var tBound2:b2Bound;
var tIndex:int;
var index:uint;
var index2:int;
var proxy2:b2Proxy;
var proxy:b2Proxy = m_proxyPool[proxyId];
var boundCount:int = (2 * m_proxyCount);
var axis:int;
while (axis < 2) {
bounds = m_bounds[axis];
lowerIndex = proxy.lowerBounds[axis];
upperIndex = proxy.upperBounds[axis];
lowerValue = bounds[lowerIndex].value;
upperValue = bounds[upperIndex].value;
tArr = new Array();
tEnd = ((upperIndex - lowerIndex) - 1);
j = 0;
while (j < tEnd) {
tArr[j] = new b2Bound();
tBound1 = tArr[j];
tBound2 = bounds[((lowerIndex + 1) + j)];
tBound1.value = tBound2.value;
tBound1.proxyId = tBound2.proxyId;
tBound1.stabbingCount = tBound2.stabbingCount;
j++;
};
tEnd = tArr.length;
tIndex = lowerIndex;
j = 0;
while (j < tEnd) {
tBound2 = tArr[j];
tBound1 = bounds[(tIndex + j)];
tBound1.value = tBound2.value;
tBound1.proxyId = tBound2.proxyId;
tBound1.stabbingCount = tBound2.stabbingCount;
j++;
};
tArr = new Array();
tEnd = ((boundCount - upperIndex) - 1);
j = 0;
while (j < tEnd) {
tArr[j] = new b2Bound();
tBound1 = tArr[j];
tBound2 = bounds[((upperIndex + 1) + j)];
tBound1.value = tBound2.value;
tBound1.proxyId = tBound2.proxyId;
tBound1.stabbingCount = tBound2.stabbingCount;
j++;
};
tEnd = tArr.length;
tIndex = (upperIndex - 1);
j = 0;
while (j < tEnd) {
tBound2 = tArr[j];
tBound1 = bounds[(tIndex + j)];
tBound1.value = tBound2.value;
tBound1.proxyId = tBound2.proxyId;
tBound1.stabbingCount = tBound2.stabbingCount;
j++;
};
tEnd = (boundCount - 2);
index = lowerIndex;
while (index < tEnd) {
proxy2 = m_proxyPool[bounds[index].proxyId];
if (bounds[index].IsLower()){
proxy2.lowerBounds[axis] = index;
} else {
proxy2.upperBounds[axis] = index;
};
index++;
};
tEnd = (upperIndex - 1);
index2 = lowerIndex;
while (index2 < tEnd) {
bounds[index2].stabbingCount--;
index2++;
};
Query([0], [0], lowerValue, upperValue, bounds, (boundCount - 2), axis);
axis++;
};
var i:int;
while (i < m_queryResultCount) {
m_pairManager.RemoveBufferedPair(proxyId, 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.SetNext(m_freeProxy);
m_freeProxy = proxyId;
m_proxyCount--;
}
public function TestOverlap(b:b2BoundValues, p:b2Proxy):Boolean{
var bounds:Array;
var axis:int;
while (axis < 2) {
bounds = m_bounds[axis];
if (b.lowerValues[axis] > bounds[p.upperBounds[axis]].value){
return (false);
};
if (b.upperValues[axis] < bounds[p.lowerBounds[axis]].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(proxyId:uint):void{
var proxy:b2Proxy = m_proxyPool[proxyId];
if (proxy.timeStamp < m_timeStamp){
proxy.timeStamp = m_timeStamp;
proxy.overlapCount = 1;
} else {
proxy.overlapCount = 2;
m_queryResults[m_queryResultCount] = proxyId;
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 MoveProxy(proxyId:uint, aabb:b2AABB):void{
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 prevProxyId:uint;
var prevProxy:b2Proxy;
if ((((proxyId == b2Pair.b2_nullProxy)) || ((b2Settings.b2_maxProxies <= proxyId)))){
return;
};
if (aabb.IsValid() == false){
return;
};
var boundCount:uint = (2 * m_proxyCount);
var proxy:b2Proxy = m_proxyPool[proxyId];
var newValues:b2BoundValues = new b2BoundValues();
ComputeBounds(newValues.lowerValues, newValues.upperValues, aabb);
var oldValues:b2BoundValues = new b2BoundValues();
axis = 0;
while (axis < 2) {
oldValues.lowerValues[axis] = m_bounds[axis][proxy.lowerBounds[axis]].value;
oldValues.upperValues[axis] = m_bounds[axis][proxy.upperBounds[axis]].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];
deltaLower = (lowerValue - bounds[lowerIndex].value);
deltaUpper = (upperValue - bounds[upperIndex].value);
bounds[lowerIndex].value = lowerValue;
bounds[upperIndex].value = upperValue;
if (deltaLower < 0){
index = lowerIndex;
while ((((index > 0)) && ((lowerValue < bounds[(index - 1)].value)))) {
bound = bounds[index];
prevBound = bounds[(index - 1)];
prevProxyId = prevBound.proxyId;
prevProxy = m_proxyPool[prevBound.proxyId];
prevBound.stabbingCount++;
if (prevBound.IsUpper() == true){
if (TestOverlap(newValues, prevProxy)){
m_pairManager.AddBufferedPair(proxyId, prevProxyId);
};
var _local23 = prevProxy.upperBounds;
var _local24 = axis;
var _local25 = (_local23[_local24] + 1);
_local23[_local24] = _local25;
bound.stabbingCount++;
} else {
_local23 = prevProxy.lowerBounds;
_local24 = axis;
_local25 = (_local23[_local24] + 1);
_local23[_local24] = _local25;
bound.stabbingCount--;
};
_local23 = proxy.lowerBounds;
_local24 = axis;
_local25 = (_local23[_local24] - 1);
_local23[_local24] = _local25;
bound.Swap(prevBound);
index--;
};
};
if (deltaUpper > 0){
index = upperIndex;
while ((((index < (boundCount - 1))) && ((bounds[(index + 1)].value <= upperValue)))) {
bound = bounds[index];
nextBound = bounds[(index + 1)];
nextProxyId = nextBound.proxyId;
nextProxy = m_proxyPool[nextProxyId];
nextBound.stabbingCount++;
if (nextBound.IsLower() == true){
if (TestOverlap(newValues, nextProxy)){
m_pairManager.AddBufferedPair(proxyId, nextProxyId);
};
_local23 = nextProxy.lowerBounds;
_local24 = axis;
_local25 = (_local23[_local24] - 1);
_local23[_local24] = _local25;
bound.stabbingCount++;
} else {
_local23 = nextProxy.upperBounds;
_local24 = axis;
_local25 = (_local23[_local24] - 1);
_local23[_local24] = _local25;
bound.stabbingCount--;
};
_local23 = proxy.upperBounds;
_local24 = axis;
_local25 = (_local23[_local24] + 1);
_local23[_local24] = _local25;
bound.Swap(nextBound);
index++;
};
};
if (deltaLower > 0){
index = lowerIndex;
while ((((index < (boundCount - 1))) && ((bounds[(index + 1)].value <= lowerValue)))) {
bound = bounds[index];
nextBound = bounds[(index + 1)];
nextProxyId = nextBound.proxyId;
nextProxy = m_proxyPool[nextProxyId];
nextBound.stabbingCount--;
if (nextBound.IsUpper()){
if (TestOverlap(oldValues, nextProxy)){
m_pairManager.RemoveBufferedPair(proxyId, nextProxyId);
};
_local23 = nextProxy.upperBounds;
_local24 = axis;
_local25 = (_local23[_local24] - 1);
_local23[_local24] = _local25;
bound.stabbingCount--;
} else {
_local23 = nextProxy.lowerBounds;
_local24 = axis;
_local25 = (_local23[_local24] - 1);
_local23[_local24] = _local25;
bound.stabbingCount++;
};
_local23 = proxy.lowerBounds;
_local24 = axis;
_local25 = (_local23[_local24] + 1);
_local23[_local24] = _local25;
bound.Swap(nextBound);
index++;
};
};
if (deltaUpper < 0){
index = upperIndex;
while ((((index > 0)) && ((upperValue < bounds[(index - 1)].value)))) {
bound = bounds[index];
prevBound = bounds[(index - 1)];
prevProxyId = prevBound.proxyId;
prevProxy = m_proxyPool[prevProxyId];
prevBound.stabbingCount--;
if (prevBound.IsLower() == true){
if (TestOverlap(oldValues, prevProxy)){
m_pairManager.RemoveBufferedPair(proxyId, prevProxyId);
};
_local23 = prevProxy.lowerBounds;
_local24 = axis;
_local25 = (_local23[_local24] + 1);
_local23[_local24] = _local25;
bound.stabbingCount--;
} else {
_local23 = prevProxy.upperBounds;
_local24 = axis;
_local25 = (_local23[_local24] + 1);
_local23[_local24] = _local25;
bound.stabbingCount++;
};
_local23 = proxy.upperBounds;
_local24 = axis;
_local25 = (_local23[_local24] - 1);
_local23[_local24] = _local25;
bound.Swap(prevBound);
index--;
};
};
axis++;
};
}
public static function BinarySearch(bounds:Array, count:int, value:uint):uint{
var mid:int;
var low:int;
var high:int = (count - 1);
while (low <= high) {
mid = ((low + high) / 2);
if (bounds[mid].value > value){
high = (mid - 1);
} else {
if (bounds[mid].value < value){
low = (mid + 1);
} else {
return (uint(mid));
};
};
};
return (uint(low));
}
}
}//package Box2D.Collision
Section 12
//b2BufferedPair (Box2D.Collision.b2BufferedPair)
package Box2D.Collision {
public class b2BufferedPair {
public var proxyId1:uint;
public var proxyId2:uint;
public function b2BufferedPair(){
super();
}
}
}//package Box2D.Collision
Section 13
//b2Collision (Box2D.Collision.b2Collision)
package Box2D.Collision {
import Box2D.Common.Math.*;
import Box2D.Collision.Shapes.*;
import Box2D.Common.*;
public class b2Collision {
public static const b2_nullFeature:uint = 0xFF;
public static const b2_oldPoint:uint = 4;
public static const b2_newPoint:uint = 2;
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;
tMat = xf1.R;
tVec = poly1.m_normals[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 < poly2.m_vertexCount) {
tVec = poly2.m_vertices[i];
dot = ((tVec.x * normal1X) + (tVec.y * normal1Y));
if (dot < minDot){
minDot = dot;
index = i;
};
i++;
};
tVec = poly1.m_vertices[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 = poly2.m_vertices[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;
tMat = xf1.R;
tVec = poly1.m_normals[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 < poly2.m_vertexCount) {
tVec = poly2.m_normals[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) < poly2.m_vertexCount)) ? (i1 + 1) : 0;
tClip = c[0];
tVec = poly2.m_vertices[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.referenceFace = edge1;
tClip.id.features.incidentEdge = i1;
tClip.id.features.incidentVertex = 0;
tClip = c[1];
tVec = poly2.m_vertices[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.referenceFace = 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 poly1:b2PolygonShape;
var poly2:b2PolygonShape;
var edge1:int;
var flip:uint;
var np:int;
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 vert1s:Array = poly1.m_vertices;
var v11:b2Vec2 = vert1s[edge1].Copy();
var v12:b2Vec2 = (((edge1 + 1) < count1)) ? vert1s[(edge1 + 1)].Copy() : vert1s[0].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) {
separation = (b2Math.b2Dot(frontNormal, clipPoints2[i].v) - frontOffset);
if (separation <= 0){
cp = manifold.points[pointCount];
cp.separation = separation;
cp.localPoint1 = b2Math.b2MulXT(xfA, clipPoints2[i].v);
cp.localPoint2 = b2Math.b2MulXT(xfB, clipPoints2[i].v);
cp.id.key = clipPoints2[i].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;
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) {
dot = ((poly1.m_normals[i].x * dLocal1X) + (poly1.m_normals[i].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 vIn1:b2Vec2;
var distance0:Number;
var interp:Number;
var tVec:b2Vec2;
var numOut:int;
var vIn0:b2Vec2 = vIn[0].v;
vIn1 = vIn[1].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 _local12 = _temp1;
vOut[_local12] = vIn[0];
};
if (distance1 <= 0){
var _temp2 = numOut;
numOut = (numOut + 1);
_local12 = _temp2;
vOut[_local12] = vIn[1];
};
if ((distance0 * distance1) < 0){
interp = (distance0 / (distance0 - distance1));
tVec = vOut[numOut].v;
tVec.x = (vIn0.x + (interp * (vIn1.x - vIn0.x)));
tVec.y = (vIn0.y + (interp * (vIn1.y - vIn0.y)));
if (distance0 > 0){
vOut[numOut].id = vIn[0].id;
} else {
vOut[numOut].id = vIn[1].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 radiusSum:Number = (circle1.m_radius + circle2.m_radius);
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 + (circle1.m_radius * manifold.normal.x));
p1Y = (p1Y + (circle1.m_radius * manifold.normal.y));
p2X = (p2X - (circle2.m_radius * manifold.normal.x));
p2Y = (p2Y - (circle2.m_radius * 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 i:int;
while (i < polygon.m_vertexCount) {
dX = (cLocalX - polygon.m_vertices[i].x);
dY = (cLocalY - polygon.m_vertices[i].y);
s = ((polygon.m_normals[i].x * dX) + (polygon.m_normals[i].y * dY));
if (s > radius){
return;
};
if (s > separation){
separation = s;
normalIndex = i;
};
i++;
};
if (separation < Number.MIN_VALUE){
manifold.pointCount = 1;
tVec = polygon.m_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.referenceFace = b2_nullFeature;
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) < polygon.m_vertexCount)) ? (vertIndex1 + 1) : 0;
var eX:Number = (polygon.m_vertices[vertIndex2].x - polygon.m_vertices[vertIndex1].x);
var eY:Number = (polygon.m_vertices[vertIndex2].y - polygon.m_vertices[vertIndex1].y);
var length:Number = Math.sqrt(((eX * eX) + (eY * eY)));
eX = (eX / length);
eY = (eY / length);
if (length < Number.MIN_VALUE){
dX = (cLocalX - polygon.m_vertices[vertIndex1].x);
dY = (cLocalY - polygon.m_vertices[vertIndex1].y);
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));
tPoint = manifold.points[0];
tPoint.id.features.incidentEdge = b2_nullFeature;
tPoint.id.features.incidentVertex = vertIndex1;
tPoint.id.features.referenceFace = b2_nullFeature;
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 = (dist - radius);
return;
};
dX = (cLocalX - polygon.m_vertices[vertIndex1].x);
dY = (cLocalY - polygon.m_vertices[vertIndex1].y);
var u:Number = ((dX * eX) + (dY * eY));
tPoint = manifold.points[0];
tPoint.id.features.incidentEdge = b2_nullFeature;
tPoint.id.features.incidentVertex = b2_nullFeature;
tPoint.id.features.referenceFace = b2_nullFeature;
tPoint.id.features.flip = 0;
if (u <= 0){
pX = polygon.m_vertices[vertIndex1].x;
pY = polygon.m_vertices[vertIndex1].y;
tPoint.id.features.incidentVertex = vertIndex1;
} else {
if (u >= length){
pX = polygon.m_vertices[vertIndex2].x;
pY = polygon.m_vertices[vertIndex2].y;
tPoint.id.features.incidentVertex = vertIndex2;
} else {
pX = ((eX * u) + polygon.m_vertices[vertIndex1].x);
pY = ((eY * u) + polygon.m_vertices[vertIndex1].y);
tPoint.id.features.incidentEdge = vertIndex1;
};
};
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);
}
}
}//package Box2D.Collision
Section 14
//b2ContactID (Box2D.Collision.b2ContactID)
package Box2D.Collision {
public class b2ContactID {
public 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._referenceFace = (_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 15
//b2ContactPoint (Box2D.Collision.b2ContactPoint)
package Box2D.Collision {
import Box2D.Common.Math.*;
import Box2D.Collision.Shapes.*;
public class b2ContactPoint {
public var normalForce:Number;
public var separation:Number;
public var normal:b2Vec2;
public var position:b2Vec2;
public var tangentForce:Number;
public var shape1:b2Shape;
public var shape2:b2Shape;
public var id:b2ContactID;
public function b2ContactPoint(){
position = new b2Vec2();
normal = new b2Vec2();
id = new b2ContactID();
super();
}
}
}//package Box2D.Collision
Section 16
//b2Distance (Box2D.Collision.b2Distance)
package Box2D.Collision {
import Box2D.Common.Math.*;
import Box2D.Collision.Shapes.*;
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 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) {
dX = Math.abs((w.x - points[i].x));
dY = Math.abs((w.y - points[i].y));
mX = Math.max(Math.abs(w.x), Math.abs(points[i].x));
mY = Math.max(Math.abs(w.y), Math.abs(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 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 - ((vX * wX) + (vY * wY))) <= (0.01 * vSqr)){
if (pointCount == 0){
x1.SetV(w1);
x2.SetV(w2);
};
g_GJK_Iterations = iter;
return (Math.sqrt(vSqr));
};
switch (pointCount){
case 0:
p1s[0].SetV(w1);
p2s[0].SetV(w2);
points[0].Set(wX, wY);
x1.SetV(p1s[0]);
x2.SetV(p2s[0]);
pointCount++;
break;
case 1:
p1s[1].SetV(w1);
p2s[1].SetV(w2);
points[1].x = wX;
points[1].y = wY;
pointCount = ProcessTwo(x1, x2, p1s, p2s, points);
break;
case 2:
p1s[2].SetV(w1);
p2s[2].SetV(w2);
points[2].x = wX;
points[2].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) {
maxSqr = b2Math.b2Max(maxSqr, ((points[i].x * points[i].x) + (points[i].y * points[i].y)));
i++;
};
if ((((pointCount == 3)) || ((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 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(((dX * dX) + (dY * dY)));
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(((dX * dX) + (dY * dY)));
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 lambda:Number;
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:* = points[2].x;
var cY:* = 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)))){
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)))){
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.GetRadius() - 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.GetType();
var type2:int = shape2.GetType();
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 as b2PolygonShape), xf1, (shape2 as b2PolygonShape), xf2));
};
return (0);
}
public static function ProcessTwo(x1:b2Vec2, x2:b2Vec2, p1s:Array, p2s:Array, points:Array):int{
var lambda:Number;
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 17
//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){
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(){
var i:int;
while (i < b2Settings.b2_maxManifoldPoints) {
(points[i] as b2ManifoldPoint).Reset();
i++;
};
normal.SetZero();
pointCount = 0;
}
}
}//package Box2D.Collision
Section 18
//b2ManifoldPoint (Box2D.Collision.b2ManifoldPoint)
package Box2D.Collision {
import Box2D.Common.Math.*;
public class b2ManifoldPoint {
public var normalForce:Number;
public var tangentForce:Number;
public var id:b2ContactID;
public var separation:Number;
public var localPoint2:b2Vec2;
public var localPoint1:b2Vec2;
public function b2ManifoldPoint(){
localPoint1 = new b2Vec2();
localPoint2 = new b2Vec2();
id = new b2ContactID();
super();
}
public function Set(m:b2ManifoldPoint){
localPoint1.SetV(m.localPoint1);
localPoint2.SetV(m.localPoint2);
separation = m.separation;
normalForce = m.normalForce;
tangentForce = m.tangentForce;
id.key = m.id.key;
}
public function Reset(){
localPoint1.SetZero();
localPoint2.SetZero();
separation = 0;
normalForce = 0;
tangentForce = 0;
id.key = 0;
}
}
}//package Box2D.Collision
Section 19
//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 20
//b2Pair (Box2D.Collision.b2Pair)
package Box2D.Collision {
import Box2D.Common.*;
public class b2Pair {
public var proxyId1:uint;
public var userData;// = null
public var proxyId2:uint;
public var status:uint;
public var next:uint;
public static var e_pairFinal:uint = 4;
public static var b2_tableMask:int = (b2_tableCapacity - 1);
public static var e_pairRemoved:uint = 2;
public static var b2_nullPair:uint = b2Settings.USHRT_MAX;
public static var e_pairBuffered:uint = 1;
public static var b2_nullProxy:uint = b2Settings.USHRT_MAX;
public static var b2_tableCapacity:int = b2Settings.b2_maxPairs;
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 21
//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 22
//b2PairManager (Box2D.Collision.b2PairManager)
package Box2D.Collision {
import Box2D.Common.Math.*;
import Box2D.Common.*;
public class b2PairManager {
public var m_pairCount:int;
public var m_pairBuffer:Array;
public var m_hashTable:Array;
public var m_callback:b2PairCallback;
public var m_pairs:Array;
public var m_pairBufferCount:int;
public var m_broadPhase:b2BroadPhase;
public var m_freePair:uint;
public function b2PairManager(){
var i:uint;
super();
m_hashTable = new Array(b2Pair.b2_tableCapacity);
i = 0;
while (i < b2Pair.b2_tableCapacity) {
m_hashTable[i] = b2Pair.b2_nullPair;
i++;
};
m_pairs = new Array(b2Settings.b2_maxPairs);
i = 0;
while (i < b2Settings.b2_maxPairs) {
m_pairs[i] = new b2Pair();
i++;
};
m_pairBuffer = new Array(b2Settings.b2_maxPairs);
i = 0;
while (i < b2Settings.b2_maxPairs) {
m_pairBuffer[i] = new b2BufferedPair();
i++;
};
i = 0;
while (i < b2Settings.b2_maxPairs) {
m_pairs[i].proxyId1 = b2Pair.b2_nullProxy;
m_pairs[i].proxyId2 = b2Pair.b2_nullProxy;
m_pairs[i].userData = null;
m_pairs[i].status = 0;
m_pairs[i].next = (i + 1);
i++;
};
m_pairs[(b2Settings.b2_maxPairs - 1)].next = b2Pair.b2_nullPair;
m_pairCount = 0;
m_pairBufferCount = 0;
}
private function FindHash(proxyId1:uint, proxyId2:uint, hash:uint):b2Pair{
var index:uint = m_hashTable[hash];
while (((!((index == b2Pair.b2_nullPair))) && ((Equals(m_pairs[index], proxyId1, proxyId2) == false)))) {
index = m_pairs[index].next;
};
if (index == b2Pair.b2_nullPair){
return (null);
};
return (m_pairs[index]);
}
private function Find(proxyId1:uint, proxyId2:uint):b2Pair{
var temp:uint;
if (proxyId1 > proxyId2){
temp = proxyId1;
proxyId1 = proxyId2;
proxyId2 = temp;
};
var hash:uint = (Hash(proxyId1, proxyId2) & b2Pair.b2_tableMask);
return (FindHash(proxyId1, proxyId2, hash));
}
private function ValidateBuffer():void{
}
public function Commit():void{
var i:int;
var pair:b2Pair;
var proxy1:b2Proxy;
var proxy2:b2Proxy;
var removeCount:int;
var proxies:Array = m_broadPhase.m_proxyPool;
i = 0;
while (i < m_pairBufferCount) {
pair = Find(m_pairBuffer[i].proxyId1, m_pairBuffer[i].proxyId2);
pair.ClearBuffered();
proxy1 = proxies[pair.proxyId1];
proxy2 = proxies[pair.proxyId2];
if (pair.IsRemoved()){
if (pair.IsFinal() == true){
m_callback.PairRemoved(proxy1.userData, proxy2.userData, pair.userData);
};
m_pairBuffer[removeCount].proxyId1 = pair.proxyId1;
m_pairBuffer[removeCount].proxyId2 = pair.proxyId2;
removeCount++;
} else {
if (pair.IsFinal() == false){
pair.userData = m_callback.PairAdded(proxy1.userData, proxy2.userData);
pair.SetFinal();
};
};
i++;
};
i = 0;
while (i < removeCount) {
RemovePair(m_pairBuffer[i].proxyId1, m_pairBuffer[i].proxyId2);
i++;
};
m_pairBufferCount = 0;
if (b2BroadPhase.s_validate){
ValidateTable();
};
}
public function RemoveBufferedPair(proxyId1:int, proxyId2:int):void{
var pair:b2Pair = Find(proxyId1, proxyId2);
if (pair == null){
return;
};
if (pair.IsBuffered() == false){
pair.SetBuffered();
m_pairBuffer[m_pairBufferCount].proxyId1 = pair.proxyId1;
m_pairBuffer[m_pairBufferCount].proxyId2 = pair.proxyId2;
m_pairBufferCount++;
};
pair.SetRemoved();
if (b2BroadPhase.s_validate){
ValidateBuffer();
};
}
private function RemovePair(proxyId1:uint, proxyId2:uint){
var temp:uint;
var index:uint;
var pair:b2Pair;
var userData:*;
if (proxyId1 > proxyId2){
temp = proxyId1;
proxyId1 = proxyId2;
proxyId2 = temp;
};
var hash:uint = (Hash(proxyId1, proxyId2) & b2Pair.b2_tableMask);
var node:uint = m_hashTable[hash];
var pNode:b2Pair;
while (node != b2Pair.b2_nullPair) {
if (Equals(m_pairs[node], proxyId1, proxyId2)){
index = node;
if (pNode){
pNode.next = m_pairs[node].next;
} else {
m_hashTable[hash] = m_pairs[node].next;
};
pair = m_pairs[index];
userData = pair.userData;
pair.next = m_freePair;
pair.proxyId1 = b2Pair.b2_nullProxy;
pair.proxyId2 = b2Pair.b2_nullProxy;
pair.userData = null;
pair.status = 0;
m_freePair = index;
m_pairCount--;
return (userData);
} else {
pNode = m_pairs[node];
node = pNode.next;
};
};
return (null);
}
public function Initialize(broadPhase:b2BroadPhase, callback:b2PairCallback):void{
m_broadPhase = broadPhase;
m_callback = callback;
}
public function AddBufferedPair(proxyId1:int, proxyId2:int):void{
var pair:b2Pair = AddPair(proxyId1, proxyId2);
if (pair.IsBuffered() == false){
pair.SetBuffered();
m_pairBuffer[m_pairBufferCount].proxyId1 = pair.proxyId1;
m_pairBuffer[m_pairBufferCount].proxyId2 = pair.proxyId2;
m_pairBufferCount++;
};
pair.ClearRemoved();
if (b2BroadPhase.s_validate){
ValidateBuffer();
};
}
private function AddPair(proxyId1:uint, proxyId2:uint):b2Pair{
var temp:uint;
if (proxyId1 > proxyId2){
temp = proxyId1;
proxyId1 = proxyId2;
proxyId2 = temp;
};
var hash:uint = (Hash(proxyId1, proxyId2) & b2Pair.b2_tableMask);
var pair = FindHash(proxyId1, proxyId2, hash);
if (pair != null){
return (pair);
};
var pIndex:uint = m_freePair;
pair = m_pairs[pIndex];
m_freePair = pair.next;
pair.proxyId1 = proxyId1;
pair.proxyId2 = proxyId2;
pair.status = 0;
pair.userData = null;
pair.next = m_hashTable[hash];
m_hashTable[hash] = pIndex;
m_pairCount++;
return (pair);
}
private function ValidateTable():void{
}
public static function EqualsPair(pair1:b2BufferedPair, pair2:b2BufferedPair):Boolean{
return ((((pair1.proxyId1 == pair2.proxyId1)) && ((pair1.proxyId2 == pair2.proxyId2))));
}
public static function Hash(proxyId1:uint, proxyId2:uint):uint{
var key:uint = (((proxyId2 << 16) & 4294901760) | proxyId1);
key = (~(key) + ((key << 15) & 4294934528));
key = (key ^ ((key >> 12) & 1048575));
key = (key + ((key << 2) & 4294967292));
key = (key ^ ((key >> 4) & 268435455));
key = (key * 2057);
key = (key ^ ((key >> 16) & 0xFFFF));
return (key);
}
public static function Equals(pair:b2Pair, proxyId1:uint, proxyId2:uint):Boolean{
return ((((pair.proxyId1 == proxyId1)) && ((pair.proxyId2 == proxyId2))));
}
}
}//package Box2D.Collision
Section 23
//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 24
//b2Proxy (Box2D.Collision.b2Proxy)
package Box2D.Collision {
public class b2Proxy {
public var overlapCount:uint;
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)];
super();
}
public function GetNext():uint{
return (lowerBounds[0]);
}
public function IsValid():Boolean{
return (!((overlapCount == b2BroadPhase.b2_invalid)));
}
public function SetNext(next:uint):void{
lowerBounds[0] = (next & 0xFFFF);
}
}
}//package Box2D.Collision
Section 25
//b2Segment (Box2D.Collision.b2Segment)
package Box2D.Collision {
import Box2D.Common.Math.*;
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 = ((-(rY) * 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);
}
}
}//package Box2D.Collision
Section 26
//b2TimeOfImpact (Box2D.Collision.b2TimeOfImpact)
package Box2D.Collision {
import Box2D.Common.Math.*;
import Box2D.Collision.Shapes.*;
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 t:Number;
var xf1:b2XForm;
var xf2:b2XForm;
var nLen:Number;
var approachVelocityBound:Number;
var dAlpha:Number;
var newAlpha:Number;
var r1:Number = shape1.GetSweepRadius();
var r2:Number = shape2.GetSweepRadius();
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 {
targetDistance = Math.max((0.05 * b2Settings.b2_toiSlop), (distance - (0.5 * b2Settings.b2_toiSlop)));
};
};
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))) + (Math.abs(omega1) * r1)) + (Math.abs(omega2) * r2));
if (Math.abs(approachVelocityBound) < Number.MIN_VALUE){
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 27
//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 28
//Features (Box2D.Collision.Features)
package Box2D.Collision {
public class Features {
public var _referenceFace:int;
public var _incidentEdge:int;
public var _flip:int;
public var _incidentVertex:int;
public var _m_id:b2ContactID;
public function Features(){
super();
}
public function get referenceFace():int{
return (_referenceFace);
}
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 referenceFace(value:int):void{
_referenceFace = value;
_m_id._key = ((_m_id._key & 4294967040) | (_referenceFace & 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 29
//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 Invert(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 30
//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 31
//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 32
//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{
x = Math.abs(x);
y = Math.abs(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 33
//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){
position.SetV(x.position);
R.SetM(x.R);
}
public function SetIdentity():void{
position.SetZero();
R.SetIdentity();
}
}
}//package Box2D.Common.Math
Section 34
//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 | (_g << 8)) | (_b << 16)));
}
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 35
//b2Settings (Box2D.Common.b2Settings)
package Box2D.Common {
import Box2D.Common.Math.*;
public class b2Settings {
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_pi:Number = 3.14159265358979;
public static const b2_maxProxies:int = 0x0200;
public static const b2_maxAngularVelocitySquared:Number = 62500;
public static const b2_maxPolygonVertices:int = 10;
public static const b2_velocityThreshold:Number = 1;
public static const b2_contactBaumgarte:Number = 0.2;
public static const b2_maxPairs:int = 4096;
public static const b2_maxTOIContactsPerIsland:int = 32;
public static const b2_timeToSleep:Number = 0.5;
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 USHRT_MAX:int = 0xFFFF;
public static const b2_maxLinearVelocity:Number = 200;
public static const b2_maxLinearCorrection:Number = 0.2;
public static const b2_toiSlop:Number = 0.04;
public static const b2_maxLinearVelocitySquared:Number = 40000;
public function b2Settings(){
super();
}
public static function b2Assert(a:Boolean):void{
var nullVec:b2Vec2;
if (!a){
nullVec.x++;
};
}
}
}//package Box2D.Common
Section 36
//b2CircleContact (Box2D.Dynamics.Contacts.b2CircleContact)
package Box2D.Dynamics.Contacts {
import Box2D.Dynamics.*;
import Box2D.Common.Math.*;
import Box2D.Collision.*;
import Box2D.Collision.Shapes.*;
import Box2D.Common.*;
public class b2CircleContact extends b2Contact {
private var m_manifolds:Array;
public var m_manifold:b2Manifold;
private var m0:b2Manifold;
private static var 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;
m_manifold.points[0].normalForce = 0;
m_manifold.points[0].tangentForce = 0;
}
override public function Evaluate(listener:b2ContactListener):void{
var cp:b2ContactPoint;
var tMat:b2Mat22;
var tVec:b2Vec2;
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);
if (m_manifold.pointCount > 0){
m_manifoldCount = 1;
if (m0.pointCount == 0){
m_manifold.points[0].id.features.flip = (m_manifold.points[0].id.features.flip | b2Collision.b2_newPoint);
} else {
m_manifold.points[0].id.features.flip = (m_manifold.points[0].id.features.flip & ~(b2Collision.b2_newPoint));
};
} else {
m_manifoldCount = 0;
if ((((m0.pointCount > 0)) && (listener))){
cp = s_evalCP;
cp.shape1 = m_shape1;
cp.shape2 = m_shape2;
cp.normal.SetV(m0.normal);
tMat = b1.m_xf.R;
tVec = m0.points[0].localPoint1;
cp.position.x = (b1.m_xf.position.x + ((tMat.col1.x * tVec.x) + (tMat.col2.x * tVec.y)));
cp.position.y = (b1.m_xf.position.y + ((tMat.col1.y * tVec.x) + (tMat.col2.y * tVec.y)));
cp.separation = m0.points[0].separation;
cp.normalForce = m0.points[0].normalForce;
cp.tangentForce = m0.points[0].tangentForce;
cp.id.key = m0.points[0].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 37
//b2Contact (Box2D.Dynamics.Contacts.b2Contact)
package Box2D.Dynamics.Contacts {
import Box2D.Dynamics.*;
import Box2D.Common.Math.*;
import Box2D.Collision.*;
import Box2D.Collision.Shapes.*;
import Box2D.Common.*;
public class b2Contact {
public var m_shape1:b2Shape;
public var m_shape2:b2Shape;
public var m_prev:b2Contact;
public var m_toi:Number;
public var m_next:b2Contact;
public var m_friction:Number;
public var m_manifoldCount:int;
public var m_node1:b2ContactEdge;
public var m_node2:b2ContactEdge;
public var m_restitution:Number;
public var m_flags:uint;
public static var e_toiFlag:uint = 8;
public static var e_nonSolidFlag:uint = 1;
public static var e_slowFlag:uint = 2;
public static var e_islandFlag:uint = 4;
public static var s_registers:Array;
public 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_friction = Math.sqrt((m_shape1.m_friction * m_shape2.m_friction));
m_restitution = b2Math.b2Max(m_shape1.m_restitution, m_shape2.m_restitution);
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);
}
public function Update(listener:b2ContactListener):void{
Evaluate(listener);
var body1:b2Body = m_shape1.GetBody();
var body2:b2Body = m_shape2.GetBody();
if (((((((body1.IsStatic()) || (body1.IsBullet()))) || (body2.IsStatic()))) || (body2.IsBullet()))){
m_flags = (m_flags & ~(e_slowFlag));
} else {
m_flags = (m_flags | e_slowFlag);
};
}
public function Evaluate(listener:b2ContactListener):void{
}
public 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);
}
public static function Destroy(contact:b2Contact, allocator):void{
if (contact.GetManifoldCount() > 0){
contact.GetShape1().GetBody().WakeUp();
contact.GetShape2().GetBody().WakeUp();
};
var type1:int = contact.GetShape1().GetType();
var type2:int = contact.GetShape2().GetType();
var destroyFcn:* = s_registers[type1][type2].destroyFcn;
destroyFcn(contact, allocator);
}
public static function AddType(createFcn, destroyFcn, 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;
};
}
public 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 createFcn:* = s_registers[type1][type2].createFcn;
if (createFcn){
if (s_registers[type1][type2].primary){
return (createFcn(shape1, shape2, allocator));
};
c = createFcn(shape2, shape1, allocator);
i = 0;
while (i < c.GetManifoldCount()) {
m = c.GetManifolds()[i];
m.normal = m.normal.Negative();
i++;
};
return (c);
//unresolved jump
};
return (null);
}
}
}//package Box2D.Dynamics.Contacts
Section 38
//b2ContactConstraint (Box2D.Dynamics.Contacts.b2ContactConstraint)
package Box2D.Dynamics.Contacts {
import Box2D.Dynamics.*;
import Box2D.Common.Math.*;
import Box2D.Collision.*;
import Box2D.Common.*;
public class b2ContactConstraint {
public var points:Array;
public var normal:b2Vec2;
public var restitution:Number;
public var body1:b2Body;
public var manifold:b2Manifold;
public var body2:b2Body;
public var friction:Number;
public var pointCount:int;
public function b2ContactConstraint(){
normal = new b2Vec2();
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 39
//b2ContactConstraintPoint (Box2D.Dynamics.Contacts.b2ContactConstraintPoint)
package Box2D.Dynamics.Contacts {
import Box2D.Common.Math.*;
public class b2ContactConstraintPoint {
public var tangentForce:Number;
public var normalForce:Number;
public var positionImpulse:Number;
public var separation:Number;
public var localAnchor1:b2Vec2;
public var localAnchor2:b2Vec2;
public var tangentMass:Number;
public var normalMass:Number;
public var velocityBias:Number;
public var equalizedMass:Number;
public function b2ContactConstraintPoint(){
localAnchor1 = new b2Vec2();
localAnchor2 = new b2Vec2();
super();
}
}
}//package Box2D.Dynamics.Contacts
Section 40
//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 41
//b2ContactRegister (Box2D.Dynamics.Contacts.b2ContactRegister)
package Box2D.Dynamics.Contacts {
public class b2ContactRegister {
public var primary:Boolean;
public var createFcn;
public var destroyFcn;
public function b2ContactRegister(){
super();
}
}
}//package Box2D.Dynamics.Contacts
Section 42
//b2ContactSolver (Box2D.Dynamics.Contacts.b2ContactSolver)
package Box2D.Dynamics.Contacts {
import Box2D.Dynamics.*;
import Box2D.Common.Math.*;
import Box2D.Collision.*;
import Box2D.Common.*;
public class b2ContactSolver {
public var m_constraintCount:int;
public var m_constraints:Array;
public var m_allocator;
public var m_step:b2TimeStep;
public function b2ContactSolver(step:b2TimeStep, contacts:Array, contactCount:int, allocator){
var i:int;
var tVec:b2Vec2;
var tMat:b2Mat22;
var contact:b2Contact;
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 c: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 r1Sqr:Number;
var r2Sqr: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;
m_step = new b2TimeStep();
m_constraints = new Array();
super();
m_step.dt = step.dt;
m_step.inv_dt = step.inv_dt;
m_step.maxIterations = step.maxIterations;
m_allocator = allocator;
m_constraintCount = 0;
i = 0;
while (i < contactCount) {
m_constraintCount = (m_constraintCount + contacts[i].GetManifoldCount());
i++;
};
i = 0;
while (i < m_constraintCount) {
m_constraints[i] = new b2ContactConstraint();
i++;
};
var count:int;
i = 0;
while (i < contactCount) {
contact = contacts[i];
b1 = contact.m_shape1.m_body;
b2 = contact.m_shape2.m_body;
manifoldCount = contact.GetManifoldCount();
manifolds = contact.GetManifolds();
friction = contact.m_friction;
restitution = contact.m_restitution;
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;
c = m_constraints[count];
c.body1 = b1;
c.body2 = b2;
c.manifold = manifold;
c.normal.x = normalX;
c.normal.y = normalY;
c.pointCount = manifold.pointCount;
c.friction = friction;
c.restitution = restitution;
k = 0;
while (k < c.pointCount) {
cp = manifold.points[k];
ccp = c.points[k];
ccp.normalForce = cp.normalForce;
ccp.tangentForce = cp.tangentForce;
ccp.separation = cp.separation;
ccp.positionImpulse = 0;
ccp.localAnchor1.SetV(cp.localPoint1);
ccp.localAnchor2.SetV(cp.localPoint2);
tMat = b1.m_xf.R;
r1X = (ccp.localAnchor1.x - b1.GetLocalCenter().x);
r1Y = (ccp.localAnchor1.y - b1.GetLocalCenter().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 = (ccp.localAnchor2.x - b2.GetLocalCenter().x);
r2Y = (ccp.localAnchor2.y - b2.GetLocalCenter().y);
tX = ((tMat.col1.x * r2X) + (tMat.col2.x * r2Y));
r2Y = ((tMat.col1.y * r2X) + (tMat.col2.y * r2Y));
r2X = tX;
r1Sqr = ((r1X * r1X) + (r1Y * r1Y));
r2Sqr = ((r2X * r2X) + (r2Y * r2Y));
rn1 = ((r1X * normalX) + (r1Y * normalY));
rn2 = ((r2X * normalX) + (r2Y * normalY));
kNormal = (b1.m_invMass + b2.m_invMass);
kNormal = (kNormal + ((b1.m_invI * (r1Sqr - (rn1 * rn1))) + (b2.m_invI * (r2Sqr - (rn2 * 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) * (r1Sqr - (rn1 * rn1))) + ((b2.m_mass * b2.m_invI) * (r2Sqr - (rn2 * rn2)))));
ccp.equalizedMass = (1 / kEqualized);
tangentX = normalY;
tangentY = -(normalX);
rt1 = ((r1X * tangentX) + (r1Y * tangentY));
rt2 = ((r2X * tangentX) + (r2Y * tangentY));
kTangent = (b1.m_invMass + b2.m_invMass);
kTangent = (kTangent + ((b1.m_invI * (r1Sqr - (rt1 * rt1))) + (b2.m_invI * (r2Sqr - (rt2 * rt2)))));
ccp.tangentMass = (1 / kTangent);
ccp.velocityBias = 0;
if (ccp.separation > 0){
ccp.velocityBias = (-60 * ccp.separation);
};
tX = (((v2X + (-(w2) * r2Y)) - v1X) - (-(w1) * r1Y));
tY = (((v2Y + (w2 * r2X)) - v1Y) - (w1 * r1X));
vRel = ((c.normal.x * tX) + (c.normal.y * tY));
if (vRel < -(b2Settings.b2_velocityThreshold)){
ccp.velocityBias = (ccp.velocityBias + (-(c.restitution) * vRel));
};
k++;
};
count++;
j++;
};
i++;
};
}
public function InitVelocityConstraints():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 r1X:Number;
var r1Y:Number;
var r2X:Number;
var r2Y: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 (b2World.s_enableWarmStarting){
tCount = c.pointCount;
j = 0;
while (j < tCount) {
ccp = c.points[j];
PX = (m_step.dt * ((ccp.normalForce * normalX) + (ccp.tangentForce * tangentX)));
PY = (m_step.dt * ((ccp.normalForce * normalY) + (ccp.tangentForce * tangentY)));
tMat = b1.m_xf.R;
tVec = b1.GetLocalCenter();
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.GetLocalCenter();
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;
b1.m_angularVelocity = (b1.m_angularVelocity - (invI1 * ((r1X * PY) - (r1Y * 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 * ((r2X * PY) - (r2Y * 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.normalForce = 0;
ccp2.tangentForce = 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 impulse0:Number;
var impulseX:Number;
var impulseY: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.GetLocalCenter();
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.GetLocalCenter();
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);
impulse0 = ccp.positionImpulse;
ccp.positionImpulse = b2Math.b2Max((impulse0 + dImpulse), 0);
dImpulse = (ccp.positionImpulse - impulse0);
impulseX = (dImpulse * normalX);
impulseY = (dImpulse * normalY);
b1_sweep_c.x = (b1_sweep_c.x - (invMass1 * impulseX));
b1_sweep_c.y = (b1_sweep_c.y - (invMass1 * impulseY));
b1_sweep_a = (b1_sweep_a - (invI1 * ((r1X * impulseY) - (r1Y * impulseX))));
b1.m_sweep.a = b1_sweep_a;
b1.SynchronizeTransform();
b2_sweep_c.x = (b2_sweep_c.x + (invMass2 * impulseX));
b2_sweep_c.y = (b2_sweep_c.y + (invMass2 * impulseY));
b2_sweep_a = (b2_sweep_a + (invI2 * ((r2X * impulseY) - (r2Y * impulseX))));
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 lambda:Number;
var newImpulse:Number;
var PX:Number;
var PY:Number;
var tMat:b2Mat22;
var tVec:b2Vec2;
var c:b2ContactConstraint;
var b1:b2Body;
var b2:b2Body;
var b1_angularVelocity:Number;
var b1_linearVelocity:b2Vec2;
var b2_angularVelocity:Number;
var b2_linearVelocity: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 tX:Number;
var tCount:int;
var vn:Number;
var newForce:Number;
var vt:Number;
var maxFriction:Number;
var i:int;
while (i < m_constraintCount) {
c = m_constraints[i];
b1 = c.body1;
b2 = c.body2;
b1_angularVelocity = b1.m_angularVelocity;
b1_linearVelocity = b1.m_linearVelocity;
b2_angularVelocity = b2.m_angularVelocity;
b2_linearVelocity = 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);
tCount = c.pointCount;
j = 0;
while (j < tCount) {
ccp = c.points[j];
tMat = b1.m_xf.R;
tVec = b1.GetLocalCenter();
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.GetLocalCenter();
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;
dvX = (((b2_linearVelocity.x + (-(b2_angularVelocity) * r2Y)) - b1_linearVelocity.x) - (-(b1_angularVelocity) * r1Y));
dvY = (((b2_linearVelocity.y + (b2_angularVelocity * r2X)) - b1_linearVelocity.y) - (b1_angularVelocity * r1X));
vn = ((dvX * normalX) + (dvY * normalY));
lambda = ((-(m_step.inv_dt) * ccp.normalMass) * (vn - ccp.velocityBias));
newForce = b2Math.b2Max((ccp.normalForce + lambda), 0);
lambda = (newForce - ccp.normalForce);
PX = ((m_step.dt * lambda) * normalX);
PY = ((m_step.dt * lambda) * normalY);
b1_linearVelocity.x = (b1_linearVelocity.x - (invMass1 * PX));
b1_linearVelocity.y = (b1_linearVelocity.y - (invMass1 * PY));
b1_angularVelocity = (b1_angularVelocity - (invI1 * ((r1X * PY) - (r1Y * PX))));
b2_linearVelocity.x = (b2_linearVelocity.x + (invMass2 * PX));
b2_linearVelocity.y = (b2_linearVelocity.y + (invMass2 * PY));
b2_angularVelocity = (b2_angularVelocity + (invI2 * ((r2X * PY) - (r2Y * PX))));
ccp.normalForce = newForce;
dvX = (((b2_linearVelocity.x + (-(b2_angularVelocity) * r2Y)) - b1_linearVelocity.x) - (-(b1_angularVelocity) * r1Y));
dvY = (((b2_linearVelocity.y + (b2_angularVelocity * r2X)) - b1_linearVelocity.y) - (b1_angularVelocity * r1X));
vt = ((dvX * tangentX) + (dvY * tangentY));
lambda = ((m_step.inv_dt * ccp.tangentMass) * -(vt));
maxFriction = (c.friction * ccp.normalForce);
newForce = b2Math.b2Clamp((ccp.tangentForce + lambda), -(maxFriction), maxFriction);
lambda = (newForce - ccp.tangentForce);
PX = ((m_step.dt * lambda) * tangentX);
PY = ((m_step.dt * lambda) * tangentY);
b1_linearVelocity.x = (b1_linearVelocity.x - (invMass1 * PX));
b1_linearVelocity.y = (b1_linearVelocity.y - (invMass1 * PY));
b1_angularVelocity = (b1_angularVelocity - (invI1 * ((r1X * PY) - (r1Y * PX))));
b2_linearVelocity.x = (b2_linearVelocity.x + (invMass2 * PX));
b2_linearVelocity.y = (b2_linearVelocity.y + (invMass2 * PY));
b2_angularVelocity = (b2_angularVelocity + (invI2 * ((r2X * PY) - (r2Y * PX))));
ccp.tangentForce = newForce;
j++;
};
b1.m_angularVelocity = b1_angularVelocity;
b2.m_angularVelocity = b2_angularVelocity;
i++;
};
}
public function FinalizeVelocityConstraints():void{
var c:b2ContactConstraint;
var m:b2Manifold;
var j:int;
var i:int;
while (i < m_constraintCount) {
c = m_constraints[i];
m = c.manifold;
j = 0;
while (j < c.pointCount) {
m.points[j].normalForce = c.points[j].normalForce;
m.points[j].tangentForce = c.points[j].tangentForce;
j++;
};
i++;
};
}
}
}//package Box2D.Dynamics.Contacts
Section 43
//b2NullContact (Box2D.Dynamics.Contacts.b2NullContact)
package Box2D.Dynamics.Contacts {
import Box2D.Dynamics.*;
public class b2NullContact extends b2Contact {
public function b2NullContact(){
super();
}
override public function Evaluate(l:b2ContactListener):void{
}
override public function GetManifolds():Array{
return (null);
}
}
}//package Box2D.Dynamics.Contacts
Section 44
//b2PolyAndCircleContact (Box2D.Dynamics.Contacts.b2PolyAndCircleContact)
package Box2D.Dynamics.Contacts {
import Box2D.Dynamics.*;
import Box2D.Common.Math.*;
import Box2D.Collision.*;
import Box2D.Collision.Shapes.*;
import Box2D.Common.*;
public class b2PolyAndCircleContact extends b2Contact {
private var m_manifolds:Array;
public var m_manifold:b2Manifold;
private var m0:b2Manifold;
private static var 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;
m_manifold.points[0].normalForce = 0;
m_manifold.points[0].tangentForce = 0;
}
override public function Evaluate(listener:b2ContactListener):void{
var cp:b2ContactPoint;
var tMat:b2Mat22;
var tVec:b2Vec2;
var b1:b2Body = m_shape1.GetBody();
var b2:b2Body = m_shape2.GetBody();
m0.Set(m_manifold);
b2Collision.b2CollidePolygonAndCircle(m_manifold, (m_shape1 as b2PolygonShape), b1.m_xf, (m_shape2 as b2CircleShape), b2.m_xf);
if (m_manifold.pointCount > 0){
m_manifoldCount = 1;
if (m0.pointCount == 0){
m_manifold.points[0].id.features.flip = (m_manifold.points[0].id.features.flip | b2Collision.b2_newPoint);
} else {
m_manifold.points[0].id.features.flip = (m_manifold.points[0].id.features.flip & ~(b2Collision.b2_newPoint));
};
} else {
m_manifoldCount = 0;
if ((((m0.pointCount > 0)) && (listener))){
cp = s_evalCP;
cp.shape1 = m_shape1;
cp.shape2 = m_shape2;
cp.normal.SetV(m0.normal);
tMat = b1.m_xf.R;
tVec = m0.points[0].localPoint1;
cp.position.x = (b1.m_xf.position.x + ((tMat.col1.x * tVec.x) + (tMat.col2.x * tVec.y)));
cp.position.y = (b1.m_xf.position.y + ((tMat.col1.y * tVec.x) + (tMat.col2.y * tVec.y)));
cp.separation = m0.points[0].separation;
cp.normalForce = m0.points[0].normalForce;
cp.tangentForce = m0.points[0].tangentForce;
cp.id = m0.points[0].id;
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 b2PolyAndCircleContact(shape1, shape2));
}
}
}//package Box2D.Dynamics.Contacts
Section 45
//b2PolygonContact (Box2D.Dynamics.Contacts.b2PolygonContact)
package Box2D.Dynamics.Contacts {
import Box2D.Dynamics.*;
import Box2D.Common.Math.*;
import Box2D.Collision.*;
import Box2D.Collision.Shapes.*;
public class b2PolygonContact extends b2Contact {
private var m_manifolds:Array;
private var m0:b2Manifold;
public var m_manifold:b2Manifold;
private static var 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 public function Evaluate(listener:b2ContactListener):void{
var cp:b2ContactPoint;
var i:int;
var mp:b2ManifoldPoint;
var matched:Boolean;
var idKey:uint;
var j:int;
var cp0:b2ManifoldPoint;
var id0:b2ContactID;
var mp0:b2ManifoldPoint;
var tMat:b2Mat22;
var tVec:b2Vec2;
var b1:b2Body = m_shape1.GetBody();
var b2:b2Body = m_shape2.GetBody();
m0.Set(m_manifold);
b2Collision.b2CollidePolygons(m_manifold, (m_shape1 as b2PolygonShape), b1.m_xf, (m_shape2 as b2PolygonShape), b2.m_xf);
var match:Array = [false, false];
if (m_manifold.pointCount > 0){
i = 0;
while (i < m_manifold.pointCount) {
mp = m_manifold.points[i];
mp.normalForce = 0;
mp.tangentForce = 0;
matched = false;
idKey = mp.id.key;
j = 0;
while (j < m0.pointCount) {
if (match[j] == true){
} else {
cp0 = m0.points[j];
id0 = cp0.id;
id0.features.flip = (id0.features.flip & ~(b2Collision.b2_newPoint));
if (id0.key == idKey){
match[j] = true;
mp.normalForce = cp0.normalForce;
mp.tangentForce = cp0.tangentForce;
matched = true;
break;
};
};
j++;
};
if (matched == false){
mp.id.features.flip = (mp.id.features.flip | b2Collision.b2_newPoint);
};
i++;
};
m_manifoldCount = 1;
} else {
m_manifoldCount = 0;
};
if (((listener) && ((m0.pointCount > 0)))){
cp = s_evalCP;
cp.shape1 = m_shape1;
cp.shape2 = m_shape2;
cp.normal.SetV(m0.normal);
i = 0;
while (i < m0.pointCount) {
if (match[i]){
} else {
mp0 = m0.points[i];
tMat = b1.m_xf.R;
tVec = mp0.localPoint1;
cp.position.x = (b1.m_xf.position.x + ((tMat.col1.x * tVec.x) + (tMat.col2.x * tVec.y)));
cp.position.y = (b1.m_xf.position.y + ((tMat.col1.y * tVec.x) + (tMat.col2.y * tVec.y)));
cp.separation = mp0.separation;
cp.normalForce = mp0.normalForce;
cp.tangentForce = mp0.tangentForce;
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 46
//b2DistanceJoint (Box2D.Dynamics.Joints.b2DistanceJoint)
package Box2D.Dynamics.Joints {
import Box2D.Dynamics.*;
import Box2D.Common.Math.*;
import Box2D.Common.*;
public class b2DistanceJoint extends b2Joint {
public var m_localAnchor1:b2Vec2;
public var m_localAnchor2:b2Vec2;
public var m_u:b2Vec2;
public var m_length:Number;
public var m_force:Number;
public var m_mass: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_force = 0;
}
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 GetReactionTorque():Number{
return (0);
}
override public function GetReactionForce():b2Vec2{
var F:b2Vec2 = new b2Vec2();
F.SetV(m_u);
F.Multiply(m_force);
return (F);
}
override public function SolvePositionConstraints():Boolean{
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.GetLocalCenter().x);
var r1Y:Number = (m_localAnchor1.y - b1.GetLocalCenter().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.GetLocalCenter().x);
var r2Y:Number = (m_localAnchor2.y - b2.GetLocalCenter().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 public function InitVelocityConstraints(step:b2TimeStep):void{
var tMat:b2Mat22;
var tX:Number;
var PX:Number;
var PY:Number;
var b1:b2Body = m_body1;
var b2:b2Body = m_body2;
tMat = b1.m_xf.R;
var r1X:Number = (m_localAnchor1.x - b1.GetLocalCenter().x);
var r1Y:Number = (m_localAnchor1.y - b1.GetLocalCenter().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.GetLocalCenter().x);
var r2Y:Number = (m_localAnchor2.y - b2.GetLocalCenter().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);
m_u.y = ((b2.m_sweep.c.y + r2Y) - b1.m_sweep.c.y);
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));
m_mass = (((b1.m_invMass + ((b1.m_invI * cr1u) * cr1u)) + b2.m_invMass) + ((b2.m_invI * cr2u) * cr2u));
m_mass = (1 / m_mass);
if (b2World.s_enableWarmStarting){
PX = ((step.dt * m_force) * m_u.x);
PY = ((step.dt * m_force) * 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_force = 0;
};
}
override public 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.GetLocalCenter().x);
var r1Y:Number = (m_localAnchor1.y - b1.GetLocalCenter().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.GetLocalCenter().x);
var r2Y:Number = (m_localAnchor2.y - b2.GetLocalCenter().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 force:Number = ((-(step.inv_dt) * m_mass) * Cdot);
m_force = (m_force + force);
var PX:Number = ((step.dt * force) * m_u.x);
var PY:Number = ((step.dt * force) * 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 47
//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 localAnchor2:b2Vec2;
public function b2DistanceJointDef(){
localAnchor1 = new b2Vec2();
localAnchor2 = new b2Vec2();
super();
type = b2Joint.e_distanceJoint;
length = 1;
}
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)));
}
}
}//package Box2D.Dynamics.Joints
Section 48
//b2GearJoint (Box2D.Dynamics.Joints.b2GearJoint)
package Box2D.Dynamics.Joints {
import Box2D.Dynamics.*;
import Box2D.Common.Math.*;
import Box2D.Common.*;
public class b2GearJoint extends b2Joint {
public var m_ground2:b2Body;
public var m_groundAnchor1:b2Vec2;
public var m_groundAnchor2:b2Vec2;
public var m_localAnchor1:b2Vec2;
public var m_localAnchor2:b2Vec2;
public var m_ratio:Number;
public var m_revolute2:b2RevoluteJoint;
public var m_force:Number;
public var m_mass:Number;
public var m_prismatic2:b2PrismaticJoint;
public var m_ground1:b2Body;
public var m_revolute1:b2RevoluteJoint;
public var m_prismatic1:b2PrismaticJoint;
public var m_constant:Number;
public 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);
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 (def.joint1.m_type == 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 (def.joint2.m_type == 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_force = 0;
}
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 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 P: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.GetLocalCenter().x);
rY = (m_localAnchor1.y - b1.GetLocalCenter().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.GetLocalCenter().x);
rY = (m_localAnchor2.y - b2.GetLocalCenter().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 (b2World.s_enableWarmStarting){
P = (step.dt * m_force);
b1.m_linearVelocity.x = (b1.m_linearVelocity.x + ((b1.m_invMass * P) * m_J.linear1.x));
b1.m_linearVelocity.y = (b1.m_linearVelocity.y + ((b1.m_invMass * P) * m_J.linear1.y));
b1.m_angularVelocity = (b1.m_angularVelocity + ((b1.m_invI * P) * m_J.angular1));
b2.m_linearVelocity.x = (b2.m_linearVelocity.x + ((b2.m_invMass * P) * m_J.linear2.x));
b2.m_linearVelocity.y = (b2.m_linearVelocity.y + ((b2.m_invMass * P) * m_J.linear2.y));
b2.m_angularVelocity = (b2.m_angularVelocity + ((b2.m_invI * P) * m_J.angular2));
} else {
m_force = 0;
};
}
override public function GetReactionTorque():Number{
var tMat:b2Mat22 = m_body2.m_xf.R;
var rX:Number = (m_localAnchor1.x - m_body2.GetLocalCenter().x);
var rY:Number = (m_localAnchor1.y - m_body2.GetLocalCenter().y);
var tX:Number = ((tMat.col1.x * rX) + (tMat.col2.x * rY));
rY = ((tMat.col1.y * rX) + (tMat.col2.y * rY));
rX = tX;
tX = ((m_force * m_J.angular2) - ((rX * (m_force * m_J.linear2.y)) - (rY * (m_force * m_J.linear2.x))));
return (tX);
}
override public function GetReactionForce():b2Vec2{
var F:b2Vec2 = new b2Vec2((m_force * m_J.linear2.x), (m_force * m_J.linear2.y));
return (F);
}
override public function SolvePositionConstraints():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 public 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 force:Number = ((-(step.inv_dt) * m_mass) * Cdot);
m_force = (m_force + force);
var P:Number = (step.dt * force);
b1.m_linearVelocity.x = (b1.m_linearVelocity.x + ((b1.m_invMass * P) * m_J.linear1.x));
b1.m_linearVelocity.y = (b1.m_linearVelocity.y + ((b1.m_invMass * P) * m_J.linear1.y));
b1.m_angularVelocity = (b1.m_angularVelocity + ((b1.m_invI * P) * m_J.angular1));
b2.m_linearVelocity.x = (b2.m_linearVelocity.x + ((b2.m_invMass * P) * m_J.linear2.x));
b2.m_linearVelocity.y = (b2.m_linearVelocity.y + ((b2.m_invMass * P) * m_J.linear2.y));
b2.m_angularVelocity = (b2.m_angularVelocity + ((b2.m_invI * P) * m_J.angular2));
}
}
}//package Box2D.Dynamics.Joints
Section 49
//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 50
//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 51
//b2Joint (Box2D.Dynamics.Joints.b2Joint)
package Box2D.Dynamics.Joints {
import Box2D.Dynamics.*;
import Box2D.Common.Math.*;
public class b2Joint {
public var m_islandFlag:Boolean;
public var m_prev:b2Joint;
public var m_next:b2Joint;
public var m_type:int;
public var m_collideConnected:Boolean;
public var m_node1:b2JointEdge;
public var m_node2:b2JointEdge;
public var m_userData;
public var m_body1:b2Body;
public var m_body2:b2Body;
public static const e_unknownJoint:int = 0;
public static const e_inactiveLimit:int = 0;
public static const e_atUpperLimit:int = 2;
public static const e_atLowerLimit:int = 1;
public static const e_gearJoint:int = 6;
public static const e_revoluteJoint:int = 1;
public static const e_equalLimits:int = 3;
public static const e_distanceJoint:int = 3;
public static const e_pulleyJoint:int = 4;
public static const e_prismaticJoint:int = 2;
public static const e_mouseJoint:int = 5;
public function b2Joint(def:b2JointDef){
m_node1 = new b2JointEdge();
m_node2 = new b2JointEdge();
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);
}
public function InitPositionConstraints():void{
}
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);
}
public function InitVelocityConstraints(step:b2TimeStep):void{
}
public function GetReactionTorque():Number{
return (0);
}
public function GetUserData(){
return (m_userData);
}
public function GetReactionForce():b2Vec2{
return (null);
}
public function SolvePositionConstraints():Boolean{
return (false);
}
public function GetBody1():b2Body{
return (m_body1);
}
public function SolveVelocityConstraints(step:b2TimeStep):void{
}
public static function Destroy(joint:b2Joint, allocator):void{
}
public 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;
default:
break;
};
return (joint);
}
}
}//package Box2D.Dynamics.Joints
Section 52
//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 53
//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 54
//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;
public var m_mass:b2Mat22;
public var m_beta:Number;
public var m_force:b2Vec2;
private var K2:b2Mat22;
public var m_target:b2Vec2;
public var m_gamma:Number;
public var m_C:b2Vec2;
public var m_localAnchor:b2Vec2;
public var m_maxForce:Number;
public function b2MouseJoint(def:b2MouseJointDef){
K = new b2Mat22();
K1 = new b2Mat22();
K2 = new b2Mat22();
m_localAnchor = new b2Vec2();
m_target = new b2Vec2();
m_force = 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);
var tY:Number = (m_target.y - m_body2.m_xf.position.y);
var tMat:* = 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_force.SetZero();
var mass:Number = m_body2.m_mass;
var omega:Number = ((2 * b2Settings.b2_pi) * def.frequencyHz);
var d:Number = (((2 * mass) * def.dampingRatio) * omega);
var k:Number = ((mass * omega) * omega);
m_gamma = (1 / (d + (def.timeStep * k)));
m_beta = ((def.timeStep * k) / (d + (def.timeStep * k)));
}
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 public function InitVelocityConstraints(step:b2TimeStep):void{
var tMat:b2Mat22;
var b:b2Body = m_body2;
tMat = b.m_xf.R;
var rX:Number = (m_localAnchor.x - b.GetLocalCenter().x);
var rY:Number = (m_localAnchor.y - b.GetLocalCenter().y);
var tX:* = ((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.Invert(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);
var PX:Number = (step.dt * m_force.x);
var PY:Number = (step.dt * m_force.y);
b.m_linearVelocity.x = (b.m_linearVelocity.x + (invMass * PX));
b.m_linearVelocity.y = (b.m_linearVelocity.y + (invMass * PY));
b.m_angularVelocity = (b.m_angularVelocity + (invI * ((rX * PY) - (rY * PX))));
}
override public function GetAnchor1():b2Vec2{
return (m_target);
}
override public function GetReactionTorque():Number{
return (0);
}
override public function GetReactionForce():b2Vec2{
return (m_force);
}
override public function SolvePositionConstraints():Boolean{
return (true);
}
override public 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.GetLocalCenter().x);
var rY:Number = (m_localAnchor.y - b.GetLocalCenter().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 * step.inv_dt) * m_C.x)) + ((m_gamma * step.dt) * m_force.x));
tY = ((CdotY + ((m_beta * step.inv_dt) * m_C.y)) + ((m_gamma * step.dt) * m_force.y));
var forceX:Number = (-(step.inv_dt) * ((tMat.col1.x * tX) + (tMat.col2.x * tY)));
var forceY:Number = (-(step.inv_dt) * ((tMat.col1.y * tX) + (tMat.col2.y * tY)));
var oldForceX:Number = m_force.x;
var oldForceY:Number = m_force.y;
m_force.x = (m_force.x + forceX);
m_force.y = (m_force.y + forceY);
var forceMagnitude:Number = m_force.Length();
if (forceMagnitude > m_maxForce){
m_force.Multiply((m_maxForce / forceMagnitude));
};
forceX = (m_force.x - oldForceX);
forceY = (m_force.y - oldForceY);
var PX:Number = (step.dt * forceX);
var PY:Number = (step.dt * forceY);
b.m_linearVelocity.x = (b.m_linearVelocity.x + (b.m_invMass * PX));
b.m_linearVelocity.y = (b.m_linearVelocity.y + (b.m_invMass * PY));
b.m_angularVelocity = (b.m_angularVelocity + (b.m_invI * ((rX * PY) - (rY * PX))));
}
}
}//package Box2D.Dynamics.Joints
Section 55
//b2MouseJointDef (Box2D.Dynamics.Joints.b2MouseJointDef)
package Box2D.Dynamics.Joints {
import Box2D.Common.Math.*;
public class b2MouseJointDef extends b2JointDef {
public var timeStep:Number;
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;
timeStep = (1 / 60);
}
}
}//package Box2D.Dynamics.Joints
Section 56
//b2PrismaticJoint (Box2D.Dynamics.Joints.b2PrismaticJoint)
package Box2D.Dynamics.Joints {
import Box2D.Dynamics.*;
import Box2D.Common.Math.*;
import Box2D.Common.*;
public class b2PrismaticJoint extends b2Joint {
public var m_limitForce:Number;
public var m_lowerTranslation:Number;
public var m_localXAxis1:b2Vec2;
public var m_refAngle:Number;
public var m_torque:Number;
public var m_motorForce:Number;
public var m_enableLimit:Boolean;
public var m_angularMass:Number;
public var m_maxMotorForce:Number;
public var m_localYAxis1:b2Vec2;
public var m_force:Number;
public var m_motorMass:Number;
public var m_upperTranslation:Number;
public var m_localAnchor1:b2Vec2;
public var m_localAnchor2:b2Vec2;
public var m_limitState:int;
public var m_linearMass:Number;
public var m_motorJacobian:b2Jacobian;
public var m_limitPositionImpulse:Number;
public var m_motorSpeed:Number;
public var m_enableMotor:Boolean;
public var m_linearJacobian:b2Jacobian;
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_linearJacobian = new b2Jacobian();
m_motorJacobian = new b2Jacobian();
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_linearJacobian.SetZero();
m_linearMass = 0;
m_force = 0;
m_angularMass = 0;
m_torque = 0;
m_motorJacobian.SetZero();
m_motorMass = 0;
m_motorForce = 0;
m_limitForce = 0;
m_limitPositionImpulse = 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;
}
override public function SolveVelocityConstraints(step:b2TimeStep):void{
var oldLimitForce:Number;
var L:Number;
var motorCdot:Number;
var motorForce:Number;
var oldMotorForce:Number;
var limitCdot:Number;
var limitForce:Number;
var b1:b2Body = m_body1;
var b2:b2Body = m_body2;
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 linearCdot:Number = m_linearJacobian.Compute(b1.m_linearVelocity, b1.m_angularVelocity, b2.m_linearVelocity, b2.m_angularVelocity);
var force:Number = ((-(step.inv_dt) * m_linearMass) * linearCdot);
m_force = (m_force + force);
var P:Number = (step.dt * force);
b1.m_linearVelocity.x = (b1.m_linearVelocity.x + ((invMass1 * P) * m_linearJacobian.linear1.x));
b1.m_linearVelocity.y = (b1.m_linearVelocity.y + ((invMass1 * P) * m_linearJacobian.linear1.y));
b1.m_angularVelocity = (b1.m_angularVelocity + ((invI1 * P) * m_linearJacobian.angular1));
b2.m_linearVelocity.x = (b2.m_linearVelocity.x + ((invMass2 * P) * m_linearJacobian.linear2.x));
b2.m_linearVelocity.y = (b2.m_linearVelocity.y + ((invMass2 * P) * m_linearJacobian.linear2.y));
b2.m_angularVelocity = (b2.m_angularVelocity + ((invI2 * P) * m_linearJacobian.angular2));
var angularCdot:Number = (b2.m_angularVelocity - b1.m_angularVelocity);
var torque:Number = ((-(step.inv_dt) * m_angularMass) * angularCdot);
m_torque = (m_torque + torque);
L = (step.dt * torque);
b1.m_angularVelocity = (b1.m_angularVelocity - (invI1 * L));
b2.m_angularVelocity = (b2.m_angularVelocity + (invI2 * L));
if (((m_enableMotor) && (!((m_limitState == e_equalLimits))))){
motorCdot = (m_motorJacobian.Compute(b1.m_linearVelocity, b1.m_angularVelocity, b2.m_linearVelocity, b2.m_angularVelocity) - m_motorSpeed);
motorForce = ((-(step.inv_dt) * m_motorMass) * motorCdot);
oldMotorForce = m_motorForce;
m_motorForce = b2Math.b2Clamp((m_motorForce + motorForce), -(m_maxMotorForce), m_maxMotorForce);
motorForce = (m_motorForce - oldMotorForce);
P = (step.dt * motorForce);
b1.m_linearVelocity.x = (b1.m_linearVelocity.x + ((invMass1 * P) * m_motorJacobian.linear1.x));
b1.m_linearVelocity.y = (b1.m_linearVelocity.y + ((invMass1 * P) * m_motorJacobian.linear1.y));
b1.m_angularVelocity = (b1.m_angularVelocity + ((invI1 * P) * m_motorJacobian.angular1));
b2.m_linearVelocity.x = (b2.m_linearVelocity.x + ((invMass2 * P) * m_motorJacobian.linear2.x));
b2.m_linearVelocity.y = (b2.m_linearVelocity.y + ((invMass2 * P) * m_motorJacobian.linear2.y));
b2.m_angularVelocity = (b2.m_angularVelocity + ((invI2 * P) * m_motorJacobian.angular2));
};
if (((m_enableLimit) && (!((m_limitState == e_inactiveLimit))))){
limitCdot = m_motorJacobian.Compute(b1.m_linearVelocity, b1.m_angularVelocity, b2.m_linearVelocity, b2.m_angularVelocity);
limitForce = ((-(step.inv_dt) * m_motorMass) * limitCdot);
if (m_limitState == e_equalLimits){
m_limitForce = (m_limitForce + limitForce);
} else {
if (m_limitState == e_atLowerLimit){
oldLimitForce = m_limitForce;
m_limitForce = b2Math.b2Max((m_limitForce + limitForce), 0);
limitForce = (m_limitForce - oldLimitForce);
} else {
if (m_limitState == e_atUpperLimit){
oldLimitForce = m_limitForce;
m_limitForce = b2Math.b2Min((m_limitForce + limitForce), 0);
limitForce = (m_limitForce - oldLimitForce);
};
};
};
P = (step.dt * limitForce);
b1.m_linearVelocity.x = (b1.m_linearVelocity.x + ((invMass1 * P) * m_motorJacobian.linear1.x));
b1.m_linearVelocity.y = (b1.m_linearVelocity.y + ((invMass1 * P) * m_motorJacobian.linear1.y));
b1.m_angularVelocity = (b1.m_angularVelocity + ((invI1 * P) * m_motorJacobian.angular1));
b2.m_linearVelocity.x = (b2.m_linearVelocity.x + ((invMass2 * P) * m_motorJacobian.linear2.x));
b2.m_linearVelocity.y = (b2.m_linearVelocity.y + ((invMass2 * P) * m_motorJacobian.linear2.y));
b2.m_angularVelocity = (b2.m_angularVelocity + ((invI2 * P) * m_motorJacobian.angular2));
};
}
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_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():b2Vec2{
var tMat:b2Mat22 = m_body1.m_xf.R;
var ax1X:Number = (m_limitForce * ((tMat.col1.x * m_localXAxis1.x) + (tMat.col2.x * m_localXAxis1.y)));
var ax1Y:Number = (m_limitForce * ((tMat.col1.y * m_localXAxis1.x) + (tMat.col2.y * m_localXAxis1.y)));
var ay1X:Number = (m_force * ((tMat.col1.x * m_localYAxis1.x) + (tMat.col2.x * m_localYAxis1.y)));
var ay1Y:Number = (m_force * ((tMat.col1.y * m_localYAxis1.x) + (tMat.col2.y * m_localYAxis1.y)));
return (new b2Vec2(((m_limitForce * ax1X) + (m_force * ay1X)), ((m_limitForce * ax1Y) + (m_force * ay1Y))));
}
override public function SolvePositionConstraints():Boolean{
var limitC:Number;
var oldLimitImpulse:Number;
var tMat:b2Mat22;
var tX:Number;
var ax1X:Number;
var ax1Y:Number;
var translation:Number;
var limitImpulse:Number;
var b1:b2Body = m_body1;
var b2:b2Body = m_body2;
var invMass1:Number = b1.m_invMass;
var invMass2:Number = b2.m_invMass;
var invI1:Number = b1.m_invI;
var invI2:Number = b2.m_invI;
tMat = b1.m_xf.R;
var r1X:Number = (m_localAnchor1.x - b1.GetLocalCenter().x);
var r1Y:Number = (m_localAnchor1.y - b1.GetLocalCenter().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.GetLocalCenter().x);
var r2Y:Number = (m_localAnchor2.y - b2.GetLocalCenter().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);
tMat = b1.m_xf.R;
var ay1X:Number = ((tMat.col1.x * m_localYAxis1.x) + (tMat.col2.x * m_localYAxis1.y));
var ay1Y:Number = ((tMat.col1.y * m_localYAxis1.x) + (tMat.col2.y * m_localYAxis1.y));
var linearC:Number = ((ay1X * dX) + (ay1Y * dY));
linearC = b2Math.b2Clamp(linearC, -(b2Settings.b2_maxLinearCorrection), b2Settings.b2_maxLinearCorrection);
var linearImpulse:Number = (-(m_linearMass) * linearC);
b1.m_sweep.c.x = (b1.m_sweep.c.x + ((invMass1 * linearImpulse) * m_linearJacobian.linear1.x));
b1.m_sweep.c.y = (b1.m_sweep.c.y + ((invMass1 * linearImpulse) * m_linearJacobian.linear1.y));
b1.m_sweep.a = (b1.m_sweep.a + ((invI1 * linearImpulse) * m_linearJacobian.angular1));
b2.m_sweep.c.x = (b2.m_sweep.c.x + ((invMass2 * linearImpulse) * m_linearJacobian.linear2.x));
b2.m_sweep.c.y = (b2.m_sweep.c.y + ((invMass2 * linearImpulse) * m_linearJacobian.linear2.y));
b2.m_sweep.a = (b2.m_sweep.a + ((invI2 * linearImpulse) * m_linearJacobian.angular2));
var positionError:Number = b2Math.b2Abs(linearC);
var angularC:Number = ((b2.m_sweep.a - b1.m_sweep.a) - m_refAngle);
angularC = b2Math.b2Clamp(angularC, -(b2Settings.b2_maxAngularCorrection), b2Settings.b2_maxAngularCorrection);
var angularImpulse:Number = (-(m_angularMass) * angularC);
b1.m_sweep.a = (b1.m_sweep.a - (b1.m_invI * angularImpulse));
b2.m_sweep.a = (b2.m_sweep.a + (b2.m_invI * angularImpulse));
b1.SynchronizeTransform();
b2.SynchronizeTransform();
var angularError:Number = b2Math.b2Abs(angularC);
if (((m_enableLimit) && (!((m_limitState == e_inactiveLimit))))){
tMat = b1.m_xf.R;
r1X = (m_localAnchor1.x - b1.GetLocalCenter().x);
r1Y = (m_localAnchor1.y - b1.GetLocalCenter().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.GetLocalCenter().x);
r2Y = (m_localAnchor2.y - b2.GetLocalCenter().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);
dX = (p2X - p1X);
dY = (p2Y - p1Y);
tMat = b1.m_xf.R;
ax1X = ((tMat.col1.x * m_localXAxis1.x) + (tMat.col2.x * m_localXAxis1.y));
ax1Y = ((tMat.col1.y * m_localXAxis1.x) + (tMat.col2.y * m_localXAxis1.y));
translation = ((ax1X * dX) + (ax1Y * dY));
limitImpulse = 0;
if (m_limitState == e_equalLimits){
limitC = b2Math.b2Clamp(translation, -(b2Settings.b2_maxLinearCorrection), b2Settings.b2_maxLinearCorrection);
limitImpulse = (-(m_motorMass) * limitC);
positionError = b2Math.b2Max(positionError, b2Math.b2Abs(angularC));
} else {
if (m_limitState == e_atLowerLimit){
limitC = (translation - m_lowerTranslation);
positionError = b2Math.b2Max(positionError, -(limitC));
limitC = b2Math.b2Clamp((limitC + b2Settings.b2_linearSlop), -(b2Settings.b2_maxLinearCorrection), 0);
limitImpulse = (-(m_motorMass) * limitC);
oldLimitImpulse = m_limitPositionImpulse;
m_limitPositionImpulse = b2Math.b2Max((m_limitPositionImpulse + limitImpulse), 0);
limitImpulse = (m_limitPositionImpulse - oldLimitImpulse);
} else {
if (m_limitState == e_atUpperLimit){
limitC = (translation - m_upperTranslation);
positionError = b2Math.b2Max(positionError, limitC);
limitC = b2Math.b2Clamp((limitC - b2Settings.b2_linearSlop), 0, b2Settings.b2_maxLinearCorrection);
limitImpulse = (-(m_motorMass) * limitC);
oldLimitImpulse = m_limitPositionImpulse;
m_limitPositionImpulse = b2Math.b2Min((m_limitPositionImpulse + limitImpulse), 0);
limitImpulse = (m_limitPositionImpulse - oldLimitImpulse);
};
};
};
b1.m_sweep.c.x = (b1.m_sweep.c.x + ((invMass1 * limitImpulse) * m_motorJacobian.linear1.x));
b1.m_sweep.c.y = (b1.m_sweep.c.y + ((invMass1 * limitImpulse) * m_motorJacobian.linear1.y));
b1.m_sweep.a = (b1.m_sweep.a + ((invI1 * limitImpulse) * m_motorJacobian.angular1));
b2.m_sweep.c.x = (b2.m_sweep.c.x + ((invMass2 * limitImpulse) * m_motorJacobian.linear2.x));
b2.m_sweep.c.y = (b2.m_sweep.c.y + ((invMass2 * limitImpulse) * m_motorJacobian.linear2.y));
b2.m_sweep.a = (b2.m_sweep.a + ((invI2 * limitImpulse) * m_motorJacobian.angular2));
b1.SynchronizeTransform();
b2.SynchronizeTransform();
};
return ((((positionError <= b2Settings.b2_linearSlop)) && ((angularError <= b2Settings.b2_angularSlop))));
}
public function SetMotorSpeed(speed:Number):void{
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.GetLocalCenter().x);
var r1Y:Number = (m_localAnchor1.y - b1.GetLocalCenter().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.GetLocalCenter().x);
var r2Y:Number = (m_localAnchor2.y - b2.GetLocalCenter().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 public function InitVelocityConstraints(step:b2TimeStep):void{
var tMat:b2Mat22;
var tX:Number;
var ax1X:Number;
var ax1Y:Number;
var dX:Number;
var dY:Number;
var jointTranslation:Number;
var P1X:Number;
var P1Y:Number;
var P2X:Number;
var P2Y:Number;
var L1:Number;
var L2:Number;
var b1:b2Body = m_body1;
var b2:b2Body = m_body2;
tMat = b1.m_xf.R;
var r1X:Number = (m_localAnchor1.x - b1.GetLocalCenter().x);
var r1Y:Number = (m_localAnchor1.y - b1.GetLocalCenter().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.GetLocalCenter().x);
var r2Y:Number = (m_localAnchor2.y - b2.GetLocalCenter().y);
tX = ((tMat.col1.x * r2X) + (tMat.col2.x * r2Y));
r2Y = ((tMat.col1.y * r2X) + (tMat.col2.y * r2Y));
r2X = tX;
var invMass1:Number = b1.m_invMass;
var invMass2:Number = b2.m_invMass;
var invI1:Number = b1.m_invI;
var invI2:Number = b2.m_invI;
tMat = b1.m_xf.R;
var ay1X:Number = ((tMat.col1.x * m_localYAxis1.x) + (tMat.col2.x * m_localYAxis1.y));
var ay1Y:Number = ((tMat.col1.y * m_localYAxis1.x) + (tMat.col2.y * m_localYAxis1.y));
var eX:Number = ((b2.m_sweep.c.x + r2X) - b1.m_sweep.c.x);
var eY:Number = ((b2.m_sweep.c.y + r2Y) - b1.m_sweep.c.y);
m_linearJacobian.linear1.x = -(ay1X);
m_linearJacobian.linear1.y = -(ay1Y);
m_linearJacobian.linear2.x = ay1X;
m_linearJacobian.linear2.y = ay1Y;
m_linearJacobian.angular1 = -(((eX * ay1Y) - (eY * ay1X)));
m_linearJacobian.angular2 = ((r2X * ay1Y) - (r2Y * ay1X));
m_linearMass = (((invMass1 + ((invI1 * m_linearJacobian.angular1) * m_linearJacobian.angular1)) + invMass2) + ((invI2 * m_linearJacobian.angular2) * m_linearJacobian.angular2));
m_linearMass = (1 / m_linearMass);
m_angularMass = (invI1 + invI2);
if (m_angularMass > Number.MIN_VALUE){
m_angularMass = (1 / m_angularMass);
};
if (((m_enableLimit) || (m_enableMotor))){
tMat = b1.m_xf.R;
ax1X = ((tMat.col1.x * m_localXAxis1.x) + (tMat.col2.x * m_localXAxis1.y));
ax1Y = ((tMat.col1.y * m_localXAxis1.x) + (tMat.col2.y * m_localXAxis1.y));
m_motorJacobian.linear1.x = -(ax1X);
m_motorJacobian.linear1.y = -(ax1Y);
m_motorJacobian.linear2.x = ax1X;
m_motorJacobian.linear2.y = ax1Y;
m_motorJacobian.angular1 = -(((eX * ax1Y) - (eY * ax1X)));
m_motorJacobian.angular2 = ((r2X * ax1Y) - (r2Y * ax1X));
m_motorMass = (((invMass1 + ((invI1 * m_motorJacobian.angular1) * m_motorJacobian.angular1)) + invMass2) + ((invI2 * m_motorJacobian.angular2) * m_motorJacobian.angular2));
m_motorMass = (1 / m_motorMass);
if (m_enableLimit){
dX = (eX - r1X);
dY = (eY - r1Y);
jointTranslation = ((ax1X * dX) + (ax1Y * dY));
if (b2Math.b2Abs((m_upperTranslation - m_lowerTranslation)) < (2 * b2Settings.b2_linearSlop)){
m_limitState = e_equalLimits;
} else {
if (jointTranslation <= m_lowerTranslation){
if (m_limitState != e_atLowerLimit){
m_limitForce = 0;
};
m_limitState = e_atLowerLimit;
} else {
if (jointTranslation >= m_upperTranslation){
if (m_limitState != e_atUpperLimit){
m_limitForce = 0;
};
m_limitState = e_atUpperLimit;
} else {
m_limitState = e_inactiveLimit;
m_limitForce = 0;
};
};
};
};
};
if (m_enableMotor == false){
m_motorForce = 0;
};
if (m_enableLimit == false){
m_limitForce = 0;
};
if (b2World.s_enableWarmStarting){
P1X = (step.dt * ((m_force * m_linearJacobian.linear1.x) + ((m_motorForce + m_limitForce) * m_motorJacobian.linear1.x)));
P1Y = (step.dt * ((m_force * m_linearJacobian.linear1.y) + ((m_motorForce + m_limitForce) * m_motorJacobian.linear1.y)));
P2X = (step.dt * ((m_force * m_linearJacobian.linear2.x) + ((m_motorForce + m_limitForce) * m_motorJacobian.linear2.x)));
P2Y = (step.dt * ((m_force * m_linearJacobian.linear2.y) + ((m_motorForce + m_limitForce) * m_motorJacobian.linear2.y)));
L1 = (step.dt * (((m_force * m_linearJacobian.angular1) - m_torque) + ((m_motorForce + m_limitForce) * m_motorJacobian.angular1)));
L2 = (step.dt * (((m_force * m_linearJacobian.angular2) + m_torque) + ((m_motorForce + m_limitForce) * m_motorJacobian.angular2)));
b1.m_linearVelocity.x = (b1.m_linearVelocity.x + (invMass1 * P1X));
b1.m_linearVelocity.y = (b1.m_linearVelocity.y + (invMass1 * P1Y));
b1.m_angularVelocity = (b1.m_angularVelocity + (invI1 * L1));
b2.m_linearVelocity.x = (b2.m_linearVelocity.x + (invMass2 * P2X));
b2.m_linearVelocity.y = (b2.m_linearVelocity.y + (invMass2 * P2Y));
b2.m_angularVelocity = (b2.m_angularVelocity + (invI2 * L2));
} else {
m_force = 0;
m_torque = 0;
m_limitForce = 0;
m_motorForce = 0;
};
m_limitPositionImpulse = 0;
}
public function GetMotorForce():Number{
return (m_motorForce);
}
public function EnableLimit(flag:Boolean):void{
m_enableLimit = flag;
}
public function SetMaxMotorForce(force:Number){
m_maxMotorForce = force;
}
override public function GetReactionTorque():Number{
return (m_torque);
}
public function IsLimitEnabled():Boolean{
return (m_enableLimit);
}
public function IsMotorEnabled():Boolean{
return (m_enableMotor);
}
public function SetLimits(lower:Number, upper:Number):void{
m_lowerTranslation = lower;
m_upperTranslation = upper;
}
}
}//package Box2D.Dynamics.Joints
Section 57
//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){
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 58
//b2PulleyJoint (Box2D.Dynamics.Joints.b2PulleyJoint)
package Box2D.Dynamics.Joints {
import Box2D.Dynamics.*;
import Box2D.Common.Math.*;
import Box2D.Common.*;
public class b2PulleyJoint extends b2Joint {
public var m_limitState1:int;
public var m_limitState2:int;
public var m_ground:b2Body;
public var m_maxLength2:Number;
public var m_maxLength1:Number;
public var m_limitPositionImpulse1:Number;
public var m_limitPositionImpulse2:Number;
public var m_force:Number;
public var m_constant:Number;
public var m_positionImpulse:Number;
public var m_state:int;
public var m_ratio:Number;
public var m_groundAnchor1:b2Vec2;
public var m_groundAnchor2:b2Vec2;
public var m_localAnchor1:b2Vec2;
public var m_localAnchor2:b2Vec2;
public var m_limitMass1:Number;
public var m_limitMass2:Number;
public var m_pulleyMass:Number;
public var m_u1:b2Vec2;
public var m_limitForce1:Number;
public var m_limitForce2:Number;
public var m_u2:b2Vec2;
public 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_force = 0;
m_limitForce1 = 0;
m_limitForce2 = 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():b2Vec2{
var F:b2Vec2 = m_u2.Copy();
F.Multiply(m_force);
return (F);
}
override public function SolvePositionConstraints():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.GetLocalCenter().x);
r1Y = (m_localAnchor1.y - b1.GetLocalCenter().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.GetLocalCenter().x);
r2Y = (m_localAnchor2.y - b2.GetLocalCenter().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);
oldImpulse = m_positionImpulse;
m_positionImpulse = b2Math.b2Max(0, (m_positionImpulse + impulse));
impulse = (m_positionImpulse - 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_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.GetLocalCenter().x);
r1Y = (m_localAnchor1.y - b1.GetLocalCenter().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);
oldLimitPositionImpulse = m_limitPositionImpulse1;
m_limitPositionImpulse1 = b2Math.b2Max(0, (m_limitPositionImpulse1 + impulse));
impulse = (m_limitPositionImpulse1 - oldLimitPositionImpulse);
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.GetLocalCenter().x);
r2Y = (m_localAnchor2.y - b2.GetLocalCenter().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);
oldLimitPositionImpulse = m_limitPositionImpulse2;
m_limitPositionImpulse2 = b2Math.b2Max(0, (m_limitPositionImpulse2 + impulse));
impulse = (m_limitPositionImpulse2 - oldLimitPositionImpulse);
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 public function InitVelocityConstraints(step:b2TimeStep):void{
var tMat:b2Mat22;
var P1X:Number;
var P1Y:Number;
var P2X:Number;
var P2Y:Number;
var b1:b2Body = m_body1;
var b2:b2Body = m_body2;
tMat = b1.m_xf.R;
var r1X:Number = (m_localAnchor1.x - b1.GetLocalCenter().x);
var r1Y:Number = (m_localAnchor1.y - b1.GetLocalCenter().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.GetLocalCenter().x);
var r2Y:Number = (m_localAnchor2.y - b2.GetLocalCenter().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_force = 0;
} else {
m_state = e_atUpperLimit;
m_positionImpulse = 0;
};
if (length1 < m_maxLength1){
m_limitState1 = e_inactiveLimit;
m_limitForce1 = 0;
} else {
m_limitState1 = e_atUpperLimit;
m_limitPositionImpulse1 = 0;
};
if (length2 < m_maxLength2){
m_limitState2 = e_inactiveLimit;
m_limitForce2 = 0;
} else {
m_limitState2 = e_atUpperLimit;
m_limitPositionImpulse2 = 0;
};
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 (b2World.s_enableWarmStarting){
P1X = ((step.dt * (-(m_force) - m_limitForce1)) * m_u1.x);
P1Y = ((step.dt * (-(m_force) - m_limitForce1)) * m_u1.y);
P2X = ((step.dt * ((-(m_ratio) * m_force) - m_limitForce2)) * m_u2.x);
P2Y = ((step.dt * ((-(m_ratio) * m_force) - m_limitForce2)) * 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_force = 0;
m_limitForce1 = 0;
m_limitForce2 = 0;
};
}
override public function GetReactionTorque():Number{
return (0);
}
public function GetRatio():Number{
return (m_ratio);
}
override public 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 force:Number;
var oldForce:Number;
var b1:b2Body = m_body1;
var b2:b2Body = m_body2;
tMat = b1.m_xf.R;
var r1X:Number = (m_localAnchor1.x - b1.GetLocalCenter().x);
var r1Y:Number = (m_localAnchor1.y - b1.GetLocalCenter().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.GetLocalCenter().x);
var r2Y:Number = (m_localAnchor2.y - b2.GetLocalCenter().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))));
force = ((-(step.inv_dt) * m_pulleyMass) * Cdot);
oldForce = m_force;
m_force = b2Math.b2Max(0, (m_force + force));
force = (m_force - oldForce);
P1X = ((-(step.dt) * force) * m_u1.x);
P1Y = ((-(step.dt) * force) * m_u1.y);
P2X = (((-(step.dt) * m_ratio) * force) * m_u2.x);
P2Y = (((-(step.dt) * m_ratio) * force) * 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)));
force = ((-(step.inv_dt) * m_limitMass1) * Cdot);
oldForce = m_limitForce1;
m_limitForce1 = b2Math.b2Max(0, (m_limitForce1 + force));
force = (m_limitForce1 - oldForce);
P1X = ((-(step.dt) * force) * m_u1.x);
P1Y = ((-(step.dt) * force) * 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)));
force = ((-(step.inv_dt) * m_limitMass2) * Cdot);
oldForce = m_limitForce2;
m_limitForce2 = b2Math.b2Max(0, (m_limitForce2 + force));
force = (m_limitForce2 - oldForce);
P2X = ((-(step.dt) * force) * m_u2.x);
P2Y = ((-(step.dt) * force) * 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 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))));
}
public function GetGroundAnchor1():b2Vec2{
var a:b2Vec2 = m_ground.m_xf.position.Copy();
a.Add(m_groundAnchor1);
return (a);
}
}
}//package Box2D.Dynamics.Joints
Section 59
//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){
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 60
//b2RevoluteJoint (Box2D.Dynamics.Joints.b2RevoluteJoint)
package Box2D.Dynamics.Joints {
import Box2D.Dynamics.*;
import Box2D.Common.Math.*;
import Box2D.Common.*;
public class b2RevoluteJoint extends b2Joint {
public var m_limitForce:Number;
public var m_pivotMass:b2Mat22;
public var m_motorForce:Number;
public var m_enableLimit:Boolean;
public var m_limitState:int;
public var m_motorMass:Number;
public var m_localAnchor1:b2Vec2;
public var m_localAnchor2:b2Vec2;
private var K1:b2Mat22;
private var K2:b2Mat22;
private var K3:b2Mat22;
private var K:b2Mat22;
public var m_pivotForce:b2Vec2;
public var m_enableMotor:Boolean;
public var m_referenceAngle:Number;
public var m_limitPositionImpulse:Number;
public var m_motorSpeed:Number;
public var m_upperAngle:Number;
public var m_lowerAngle:Number;
public var m_maxMotorTorque:Number;
public 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_pivotForce = new b2Vec2();
m_pivotMass = new b2Mat22();
super(def);
m_localAnchor1.SetV(def.localAnchor1);
m_localAnchor2.SetV(def.localAnchor2);
m_referenceAngle = def.referenceAngle;
m_pivotForce.Set(0, 0);
m_motorForce = 0;
m_limitForce = 0;
m_limitPositionImpulse = 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;
}
override public function SolveVelocityConstraints(step:b2TimeStep):void{
var tMat:b2Mat22;
var tX:Number;
var oldLimitForce:Number;
var PY:Number;
var motorCdot:Number;
var motorForce:Number;
var oldMotorForce:Number;
var limitCdot:Number;
var limitForce:Number;
var b1:b2Body = m_body1;
var b2:b2Body = m_body2;
tMat = b1.m_xf.R;
var r1X:Number = (m_localAnchor1.x - b1.GetLocalCenter().x);
var r1Y:Number = (m_localAnchor1.y - b1.GetLocalCenter().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.GetLocalCenter().x);
var r2Y:Number = (m_localAnchor2.y - b2.GetLocalCenter().y);
tX = ((tMat.col1.x * r2X) + (tMat.col2.x * r2Y));
r2Y = ((tMat.col1.y * r2X) + (tMat.col2.y * r2Y));
r2X = tX;
var pivotCdotX:Number = (((b2.m_linearVelocity.x + (-(b2.m_angularVelocity) * r2Y)) - b1.m_linearVelocity.x) - (-(b1.m_angularVelocity) * r1Y));
var pivotCdotY:Number = (((b2.m_linearVelocity.y + (b2.m_angularVelocity * r2X)) - b1.m_linearVelocity.y) - (b1.m_angularVelocity * r1X));
var pivotForceX:Number = (-(step.inv_dt) * ((m_pivotMass.col1.x * pivotCdotX) + (m_pivotMass.col2.x * pivotCdotY)));
var pivotForceY:Number = (-(step.inv_dt) * ((m_pivotMass.col1.y * pivotCdotX) + (m_pivotMass.col2.y * pivotCdotY)));
m_pivotForce.x = (m_pivotForce.x + pivotForceX);
m_pivotForce.y = (m_pivotForce.y + pivotForceY);
var PX:Number = (step.dt * pivotForceX);
PY = (step.dt * pivotForceY);
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))));
if (((m_enableMotor) && (!((m_limitState == e_equalLimits))))){
motorCdot = ((b2.m_angularVelocity - b1.m_angularVelocity) - m_motorSpeed);
motorForce = ((-(step.inv_dt) * m_motorMass) * motorCdot);
oldMotorForce = m_motorForce;
m_motorForce = b2Math.b2Clamp((m_motorForce + motorForce), -(m_maxMotorTorque), m_maxMotorTorque);
motorForce = (m_motorForce - oldMotorForce);
b1.m_angularVelocity = (b1.m_angularVelocity - ((b1.m_invI * step.dt) * motorForce));
b2.m_angularVelocity = (b2.m_angularVelocity + ((b2.m_invI * step.dt) * motorForce));
};
if (((m_enableLimit) && (!((m_limitState == e_inactiveLimit))))){
limitCdot = (b2.m_angularVelocity - b1.m_angularVelocity);
limitForce = ((-(step.inv_dt) * m_motorMass) * limitCdot);
if (m_limitState == e_equalLimits){
m_limitForce = (m_limitForce + limitForce);
} else {
if (m_limitState == e_atLowerLimit){
oldLimitForce = m_limitForce;
m_limitForce = b2Math.b2Max((m_limitForce + limitForce), 0);
limitForce = (m_limitForce - oldLimitForce);
} else {
if (m_limitState == e_atUpperLimit){
oldLimitForce = m_limitForce;
m_limitForce = b2Math.b2Min((m_limitForce + limitForce), 0);
limitForce = (m_limitForce - oldLimitForce);
};
};
};
b1.m_angularVelocity = (b1.m_angularVelocity - ((b1.m_invI * step.dt) * limitForce));
b2.m_angularVelocity = (b2.m_angularVelocity + ((b2.m_invI * step.dt) * limitForce));
};
}
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():b2Vec2{
return (m_pivotForce);
}
override public function SolvePositionConstraints():Boolean{
var oldLimitImpulse:Number;
var limitC:Number;
var tMat:b2Mat22;
var angle:Number;
var limitImpulse:Number;
var b1:b2Body = m_body1;
var b2:b2Body = m_body2;
var positionError:Number = 0;
tMat = b1.m_xf.R;
var r1X:Number = (m_localAnchor1.x - b1.GetLocalCenter().x);
var r1Y:Number = (m_localAnchor1.y - b1.GetLocalCenter().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.GetLocalCenter().x);
var r2Y:Number = (m_localAnchor2.y - b2.GetLocalCenter().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 ptpCX:Number = (p2X - p1X);
var ptpCY:Number = (p2Y - p1Y);
positionError = Math.sqrt(((ptpCX * ptpCX) + (ptpCY * ptpCY)));
var invMass1:Number = b1.m_invMass;
var invMass2:Number = b2.m_invMass;
var invI1:Number = b1.m_invI;
var invI2:Number = b2.m_invI;
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, -(ptpCX), -(ptpCY));
var impulseX:Number = tImpulse.x;
var impulseY:Number = 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();
var angularError: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){
limitC = b2Math.b2Clamp(angle, -(b2Settings.b2_maxAngularCorrection), b2Settings.b2_maxAngularCorrection);
limitImpulse = (-(m_motorMass) * limitC);
angularError = b2Math.b2Abs(limitC);
} else {
if (m_limitState == e_atLowerLimit){
limitC = (angle - m_lowerAngle);
angularError = b2Math.b2Max(0, -(limitC));
limitC = b2Math.b2Clamp((limitC + b2Settings.b2_angularSlop), -(b2Settings.b2_maxAngularCorrection), 0);
limitImpulse = (-(m_motorMass) * limitC);
oldLimitImpulse = m_limitPositionImpulse;
m_limitPositionImpulse = b2Math.b2Max((m_limitPositionImpulse + limitImpulse), 0);
limitImpulse = (m_limitPositionImpulse - oldLimitImpulse);
} else {
if (m_limitState == e_atUpperLimit){
limitC = (angle - m_upperAngle);
angularError = b2Math.b2Max(0, limitC);
limitC = b2Math.b2Clamp((limitC - b2Settings.b2_angularSlop), 0, b2Settings.b2_maxAngularCorrection);
limitImpulse = (-(m_motorMass) * limitC);
oldLimitImpulse = m_limitPositionImpulse;
m_limitPositionImpulse = b2Math.b2Min((m_limitPositionImpulse + limitImpulse), 0);
limitImpulse = (m_limitPositionImpulse - oldLimitImpulse);
};
};
};
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();
};
return ((((positionError <= b2Settings.b2_linearSlop)) && ((angularError <= b2Settings.b2_angularSlop))));
}
public function SetMotorSpeed(speed:Number){
m_motorSpeed = speed;
}
public function GetJointSpeed():Number{
return ((m_body2.m_angularVelocity - m_body1.m_angularVelocity));
}
public function SetMaxMotorTorque(torque:Number){
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_motorForce);
}
override public function InitVelocityConstraints(step:b2TimeStep):void{
var tMat:b2Mat22;
var tX:Number;
var jointAngle:Number;
var b1:b2Body = m_body1;
var b2:b2Body = m_body2;
tMat = b1.m_xf.R;
var r1X:Number = (m_localAnchor1.x - b1.GetLocalCenter().x);
var r1Y:Number = (m_localAnchor1.y - b1.GetLocalCenter().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.GetLocalCenter().x);
var r2Y:Number = (m_localAnchor2.y - b2.GetLocalCenter().y);
tX = ((tMat.col1.x * r2X) + (tMat.col2.x * r2Y));
r2Y = ((tMat.col1.y * r2X) + (tMat.col2.y * r2Y));
r2X = tX;
var invMass1:Number = b1.m_invMass;
var invMass2:Number = b2.m_invMass;
var invI1:Number = b1.m_invI;
var invI2:Number = b2.m_invI;
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.Invert(m_pivotMass);
m_motorMass = (1 / (invI1 + invI2));
if (m_enableMotor == false){
m_motorForce = 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_limitForce = 0;
};
m_limitState = e_atLowerLimit;
} else {
if (jointAngle >= m_upperAngle){
if (m_limitState != e_atUpperLimit){
m_limitForce = 0;
};
m_limitState = e_atUpperLimit;
} else {
m_limitState = e_inactiveLimit;
m_limitForce = 0;
};
};
};
} else {
m_limitForce = 0;
};
if (b2World.s_enableWarmStarting){
b1.m_linearVelocity.x = (b1.m_linearVelocity.x - ((step.dt * invMass1) * m_pivotForce.x));
b1.m_linearVelocity.y = (b1.m_linearVelocity.y - ((step.dt * invMass1) * m_pivotForce.y));
b1.m_angularVelocity = (b1.m_angularVelocity - ((step.dt * invI1) * ((((r1X * m_pivotForce.y) - (r1Y * m_pivotForce.x)) + m_motorForce) + m_limitForce)));
b2.m_linearVelocity.x = (b2.m_linearVelocity.x + ((step.dt * invMass2) * m_pivotForce.x));
b2.m_linearVelocity.y = (b2.m_linearVelocity.y + ((step.dt * invMass2) * m_pivotForce.y));
b2.m_angularVelocity = (b2.m_angularVelocity + ((step.dt * invI2) * ((((r2X * m_pivotForce.y) - (r2Y * m_pivotForce.x)) + m_motorForce) + m_limitForce)));
} else {
m_pivotForce.SetZero();
m_motorForce = 0;
m_limitForce = 0;
};
m_limitPositionImpulse = 0;
}
public function EnableLimit(flag:Boolean):void{
m_enableLimit = flag;
}
override public function GetReactionTorque():Number{
return (m_limitForce);
}
public function IsLimitEnabled():Boolean{
return (m_enableLimit);
}
public function IsMotorEnabled():Boolean{
return (m_enableMotor);
}
public function SetLimits(lower:Number, upper:Number){
m_lowerAngle = lower;
m_upperAngle = upper;
}
}
}//package Box2D.Dynamics.Joints
Section 61
//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 62
//b2Body (Box2D.Dynamics.b2Body)
package Box2D.Dynamics {
import Box2D.Common.Math.*;
import Box2D.Dynamics.Joints.*;
import Box2D.Collision.Shapes.*;
import Box2D.Dynamics.Contacts.*;
public class b2Body {
public var m_xf:b2XForm;
public var m_next:b2Body;
public var m_contactList:b2ContactEdge;
public var m_angularVelocity:Number;
public var m_shapeList:b2Shape;
public var m_force:b2Vec2;
public var m_sweep:b2Sweep;
public var m_mass:Number;
public var m_torque:Number;
public var m_userData;
public var m_flags:uint;
public var m_world:b2World;
public var m_linearVelocity:b2Vec2;
public var m_prev:b2Body;
public var m_invMass:Number;
public var m_type:uint;
public var m_linearDamping:Number;
public var m_shapeCount:int;
public var m_angularDamping:Number;
public var m_invI:Number;
public var m_sleepTime:Number;
public var m_jointList:b2JointEdge;
public var m_I:Number;
public static var e_fixedRotationFlag:uint = 64;
public static var e_frozenFlag:uint = 2;
public static var e_maxTypes:uint = 3;
public static var e_sleepFlag:uint = 8;
private static var s_massData:b2MassData = new b2MassData();
public static var e_bulletFlag:uint = 32;
public static var e_staticType:uint = 1;
public static var e_islandFlag:uint = 4;
public static var e_allowSleepFlag:uint = 16;
private static var s_xf1:b2XForm = new b2XForm();
public static var e_dynamicType:uint = 2;
public function b2Body(bd:b2BodyDef, type:uint, 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_type = type;
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_mass = 0;
m_invMass = 0;
m_I = 0;
m_invI = 0;
if (m_type == e_dynamicType){
m_mass = bd.massData.mass;
};
if (m_mass > 0){
m_invMass = (1 / m_mass);
};
if (((((m_flags & b2Body.e_fixedRotationFlag) == 0)) && ((m_type == e_dynamicType)))){
m_I = bd.massData.I;
};
if (m_I > 0){
m_invI = (1 / m_I);
};
m_userData = bd.userData;
m_shapeList = null;
m_shapeCount = 0;
}
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 GetLocalCenter():b2Vec2{
return (m_sweep.localCenter);
}
public function Unfreeze():void{
m_flags = (m_flags ^ e_frozenFlag);
m_linearVelocity.SetZero();
m_angularVelocity = 0;
}
public function IsFrozen():Boolean{
return (((m_flags & e_frozenFlag) == e_frozenFlag));
}
public function IsDynamic():Boolean{
return ((m_type == e_dynamicType));
}
public 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 ApplyTorque(torque:Number):void{
if (IsSleeping()){
WakeUp();
};
m_torque = (m_torque + torque);
}
public function IsSleeping():Boolean{
return (((m_flags & e_sleepFlag) == e_sleepFlag));
}
public function GetLinearVelocity():b2Vec2{
return (m_linearVelocity);
}
public function SetMassFromShapes():void{
var s:b2Shape;
if (m_world.m_lock == true){
return;
};
if (m_type == e_staticType){
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);
} else {
m_invMass = 0;
m_invI = 0;
};
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;
};
}
public function Freeze():void{
m_flags = (m_flags | e_frozenFlag);
m_linearVelocity.SetZero();
m_angularVelocity = 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 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 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 GetContactList():b2ContactEdge{
return (m_contactList);
}
public function GetAngularVelocity():Number{
return (m_angularVelocity);
}
public function GetMass():Number{
return (m_mass);
}
public function GetShapeList():b2Shape{
return (m_shapeList);
}
public function SetAngularVelocity(omega:Number):void{
m_angularVelocity = omega;
}
public function SetMass(massData:b2MassData):void{
if (m_world.m_lock == true){
return;
};
if (m_type == e_staticType){
return;
};
m_mass = 0;
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);
var s:b2Shape = m_shapeList;
while (s) {
s.UpdateSweepRadius(m_sweep.localCenter);
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);
}
public 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{
if (m_world.m_lock == true){
return (null);
};
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);
}
public 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 found:Boolean;
while (node != null) {
if (node == s){
node = s.m_next;
found = true;
break;
};
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 GetLocalVector(worldVector:b2Vec2):b2Vec2{
return (b2Math.b2MulTMV(m_xf.R, worldVector));
}
public function GetWorldPoint(localPoint:b2Vec2):b2Vec2{
return (b2Math.b2MulX(m_xf, localPoint));
}
public function GetPosition():b2Vec2{
return (m_xf.position);
}
}
}//package Box2D.Dynamics
Section 63
//b2BodyDef (Box2D.Dynamics.b2BodyDef)
package Box2D.Dynamics {
import Box2D.Common.Math.*;
import Box2D.Collision.Shapes.*;
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 64
//b2BoundaryListener (Box2D.Dynamics.b2BoundaryListener)
package Box2D.Dynamics {
public class b2BoundaryListener {
public function b2BoundaryListener(){
super();
}
public function Violation(body:b2Body):void{
}
}
}//package Box2D.Dynamics
Section 65
//b2ContactFilter (Box2D.Dynamics.b2ContactFilter)
package Box2D.Dynamics {
import Box2D.Collision.Shapes.*;
public class b2ContactFilter {
public static var b2_defaultFilter:b2ContactFilter = new (b2ContactFilter);
;
public function b2ContactFilter(){
super();
}
public function ShouldCollide(shape1:b2Shape, shape2:b2Shape):Boolean{
return (true);
}
}
}//package Box2D.Dynamics
Section 66
//b2ContactListener (Box2D.Dynamics.b2ContactListener)
package Box2D.Dynamics {
import Box2D.Collision.*;
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{
}
}
}//package Box2D.Dynamics
Section 67
//b2ContactManager (Box2D.Dynamics.b2ContactManager)
package Box2D.Dynamics {
import Box2D.Common.Math.*;
import Box2D.Collision.*;
import Box2D.Collision.Shapes.*;
import Box2D.Common.*;
import Box2D.Dynamics.Contacts.*;
public class b2ContactManager extends b2PairCallback {
public var m_world:b2World;
public var m_destroyImmediate:Boolean;
public var m_nullContact:b2NullContact;
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 cp:b2ContactPoint;
var b1:b2Body;
var manifolds:Array;
var i:int;
var manifold:b2Manifold;
var j:int;
var point:b2ManifoldPoint;
var tMat:b2Mat22;
var tPos:b2Vec2;
var tVec:b2Vec2;
var shape1:b2Shape = c.GetShape1();
var shape2:b2Shape = c.GetShape2();
var manifoldCount:int = c.GetManifoldCount();
if ((((manifoldCount > 0)) && (m_world.m_contactListener))){
cp = new b2ContactPoint();
cp.shape1 = c.GetShape1();
cp.shape2 = c.GetShape2();
b1 = cp.shape1.GetBody();
manifolds = c.GetManifolds();
i = 0;
while (i < manifoldCount) {
manifold = manifolds[i];
cp.normal.SetV(manifold.normal);
j = 0;
while (j < manifold.pointCount) {
point = manifold.points[j];
tMat = b1.GetXForm().R;
tPos = b1.GetXForm().position;
tVec = point.localPoint1;
cp.position.x = (tPos.x + ((tMat.col1.x * tVec.x) + (tMat.col2.x * tVec.y)));
cp.position.y = (tPos.y + ((tMat.col1.y * tVec.x) + (tMat.col2.y * tVec.y)));
cp.separation = point.separation;
cp.normalForce = point.normalForce;
cp.tangentForce = point.tangentForce;
cp.id = point.id;
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;
};
var body1:b2Body = shape1.GetBody();
var body2:b2Body = shape2.GetBody();
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.GetBody();
var body2:b2Body = shape2.GetBody();
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.GetShape1();
shape2 = c.GetShape2();
body1 = shape1.GetBody();
body2 = shape2.GetBody();
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 cp:b2ContactPoint;
var b1:b2Body;
var manifoldCount:int;
var manifolds:Array;
var i:int;
var manifold:b2Manifold;
var j:int;
var point:b2ManifoldPoint;
var tMat:b2Mat22;
var tPos:b2Vec2;
var tVec:b2Vec2;
var c:b2Contact = m_world.m_contactList;
while (c) {
body1 = c.GetShape1().GetBody();
body2 = c.GetShape2().GetBody();
if (((body1.IsSleeping()) && (body2.IsSleeping()))){
} else {
c.Update(m_world.m_contactListener);
if ((((c.IsSolid() == false)) && (m_world.m_contactListener))){
cp = new b2ContactPoint();
cp.shape1 = c.GetShape1();
cp.shape2 = c.GetShape2();
cp.normalForce = 0;
cp.tangentForce = 0;
b1 = cp.shape1.GetBody();
manifoldCount = c.GetManifoldCount();
manifolds = c.GetManifolds();
i = 0;
while (i < manifoldCount) {
manifold = manifolds[i];
cp.normal.SetV(manifold.normal);
j = 0;
while (j < manifold.pointCount) {
point = manifold.points[j];
tMat = b1.GetXForm().R;
tPos = b1.GetXForm().position;
tVec = point.localPoint1;
cp.position.x = (tPos.x + ((tMat.col1.x * tVec.x) + (tMat.col2.x * tVec.y)));
cp.position.y = (tPos.y + ((tMat.col1.y * tVec.x) + (tMat.col2.y * tVec.y)));
cp.separation = point.separation;
if ((point.id.features.flip & b2Collision.b2_newPoint)){
point.id.features.flip = (point.id.features.flip & ~(b2Collision.b2_newPoint));
cp.id = point.id;
m_world.m_contactListener.Add(cp);
} else {
cp.id = point.id;
m_world.m_contactListener.Persist(cp);
};
j++;
};
i++;
};
};
};
c = c.GetNext();
};
}
}
}//package Box2D.Dynamics
Section 68
//b2DebugDraw (Box2D.Dynamics.b2DebugDraw)
package Box2D.Dynamics {
import flash.display.*;
import Box2D.Common.Math.*;
import Box2D.Collision.*;
import Box2D.Collision.Shapes.*;
import Box2D.Common.*;
import Box2D.Dynamics.Contacts.*;
public class b2DebugDraw {
public var m_xformScale:Number;// = 1
public var m_fillAlpha:Number;// = 1
public var m_alpha:Number;// = 1
public var m_drawFlags:uint;
public var m_lineThickness:Number;// = 1
public var m_drawScale:Number;// = 1
public var m_sprite:Sprite;
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 ClearFlags(flags:uint):void{
m_drawFlags = (m_drawFlags & ~(flags));
}
public function SetFlags(flags:uint):void{
m_drawFlags = flags;
}
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 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 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 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 GetFlags():uint{
return (m_drawFlags);
}
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));
}
}
}//package Box2D.Dynamics
Section 69
//b2DestructionListener (Box2D.Dynamics.b2DestructionListener)
package Box2D.Dynamics {
import Box2D.Dynamics.Joints.*;
import Box2D.Collision.Shapes.*;
public class b2DestructionListener {
public function b2DestructionListener(){
super();
}
public function SayGoodbyeShape(shape:b2Shape):void{
}
public function SayGoodbyeJoint(joint:b2Joint):void{
}
}
}//package Box2D.Dynamics
Section 70
//b2Island (Box2D.Dynamics.b2Island)
package Box2D.Dynamics {
import Box2D.Common.Math.*;
import Box2D.Collision.*;
import Box2D.Dynamics.Joints.*;
import Box2D.Common.*;
import Box2D.Dynamics.Contacts.*;
public class b2Island {
public var m_listener:b2ContactListener;
public var m_positionIterationCount:int;
public var m_bodyCapacity:int;
public var m_bodies:Array;
public var m_joints:Array;
public var m_jointCapacity:int;
public var m_contactCount:int;
public var m_contacts:Array;
public var m_contactCapacity:int;
public var m_jointCount:int;
public var m_allocator;
public var m_bodyCount:int;
private static var s_reportCP:b2ContactPoint = new b2ContactPoint();
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++;
};
m_positionIterationCount = 0;
}
public function AddBody(body:b2Body):void{
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 cp:b2ContactPoint;
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];
cp = s_reportCP;
cp.shape1 = c.GetShape1();
cp.shape2 = c.GetShape2();
b1 = cp.shape1.GetBody();
manifoldCount = c.GetManifoldCount();
manifolds = c.GetManifolds();
j = 0;
while (j < manifoldCount) {
manifold = manifolds[j];
cp.normal.SetV(manifold.normal);
k = 0;
while (k < manifold.pointCount) {
point = manifold.points[k];
ccp = cc.points[k];
tMat = b1.GetXForm().R;
tVec = point.localPoint1;
cp.position.x = (b1.GetXForm().position.x + ((tMat.col1.x * tVec.x) + (tMat.col2.x * tVec.y)));
cp.position.y = (b1.GetXForm().position.y + ((tMat.col1.y * tVec.x) + (tMat.col2.y * tVec.y)));
cp.separation = point.separation;
cp.normalForce = ccp.normalForce;
cp.tangentForce = ccp.tangentForce;
if ((point.id.features.flip & b2Collision.b2_newPoint)){
point.id.features.flip = (point.id.features.flip & ~(b2Collision.b2_newPoint));
cp.id.key = point.id.key;
m_listener.Add(cp);
} else {
cp.id.key = point.id.key;
m_listener.Persist(cp);
};
k++;
};
j++;
};
i++;
};
}
public function AddContact(contact:b2Contact):void{
var _local2 = m_contactCount++;
m_contacts[_local2] = contact;
}
public function Solve(step:b2TimeStep, gravity:b2Vec2, correctPositions:Boolean, allowSleep:Boolean):void{
var i:int;
var b:b2Body;
var j:int;
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();
i = 0;
while (i < m_jointCount) {
m_joints[i].InitVelocityConstraints(step);
i++;
};
i = 0;
while (i < step.maxIterations) {
contactSolver.SolveVelocityConstraints();
j = 0;
while (j < m_jointCount) {
m_joints[j].SolveVelocityConstraints(step);
j++;
};
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++;
};
if (correctPositions){
i = 0;
while (i < m_jointCount) {
m_joints[i].InitPositionConstraints();
i++;
};
m_positionIterationCount = 0;
while (m_positionIterationCount < step.maxIterations) {
contactsOkay = contactSolver.SolvePositionConstraints(b2Settings.b2_contactBaumgarte);
jointsOkay = true;
i = 0;
while (i < m_jointCount) {
jointOkay = m_joints[i].SolvePositionConstraints();
jointsOkay = ((jointsOkay) && (jointOkay));
i++;
};
if (((contactsOkay) && (jointsOkay))){
break;
};
m_positionIterationCount++;
};
};
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 b:b2Body;
var contactsOkay:Boolean;
var contactSolver:b2ContactSolver = new b2ContactSolver(subStep, m_contacts, m_contactCount, m_allocator);
i = 0;
while (i < subStep.maxIterations) {
contactSolver.SolveVelocityConstraints();
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.maxIterations) {
contactsOkay = contactSolver.SolvePositionConstraints(k_toiBaumgarte);
if (contactsOkay){
break;
};
i++;
};
Report(contactSolver.m_constraints);
}
}
}//package Box2D.Dynamics
Section 71
//b2TimeStep (Box2D.Dynamics.b2TimeStep)
package Box2D.Dynamics {
public class b2TimeStep {
public var dt:Number;
public var maxIterations:int;
public var inv_dt:Number;
public function b2TimeStep(){
super();
}
}
}//package Box2D.Dynamics
Section 72
//b2World (Box2D.Dynamics.b2World)
package Box2D.Dynamics {
import Box2D.Common.Math.*;
import Box2D.Collision.*;
import Box2D.Dynamics.Joints.*;
import Box2D.Collision.Shapes.*;
import Box2D.Common.*;
import Box2D.Dynamics.Contacts.*;
public class b2World {
public var m_contactList:b2Contact;
public var m_blockAllocator;
public var m_boundaryListener:b2BoundaryListener;
public var m_allowSleep:Boolean;
public var m_contactListener:b2ContactListener;
public var m_broadPhase:b2BroadPhase;
public var m_destructionListener:b2DestructionListener;
public var m_jointCount:int;
public var m_bodyCount:int;
public var m_lock:Boolean;
public var m_positionIterationCount:int;
public var m_groundBody:b2Body;
public var m_contactCount:int;
public var m_debugDraw:b2DebugDraw;
public var m_contactFilter:b2ContactFilter;
public var m_bodyList:b2Body;
public var m_stackAllocator;
public var m_jointList:b2Joint;
public var m_gravity:b2Vec2;
public var m_contactManager:b2ContactManager;
private static var s_jointColor:b2Color = new b2Color(0.5, 0.8, 0.8);
public static var s_enablePositionCorrection:int = 1;
private static var s_coreColor:b2Color = new b2Color(0.9, 0.6, 0.6);
private static var s_xf:b2XForm = new b2XForm();
public static var s_enableWarmStarting:int = 1;
public static var s_enableTOI:int = 1;
public function b2World(worldAABB:b2AABB, gravity:b2Vec2, doSleep:Boolean){
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_allowSleep = doSleep;
m_gravity = gravity;
m_lock = false;
m_contactManager.m_world = this;
m_broadPhase = new b2BroadPhase(worldAABB, m_contactManager);
var bd:b2BodyDef = new b2BodyDef();
m_groundBody = CreateStaticBody(bd);
}
public function DrawJoint(joint:b2Joint):void{
var pulley:b2PulleyJoint;
var s1:b2Vec2;
var s2:b2Vec2;
var b1:b2Body = joint.GetBody1();
var b2:b2Body = joint.GetBody2();
var xf1:b2XForm = b1.GetXForm();
var xf2:b2XForm = b2.GetXForm();
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.GetType()){
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 SetDebugDraw(debugDraw:b2DebugDraw):void{
m_debugDraw = debugDraw;
}
public function SetListener(listener:b2ContactListener):void{
m_contactListener = listener;
}
public 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 index:uint;
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.GetXForm();
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.GetNext();
};
b = b.GetNext();
};
};
if ((flags & b2DebugDraw.e_jointBit)){
j = m_jointList;
while (j) {
DrawJoint(j);
j = j.GetNext();
};
};
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);
i = 0;
while (i < b2Pair.b2_tableCapacity) {
index = bp.m_pairManager.m_hashTable[i];
while (index != b2Pair.b2_nullPair) {
pair = bp.m_pairManager.m_pairs[index];
p1 = bp.m_proxyPool[pair.proxyId1];
p2 = bp.m_proxyPool[pair.proxyId2];
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);
index = pair.next;
};
i++;
};
};
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 < b2Settings.b2_maxProxies) {
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.GetXForm();
s = b.GetShapeList();
while (s) {
if (s.GetType() != 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.GetNext();
};
b = b.GetNext();
};
};
if ((flags & b2DebugDraw.e_centerOfMassBit)){
b = m_bodyList;
while (b) {
xf = s_xf;
xf.R = b.GetXForm().R;
xf.position = b.GetWorldCenter();
m_debugDraw.DrawXForm(xf);
b = b.GetNext();
};
};
}
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--;
}
public 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 coreColor:b2Color = s_coreColor;
switch (shape.m_type){
case b2Shape.e_circleShape:
circle = (shape as b2CircleShape);
center = b2Math.b2MulX(xf, circle.GetLocalPosition());
radius = circle.GetRadius();
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++;
};
m_debugDraw.DrawPolygon(vertices, vertexCount, coreColor);
};
break;
};
}
public 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;
m_positionIterationCount = 0;
if (m_bodyCount < 0){
m_bodyCount = 0;
};
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.GetManifoldCount() == 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, (s_enablePositionCorrection > 0), m_allowSleep);
m_positionIterationCount = Math.max(m_positionIterationCount, island.m_positionIterationCount);
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.GetNext();
};
m_broadPhase.Commit();
}
public function GetGroundBody():b2Body{
return (m_groundBody);
}
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] as b2Shape);
i++;
};
return (count);
}
public function SolveTOI(step:b2TimeStep):void{
var b:b2Body;
var s1:b2Shape;
var s2:b2Shape;
var b1:b2Body;
var b2:b2Body;
var cn:b2ContactEdge;
var c:b2Contact;
var minContact:b2Contact;
var minTOI:Number;
var seed:b2Body;
var stackCount:int;
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, 0, m_stackAllocator, m_contactListener);
var stackSize:int = m_bodyCount;
var stack:Array = new Array(stackSize);
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;
};
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.GetShape1();
s2 = c.GetShape2();
b1 = s1.GetBody();
b2 = s2.GetBody();
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 = Math.min((((1 - toi) * t0) + 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.GetShape1();
s2 = minContact.GetShape2();
b1 = s1.GetBody();
b2 = s2.GetBody();
b1.Advance(minTOI);
b2.Advance(minTOI);
minContact.Update(m_contactListener);
minContact.m_flags = (minContact.m_flags & ~(b2Contact.e_toiFlag));
if (minContact.GetManifoldCount() == 0){
} else {
seed = b1;
if (seed.IsStatic()){
seed = b2;
};
island.Clear();
stackCount = 0;
var _temp1 = stackCount;
stackCount = (stackCount + 1);
var _local22 = _temp1;
stack[_local22] = 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 (island.m_contactCount == island.m_contactCapacity){
} else {
if ((cn.contact.m_flags & ((b2Contact.e_islandFlag | b2Contact.e_slowFlag) | b2Contact.e_nonSolidFlag))){
} else {
if (cn.contact.GetManifoldCount() == 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 {
if (other.IsStatic() == false){
other.Advance(minTOI);
other.WakeUp();
};
var _temp2 = stackCount;
stackCount = (stackCount + 1);
var _local23 = _temp2;
stack[_local23] = other;
other.m_flags = (other.m_flags | b2Body.e_islandFlag);
};
};
};
};
cn = cn.next;
};
};
};
subStep = new b2TimeStep();
subStep.dt = ((1 - minTOI) * step.dt);
subStep.inv_dt = (1 / subStep.dt);
subStep.maxIterations = step.maxIterations;
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);
};
cn = b.m_contactList;
while (cn) {
cn.contact.m_flags = (cn.contact.m_flags & ~(b2Contact.e_toiFlag));
cn = cn.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++;
};
m_broadPhase.Commit();
};
};
}
public function GetJointList():b2Joint{
return (m_jointList);
}
public function GetBodyList():b2Body{
return (m_bodyList);
}
public function CreateDynamicBody(def:b2BodyDef):b2Body{
if (m_lock == true){
return (null);
};
var b:b2Body = new b2Body(def, b2Body.e_dynamicType, 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 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.ResetProxy(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.ResetProxy(m_broadPhase, b.m_xf);
s = s.m_next;
};
};
}
public function SetFilter(filter:b2ContactFilter):void{
m_contactFilter = filter;
}
public function SetBoundaryListener(listener:b2BoundaryListener):void{
m_boundaryListener = listener;
}
public function SetDestructionListener(listener:b2DestructionListener):void{
m_destructionListener = listener;
}
public function CreateStaticBody(def:b2BodyDef):b2Body{
if (m_lock == true){
return (null);
};
var b:b2Body = new b2Body(def, b2Body.e_staticType, 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 Step(dt:Number, iterations:int):void{
m_lock = true;
var step:b2TimeStep = new b2TimeStep();
step.dt = dt;
step.maxIterations = iterations;
if (dt > 0){
step.inv_dt = (1 / dt);
} else {
step.inv_dt = 0;
};
m_contactManager.Collide();
if (step.dt > 0){
Solve(step);
};
if (((s_enableTOI) && ((step.dt > 0)))){
SolveTOI(step);
};
DrawDebugData();
m_lock = false;
}
}
}//package Box2D.Dynamics
Section 73
//JSONDecoder (com.adobe.serialization.json.JSONDecoder)
package com.adobe.serialization.json {
public class JSONDecoder {
private var value;
private var tokenizer:JSONTokenizer;
private var token:JSONToken;
public function JSONDecoder(s:String){
super();
tokenizer = new JSONTokenizer(s);
nextToken();
value = parseValue();
}
private function parseObject():Object{
var key:String;
var o:Object = new Object();
nextToken();
if (token.type == JSONTokenType.RIGHT_BRACE){
return (o);
};
while (true) {
if (token.type == JSONTokenType.STRING){
key = String(token.value);
nextToken();
if (token.type == JSONTokenType.COLON){
nextToken();
o[key] = parseValue();
nextToken();
if (token.type == JSONTokenType.RIGHT_BRACE){
return (o);
};
if (token.type == JSONTokenType.COMMA){
nextToken();
} else {
tokenizer.parseError(("Expecting } or , but found " + token.value));
};
} else {
tokenizer.parseError(("Expecting : but found " + token.value));
};
} else {
tokenizer.parseError(("Expecting string but found " + token.value));
};
};
return (null);
}
private function parseValue():Object{
if (token == null){
tokenizer.parseError("Unexpected end of input");
};
switch (token.type){
case JSONTokenType.LEFT_BRACE:
return (parseObject());
case JSONTokenType.LEFT_BRACKET:
return (parseArray());
case JSONTokenType.STRING:
case JSONTokenType.NUMBER:
case JSONTokenType.TRUE:
case JSONTokenType.FALSE:
case JSONTokenType.NULL:
return (token.value);
default:
tokenizer.parseError(("Unexpected " + token.value));
};
return (null);
}
private function nextToken():JSONToken{
return ((token = tokenizer.getNextToken()));
}
public function getValue(){
return (value);
}
private function parseArray():Array{
var a:Array = new Array();
nextToken();
if (token.type == JSONTokenType.RIGHT_BRACKET){
return (a);
};
while (true) {
a.push(parseValue());
nextToken();
if (token.type == JSONTokenType.RIGHT_BRACKET){
return (a);
};
if (token.type == JSONTokenType.COMMA){
nextToken();
} else {
tokenizer.parseError(("Expecting ] or , but found " + token.value));
};
};
return (null);
}
}
}//package com.adobe.serialization.json
Section 74
//JSONParseError (com.adobe.serialization.json.JSONParseError)
package com.adobe.serialization.json {
public class JSONParseError extends Error {
private var _location:int;
private var _text:String;
public function JSONParseError(message:String="", location:int=0, text:String=""){
super(message);
_location = location;
_text = text;
}
public function get location():int{
return (_location);
}
public function get text():String{
return (_text);
}
}
}//package com.adobe.serialization.json
Section 75
//JSONToken (com.adobe.serialization.json.JSONToken)
package com.adobe.serialization.json {
public class JSONToken {
private var _value:Object;
private var _type:int;
public function JSONToken(type:int=-1, value:Object=null){
super();
_type = type;
_value = value;
}
public function get value():Object{
return (_value);
}
public function get type():int{
return (_type);
}
public function set type(value:int):void{
_type = value;
}
public function set value(v:Object):void{
_value = v;
}
}
}//package com.adobe.serialization.json
Section 76
//JSONTokenizer (com.adobe.serialization.json.JSONTokenizer)
package com.adobe.serialization.json {
public class JSONTokenizer {
private var loc:int;
private var ch:String;
private var obj:Object;
private var jsonString:String;
public function JSONTokenizer(s:String){
super();
jsonString = s;
loc = 0;
nextChar();
}
private function skipComments():void{
if (ch == "/"){
nextChar();
switch (ch){
case "/":
do {
nextChar();
} while (((!((ch == "\n"))) && (!((ch == "")))));
nextChar();
break;
case "*":
nextChar();
while (true) {
if (ch == "*"){
nextChar();
if (ch == "/"){
nextChar();
break;
};
} else {
nextChar();
};
if (ch == ""){
parseError("Multi-line comment not closed");
};
};
break;
default:
parseError((("Unexpected " + ch) + " encountered (expecting '/' or '*' )"));
};
};
}
private function isDigit(ch:String):Boolean{
return ((((ch >= "0")) && ((ch <= "9"))));
}
private function readString():JSONToken{
var _local5:String;
var i:int;
var token:JSONToken = new JSONToken();
token.type = JSONTokenType.STRING;
var string:String = "";
nextChar();
while (((!((ch == "\""))) && (!((ch == ""))))) {
if (ch == "\\"){
nextChar();
switch (ch){
case "\"":
string = (string + "\"");
break;
case "/":
string = (string + "/");
break;
case "\\":
string = (string + "\\");
break;
case "b":
string = (string + "\b");
break;
case "f":
string = (string + "\f");
break;
case "n":
string = (string + "\n");
break;
case "r":
string = (string + "\r");
break;
case "t":
string = (string + "\t");
break;
case "u":
_local5 = "";
i = 0;
while (i < 4) {
if (!isHexDigit(nextChar())){
parseError((" Excepted a hex digit, but found: " + ch));
};
_local5 = (_local5 + ch);
i++;
};
string = (string + String.fromCharCode(parseInt(_local5, 16)));
break;
default:
string = (string + ("\\" + ch));
};
} else {
string = (string + ch);
};
nextChar();
};
if (ch == ""){
parseError("Unterminated string literal");
};
nextChar();
token.value = string;
return (token);
}
private function nextChar():String{
return ((ch = jsonString.charAt(loc++)));
}
public function getNextToken():JSONToken{
var _local2:String;
var _local3:String;
var _local4:String;
var token:JSONToken = new JSONToken();
skipIgnored();
switch (ch){
case "{":
token.type = JSONTokenType.LEFT_BRACE;
token.value = "{";
nextChar();
break;
case "}":
token.type = JSONTokenType.RIGHT_BRACE;
token.value = "}";
nextChar();
break;
case "[":
token.type = JSONTokenType.LEFT_BRACKET;
token.value = "[";
nextChar();
break;
case "]":
token.type = JSONTokenType.RIGHT_BRACKET;
token.value = "]";
nextChar();
break;
case ",":
token.type = JSONTokenType.COMMA;
token.value = ",";
nextChar();
break;
case ":":
token.type = JSONTokenType.COLON;
token.value = ":";
nextChar();
break;
case "t":
_local2 = ((("t" + nextChar()) + nextChar()) + nextChar());
if (_local2 == "true"){
token.type = JSONTokenType.TRUE;
token.value = true;
nextChar();
} else {
parseError(("Expecting 'true' but found " + _local2));
};
break;
case "f":
_local3 = (((("f" + nextChar()) + nextChar()) + nextChar()) + nextChar());
if (_local3 == "false"){
token.type = JSONTokenType.FALSE;
token.value = false;
nextChar();
} else {
parseError(("Expecting 'false' but found " + _local3));
};
break;
case "n":
_local4 = ((("n" + nextChar()) + nextChar()) + nextChar());
if (_local4 == "null"){
token.type = JSONTokenType.NULL;
token.value = null;
nextChar();
} else {
parseError(("Expecting 'null' but found " + _local4));
};
break;
case "\"":
token = readString();
break;
default:
if (((isDigit(ch)) || ((ch == "-")))){
token = readNumber();
} else {
if (ch == ""){
return (null);
};
parseError((("Unexpected " + ch) + " encountered"));
};
};
return (token);
}
private function skipWhite():void{
while (isWhiteSpace(ch)) {
nextChar();
};
}
public function parseError(message:String):void{
throw (new JSONParseError(message, loc, jsonString));
}
private function isWhiteSpace(ch:String):Boolean{
return ((((((((ch == " ")) || ((ch == "\t")))) || ((ch == "\n")))) || ((ch == "\r"))));
}
private function skipIgnored():void{
skipWhite();
skipComments();
skipWhite();
}
private function isHexDigit(ch:String):Boolean{
var uc:String = ch.toUpperCase();
return (((isDigit(ch)) || ((((uc >= "A")) && ((uc <= "F"))))));
}
private function readNumber():JSONToken{
var token:JSONToken = new JSONToken();
token.type = JSONTokenType.NUMBER;
var input:String = "";
if (ch == "-"){
input = (input + "-");
nextChar();
};
if (!isDigit(ch)){
parseError("Expecting a digit");
};
if (ch == "0"){
input = (input + ch);
nextChar();
if (isDigit(ch)){
parseError("A digit cannot immediately follow 0");
};
} else {
while (isDigit(ch)) {
input = (input + ch);
nextChar();
};
};
if (ch == "."){
input = (input + ".");
nextChar();
if (!isDigit(ch)){
parseError("Expecting a digit");
};
while (isDigit(ch)) {
input = (input + ch);
nextChar();
};
};
if ((((ch == "e")) || ((ch == "E")))){
input = (input + "e");
nextChar();
if ((((ch == "+")) || ((ch == "-")))){
input = (input + ch);
nextChar();
};
if (!isDigit(ch)){
parseError("Scientific notation number needs exponent value");
};
while (isDigit(ch)) {
input = (input + ch);
nextChar();
};
};
var num:Number = Number(input);
if (((isFinite(num)) && (!(isNaN(num))))){
token.value = num;
return (token);
};
parseError((("Number " + num) + " is not valid!"));
return (null);
}
}
}//package com.adobe.serialization.json
Section 77
//JSONTokenType (com.adobe.serialization.json.JSONTokenType)
package com.adobe.serialization.json {
public class JSONTokenType {
public static const NUMBER:int = 11;
public static const FALSE:int = 8;
public static const RIGHT_BRACKET:int = 4;
public static const NULL:int = 9;
public static const TRUE:int = 7;
public static const RIGHT_BRACE:int = 2;
public static const UNKNOWN:int = -1;
public static const COMMA:int = 0;
public static const LEFT_BRACKET:int = 3;
public static const STRING:int = 10;
public static const LEFT_BRACE:int = 1;
public static const COLON:int = 6;
public function JSONTokenType(){
super();
}
}
}//package com.adobe.serialization.json
Section 78
//MemoryCrypto (com.electrotank.util.MemoryCrypto)
package com.electrotank.util {
import com.meychi.ascrypt3.*;
public class MemoryCrypto {
private static var crypto:TEA = null;
private static var INCREMENT:int = 0;
private static var initialized:Boolean = false;
private static var key:String = null;
private static var MULTIPLY:int = 2;
private static var DECREMENT:int = 1;
private static var dataHolder:Object = null;
private static var DIVIDE:int = 3;
public function MemoryCrypto(){
super();
}
public static function incrementValue(name:String, amount:Number):Number{
return (processValue(name, amount, INCREMENT));
}
public static function getValue(name:String):Number{
initIfNeeded();
var results:Number = 0;
if (!isValueSet(name)){
setValue(name, results);
} else {
results = new Number(crypto.decrypt(dataHolder[name], key));
};
return (results);
}
private static function processValue(name:String, amount:Number, operation:int):Number{
initIfNeeded();
var tempValue:Number = getValue(name);
switch (operation){
case INCREMENT:
tempValue = (tempValue + amount);
break;
case DECREMENT:
tempValue = (tempValue - amount);
break;
case MULTIPLY:
tempValue = (tempValue * amount);
break;
case DIVIDE:
tempValue = (tempValue / amount);
break;
};
setValue(name, tempValue);
return (tempValue);
}
public static function reset():void{
initialized = false;
initIfNeeded();
}
public static function decrementValue(name:String, amount:Number):Number{
return (processValue(name, amount, DECREMENT));
}
private static function initIfNeeded():void{
var firstNumber:Number;
var firstKey:String;
var secondNumber:Number;
var secondKey:String;
if (!initialized){
firstNumber = Math.random();
firstKey = new String(firstNumber);
firstKey = firstKey.substr(2, (firstKey.length - 2));
secondNumber = Math.random();
secondKey = new String(secondNumber);
secondKey = secondKey.substr(2, (secondKey.length - 2));
key = (firstKey + secondKey);
crypto = new TEA();
dataHolder = new Object();
initialized = true;
};
}
public static function multiplyValue(name:String, amount:Number):Number{
return (processValue(name, amount, MULTIPLY));
}
public static function setValue(name:String, value:Number):Number{
initIfNeeded();
dataHolder[name] = crypto.encrypt(value.toString(), key);
return (value);
}
public static function divideValue(name:String, amount:Number):Number{
if (amount == 0){
throw (new Error("Amount can't be zero when dividing!"));
};
return (processValue(name, amount, DIVIDE));
}
public static function isValueSet(name:String):Boolean{
initIfNeeded();
var results:Boolean;
if (dataHolder[name] != null){
results = true;
};
return (results);
}
}
}//package com.electrotank.util
Section 79
//Debug (com.hexagonstar.util.debug.Debug)
package com.hexagonstar.util.debug {
import flash.events.*;
import flash.display.*;
import flash.net.*;
import flash.utils.*;
import flash.system.*;
public final class Debug {
public static const LEVEL_WARN:uint = 2;
public static const LEVEL_DEBUG:uint = 0;
public static const LEVEL_INFO:uint = 1;
public static const LEVEL_FATAL:uint = 4;
public static const LEVEL_ERROR:uint = 3;
private static var _fpsMeter:FPSMeter;
private static var _filterLevel:uint = 0;
private static var _isLargeData:Boolean = false;
private static var _isConnected:Boolean = false;
private static var _isPollingFPS:Boolean = false;
private static var _isDisabled:Boolean = false;
private static var _fpsPollInterval:uint = 1000;
private static var _stopWatch:StopWatch;
private static var _connection:LocalConnection;
private static var _stage:Stage;
public function Debug(){
super();
}
public static function forceGC():void{
new LocalConnection().connect("forceGC");
new LocalConnection().connect("forceGC");
//unresolved jump
var _slot1 = e;
}
private static function send(method:String, data, level:int=1, rec:uint=0):void{
var size:uint;
var byteArray:ByteArray;
if (!_isDisabled){
if (!_isConnected){
_isConnected = true;
_connection = new LocalConnection();
_connection.addEventListener(StatusEvent.STATUS, onStatus);
};
size = 0;
if (typeof(data) == "string"){
size = String(data).length;
} else {
if (typeof(data) == "object"){
byteArray = new ByteArray();
byteArray.writeObject(data);
size = byteArray.length;
byteArray = null;
};
};
if (size > 39000){
storeDataLSO(method, data);
method = "onLargeData";
data = null;
};
_connection.send("_alcon_lc", method, data, level, rec, "");
};
}
public static function timerReset():void{
if (_stopWatch != null){
_stopWatch.reset();
};
}
public static function fpsStop():void{
if (_fpsMeter != null){
_isPollingFPS = false;
_fpsMeter.stop();
_fpsMeter.removeEventListener(FPSMeter.FPS_UPDATE, onFPSUpdate);
_fpsMeter = null;
};
}
public static function delimiter():void{
Debug.trace("[%DLT%]", 5);
}
public static function inspect(object:Object=null, depth:int=-1):void{
send("onInspect", object, 1, depth);
}
private static function onFPSUpdate(event:Event):void{
send("onFPS", ((((_fpsMeter.getFPS() + "/") + _stage.frameRate) + "|") + System.totalMemory));
}
public static function timerStart(title:String=""):void{
if (!_isDisabled){
if (_stopWatch == null){
_stopWatch = new StopWatch();
};
_stopWatch.start(title);
};
}
private static function storeDataLSO(method:String, data):void{
var flushResult:String;
var method = method;
var data = data;
var sharedObject:SharedObject = SharedObject.getLocal("alcon", "/");
sharedObject.data.alconMethod = method;
sharedObject.data.alconData = data;
flushResult = sharedObject.flush();
if (flushResult == SharedObjectFlushStatus.FLUSHED){
return;
};
//unresolved jump
var _slot1 = e;
Security.showSettings(SecurityPanel.LOCAL_STORAGE);
}
public static function setFilterLevel(level:uint=0):void{
if ((((level >= 0)) && ((level < 5)))){
_filterLevel = level;
};
}
public static function hexDump(object):void{
send("onHexDump", object, 0, 0);
}
private static function onStatus(event:StatusEvent):void{
}
public static function getFilterLevel():int{
return (_filterLevel);
}
public static function trace(arg0=undefined, arg1=null, arg2:int=-1):void{
var data:* = arg0;
var recursive:Boolean;
var level = 1;
if (typeof(arg1) == "boolean"){
recursive = arg1;
} else {
if (typeof(arg1) == "number"){
level = arg1;
};
};
if (arg2 > -1){
level = arg2;
};
if ((((level >= _filterLevel)) && ((level < 7)))){
send("onData", data, level, (recursive) ? 1 : 0);
};
}
public static function timerToString():void{
if (_stopWatch != null){
Debug.trace(_stopWatch.toString());
};
}
public static function time():void{
Debug.trace("[%TME%]", 5);
}
public static function timerMilliSeconds():void{
if (_stopWatch != null){
Debug.trace((_stopWatch.getTimeInMilliSeconds() + "ms"));
};
}
public static function clear():void{
Debug.trace("[%CLR%]", 5);
}
public static function timerStop():void{
if (_stopWatch != null){
_stopWatch.stop();
};
}
public static function disable():void{
_isDisabled = true;
}
public static function timerStopToString(reset:Boolean=false):void{
if (_stopWatch != null){
_stopWatch.stop();
Debug.trace(_stopWatch.toString());
if (reset){
_stopWatch.reset();
};
};
}
public static function pause():void{
Debug.trace("[%PSE%]", 5);
}
public static function fpsStart(stage:Stage):void{
if (((!(_isDisabled)) && ((_fpsMeter == null)))){
_isPollingFPS = true;
_stage = stage;
_fpsMeter = new FPSMeter(stage);
_fpsMeter.addEventListener(FPSMeter.FPS_UPDATE, onFPSUpdate);
_fpsMeter.start();
};
}
public static function timerSeconds():void{
if (_stopWatch != null){
Debug.trace((_stopWatch.getTimeInSeconds() + "s"));
};
}
}
}//package com.hexagonstar.util.debug
Section 80
//FPSMeter (com.hexagonstar.util.debug.FPSMeter)
package com.hexagonstar.util.debug {
import flash.events.*;
import flash.display.*;
import flash.utils.*;
public class FPSMeter extends EventDispatcher {
private var _timer:Timer;
private var _fps:int;
private var _isRunning:Boolean;
private var _stage:Stage;
public static const FPS_UPDATE:String = "fpsUpdate";
public function FPSMeter(stage:Stage){
super();
_stage = stage;
_fps = 0;
_isRunning = false;
}
public function stop():void{
if (_isRunning){
_isRunning = false;
_timer.stop();
_timer.removeEventListener(TimerEvent.TIMER, onTimer);
_stage.removeEventListener(Event.ENTER_FRAME, onEnterFrame);
_timer = null;
};
}
private function onEnterFrame(event:Event):void{
_fps++;
}
public function start(pollInterval:uint=1000):void{
if (!_isRunning){
_isRunning = true;
_timer = new Timer(pollInterval, 0);
_timer.addEventListener(TimerEvent.TIMER, onTimer);
_stage.addEventListener(Event.ENTER_FRAME, onEnterFrame);
_timer.start();
};
}
private function onTimer(event:TimerEvent):void{
dispatchEvent(new Event(FPSMeter.FPS_UPDATE));
_fps = 0;
}
public function getFPS():int{
return (_fps);
}
}
}//package com.hexagonstar.util.debug
Section 81
//StopWatch (com.hexagonstar.util.debug.StopWatch)
package com.hexagonstar.util.debug {
import flash.utils.*;
public class StopWatch {
private var _stopTimeKeys:Array;
private var _startTimeKeys:Array;
private var _title:String;
private var _started:Boolean;// = false
public function StopWatch(){
super();
reset();
}
public function getTimeInMilliSeconds():int{
if (hasStarted()){
_stopTimeKeys[(_startTimeKeys.length - 1)] = getTimer();
};
var result:int;
var i:int;
while (i < _startTimeKeys.length) {
result = (result + (_stopTimeKeys[i] - _startTimeKeys[i]));
i++;
};
return (result);
}
public function hasStarted():Boolean{
return (_started);
}
public function stop():void{
var stopTime:uint;
if (hasStarted()){
stopTime = getTimer();
_stopTimeKeys[(_startTimeKeys.length - 1)] = stopTime;
_started = false;
};
}
public function toString():String{
var result:String = "\n ********** [STOPWATCH] **********";
if (_title != ""){
result = (result + ("\n " + _title));
};
var i:int;
while (i < _startTimeKeys.length) {
result = (result + (((("\n started [" + _startTimeKeys[i]) + "ms] stopped [") + _stopTimeKeys[i]) + "ms]"));
i++;
};
if (i == 0){
result = (result + "\n never started.");
} else {
result = (result + (("\n total runnning time: " + getTimeInMilliSeconds()) + "ms"));
};
result = (result + "\n *********************************");
return (result);
}
public function reset():void{
_startTimeKeys = new Array();
_stopTimeKeys = new Array();
_started = false;
}
public function start(title:String=""):void{
if (!hasStarted()){
_title = title;
_started = true;
_startTimeKeys.push(getTimer());
};
}
public function getTimeInSeconds():Number{
return ((getTimeInMilliSeconds() / 1000));
}
}
}//package com.hexagonstar.util.debug
Section 82
//TEA (com.meychi.ascrypt3.TEA)
package com.meychi.ascrypt3 {
public class TEA {
public function TEA(){
super();
}
public function decrypt(src:String, key:String):String{
var mx:Number;
var e:Number;
var p:Number;
var v:Array = charsToLongs(hexToChars(src));
var k:Array = charsToLongs(strToChars(key));
var n:Number = v.length;
if (n == 0){
return ("");
};
var z:Number = v[(n - 1)];
var y:Number = v[0];
var delta:Number = 2654435769;
var q:Number = Math.floor((6 + (52 / n)));
var sum:Number = (q * delta);
while (sum != 0) {
e = ((sum >>> 2) & 3);
p = (n - 1);
while (p > 0) {
z = v[(p - 1)];
mx = ((((z >>> 5) ^ (y << 2)) + ((y >>> 3) ^ (z << 4))) ^ ((sum ^ y) + (k[((p & 3) ^ e)] ^ z)));
y = (v[p] = (v[p] - mx));
p--;
};
z = v[(n - 1)];
mx = ((((z >>> 5) ^ (y << 2)) + ((y >>> 3) ^ (z << 4))) ^ ((sum ^ y) + (k[((p & 3) ^ e)] ^ z)));
y = (v[0] = (v[0] - mx));
sum = (sum - delta);
};
return (charsToStr(longsToChars(v)));
}
public function encrypt(src:String, key:String):String{
var mx:Number;
var e:Number;
var p:Number;
var v:Array = charsToLongs(strToChars(src));
var k:Array = charsToLongs(strToChars(key));
var n:Number = v.length;
if (n == 0){
return ("");
};
if (n == 1){
var _temp1 = n;
n = (n + 1);
var _local14 = _temp1;
v[_local14] = 0;
};
var z:Number = v[(n - 1)];
var y:Number = v[0];
var delta:Number = 2654435769;
var q:Number = Math.floor((6 + (52 / n)));
var sum:Number = 0;
while (q-- > 0) {
sum = (sum + delta);
e = ((sum >>> 2) & 3);
p = 0;
while (p < (n - 1)) {
y = v[(p + 1)];
mx = ((((z >>> 5) ^ (y << 2)) + ((y >>> 3) ^ (z << 4))) ^ ((sum ^ y) + (k[((p & 3) ^ e)] ^ z)));
z = (v[p] = (v[p] + mx));
p++;
};
y = v[0];
mx = ((((z >>> 5) ^ (y << 2)) + ((y >>> 3) ^ (z << 4))) ^ ((sum ^ y) + (k[((p & 3) ^ e)] ^ z)));
z = (v[(n - 1)] = (v[(n - 1)] + mx));
};
return (charsToHex(longsToChars(v)));
}
private static function strToChars(str:String):Array{
var codes:Array = new Array();
var i:Number = 0;
while (i < str.length) {
codes.push(str.charCodeAt(i));
i++;
};
return (codes);
}
private static function charsToHex(chars:Array):String{
var result:String = new String("");
var hexes:Array = new Array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f");
var i:Number = 0;
while (i < chars.length) {
result = (result + (hexes[(chars[i] >> 4)] + hexes[(chars[i] & 15)]));
i++;
};
return (result);
}
private static function hexToChars(hex:String):Array{
var codes:Array = new Array();
var i:Number = ((hex.substr(0, 2))=="0x") ? 2 : 0;
while (i < hex.length) {
codes.push(parseInt(hex.substr(i, 2), 16));
i = (i + 2);
};
return (codes);
}
private static function charsToStr(chars:Array):String{
var result:String = new String("");
var i:Number = 0;
while (i < chars.length) {
result = (result + String.fromCharCode(chars[i]));
i++;
};
return (result);
}
private static function longsToChars(longs:Array):Array{
var codes:Array = new Array();
var i:Number = 0;
while (i < longs.length) {
codes.push((longs[i] & 0xFF), ((longs[i] >>> 8) & 0xFF), ((longs[i] >>> 16) & 0xFF), ((longs[i] >>> 24) & 0xFF));
i++;
};
return (codes);
}
private static function charsToLongs(chars:Array):Array{
var temp:Array = new Array(Math.ceil((chars.length / 4)));
var i:Number = 0;
while (i < temp.length) {
temp[i] = (((chars[(i * 4)] + (chars[((i * 4) + 1)] << 8)) + (chars[((i * 4) + 2)] << 16)) + (chars[((i * 4) + 3)] << 24));
i++;
};
return (temp);
}
}
}//package com.meychi.ascrypt3
Section 83
//BitmapEmitter (com.roguedevelopment.pulse.emitter.BitmapEmitter)
package com.roguedevelopment.pulse.emitter {
import flash.events.*;
import flash.display.*;
import flash.geom.*;
import com.roguedevelopment.pulse.*;
import flash.filters.*;
public class BitmapEmitter extends GenericEmitter {
protected var origin:Point;
protected var bitmap:BitmapData;
protected var fullRect:Rectangle;
protected var fader:ColorMatrixFilter;
public function BitmapEmitter(particlesPerSecond:Number, bitmap:BitmapData, fadeAmount:Number=0.85){
origin = new Point(0, 0);
fader = new ColorMatrixFilter([1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, fadeAmount, 0]);
super(particlesPerSecond);
this.bitmap = bitmap;
fullRect = new Rectangle(0, 0, bitmap.width, bitmap.height);
root = new Sprite();
}
override public function stop():void{
super.stop();
}
override public function start():void{
PulseEngine.instance.root.addEventListener(Event.ENTER_FRAME, onEnterFrame);
super.start();
}
protected function onEnterFrame(e:Event):void{
bitmap.applyFilter(bitmap, fullRect, origin, fader);
var copyMatrix:Matrix = new Matrix();
copyMatrix.rotate(((root.rotation * Math.PI) / 180));
copyMatrix.translate(root.x, root.y);
copyMatrix.scale(root.scaleX, root.scaleY);
bitmap.draw(root, copyMatrix);
}
}
}//package com.roguedevelopment.pulse.emitter
Section 84
//GenericEmitter (com.roguedevelopment.pulse.emitter.GenericEmitter)
package com.roguedevelopment.pulse.emitter {
import flash.events.*;
import flash.display.*;
import com.roguedevelopment.pulse.particle.*;
import com.roguedevelopment.pulse.*;
import flash.utils.*;
public class GenericEmitter implements IParticleEmitter {
protected var _y:Number;// = 10
protected var timer:Timer;
public var width:Number;// = 1
public var newParticlesOnTop:Boolean;// = true
protected var factory:IParticleFactory;
public var particleLimit:uint;// = 0
public var root:DisplayObjectContainer;// = null
public var height:Number;// = 1
protected var particleCount:uint;// = 0
protected var _x:Number;// = 10
public function GenericEmitter(particlesPerSecond:Number){
super();
pps = particlesPerSecond;
root = PulseEngine.instance.root;
}
public function get y():Number{
return (_y);
}
public function stop():void{
if (factory != null){
factory.cleanup();
};
timer.stop();
}
public function setFactory(factory:IParticleFactory):void{
this.factory = factory;
}
protected function emit(event:TimerEvent):void{
if (factory == null){
return;
};
if (particleLimit > 0){
particleCount++;
if (particleCount > particleLimit){
timer.stop();
return;
};
};
var particle:IParticle = factory.newParticle();
particle.x = (x + (Math.random() * width));
particle.y = (y + (Math.random() * height));
if ((particle is DisplayObject)){
if (newParticlesOnTop){
root.addChild((particle as DisplayObject));
} else {
root.addChildAt((particle as DisplayObject), 0);
};
};
PulseEngine.instance.addParticle(particle);
}
public function getFactory():IParticleFactory{
return (factory);
}
public function set y(v:Number):void{
_y = v;
}
public function set pps(val:Number):void{
if (timer != null){
timer.stop();
};
timer = new Timer((1000 / val));
timer.addEventListener(TimerEvent.TIMER, emit);
timer.start();
}
public function set x(v:Number):void{
_x = v;
}
public function start():void{
particleCount = 0;
timer.start();
}
public function get pps():Number{
return (10);
}
public function get x():Number{
return (_x);
}
}
}//package com.roguedevelopment.pulse.emitter
Section 85
//IParticleEmitter (com.roguedevelopment.pulse.emitter.IParticleEmitter)
package com.roguedevelopment.pulse.emitter {
import com.roguedevelopment.pulse.particle.*;
public interface IParticleEmitter {
function set x(:Number):void;
function stop():void;
function set y(:Number):void;
function get x():Number;
function get y():Number;
function start():void;
function setFactory(:IParticleFactory):void;
}
}//package com.roguedevelopment.pulse.emitter
Section 86
//AngleRandomizerInitializer (com.roguedevelopment.pulse.initializers.AngleRandomizerInitializer)
package com.roguedevelopment.pulse.initializers {
public class AngleRandomizerInitializer extends ParameterRandomizerInitializer {
public function AngleRandomizerInitializer(minValue:Number, maxValue:Number){
super("angle", ((minValue * Math.PI) / 180), ((maxValue * Math.PI) / 180), round);
}
}
}//package com.roguedevelopment.pulse.initializers
Section 87
//IPulseInitializer (com.roguedevelopment.pulse.initializers.IPulseInitializer)
package com.roguedevelopment.pulse.initializers {
import com.roguedevelopment.pulse.particle.*;
public interface IPulseInitializer {
function init(:IParticle):void;
}
}//package com.roguedevelopment.pulse.initializers
Section 88
//ParameterInitializer (com.roguedevelopment.pulse.initializers.ParameterInitializer)
package com.roguedevelopment.pulse.initializers {
import com.roguedevelopment.pulse.particle.*;
public class ParameterInitializer implements IPulseInitializer {
protected var value:Object;
protected var propName:String;
public function ParameterInitializer(propName:String, value:Object){
super();
this.propName = propName;
this.value = value;
}
public function init(particle:IParticle):void{
var o:Object = (particle as Object);
if (o.hasOwnProperty(propName)){
o[propName] = value;
} else {
if (o.hasOwnProperty("params")){
o.params[propName] = value;
};
};
}
}
}//package com.roguedevelopment.pulse.initializers
Section 89
//ParameterRandomizerInitializer (com.roguedevelopment.pulse.initializers.ParameterRandomizerInitializer)
package com.roguedevelopment.pulse.initializers {
import com.roguedevelopment.pulse.particle.*;
public class ParameterRandomizerInitializer implements IPulseInitializer {
protected var propName:String;
protected var round:Boolean;
protected var maxValue:Number;
protected var minValue:Number;
public function ParameterRandomizerInitializer(propName:String, minValue:Number, maxValue:Number, round:Boolean=false){
super();
this.minValue = minValue;
this.maxValue = maxValue;
this.propName = propName;
this.round = round;
}
public function init(particle:IParticle):void{
var o:Object = particle;
var v:Number = (minValue + (Math.random() * (maxValue - minValue)));
if (round){
v = Math.round(v);
};
if (o.hasOwnProperty(propName)){
o[propName] = v;
} else {
if (o.hasOwnProperty("params")){
o.params[propName] = v;
};
};
}
}
}//package com.roguedevelopment.pulse.initializers
Section 90
//RandomFrameInit (com.roguedevelopment.pulse.initializers.RandomFrameInit)
package com.roguedevelopment.pulse.initializers {
import flash.display.*;
import com.roguedevelopment.pulse.particle.*;
public class RandomFrameInit implements IPulseInitializer {
public function RandomFrameInit(){
super();
}
public function init(particle:IParticle):void{
var mc:MovieClip;
var particle = particle;
if ((particle is MovieClip)){
mc = (particle as MovieClip);
mc.gotoAndStop(Math.round((Math.random() * mc.totalFrames)));
} else {
if ((particle is Sprite)){
mc = ((particle as Sprite).getChildAt(0) as MovieClip);
if (mc != null){
mc.gotoAndStop(Math.round((Math.random() * mc.totalFrames)));
};
//unresolved jump
var _slot1 = e;
};
};
}
}
}//package com.roguedevelopment.pulse.initializers
Section 91
//ScaleRandomizerInitializer (com.roguedevelopment.pulse.initializers.ScaleRandomizerInitializer)
package com.roguedevelopment.pulse.initializers {
import com.roguedevelopment.pulse.particle.*;
public class ScaleRandomizerInitializer implements IPulseInitializer {
protected var maxValue:Number;
protected var minValue:Number;
public function ScaleRandomizerInitializer(minValue:Number, maxValue:Number){
super();
this.minValue = minValue;
this.maxValue = maxValue;
}
public function init(particle:IParticle):void{
var o:Object = particle;
var v:Number = (minValue + (Math.random() * (maxValue - minValue)));
o["scaleX"] = v;
o["scaleY"] = v;
}
}
}//package com.roguedevelopment.pulse.initializers
Section 92
//DotParticle (com.roguedevelopment.pulse.particle.DotParticle)
package com.roguedevelopment.pulse.particle {
public class DotParticle extends GenericParticle {
protected var _size:Number;// = 1
protected var _color:uint;// = 0xFFFFFF
public function DotParticle(){
super();
redraw();
}
public function set size(s:Number):void{
_size = s;
redraw();
}
public function set color(c:uint):void{
_color = c;
redraw();
}
protected function redraw():void{
graphics.clear();
graphics.beginFill(_color, 1);
graphics.drawCircle(0, 0, _size);
graphics.endFill();
}
}
}//package com.roguedevelopment.pulse.particle
Section 93
//GenericFactory (com.roguedevelopment.pulse.particle.GenericFactory)
package com.roguedevelopment.pulse.particle {
import flash.display.*;
import com.roguedevelopment.pulse.initializers.*;
public final class GenericFactory implements IParticleFactory {
protected var partClass:Class;
protected var _initializers:Array;
protected var recycled:Array;
public var isRunning:Boolean;// = true
protected var _rules:Array;
public function GenericFactory(particleClass:Class, rules:Array, initializers:Array){
recycled = [];
super();
this.partClass = particleClass;
_rules = rules;
this.initializers = initializers;
}
public function cleanup():void{
var p:IParticle;
isRunning = false;
for each (p in recycled) {
p.remove();
};
recycled = [];
}
public function newParticle():IParticle{
var particle:IParticle;
var initRule:IPulseInitializer;
var obj:Object;
isRunning = true;
if (recycled.length > 0){
particle = (recycled.shift() as IParticle);
(particle as IRecyleableParticle).recycle();
} else {
obj = new partClass();
if ((obj is IParticle)){
particle = (obj as IParticle);
} else {
if ((obj is Sprite)){
particle = new GenericParticle();
(particle as GenericParticle).addChild((obj as Sprite));
};
};
if ((particle is IRecyleableParticle)){
(particle as IRecyleableParticle).factory = this;
};
};
particle.rules = _rules.concat();
for each (initRule in _initializers) {
trace(initRule);
initRule.init(particle);
};
return (particle);
}
public function set initializers(rules:Array):void{
_initializers = rules;
}
public function recycle(particle:IParticle):void{
if (isRunning){
particle.visible = false;
recycled.push(particle);
} else {
particle.remove();
};
}
public function set rules(rules:Array):void{
_rules = rules;
}
}
}//package com.roguedevelopment.pulse.particle
Section 94
//GenericParticle (com.roguedevelopment.pulse.particle.GenericParticle)
package com.roguedevelopment.pulse.particle {
import flash.display.*;
import flash.geom.*;
public class GenericParticle extends Sprite implements IRecyleableParticle {
protected var _birth:Number;
protected var _factory:IParticleFactory;
protected var _params:Object;
protected var _rules:Array;
public function GenericParticle(){
_params = {angle:0, speed:0};
super();
_birth = new Date().time;
}
public function remove():void{
if (parent != null){
parent.removeChild(this);
};
}
public function get params():Object{
return (_params);
}
public function get factory():IParticleFactory{
return (_factory);
}
public function recycle():void{
_birth = new Date().time;
scaleX = 1;
rotation = 0;
scaleY = 1;
alpha = 1;
visible = true;
transform.colorTransform = new ColorTransform();
}
public function set factory(v:IParticleFactory):void{
_factory = v;
}
public function get rules():Array{
return (_rules);
}
public function get birthTime():Number{
return (_birth);
}
public function set rules(rules:Array):void{
_rules = rules;
}
}
}//package com.roguedevelopment.pulse.particle
Section 95
//ImageParticle (com.roguedevelopment.pulse.particle.ImageParticle)
package com.roguedevelopment.pulse.particle {
import flash.display.*;
import flash.geom.*;
public final class ImageParticle extends GenericParticle implements IRecyleableParticle {
protected var imaged:Boolean;// = false
public function ImageParticle(){
super();
}
public function set image(v:Class):void{
if (imaged){
return;
};
imaged = true;
var i:Bitmap = new (v);
addChild(i);
}
override public function recycle():void{
_birth = new Date().time;
scaleX = 1;
rotation = 0;
scaleY = 1;
alpha = 1;
visible = true;
transform.colorTransform = new ColorTransform();
}
}
}//package com.roguedevelopment.pulse.particle
Section 96
//IParticle (com.roguedevelopment.pulse.particle.IParticle)
package com.roguedevelopment.pulse.particle {
public interface IParticle {
function get visible():Boolean;
function set alpha(com.roguedevelopment.pulse.particle:IParticle/com.roguedevelopment.pulse.particle:IParticle:params/get:Number):void;
function set visible(com.roguedevelopment.pulse.particle:IParticle/com.roguedevelopment.pulse.particle:IParticle:params/get:Boolean):void;
function get alpha():Number;
function get params():Object;
function set rotation(com.roguedevelopment.pulse.particle:IParticle/com.roguedevelopment.pulse.particle:IParticle:params/get:Number):void;
function get birthTime():Number;
function get rotation():Number;
function set rules(com.roguedevelopment.pulse.particle:IParticle/com.roguedevelopment.pulse.particle:IParticle:params/get:Array):void;
function get scaleY():Number;
function set x(com.roguedevelopment.pulse.particle:IParticle/com.roguedevelopment.pulse.particle:IParticle:params/get:Number):void;
function set y(com.roguedevelopment.pulse.particle:IParticle/com.roguedevelopment.pulse.particle:IParticle:params/get:Number):void;
function remove():void;
function get scaleX():Number;
function get rules():Array;
function get x():Number;
function get y():Number;
function set scaleX(com.roguedevelopment.pulse.particle:IParticle/com.roguedevelopment.pulse.particle:IParticle:params/get:Number):void;
function set scaleY(com.roguedevelopment.pulse.particle:IParticle/com.roguedevelopment.pulse.particle:IParticle:params/get:Number):void;
}
}//package com.roguedevelopment.pulse.particle
Section 97
//IParticleFactory (com.roguedevelopment.pulse.particle.IParticleFactory)
package com.roguedevelopment.pulse.particle {
public interface IParticleFactory {
function set initializers(C:\Documents and Settings\mike\My Documents\Flex Builder 3\pachinko;com\roguedevelopment\pulse\particle;IParticleFactory.as:Array):void;
function cleanup():void;
function newParticle():IParticle;
function recycle(C:\Documents and Settings\mike\My Documents\Flex Builder 3\pachinko;com\roguedevelopment\pulse\particle;IParticleFactory.as:IParticle):void;
function set rules(C:\Documents and Settings\mike\My Documents\Flex Builder 3\pachinko;com\roguedevelopment\pulse\particle;IParticleFactory.as:Array):void;
}
}//package com.roguedevelopment.pulse.particle
Section 98
//IRecyleableParticle (com.roguedevelopment.pulse.particle.IRecyleableParticle)
package com.roguedevelopment.pulse.particle {
public interface IRecyleableParticle extends IParticle {
function get factory():IParticleFactory;
function recycle():void;
function set factory(C:\Documents and Settings\mike\My Documents\Flex Builder 3\pachinko;com\roguedevelopment\pulse\particle;IRecyleableParticle.as:IParticleFactory):void;
}
}//package com.roguedevelopment.pulse.particle
Section 99
//LineParticle (com.roguedevelopment.pulse.particle.LineParticle)
package com.roguedevelopment.pulse.particle {
public class LineParticle extends GenericParticle {
protected var _size:Number;// = 1
protected var _color:uint;// = 0xFFFFFF
public function LineParticle(){
super();
redraw();
}
public function set size(s:Number):void{
_size = s;
redraw();
}
public function set color(c:uint):void{
_color = c;
redraw();
}
protected function redraw():void{
graphics.clear();
graphics.lineStyle(1, _color);
graphics.moveTo(0, 0);
graphics.lineTo(_size, 0);
}
}
}//package com.roguedevelopment.pulse.particle
Section 100
//AccelerationRule (com.roguedevelopment.pulse.rule.AccelerationRule)
package com.roguedevelopment.pulse.rule {
import com.roguedevelopment.pulse.particle.*;
public final class AccelerationRule implements IPulseRule {
protected var amount:Number;// = 1
public function AccelerationRule(amount:Number=1){
super();
this.amount = amount;
}
public function applyRule(pulse:IParticle, currentMs:Number, lastMs:Number):void{
var speed:Number;
if (pulse.params.hasOwnProperty("speed")){
speed = pulse.params["speed"];
speed = (speed + amount);
if ((((amount < 0)) && ((speed < 0)))){
speed = 0;
};
};
pulse.params["speed"] = speed;
}
public function configure(params:Array):void{
amount = params[0];
}
}
}//package com.roguedevelopment.pulse.rule
Section 101
//BoundingBoxRule (com.roguedevelopment.pulse.rule.BoundingBoxRule)
package com.roguedevelopment.pulse.rule {
import flash.geom.*;
import com.roguedevelopment.pulse.particle.*;
public final class BoundingBoxRule implements IPulseRule {
protected var box:Rectangle;
public function BoundingBoxRule(box:Rectangle=null){
super();
this.box = box;
}
public function applyRule(pulse:IParticle, currentMs:Number, lastMs:Number):void{
var s:Number;
var dx:Number;
var dy:Number;
var a:Number = pulse.params.angle;
if ((((((((pulse.x <= box.x)) && ((a > (Math.PI / 2))))) && ((a < ((3 * Math.PI) / 2))))) || ((((pulse.x >= box.right)) && ((((a > ((3 * Math.PI) / 2))) || ((a < (Math.PI / 2))))))))){
s = pulse.params.speed;
dx = (Math.cos(a) * s);
dy = (Math.sin(a) * s);
dx = (dx * -1);
a = Math.atan2(dy, dx);
if (a < 0){
a = (a + (2 * Math.PI));
};
if (a > (2 * Math.PI)){
a = (a - (2 * Math.PI));
};
pulse.params.angle = a;
};
if ((((((((pulse.y <= box.y)) && ((a > Math.PI)))) && ((a < (2 * Math.PI))))) || ((((((pulse.y >= box.bottom)) && ((a > 0)))) && ((a < Math.PI)))))){
s = pulse.params.speed;
dx = (Math.cos(a) * s);
dy = (Math.sin(a) * s);
dy = (dy * -1);
a = Math.atan2(dy, dx);
if (a < 0){
a = (a + (2 * Math.PI));
};
if (a > 360){
a = (a - (2 * Math.PI));
};
pulse.params.angle = a;
};
}
public function configure(params:Array):void{
if (params.length != 4){
return;
};
box = new Rectangle(params[0], params[1], params[2], params[3]);
}
}
}//package com.roguedevelopment.pulse.rule
Section 102
//ColorTransformRule (com.roguedevelopment.pulse.rule.ColorTransformRule)
package com.roguedevelopment.pulse.rule {
import flash.display.*;
import flash.geom.*;
import com.roguedevelopment.pulse.particle.*;
public class ColorTransformRule implements IPulseRule {
public var rMult:Number;// = 1
public var rOffset:Number;// = 0
public var endTime:Number;
public var startTime:Number;
public var bMult:Number;// = 1
public var bOffset:Number;// = 0
public var gMult:Number;// = 1
public var gOffset:Number;// = 0
public function ColorTransformRule(){
super();
var c:ColorTransform = new ColorTransform();
}
public function configure(params:Array):void{
if (params.length != 8){
return;
};
startTime = (params.shift() as Number);
endTime = (params.shift() as Number);
rMult = (params.shift() as Number);
gMult = (params.shift() as Number);
bMult = (params.shift() as Number);
rOffset = (params.shift() as Number);
gOffset = (params.shift() as Number);
bOffset = (params.shift() as Number);
}
public function applyRule(pulse:IParticle, currentMs:Number, lastMs:Number):void{
var ds:Number = (currentMs - pulse.birthTime);
if ((((ds < startTime)) || ((ds > endTime)))){
return;
};
var dob:DisplayObject = (pulse as DisplayObject);
if (dob == null){
return;
};
var percent:Number = ((ds - startTime) / (endTime - startTime));
dob.transform.colorTransform = new ColorTransform((1 + ((rMult - 1) * percent)), (1 + ((gMult - 1) * percent)), (1 + ((bMult - 1) * percent)), 1, (rOffset * percent), (gOffset * percent), (bOffset * percent), 0);
}
}
}//package com.roguedevelopment.pulse.rule
Section 103
//DeathRule (com.roguedevelopment.pulse.rule.DeathRule)
package com.roguedevelopment.pulse.rule {
import com.roguedevelopment.pulse.particle.*;
import com.roguedevelopment.pulse.*;
public final class DeathRule implements IPulseRule {
protected var maxAge:Number;
public function DeathRule(maxAge:Number=3000){
super();
this.maxAge = maxAge;
}
public function configure(params:Array):void{
maxAge = (params[0] as Number);
}
public function applyRule(pulse:IParticle, currentMs:Number, lastMs:Number):void{
if (currentMs > (maxAge + pulse.birthTime)){
PulseEngine.instance.removeParticle(pulse);
pulse.rules.splice(pulse.rules.indexOf(this), 1);
};
}
}
}//package com.roguedevelopment.pulse.rule
Section 104
//FadeRule (com.roguedevelopment.pulse.rule.FadeRule)
package com.roguedevelopment.pulse.rule {
import com.roguedevelopment.pulse.particle.*;
public final class FadeRule implements IPulseRule {
protected var maxAge:Number;
public function FadeRule(maxAge:Number=3000){
super();
this.maxAge = maxAge;
}
public function configure(params:Array):void{
maxAge = (params[0] as Number);
}
public function applyRule(pulse:IParticle, currentMs:Number, lastMs:Number):void{
if (currentMs == pulse.birthTime){
return;
};
var age:Number = (currentMs - pulse.birthTime);
if (age > maxAge){
pulse.rules.splice(pulse.rules.indexOf(this), 1);
return;
};
pulse.alpha = (1 - (age / maxAge));
}
}
}//package com.roguedevelopment.pulse.rule
Section 105
//GravityRule (com.roguedevelopment.pulse.rule.GravityRule)
package com.roguedevelopment.pulse.rule {
import com.roguedevelopment.pulse.particle.*;
public final class GravityRule implements IPulseRule {
protected var gravityAmount:Number;
public function GravityRule(gravityAmount:Number=5){
super();
this.gravityAmount = gravityAmount;
}
public function applyRule(pulse:IParticle, currentMs:Number, lastMs:Number):void{
var s:Number = pulse.params.speed;
var a:Number = pulse.params.angle;
var dx:Number = (Math.cos(a) * s);
var dy:Number = ((Math.sin(a) * s) + gravityAmount);
a = Math.atan2(dy, dx);
if (a < 0){
a = (a + (2 * Math.PI));
};
if (a > (2 * Math.PI)){
a = (a - (2 * Math.PI));
};
pulse.params.angle = a;
pulse.params.speed = Math.sqrt(((dx * dx) + (dy * dy)));
}
public function configure(params:Array):void{
gravityAmount = (params[0] as Number);
}
}
}//package com.roguedevelopment.pulse.rule
Section 106
//IPulseRule (com.roguedevelopment.pulse.rule.IPulseRule)
package com.roguedevelopment.pulse.rule {
import com.roguedevelopment.pulse.particle.*;
public interface IPulseRule {
function applyRule(_arg1:IParticle, _arg2:Number, _arg3:Number):void;
function configure(:Array):void;
}
}//package com.roguedevelopment.pulse.rule
Section 107
//MouseSwarmRule (com.roguedevelopment.pulse.rule.MouseSwarmRule)
package com.roguedevelopment.pulse.rule {
import flash.events.*;
import flash.display.*;
import flash.geom.*;
import com.roguedevelopment.pulse.particle.*;
public final class MouseSwarmRule implements IPulseRule {
protected var mouse:Point;
public function MouseSwarmRule(stage:Stage=null){
mouse = new Point();
super();
if (stage != null){
stage.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
};
}
public function configure(params:Array):void{
(params[0] as Stage).addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
}
protected function onMouseMove(event:MouseEvent):void{
mouse.x = event.stageX;
mouse.y = event.stageY;
}
public function applyRule(pulse:IParticle, currentMs:Number, lastMs:Number):void{
var a:Number = Math.atan2((mouse.y - pulse.y), (mouse.x - pulse.x));
if (a < 0){
a = (a + (2 * Math.PI));
};
if (pulse.params.angle < 0){
pulse.params.angle = (pulse.params.angle + (2 * Math.PI));
};
if (pulse.params.angle > (2 * Math.PI)){
pulse.params.angle = (pulse.params.angle - (2 * Math.PI));
};
var dif:Number = (pulse.params.angle - a);
if ((((((dif > 0)) && ((dif <= Math.PI)))) || ((dif < -(Math.PI))))){
pulse.params.angle = (pulse.params.angle - Math.min(0.1, Math.abs(dif)));
} else {
if ((((((dif >= -(Math.PI))) && ((dif < 0)))) || ((dif > Math.PI)))){
pulse.params.angle = (pulse.params.angle + Math.min(0.1, Math.abs(dif)));
};
};
}
}
}//package com.roguedevelopment.pulse.rule
Section 108
//MovementRule (com.roguedevelopment.pulse.rule.MovementRule)
package com.roguedevelopment.pulse.rule {
import com.roguedevelopment.pulse.particle.*;
import com.roguedevelopment.pulse.*;
public final class MovementRule implements IPulseRule {
public function MovementRule(){
super();
}
public function applyRule(pulse:IParticle, currentMs:Number, lastMs:Number):void{
var speed:Number = 1;
var angle:Number = 0;
if (pulse.params.hasOwnProperty("speed")){
speed = pulse.params["speed"];
};
if (pulse.params.hasOwnProperty("angle")){
angle = pulse.params["angle"];
};
var desiredDistance:Number = ((PulseEngine.PARTICLE_LOOP_TIME / 1000) * speed);
var dx:Number = (Math.cos(angle) * desiredDistance);
var dy:Number = (Math.sin(angle) * desiredDistance);
pulse.x = (pulse.x + dx);
pulse.y = (pulse.y + dy);
}
public function configure(params:Array):void{
}
}
}//package com.roguedevelopment.pulse.rule
Section 109
//MovementStopRule (com.roguedevelopment.pulse.rule.MovementStopRule)
package com.roguedevelopment.pulse.rule {
import flash.geom.*;
import com.roguedevelopment.pulse.particle.*;
public final class MovementStopRule implements IPulseRule {
protected var box:Rectangle;
public function MovementStopRule(box:Rectangle=null){
super();
this.box = box;
}
public function applyRule(pulse:IParticle, currentMs:Number, lastMs:Number):void{
var rule:IPulseRule;
var i:int;
if (box.contains(pulse.x, pulse.y)){
for each (rule in pulse.rules) {
if ((rule is MovementRule)){
i = pulse.rules.lastIndexOf(rule);
pulse.rules.splice(i, 1);
};
};
pulse.params.speed = 0;
};
}
public function configure(params:Array):void{
if (params.length != 4){
return;
};
box = new Rectangle(params[0], params[1], params[2], params[3]);
}
}
}//package com.roguedevelopment.pulse.rule
Section 110
//PointSwarmRule (com.roguedevelopment.pulse.rule.PointSwarmRule)
package com.roguedevelopment.pulse.rule {
import flash.geom.*;
import com.roguedevelopment.pulse.particle.*;
public final class PointSwarmRule implements IPulseRule {
protected var dest:Point;
public function PointSwarmRule(destination:Point=null){
dest = new Point();
super();
if (destination != null){
dest = destination;
};
}
public function configure(params:Array):void{
if ((params[0] is Point)){
dest = (params[0] as Point);
} else {
dest.x = (params[0] as Number);
dest.y = (params[1] as Number);
};
}
public function applyRule(pulse:IParticle, currentMs:Number, lastMs:Number):void{
var a:Number = Math.atan2((dest.y - pulse.y), (dest.x - pulse.x));
if (a < 0){
a = (a + (2 * Math.PI));
};
if (pulse.params.angle < 0){
pulse.params.angle = (pulse.params.angle + (2 * Math.PI));
};
if (pulse.params.angle > (2 * Math.PI)){
pulse.params.angle = (pulse.params.angle - (2 * Math.PI));
};
var dif:Number = (pulse.params.angle - a);
if ((((((dif > 0)) && ((dif <= Math.PI)))) || ((dif < -(Math.PI))))){
pulse.params.angle = (pulse.params.angle - Math.min(0.1, Math.abs(dif)));
} else {
if ((((((dif >= -(Math.PI))) && ((dif < 0)))) || ((dif > Math.PI)))){
pulse.params.angle = (pulse.params.angle + Math.min(0.1, Math.abs(dif)));
};
};
}
}
}//package com.roguedevelopment.pulse.rule
Section 111
//RotateRule (com.roguedevelopment.pulse.rule.RotateRule)
package com.roguedevelopment.pulse.rule {
import com.roguedevelopment.pulse.particle.*;
public final class RotateRule implements IPulseRule {
protected var min:Number;
protected var max:Number;
public function RotateRule(min:Number=1, max:Number=3){
super();
this.min = min;
this.max = max;
}
public function configure(params:Array):void{
min = (params[0] as Number);
max = (params[1] as Number);
}
public function applyRule(pulse:IParticle, currentMs:Number, lastMs:Number):void{
if (!pulse.params.hasOwnProperty("rotationSpeed")){
pulse.params["rotationSpeed"] = (min + (Math.random() * (max - min)));
};
pulse.rotation = (pulse.rotation + pulse.params["rotationSpeed"]);
}
}
}//package com.roguedevelopment.pulse.rule
Section 112
//RotateToAngleRule (com.roguedevelopment.pulse.rule.RotateToAngleRule)
package com.roguedevelopment.pulse.rule {
import com.roguedevelopment.pulse.particle.*;
public final class RotateToAngleRule implements IPulseRule {
public function RotateToAngleRule(){
super();
}
public function applyRule(pulse:IParticle, currentMs:Number, lastMs:Number):void{
pulse.rotation = ((pulse.params.angle * 180) / Math.PI);
}
public function configure(params:Array):void{
}
}
}//package com.roguedevelopment.pulse.rule
Section 113
//ScaleRule (com.roguedevelopment.pulse.rule.ScaleRule)
package com.roguedevelopment.pulse.rule {
import com.roguedevelopment.pulse.particle.*;
import com.roguedevelopment.*;
public final class ScaleRule implements IPulseRule {
protected var startScale:Number;
protected var targetScale:Number;
protected var maxAge:Number;
public function ScaleRule(maxAge:Number=3000, startScale:Number=1, targetScale:Number=5){
super();
this.maxAge = maxAge;
this.targetScale = targetScale;
this.startScale = startScale;
}
public function applyRule(pulse:IParticle, currentMs:Number, lastMs:Number):void{
var age:Number = (currentMs - pulse.birthTime);
if (age > maxAge){
pulse.rules.splice(pulse.rules.indexOf(this), 1);
return;
};
if (startScale > targetScale){
pulse.scaleX = (startScale - PennerEasing.sineEaseInOut(age, targetScale, startScale, maxAge));
} else {
pulse.scaleX = PennerEasing.sineEaseInOut(age, startScale, targetScale, maxAge);
};
pulse.scaleY = pulse.scaleX;
}
public function configure(params:Array):void{
maxAge = (params[0] as Number);
startScale = (params[1] as Number);
targetScale = (params[2] as Number);
}
}
}//package com.roguedevelopment.pulse.rule
Section 114
//TweenRule (com.roguedevelopment.pulse.rule.TweenRule)
package com.roguedevelopment.pulse.rule {
import com.roguedevelopment.pulse.particle.*;
import com.roguedevelopment.*;
public final class TweenRule implements IPulseRule {
protected var start:Number;
protected var maxAge:Number;
protected var ease:Function;
protected var field:String;
protected var end:Number;
public function TweenRule(field:String="", start:Number=1, end:Number=1, maxAge:Number=1, ease:Function=null){
super();
this.field = field;
this.start = start;
this.end = end;
this.maxAge = maxAge;
this.ease = ease;
if (this.ease == null){
this.ease = PennerEasing.linearEaseNone;
};
}
public function configure(params:Array):void{
field = params[0];
start = params[1];
end = params[2];
maxAge = params[3];
}
public function applyRule(pulse:IParticle, currentMs:Number, lastMs:Number):void{
var age:Number = (currentMs - pulse.birthTime);
if (age > maxAge){
pulse.rules.splice(pulse.rules.indexOf(this), 1);
return;
};
var o:Object = pulse;
if (end > start){
o[field] = ease(age, start, end, maxAge);
} else {
o[field] = (start - ease(age, end, start, maxAge));
};
}
}
}//package com.roguedevelopment.pulse.rule
Section 115
//XOscillatorRule (com.roguedevelopment.pulse.rule.XOscillatorRule)
package com.roguedevelopment.pulse.rule {
import com.roguedevelopment.pulse.particle.*;
public final class XOscillatorRule implements IPulseRule {
protected var amount:Number;// = 5
protected var dampen:Number;// = 100
public function XOscillatorRule(amount:Number=1, dampen:Number=100){
super();
this.amount = amount;
this.dampen = dampen;
}
public function configure(params:Array):void{
amount = (params[0] as Number);
dampen = (params[1] as Number);
}
public function applyRule(pulse:IParticle, currentMs:Number, lastMs:Number):void{
pulse.x = (pulse.x + (Math.cos(((currentMs - pulse.birthTime) / dampen)) * amount));
}
}
}//package com.roguedevelopment.pulse.rule
Section 116
//SimpleParticles (com.roguedevelopment.pulse.simple.SimpleParticles)
package com.roguedevelopment.pulse.simple {
import flash.display.*;
import com.roguedevelopment.pulse.particle.*;
import com.roguedevelopment.pulse.emitter.*;
import com.roguedevelopment.pulse.*;
import com.adobe.serialization.json.*;
import com.roguedevelopment.pulse.rule.*;
import com.roguedevelopment.pulse.initializers.*;
public class SimpleParticles {
protected static var rules:Object = {scale:ScaleRule, fade:FadeRule, gravity:GravityRule, movement:MovementRule, lifespan:DeathRule, mouseSwarm:MouseSwarmRule, rotateToAngle:RotateToAngleRule, xOscillate:XOscillatorRule, tween:TweenRule, pointSwarm:PointSwarmRule, rotate:RotateRule, accel:AccelerationRule, bound:BoundingBoxRule, stop:MovementStopRule, colorTransform:ColorTransformRule};
public function SimpleParticles(){
super();
}
public static function createEmitter(params:Object):IParticleEmitter{
var emitter:GenericEmitter;
var bmd:BitmapData;
var bm:Bitmap;
var pps = 10;
if (params.hasOwnProperty("pps")){
pps = params.pps;
};
if (((params.hasOwnProperty("bme")) && (params.bme))){
bmd = new BitmapData(PulseEngine.instance.root.stage.width, PulseEngine.instance.root.stage.height, true, 0);
bm = new Bitmap(bmd);
PulseEngine.instance.root.addChild(bm);
emitter = new BitmapEmitter(pps, bmd);
} else {
emitter = new GenericEmitter(pps);
};
configureEmitterByObject(emitter, params);
return (emitter);
}
protected static function doInitializer(ruleName:String, params:Object, currentInits:Array):Boolean{
var a:Array = (params as Array);
switch (ruleName){
case "startScale":
currentInits.push(new ScaleRandomizerInitializer(a[0], a[1]));
return (true);
case "angle":
currentInits.push(new AngleRandomizerInitializer(a[0], a[1]));
return (true);
case "randomFrame":
currentInits.push(new RandomFrameInit());
return (true);
};
return (false);
}
public static function configureEmitter(emitter:GenericEmitter, params:String):IParticleEmitter{
var r:RegExp;
var d:JSONDecoder;
var o:Object;
var emitter = emitter;
var params = params;
r = /([a-zA-Z0-9_]+):/g;
params = params.replace(r, "\"$1\":");
d = new JSONDecoder(params);
o = d.getValue();
//unresolved jump
var _slot1 = e;
return (emitter);
return (configureEmitterByObject(emitter, o));
}
protected static function createLineFactory(param:Object, rules:Array, initializers:Array):IParticleFactory{
return (new GenericFactory(LineParticle, rules, initializers));
}
protected static function createImageFactory(param:Object, rules:Array, initializers:Array):IParticleFactory{
return (new GenericFactory(ImageParticle, rules, initializers));
}
protected static function createDotFactory(param:Object, rules:Array, initializers:Array):IParticleFactory{
return (new GenericFactory(DotParticle, rules, initializers));
}
public static function configureEmitterByObject(emitter:GenericEmitter, params:Object):IParticleEmitter{
var param:String;
var aparam:Array;
var start:Boolean;
var factory:IParticleFactory = emitter.getFactory();
var rules:Array = [];
var initializers:Array = [];
if (((params.hasOwnProperty("minSpeed")) && (params.hasOwnProperty("maxSpeed")))){
initializers.push(new ParameterRandomizerInitializer("speed", params.minSpeed, params.maxSpeed, true));
};
if (((params.hasOwnProperty("minAngle")) && (params.hasOwnProperty("maxAngle")))){
initializers.push(new AngleRandomizerInitializer(params.minAngle, params.maxAngle));
};
if (((params.hasOwnProperty("minScale")) && (params.hasOwnProperty("maxScale")))){
initializers.push(new ScaleRandomizerInitializer(params.minScale, params.maxScale));
};
for (param in params) {
switch (param){
case "start":
start = params.start;
break;
case "x":
emitter.x = params.x;
break;
case "y":
emitter.y = params.y;
break;
case "dot":
factory = createDotFactory(params[param], rules, initializers);
break;
case "line":
factory = createLineFactory(params[param], rules, initializers);
break;
case "image":
initializers.push(new ParameterInitializer("image", params[param]));
factory = createImageFactory(params[param], rules, initializers);
break;
case "width":
emitter.width = (params[param] as Number);
break;
case "height":
emitter.height = (params[param] as Number);
break;
case "limit":
emitter.particleLimit = (params[param] as Number);
break;
default:
if (((!(doRule(param, params[param], rules))) && (!(doInitializer(param, params[param], initializers))))){
if ((params[param] is Array)){
aparam = (params[param] as Array);
initializers.push(new ParameterRandomizerInitializer(param, aparam[0], aparam[1], true));
};
if ((params[param] is Number)){
initializers.push(new ParameterInitializer(param, (params[param] as Number)));
};
};
break;
};
};
if (factory == null){
factory = createDotFactory(null, rules, initializers);
} else {
factory.rules = rules;
factory.initializers = initializers;
};
emitter.setFactory(factory);
if (start){
emitter.start();
};
return (emitter);
}
protected static function doRule(ruleName:String, params:Object, currentRules:Array):Boolean{
if (!rules.hasOwnProperty(ruleName)){
return (false);
};
var ruleClass:Class = rules[ruleName];
var rule:IPulseRule = new (ruleClass);
if ((params is Array)){
rule.configure((params as Array));
} else {
rule.configure([params]);
};
currentRules.push(rule);
return (true);
}
}
}//package com.roguedevelopment.pulse.simple
Section 117
//PulseEngine (com.roguedevelopment.pulse.PulseEngine)
package com.roguedevelopment.pulse {
import flash.events.*;
import flash.display.*;
import com.roguedevelopment.pulse.particle.*;
import flash.utils.*;
import com.roguedevelopment.pulse.rule.*;
public final class PulseEngine {
public var root:DisplayObjectContainer;
protected var emitters:Array;
protected var timer:Timer;
protected var particles:Array;
public var updateAfterTimer:Boolean;// = false
protected var lastUpdate:Number;
public static const PARTICLE_LOOP_TIME:Number = 30;
protected static var _instance:PulseEngine;
public function PulseEngine(){
emitters = [];
particles = [];
super();
if (_instance != null){
throw (new Error("only one engine allowed"));
};
timer = new Timer(PARTICLE_LOOP_TIME);
timer.addEventListener(TimerEvent.TIMER, onTime);
timer.start();
lastUpdate = new Date().time;
}
public function addParticle(particle:IParticle):void{
particle.visible = false;
particles.push(particle);
}
public function addEmitter(emitter:IParticleFactory):void{
emitters.push(emitter);
}
public function removeParticle(particle:IParticle):void{
particles.splice(particles.indexOf(particle), 1);
if ((particle is IRecyleableParticle)){
(particle as IRecyleableParticle).factory.recycle(particle);
} else {
particle.remove();
};
}
protected function onTime(event:TimerEvent):void{
var particle:IParticle;
var rule:IPulseRule;
var now:Date = new Date();
for each (particle in particles) {
particle.visible = true;
for each (rule in particle.rules) {
rule.applyRule(particle, now.time, lastUpdate);
};
};
lastUpdate = now.time;
if (updateAfterTimer){
event.updateAfterEvent();
};
}
public function stopAndRemoveAllParticles():void{
var particle:IParticle;
for each (particle in particles) {
particle.remove();
};
particles = [];
}
public static function get instance():PulseEngine{
if (_instance == null){
_instance = new (PulseEngine);
};
return (_instance);
}
}
}//package com.roguedevelopment.pulse
Section 118
//PennerEasing (com.roguedevelopment.PennerEasing)
package com.roguedevelopment {
public class PennerEasing {
public function PennerEasing(){
super();
}
public static function quartEaseOut(t:Number, b:Number, c:Number, d:Number):Number{
t = ((t / d) - 1);
return (((-(c) * ((((t * t) * t) * t) - 1)) + b));
}
public static function circEaseInOut(t:Number, b:Number, c:Number, d:Number):Number{
t = (t / (d / 2));
if (t < 1){
return ((((-(c) / 2) * (Math.sqrt((1 - (t * t))) - 1)) + b));
};
t = (t - 2);
return ((((c / 2) * (Math.sqrt((1 - (t * t))) + 1)) + b));
}
public static function expoEaseIn(t:Number, b:Number, c:Number, d:Number):Number{
return (((t)==0) ? b : ((c * Math.pow(2, (10 * ((t / d) - 1)))) + b));
}
public static function elasticEaseInOut(t:Number, b:Number, c:Number, d:Number, a:Number, p:Number):Number{
var s:Number;
if (t == 0){
return (b);
};
t = (t / (d / 2));
if (t == 2){
return ((b + c));
};
if (!p){
p = (d * (0.3 * 1.5));
};
if (((!(a)) || ((a < Math.abs(c))))){
a = c;
s = (p / 4);
} else {
s = ((p / (2 * Math.PI)) * Math.asin((c / a)));
};
if (t < 1){
--t;
return (((-0.5 * ((a * Math.pow(2, (10 * t))) * Math.sin(((((t * d) - s) * (2 * Math.PI)) / p)))) + b));
};
--t;
return ((((((a * Math.pow(2, (-10 * t))) * Math.sin(((((t * d) - s) * (2 * Math.PI)) / p))) * 0.5) + c) + b));
}
public static function expoEaseInOut(t:Number, b:Number, c:Number, d:Number):Number{
if (t == 0){
return (b);
};
if (t == d){
return ((b + c));
};
t = (t / (d / 2));
if (t < 1){
return ((((c / 2) * Math.pow(2, (10 * (t - 1)))) + b));
};
--t;
return ((((c / 2) * (-(Math.pow(2, (-10 * t))) + 2)) + b));
}
public static function linearEaseNone(t:Number, b:Number, c:Number, d:Number):Number{
return ((((c * t) / d) + b));
}
public static function sineEaseInOut(t:Number, b:Number, c:Number, d:Number):Number{
return ((((-(c) / 2) * (Math.cos(((Math.PI * t) / d)) - 1)) + b));
}
public static function quintEaseInOut(t:Number, b:Number, c:Number, d:Number):Number{
t = (t / (d / 2));
if (t < 1){
return ((((((((c / 2) * t) * t) * t) * t) * t) + b));
};
t = (t - 2);
return ((((c / 2) * (((((t * t) * t) * t) * t) + 2)) + b));
}
public static function quartEaseIn(t:Number, b:Number, c:Number, d:Number):Number{
t = (t / d);
return ((((((c * t) * t) * t) * t) + b));
}
public static function quadEaseInOut(t:Number, b:Number, c:Number, d:Number):Number{
t = (t / (d / 2));
if (t < 1){
return (((((c / 2) * t) * t) + b));
};
--t;
return ((((-(c) / 2) * ((t * (t - 2)) - 1)) + b));
}
public static function cubicEaseOut(t:Number, b:Number, c:Number, d:Number):Number{
t = ((t / d) - 1);
return (((c * (((t * t) * t) + 1)) + b));
}
public static function bounceEaseOut(t:Number, b:Number, c:Number, d:Number):Number{
t = (t / d);
if (t < (1 / 2.75)){
return (((c * ((7.5625 * t) * t)) + b));
};
if (t < (2 / 2.75)){
t = (t - (1.5 / 2.75));
return (((c * (((7.5625 * t) * t) + 0.75)) + b));
};
if (t < (2.5 / 2.75)){
t = (t - (2.25 / 2.75));
return (((c * (((7.5625 * t) * t) + 0.9375)) + b));
};
t = (t - (2.625 / 2.75));
return (((c * (((7.5625 * t) * t) + 0.984375)) + b));
}
public static function backEaseOut(t:Number, b:Number, c:Number, d:Number, s:Number=1.70158):Number{
t = ((t / d) - 1);
return (((c * (((t * t) * (((s + 1) * t) + s)) + 1)) + b));
}
public static function quadEaseIn(t:Number, b:Number, c:Number, d:Number):Number{
t = (t / d);
return ((((c * t) * t) + b));
}
public static function bounceEaseIn(t:Number, b:Number, c:Number, d:Number):Number{
return (((c - bounceEaseOut((d - t), 0, c, d)) + b));
}
public static function quartEaseInOut(t:Number, b:Number, c:Number, d:Number):Number{
t = (t / (d / 2));
if (t < 1){
return (((((((c / 2) * t) * t) * t) * t) + b));
};
t = (t - 2);
return ((((-(c) / 2) * ((((t * t) * t) * t) - 2)) + b));
}
public static function cubicEaseIn(t:Number, b:Number, c:Number, d:Number):Number{
t = (t / d);
return (((((c * t) * t) * t) + b));
}
public static function quintEaseIn(t:Number, b:Number, c:Number, d:Number):Number{
t = (t / d);
return (((((((c * t) * t) * t) * t) * t) + b));
}
public static function sineEaseIn(t:Number, b:Number, c:Number, d:Number):Number{
return ((((-(c) * Math.cos(((t / d) * (Math.PI / 2)))) + c) + b));
}
public static function backEaseIn(t:Number, b:Number, c:Number, d:Number, s:Number=1.70158):Number{
t = (t / d);
return (((((c * t) * t) * (((s + 1) * t) - s)) + b));
}
public static function elasticEaseIn(t:Number, b:Number, c:Number, d:Number, a:Number, p:Number):Number{
var s:Number;
if (t == 0){
return (b);
};
t = (t / d);
if (t == 1){
return ((b + c));
};
if (!p){
p = (d * 0.3);
};
if (((!(a)) || ((a < Math.abs(c))))){
a = c;
s = (p / 4);
} else {
s = ((p / (2 * Math.PI)) * Math.asin((c / a)));
};
--t;
return ((-(((a * Math.pow(2, (10 * t))) * Math.sin(((((t * d) - s) * (2 * Math.PI)) / p)))) + b));
}
public static function circEaseOut(t:Number, b:Number, c:Number, d:Number):Number{
t = ((t / d) - 1);
return (((c * Math.sqrt((1 - (t * t)))) + b));
}
public static function circEaseIn(t:Number, b:Number, c:Number, d:Number):Number{
t = (t / d);
return (((-(c) * (Math.sqrt((1 - (t * t))) - 1)) + b));
}
public static function elasticEaseOut(t:Number, b:Number, c:Number, d:Number, a:Number, p:Number):Number{
var s:Number;
if (t == 0){
return (b);
};
t = (t / d);
if (t == 1){
return ((b + c));
};
if (!p){
p = (d * 0.3);
};
if (((!(a)) || ((a < Math.abs(c))))){
a = c;
s = (p / 4);
} else {
s = ((p / (2 * Math.PI)) * Math.asin((c / a)));
};
return (((((a * Math.pow(2, (-10 * t))) * Math.sin(((((t * d) - s) * (2 * Math.PI)) / p))) + c) + b));
}
public static function expoEaseOut(t:Number, b:Number, c:Number, d:Number):Number{
return (((t)==d) ? (b + c) : ((c * (-(Math.pow(2, ((-10 * t) / d))) + 1)) + b));
}
public static function cubicEaseInOut(t:Number, b:Number, c:Number, d:Number):Number{
t = (t / (d / 2));
if (t < 1){
return ((((((c / 2) * t) * t) * t) + b));
};
t = (t - 2);
return ((((c / 2) * (((t * t) * t) + 2)) + b));
}
public static function sineEaseOut(t:Number, b:Number, c:Number, d:Number):Number{
return (((c * Math.sin(((t / d) * (Math.PI / 2)))) + b));
}
public static function backEaseInOut(t:Number, b:Number, c:Number, d:Number, s:Number=1.70158):Number{
t = (t / (d / 2));
if (t < 1){
s = (s * 1.525);
return ((((c / 2) * ((t * t) * (((s + 1) * t) - s))) + b));
};
t = (t - 2);
s = (s * 1.525);
return ((((c / 2) * (((t * t) * (((s + 1) * t) + s)) + 2)) + b));
}
public static function quintEaseOut(t:Number, b:Number, c:Number, d:Number):Number{
t = ((t / d) - 1);
return (((c * (((((t * t) * t) * t) * t) + 1)) + b));
}
public static function quadEaseOut(t:Number, b:Number, c:Number, d:Number):Number{
t = (t / d);
return ((((-(c) * t) * (t - 2)) + b));
}
public static function bounceEaseInOut(t:Number, b:Number, c:Number, d:Number):Number{
if (t < (d / 2)){
return (((bounceEaseIn((t * 2), 0, c, d) * 0.5) + b));
};
return ((((bounceEaseOut(((t * 2) - d), 0, c, d) * 0.5) + (c * 0.5)) + b));
}
}
}//package com.roguedevelopment
Section 119
//Collection (de.polygonal.ds.Collection)
package de.polygonal.ds {
public interface Collection {
function get size():int;
function isEmpty():Boolean;
function getIterator():Iterator;
function clear():void;
function toArray():Array;
function contains():Boolean;
}
}//package de.polygonal.ds
Section 120
//HashMap (de.polygonal.ds.HashMap)
package de.polygonal.ds {
import flash.utils.*;
public class HashMap implements Collection {
private var _objMap:Dictionary;
private var _keyMap:Dictionary;
private var _size:int;
public function HashMap(){
super();
_keyMap = new Dictionary(true);
_objMap = new Dictionary(true);
_size = 0;
}
public function containsKey(key):Boolean{
return ((_keyMap[key]) ? true : false);
}
public function get size():int{
return (_size);
}
public function isEmpty():Boolean{
return ((_size == 0));
}
public function remove(key){
var obj:* = _keyMap[key];
if (obj){
_size--;
delete _keyMap[key];
delete _objMap[obj];
return (obj);
};
return (null);
}
public function clear():void{
_keyMap = new Dictionary(true);
_objMap = new Dictionary(true);
_size = 0;
}
public function find(key){
return (((_keyMap[key]) || (null)));
}
public function getKeySet():Array{
var i:*;
var a:Array = new Array(_size);
var j:int;
for each (i in _objMap) {
var _temp1 = j;
j = (j + 1);
var _local6 = _temp1;
a[_local6] = i;
};
return (a);
}
public function getIterator():Iterator{
return (new HashMapValueIterator(this));
}
public function toArray():Array{
var i:*;
var a:Array = new Array(_size);
var j:int;
for each (i in _keyMap) {
var _temp1 = j;
j = (j + 1);
var _local6 = _temp1;
a[_local6] = i;
};
return (a);
}
public function findKey(val){
return (((_objMap[val]) || (null)));
}
public function toString():String{
return ((("[HashMap, size=" + size) + "]"));
}
public function contains(obj):Boolean{
return ((_objMap[obj]) ? true : false);
}
public function dump():String{
var i:*;
var s:String = "HashMap:\n";
for each (i in _objMap) {
s = (s + (((("[key: " + i) + " val:") + _keyMap[i]) + "]\n"));
};
return (s);
}
public function getKeyIterator():Iterator{
return (new HashMapKeyIterator(this));
}
public function insert(key, obj):Boolean{
if (_keyMap[key]){
return (false);
};
_size++;
_objMap[obj] = key;
_keyMap[key] = obj;
return (true);
}
}
}//package de.polygonal.ds
class HashMapKeyIterator implements Iterator {
private var _size:int;
private var _h:HashMap;
private var _keys:Array;
private var _cursor:int;
private function HashMapKeyIterator(h:HashMap){
super();
_h = h;
_keys = h.getKeySet();
_cursor = 0;
_size = _h.size;
}
public function start():void{
_cursor = 0;
}
public function get data(){
return (_keys[_cursor]);
}
public function next(){
return (_keys[_cursor++]);
}
public function hasNext():Boolean{
return ((_cursor < _size));
}
public function set data(obj):void{
var key:* = _keys[_cursor];
var val:* = _h.find(key);
_h.remove(key);
_h.insert(obj, val);
}
}
class HashMapValueIterator implements Iterator {
private var _size:int;
private var _values:Array;
private var _h:HashMap;
private var _cursor:int;
private function HashMapValueIterator(h:HashMap){
super();
_h = h;
_values = h.toArray();
_cursor = 0;
_size = _h.size;
}
public function next(){
return (_values[_cursor++]);
}
public function hasNext():Boolean{
return ((_cursor < _size));
}
public function set data(obj):void{
var key:* = _h.findKey(_values[_cursor]);
_h.remove(key);
_h.insert(key, obj);
}
public function get data(){
return (_values[_cursor]);
}
public function start():void{
_cursor = 0;
}
}
Section 121
//Iterator (de.polygonal.ds.Iterator)
package de.polygonal.ds {
public interface Iterator {
function start():void;
function set data(C:\Documents and Settings\mike\My Documents\Flex Builder 3\pachinko;de\polygonal\ds;Iterator.as):void;
function get data();
function next();
function hasNext():Boolean;
}
}//package de.polygonal.ds
Section 122
//FRateLimiter (General.FRateLimiter)
package General {
import flash.utils.*;
public class FRateLimiter {
private static var newT:uint = oldT;
private static var oldT:uint = getTimer();
public function FRateLimiter(){
super();
}
public static function limitFrame(maxFPS:uint):void{
var fTime:uint = (1000 / maxFPS);
while (Math.abs((newT - oldT)) < fTime) {
newT = getTimer();
};
oldT = getTimer();
}
}
}//package General
Section 123
//MochiScores (mochi.MochiScores)
package mochi {
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 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;
};
};
};
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;
};
};
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{
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
Section 124
//MochiServices (mochi.MochiServices)
package mochi {
import flash.events.*;
import flash.display.*;
import flash.net.*;
import flash.utils.*;
import flash.system.*;
public class MochiServices {
private static var _container:Object;
private static var _connected:Boolean = false;
private static var _swfVersion:String;
private static var _sendChannel:LocalConnection;
private static var _rcvChannelName:String;
private static var _gatewayURL:String = "http://www.mochiads.com/static/lib/services/services.swf";
private static var _clip:MovieClip;
private static var _loader:Loader;
private static var _id:String;
private static var _listenChannel:LocalConnection;
private static var _timer:Timer;
private static var _sendChannelName:String;
private static var _startTime:Number;
private static var _connecting:Boolean = false;
public static var onError:Object;
private static var _listenChannelName:String = "__mochiservices";
private static var _rcvChannel:LocalConnection;
public function MochiServices(){
super();
}
public static function isNetworkAvailable():Boolean{
return (!((Security.sandboxType == "localWithFile")));
}
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++;
};
};
}
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);
};
};
};
};
};
}
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);
}
public static function get id():String{
return (_id);
}
public static function stayOnTop():void{
_container.addEventListener(Event.ENTER_FRAME, MochiServices.bringToTop, false, 0, true);
if (_clip != null){
_clip.visible = true;
};
}
public static function getVersion():String{
return ("1.31");
}
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();
_rcvChannel.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;
Security.allowDomain("*");
Security.allowInsecureDomain("*");
if (server.indexOf("http://") != -1){
hostname = server.split("/")[2].split(":")[0];
Security.allowDomain(hostname);
Security.allowInsecureDomain(hostname);
};
return (hostname);
}
public static function doClose():void{
_container.removeEventListener(Event.ENTER_FRAME, MochiServices.bringToTop);
if (_clip.parent != null){
Sprite(_clip.parent).removeChild(_clip);
};
}
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 onStatus(event:StatusEvent):void{
switch (event.level){
case "error":
_connected = false;
_listenChannel.connect(_listenChannelName);
break;
};
}
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()});
_rcvChannel.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");
};
_rcvChannel.connect(_rcvChannelName);
trace("connected!");
_connecting = false;
_connected = true;
_listenChannel.close();
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...");
}
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 (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;
};
};
};
}
public static function get clip():Object{
return (_container);
}
public static function set comChannelName(val:String):void{
if (val != null){
if (val.length > 3){
_sendChannelName = (val + "_fromgame");
_rcvChannelName = val;
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);
};
MochiServices.allowDomains(_gatewayURL);
_clip = createEmptyMovieClip(clip, clipname, 10336, false);
_loader = new Loader();
_timer = new Timer(1000, 0);
_startTime = getTimer();
_timer.addEventListener(TimerEvent.TIMER, connectWait);
_timer.start();
var f:Function = function (ev:Object):void{
_clip._mochiad_ctr_failed = true;
trace("MochiServices could not load.");
MochiServices.disconnect();
MochiServices.onError("IOError");
};
_loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, f);
var req:URLRequest = new URLRequest(_gatewayURL);
_loader.load(req);
_clip.addChild(_loader);
_clip._mochiservices_com = _loader;
_sendChannel = new LocalConnection();
_clip._queue = [];
_rcvChannel = new LocalConnection();
_rcvChannel.allowDomain("*", "localhost");
_rcvChannel.allowInsecureDomain("*", "localhost");
_rcvChannel.client = _clip;
_clip._nextcallbackID = 0;
_clip._callbacks = {};
listen();
return (_clip);
}
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 ((getTimer() - _startTime) > 10000){
if (!_connected){
_clip._mochiad_ctr_failed = true;
trace("MochiServices could not load.");
MochiServices.disconnect();
MochiServices.onError("IOError");
};
_timer.stop();
};
}
}
}//package mochi
Section 125
//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.0.0.0";
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 126
//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.0.0.0";
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 127
//IFlexAsset (mx.core.IFlexAsset)
package mx.core {
public interface IFlexAsset {
}
}//package mx.core
Section 128
//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 129
//IRepeaterClient (mx.core.IRepeaterClient)
package mx.core {
public interface IRepeaterClient {
function get instanceIndices():Array;
function set instanceIndices(E:\dev\3.0.x\frameworks\projects\framework\src;mx\core;IRepeaterClient.as:Array):void;
function get isDocument():Boolean;
function set repeaters(E:\dev\3.0.x\frameworks\projects\framework\src;mx\core;IRepeaterClient.as:Array):void;
function initializeRepeaterArrays(E:\dev\3.0.x\frameworks\projects\framework\src;mx\core;IRepeaterClient.as:IRepeaterClient):void;
function get repeaters():Array;
function set repeaterIndices(E:\dev\3.0.x\frameworks\projects\framework\src;mx\core;IRepeaterClient.as:Array):void;
function get repeaterIndices():Array;
}
}//package mx.core
Section 130
//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 131
//SoundAsset (mx.core.SoundAsset)
package mx.core {
import flash.media.*;
public class SoundAsset extends Sound implements IFlexAsset {
mx_internal static const VERSION:String = "3.0.0.0";
public function SoundAsset(){
super();
}
}
}//package mx.core
Section 132
//NameUtil (mx.utils.NameUtil)
package mx.utils {
import flash.display.*;
import mx.core.*;
import flash.utils.*;
public class NameUtil {
mx_internal static const VERSION:String = "3.0.0.0";
private static var counter:int = 0;
public function NameUtil(){
super();
}
public static function displayObjectToString(displayObject:DisplayObject):String{
var result:String;
var s:String;
var indices:Array;
var o:DisplayObject = 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;
};
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 133
//Action (org.flintparticles.actions.Action)
package org.flintparticles.actions {
import org.flintparticles.emitters.*;
import org.flintparticles.particles.*;
public class Action {
public function Action(){
super();
}
public function update(emitter:Emitter, particle:Particle, time:Number):void{
}
public function addedToEmitter(emitter:Emitter):void{
}
public function getDefaultPriority():Number{
return (0);
}
}
}//package org.flintparticles.actions
Section 134
//Activity (org.flintparticles.activities.Activity)
package org.flintparticles.activities {
import org.flintparticles.emitters.*;
public class Activity {
public function Activity(){
super();
}
public function initialize(emitter:Emitter):void{
}
public function update(emitter:Emitter, time:Number):void{
}
public function addedToEmitter(emitter:Emitter):void{
}
public function getDefaultPriority():Number{
return (0);
}
}
}//package org.flintparticles.activities
Section 135
//Counter (org.flintparticles.counters.Counter)
package org.flintparticles.counters {
public interface Counter {
function startEmitter():uint;
function updateEmitter(:Number):uint;
}
}//package org.flintparticles.counters
Section 136
//Emitter (org.flintparticles.emitters.Emitter)
package org.flintparticles.emitters {
import flash.events.*;
import flash.display.*;
import org.flintparticles.particles.*;
import flash.geom.*;
import org.flintparticles.initializers.*;
import org.flintparticles.actions.*;
import org.flintparticles.activities.*;
import org.flintparticles.counters.*;
import flash.utils.*;
import org.flintparticles.events.*;
import org.flintparticles.utils.*;
public class Emitter extends Sprite {
protected var _actionsPriority:Array;
protected var _y:Number;// = 0
protected var _activities:Array;
protected var _particlesPriority:Array;
private var _time:uint;
protected var _particles:Array;
protected var _initializers:Array;
protected var _counter:Counter;
public var spaceSort:Boolean;// = false
protected var _actions:Array;
protected var _activitiesPriority:Array;
public var spaceSortedX:Array;
protected var _rotation:Number;// = 0
protected var _initializersPriority:Array;
protected var _x:Number;// = 0
private static var _creator:ParticleCreator = new ParticleCreator();
public function Emitter(){
super();
_particles = new Array();
_actions = new Array();
_initializers = new Array();
_activities = new Array();
_particlesPriority = new Array();
_actionsPriority = new Array();
_initializersPriority = new Array();
_activitiesPriority = new Array();
addEventListener(Event.REMOVED_FROM_STAGE, removed, false, 0, true);
}
override public function get y():Number{
return (_y);
}
public function addInitializer(initializer:Initializer, priority:Number=NaN):void{
if (isNaN(priority)){
priority = initializer.getDefaultPriority();
};
var i:uint;
while (i < _initializersPriority.length) {
if (_initializersPriority[i] < priority){
break;
};
i++;
};
_initializers.splice(i, 0, initializer);
_initializersPriority.splice(i, 0, priority);
initializer.addedToEmitter(this);
}
override public function globalToLocal(point:Point):Point{
var p:Point = super.globalToLocal(point);
p.x = (p.x - _x);
p.y = (p.y - _y);
return (p);
}
override public function localToGlobal(point:Point):Point{
var p:Point = super.localToGlobal(point);
p.x = (p.x + _x);
p.y = (p.y + _y);
return (p);
}
protected function particleCreated(particle:Particle):void{
}
protected function frameUpdate(time:Number):void{
var i:uint;
var particle:Particle;
var action:Action;
var len2:uint;
var j:uint;
var len:uint = _counter.updateEmitter(time);
i = 0;
while (i < len) {
createParticle();
i++;
};
if (spaceSort){
spaceSortedX = _particles.sortOn("x", (Array.NUMERIC | Array.RETURNINDEXEDARRAY));
len = _particles.length;
i = 0;
while (i < len) {
_particles[spaceSortedX[i]].spaceSortX = i;
i++;
};
};
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 FlintEvent(FlintEvent.PARTICLE_DEAD, particle));
particleDestroyed(particle);
_creator.disposeParticle(particle);
_particles.splice(i, 1);
};
};
} else {
dispatchEvent(new FlintEvent(FlintEvent.EMITTER_EMPTY));
};
render(time);
}
public function get rotRadians():Number{
return (_rotation);
}
protected function render(time:Number):void{
}
private function dispose():void{
removeEventListener(Event.ENTER_FRAME, frameLoop);
var len:uint = _particles.length;
var i:uint;
while (i < len) {
_creator.disposeParticle(_particles[i]);
i++;
};
_particles.length = 0;
cleanUp();
}
private function createParticle():Particle{
var particle:Particle = _creator.createParticle();
var len:uint = _initializers.length;
var i:uint;
while (i < len) {
_initializers[i].initialize(this, particle);
i++;
};
particle.x = (particle.x + _x);
particle.y = (particle.y + _y);
_particles.unshift(particle);
particleCreated(particle);
return (particle);
}
public function get particles():Array{
return (_particles);
}
private function frameLoop(ev:Event):void{
var oldTime:uint = _time;
_time = getTimer();
var frameTime:Number = ((_time - oldTime) * 0.001);
frameUpdate(frameTime);
}
public function removeActivity(activity:Activity):void{
var i:uint;
while (i < _activities.length) {
if (_activities[i] == activity){
_activities.splice(i, 1);
_activitiesPriority.splice(i, 1);
return;
};
i++;
};
}
public function resume():void{
removeEventListener(Event.ENTER_FRAME, frameLoop);
addEventListener(Event.ENTER_FRAME, frameLoop, false, 0, true);
_time = getTimer();
}
public function set rotRadians(value:Number):void{
_rotation = value;
}
public function addAction(action:Action, priority:Number=NaN):void{
if (isNaN(priority)){
priority = action.getDefaultPriority();
};
var i:uint;
while (i < _actionsPriority.length) {
if (_actionsPriority[i] < priority){
break;
};
i++;
};
_actions.splice(i, 0, action);
_actionsPriority.splice(i, 0, priority);
action.addedToEmitter(this);
}
public function removeInitializer(initializer:Initializer):void{
var i:uint;
while (i < _initializers.length) {
if (_initializers[i] == initializer){
_initializers.splice(i, 1);
_initializersPriority.splice(i, 1);
return;
};
i++;
};
}
public function setCounter(counter:Counter):void{
_counter = counter;
}
protected function particleDestroyed(particle:Particle):void{
}
protected function cleanUp():void{
}
public function addActivity(activity:Activity, priority:Number=NaN):void{
if (isNaN(priority)){
priority = activity.getDefaultPriority();
};
var i:uint;
while (i < _activitiesPriority.length) {
if (_activitiesPriority[i] < priority){
break;
};
i++;
};
_activities.splice(i, 0, activity);
_activitiesPriority.splice(i, 0, priority);
activity.addedToEmitter(this);
}
public function removeAction(action:Action):void{
var i:uint;
while (i < _actions.length) {
if (_actions[i] == action){
_actions.splice(i, 1);
_actionsPriority.splice(i, 1);
return;
};
i++;
};
}
public function start():void{
removeEventListener(Event.ENTER_FRAME, frameLoop);
addEventListener(Event.ENTER_FRAME, frameLoop, false, 0, true);
_time = getTimer();
var len:uint = _activities.length;
var i:uint;
while (i < len) {
_activities[i].initialize(this);
i++;
};
len = _counter.startEmitter();
i = 0;
while (i < len) {
createParticle();
i++;
};
}
private function removed(ev:Event):void{
if (ev.target == this){
dispose();
};
}
override public function set x(value:Number):void{
_x = value;
}
override public function set y(value:Number):void{
_y = value;
}
public function pause():void{
removeEventListener(Event.ENTER_FRAME, frameLoop);
}
override public function get x():Number{
return (_x);
}
override public function set rotation(value:Number):void{
_rotation = Maths.asRadians(value);
}
public function runAhead(time:Number, frameRate:Number=10):void{
pause();
var step:Number = (1 / frameRate);
while (time > 0) {
time = (time - step);
frameUpdate(step);
};
resume();
}
override public function get rotation():Number{
return (Maths.asDegrees(_rotation));
}
}
}//package org.flintparticles.emitters
Section 137
//FlintEvent (org.flintparticles.events.FlintEvent)
package org.flintparticles.events {
import flash.events.*;
import org.flintparticles.particles.*;
public class FlintEvent extends Event {
public var particle:Particle;
public static var EMITTER_EMPTY:String = "emitterEmpty";
public static var PARTICLE_DEAD:String = "particleDead";
public function FlintEvent(type:String, pParticle:Particle=null, bubbles:Boolean=false, cancelable:Boolean=false){
super(type, bubbles, cancelable);
particle = pParticle;
}
}
}//package org.flintparticles.events
Section 138
//ImageClass (org.flintparticles.initializers.ImageClass)
package org.flintparticles.initializers {
import org.flintparticles.emitters.*;
import org.flintparticles.particles.*;
import org.flintparticles.utils.*;
public class ImageClass extends Initializer {
private var _parameters:Array;
private var _imageClass:Class;
public function ImageClass(imageClass:Class, ... _args){
super();
_imageClass = imageClass;
_parameters = _args;
}
override public function initialize(emitter:Emitter, particle:Particle):void{
particle.image = construct(_imageClass, _parameters);
}
}
}//package org.flintparticles.initializers
Section 139
//Initializer (org.flintparticles.initializers.Initializer)
package org.flintparticles.initializers {
import org.flintparticles.emitters.*;
import org.flintparticles.particles.*;
public class Initializer {
public function Initializer(){
super();
}
public function initialize(emitter:Emitter, particle:Particle):void{
}
public function addedToEmitter(emitter:Emitter):void{
}
public function getDefaultPriority():Number{
return (0);
}
}
}//package org.flintparticles.initializers
Section 140
//Particle (org.flintparticles.particles.Particle)
package org.flintparticles.particles {
import flash.display.*;
import flash.geom.*;
import flash.utils.*;
public class Particle {
public var rotation:Number;// = 0
public var energy:Number;// = 1
public var lifetime:Number;// = 0
public var scale:Number;// = 1
public var dictionary:Dictionary;
public var angVelocity:Number;// = 0
public var image:DisplayObject;// = null
public var velY:Number;// = 0
public var velX:Number;// = 0
public var color:uint;// = 4294967295
public var spaceSortX:uint;
public var isDead:Boolean;// = false
public var x:Number;// = 0
public var y:Number;// = 0
public var age:Number;// = 0
public function Particle(){
super();
}
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 colorTransform():ColorTransform{
return (new ColorTransform((((color >>> 16) & 0xFF) / 0xFF), (((color >>> 8) & 0xFF) / 0xFF), ((color & 0xFF) / 0xFF), (((color >>> 24) & 0xFF) / 0xFF), 0, 0, 0, 0));
}
public function initialize():void{
x = 0;
y = 0;
velX = 0;
velY = 0;
rotation = 0;
angVelocity = 0;
color = 4294967295;
scale = 1;
lifetime = 0;
age = 0;
energy = 1;
isDead = false;
image = null;
spaceSortX = 0;
dictionary = new Dictionary();
}
}
}//package org.flintparticles.particles
Section 141
//ParticleCreator (org.flintparticles.particles.ParticleCreator)
package org.flintparticles.particles {
public class ParticleCreator {
private var _particles:Array;
public function ParticleCreator(){
super();
_particles = new Array();
}
public function clearAllParticles():void{
_particles = new Array();
}
public function createParticle():Particle{
if (_particles.length){
return (_particles.pop());
};
return (new Particle());
}
public function disposeParticle(particle:Particle):void{
particle.initialize();
_particles.push(particle);
}
}
}//package org.flintparticles.particles
Section 142
//construct (org.flintparticles.utils.construct)
package org.flintparticles.utils {
public function construct(type:Class, parameters:Array){
switch (parameters.length){
case 0:
return (new (type));
case 1:
return (new type(parameters[0]));
case 2:
return (new type(parameters[0], parameters[1]));
case 3:
return (new type(parameters[0], parameters[1], parameters[2]));
case 4:
return (new type(parameters[0], parameters[1], parameters[2], parameters[3]));
case 5:
return (new type(parameters[0], parameters[1], parameters[2], parameters[3], parameters[4]));
case 6:
return (new type(parameters[0], parameters[1], parameters[2], parameters[3], parameters[4], parameters[5]));
case 7:
return (new type(parameters[0], parameters[1], parameters[2], parameters[3], parameters[4], parameters[5], parameters[6]));
case 8:
return (new type(parameters[0], parameters[1], parameters[2], parameters[3], parameters[4], parameters[5], parameters[6], parameters[7]));
case 9:
return (new type(parameters[0], parameters[1], parameters[2], parameters[3], parameters[4], parameters[5], parameters[6], parameters[7], parameters[8]));
case 10:
return (new type(parameters[0], parameters[1], parameters[2], parameters[3], parameters[4], parameters[5], parameters[6], parameters[7], parameters[8], parameters[9]));
default:
return (null);
};
}
}//package org.flintparticles.utils
Section 143
//Maths (org.flintparticles.utils.Maths)
package org.flintparticles.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.utils
Section 144
//Button (Button)
package {
import flash.events.*;
import flash.display.*;
import flash.geom.*;
public class Button {
private var upImage:Image;
private var animateValue:Number;
private var explosion:int;
private var downImage:Image;
private var startAnimating:int;
private var rect:Rectangle;
private var clicked:Boolean;
private var screen:Bitmap;
private var isDown:Boolean;
public function Button(rectangle:Rectangle, dImage:Class, uImage:Class, s:Bitmap){
super();
rect = rectangle;
isDown = false;
downImage = new Image(s, dImage);
upImage = new Image(s, uImage);
clicked = false;
animateValue = 0;
explosion = 0;
}
public function onMouseUp(event:MouseEvent):void{
isDown = false;
}
public function onMouseDown(event:MouseEvent):void{
if (rect.contains(event.stageX, event.stageY)){
isDown = true;
} else {
isDown = false;
};
}
public function render(){
upImage.render(null, true, new Matrix(1, 0, 0, 1, rect.left, rect.top));
if (startAnimating){
if (!isDown){
downImage.render(null, true, new Matrix(1, 0, 0, 1, rect.left, rect.top), new ColorTransform(1, 1, 1, animateValue, 0, 0, 0, 0));
} else {
downImage.render(null, true, new Matrix(1, 0, 0, 1, rect.left, rect.top), new ColorTransform(1, 1, 1, 1, 0, 0, 0, 0));
};
} else {
upImage.render(null, true, new Matrix(1, 0, 0, 1, rect.left, rect.top));
};
}
public function getRect():Rectangle{
return (rect);
}
public function isClicked():Boolean{
if (clicked){
animateValue = 0;
isDown = false;
clicked = false;
return (true);
};
return (false);
}
public function renderDownImage(){
downImage.render(null, true, new Matrix(1, 0, 0, 1, rect.left, rect.top), new ColorTransform(1, 1, 1, 1, 0, 0, 0, 0));
}
public function process(s:SharedData){
if (((startAnimating) && ((animateValue <= 1)))){
animateValue = (animateValue + 0.08);
};
if (s.input.mouseToggle){
if (rect.contains(s.input.mousex, s.input.mousey)){
isDown = true;
clicked = true;
};
};
if (rect.contains(s.input.mousex, s.input.mousey)){
startAnimating = 1;
} else {
isDown = false;
animateValue = 0;
startAnimating = 0;
};
}
public function onEnterFrame(event:Event):void{
}
public function onMouseMove(event:MouseEvent):void{
if (!rect.contains(event.stageX, event.stageY)){
isDown = false;
};
}
}
}//package
Section 145
//Buttons (Buttons)
package {
import flash.display.*;
import flash.geom.*;
public class Buttons {
public var c_clearbuttondown:Class;
public var b_nextlevelbutton:Button;
public var c_nextlevelbutton:Class;
public var c_polinkolinkbuttondown:Class;
public var c_okbuttondown:Class;
public var b_loadcustombutton:Button;
public var c_movetocirclebuttondown:Class;
public var c_undobuttondown:Class;
public var b_continuebutton:Button;
public var b_menu:Button;
public var c_continuebuttondown:Class;
public var c_makestaticbuttondown:Class;
public var c_loadcustombutton:Class;
public var c_nextlevelbuttondown:Class;
public var c_cancelbuttondown:Class;
public var b_levelselectbutton:Button;
public var b_clear:Button;
public var b_copy:Button;
public var b_loadlevelbutton:Button;
public var c_loadlevelbutton:Class;
public var c_backbutton:Class;
public var b_save:Button;
public var b_testbutton:Button;
public var c_copybutton:Class;
public var b_restartlevelbutton:Button;
public var c_loadcustombuttondown:Class;
public var c_testbuttondown:Class;
public var b_makestaticbutton:Button;
public var b_props:Button;
public var c_backbuttondown:Class;
public var c_savebutton:Class;
public var c_copybuttondown:Class;
public var c_polinkolinkbutton:Class;
public var c_propsbuttondown:Class;
public var b_cancelbutton2:Button;
public var c_makestaticbutton:Class;
public var c_savebuttondown:Class;
public var b_restartlevelbutton2:Button;
public var c_okbutton:Class;
public var c_movetopointbutton:Class;
public var c_levelselectbuttondown:Class;
public var b_ok2:Button;
public var c_undobutton:Class;
public var c_movetocirclebutton:Class;
public var c_leveleditorbutton:Class;
public var c_cancelbutton:Class;
public var c_highscoresbutton:Class;
public var b_highscoresbutton:Button;
public var b_movetocircle:Button;
public var c_loadbuttondown:Class;
public var c_testbutton:Class;
public var b_undo:Button;
public var b_load:Button;
public var b_back:Button;
public var b_movetopoint:Button;
public var c_leveleditorbuttondown:Class;
public var c_restartlevelbutton:Class;
public var c_menubutton:Class;
public var b_polinkolink:Button;
public var c_highscoresbuttondown:Class;
public var c_restartlevelbuttondown:Class;
public var c_propsbutton:Class;
public var c_menubuttondown:Class;
public var b_leveleditorbutton:Button;
public var c_loadlevelbuttondown:Class;
public var b_ok:Button;
public var c_levelselectbutton:Class;
public var c_clearbutton:Class;
public var b_cancelbutton:Button;
public var c_loadbutton:Class;
public var c_continuebutton:Class;
public var c_movetopointbuttondown:Class;
public function Buttons(){
c_propsbutton = Buttons_c_propsbutton;
c_propsbuttondown = Buttons_c_propsbuttondown;
c_copybutton = Buttons_c_copybutton;
c_copybuttondown = Buttons_c_copybuttondown;
c_undobutton = Buttons_c_undobutton;
c_undobuttondown = Buttons_c_undobuttondown;
c_savebutton = Buttons_c_savebutton;
c_savebuttondown = Buttons_c_savebuttondown;
c_loadbutton = Buttons_c_loadbutton;
c_loadbuttondown = Buttons_c_loadbuttondown;
c_okbutton = Buttons_c_okbutton;
c_okbuttondown = Buttons_c_okbuttondown;
c_menubutton = Buttons_c_menubutton;
c_menubuttondown = Buttons_c_menubuttondown;
c_backbutton = Buttons_c_backbutton;
c_backbuttondown = Buttons_c_backbuttondown;
c_clearbutton = Buttons_c_clearbutton;
c_clearbuttondown = Buttons_c_clearbuttondown;
c_polinkolinkbutton = Buttons_c_polinkolinkbutton;
c_polinkolinkbuttondown = Buttons_c_polinkolinkbuttondown;
c_movetocirclebutton = Buttons_c_movetocirclebutton;
c_movetocirclebuttondown = Buttons_c_movetocirclebuttondown;
c_movetopointbutton = Buttons_c_movetopointbutton;
c_movetopointbuttondown = Buttons_c_movetopointbuttondown;
c_cancelbutton = Buttons_c_cancelbutton;
c_cancelbuttondown = Buttons_c_cancelbuttondown;
c_makestaticbutton = Buttons_c_makestaticbutton;
c_makestaticbuttondown = Buttons_c_makestaticbuttondown;
c_restartlevelbutton = Buttons_c_restartlevelbutton;
c_restartlevelbuttondown = Buttons_c_restartlevelbuttondown;
c_nextlevelbutton = Buttons_c_nextlevelbutton;
c_nextlevelbuttondown = Buttons_c_nextlevelbuttondown;
c_leveleditorbutton = Buttons_c_leveleditorbutton;
c_leveleditorbuttondown = Buttons_c_leveleditorbuttondown;
c_testbutton = Buttons_c_testbutton;
c_testbuttondown = Buttons_c_testbuttondown;
c_loadcustombutton = Buttons_c_loadcustombutton;
c_loadcustombuttondown = Buttons_c_loadcustombuttondown;
c_loadlevelbutton = Buttons_c_loadlevelbutton;
c_loadlevelbuttondown = Buttons_c_loadlevelbuttondown;
c_levelselectbutton = Buttons_c_levelselectbutton;
c_levelselectbuttondown = Buttons_c_levelselectbuttondown;
c_highscoresbutton = Buttons_c_highscoresbutton;
c_highscoresbuttondown = Buttons_c_highscoresbuttondown;
c_continuebutton = Buttons_c_continuebutton;
c_continuebuttondown = Buttons_c_continuebuttondown;
super();
}
public function init(screen:Bitmap){
b_ok = new Button(new Rectangle(530, 427, 60, 19), c_okbuttondown, c_okbutton, screen);
b_ok2 = new Button(new Rectangle(403, 288, 60, 19), c_okbuttondown, c_okbutton, screen);
b_props = new Button(new Rectangle(10, (294 - 150), 60, 19), c_propsbuttondown, c_propsbutton, screen);
b_undo = new Button(new Rectangle(10, (294 - 100), 60, 19), c_undobuttondown, c_undobutton, screen);
b_save = new Button(new Rectangle(10, (394 - 100), 60, 19), c_savebuttondown, c_savebutton, screen);
b_load = new Button(new Rectangle(10, (430 - 100), 60, 19), c_loadbuttondown, c_loadbutton, screen);
b_menu = new Button(new Rectangle(10, (530 - 100), 60, 19), c_menubuttondown, c_menubutton, screen);
b_back = new Button(new Rectangle(10, (530 - 100), 60, 19), c_backbuttondown, c_backbutton, screen);
b_clear = new Button(new Rectangle(10, (530 - 130), 60, 19), c_clearbuttondown, c_clearbutton, screen);
b_copy = new Button(new Rectangle((530 - 70), 427, 60, 19), c_copybuttondown, c_copybutton, screen);
b_polinkolink = new Button(new Rectangle(477, 457, 152, 19), c_polinkolinkbuttondown, c_polinkolinkbutton, screen);
b_movetopoint = new Button(new Rectangle(96, 30, 140, 19), c_movetopointbuttondown, c_movetopointbutton, screen);
b_movetocircle = new Button(new Rectangle(96, 8, 140, 19), c_movetocirclebuttondown, c_movetocirclebutton, screen);
b_levelselectbutton = new Button(new Rectangle(290, 203, 140, 19), c_levelselectbuttondown, c_levelselectbutton, screen);
b_cancelbutton = new Button(new Rectangle(96, 25, 79, 19), c_cancelbuttondown, c_cancelbutton, screen);
b_cancelbutton2 = new Button(new Rectangle(136, 429, 79, 19), c_cancelbuttondown, c_cancelbutton, screen);
b_makestaticbutton = new Button(new Rectangle(427, 8, 140, 19), c_makestaticbuttondown, c_makestaticbutton, screen);
b_restartlevelbutton2 = new Button(new Rectangle(285, 161, 140, 19), c_restartlevelbuttondown, c_restartlevelbutton, screen);
b_restartlevelbutton = new Button(new Rectangle(287, 232, 140, 19), c_restartlevelbuttondown, c_restartlevelbutton, screen);
b_leveleditorbutton = new Button(new Rectangle(18, 453, 140, 19), c_leveleditorbuttondown, c_leveleditorbutton, screen);
b_nextlevelbutton = new Button(new Rectangle(279, 400, 140, 19), c_nextlevelbuttondown, c_nextlevelbutton, screen);
b_continuebutton = new Button(new Rectangle(279, 400, 140, 19), c_continuebuttondown, c_continuebutton, screen);
b_testbutton = new Button(new Rectangle(10, (294 - 36), 60, 19), c_testbuttondown, c_testbutton, screen);
b_loadcustombutton = new Button(new Rectangle(0x0100, 453, 140, 19), c_loadcustombuttondown, c_loadcustombutton, screen);
b_loadlevelbutton = new Button(new Rectangle(((0x0100 + 246) - 8), 453, 140, 19), c_loadlevelbuttondown, c_loadlevelbutton, screen);
b_highscoresbutton = new Button(new Rectangle(3, 350, 78, 30), c_highscoresbuttondown, c_highscoresbutton, screen);
}
}
}//package
Section 146
//Buttons_c_backbutton (Buttons_c_backbutton)
package {
import mx.core.*;
public class Buttons_c_backbutton extends BitmapAsset {
}
}//package
Section 147
//Buttons_c_backbuttondown (Buttons_c_backbuttondown)
package {
import mx.core.*;
public class Buttons_c_backbuttondown extends BitmapAsset {
}
}//package
Section 148
//Buttons_c_cancelbutton (Buttons_c_cancelbutton)
package {
import mx.core.*;
public class Buttons_c_cancelbutton extends BitmapAsset {
}
}//package
Section 149
//Buttons_c_cancelbuttondown (Buttons_c_cancelbuttondown)
package {
import mx.core.*;
public class Buttons_c_cancelbuttondown extends BitmapAsset {
}
}//package
Section 150
//Buttons_c_clearbutton (Buttons_c_clearbutton)
package {
import mx.core.*;
public class Buttons_c_clearbutton extends BitmapAsset {
}
}//package
Section 151
//Buttons_c_clearbuttondown (Buttons_c_clearbuttondown)
package {
import mx.core.*;
public class Buttons_c_clearbuttondown extends BitmapAsset {
}
}//package
Section 152
//Buttons_c_continuebutton (Buttons_c_continuebutton)
package {
import mx.core.*;
public class Buttons_c_continuebutton extends BitmapAsset {
}
}//package
Section 153
//Buttons_c_continuebuttondown (Buttons_c_continuebuttondown)
package {
import mx.core.*;
public class Buttons_c_continuebuttondown extends BitmapAsset {
}
}//package
Section 154
//Buttons_c_copybutton (Buttons_c_copybutton)
package {
import mx.core.*;
public class Buttons_c_copybutton extends BitmapAsset {
}
}//package
Section 155
//Buttons_c_copybuttondown (Buttons_c_copybuttondown)
package {
import mx.core.*;
public class Buttons_c_copybuttondown extends BitmapAsset {
}
}//package
Section 156
//Buttons_c_highscoresbutton (Buttons_c_highscoresbutton)
package {
import mx.core.*;
public class Buttons_c_highscoresbutton extends BitmapAsset {
}
}//package
Section 157
//Buttons_c_highscoresbuttondown (Buttons_c_highscoresbuttondown)
package {
import mx.core.*;
public class Buttons_c_highscoresbuttondown extends BitmapAsset {
}
}//package
Section 158
//Buttons_c_leveleditorbutton (Buttons_c_leveleditorbutton)
package {
import mx.core.*;
public class Buttons_c_leveleditorbutton extends BitmapAsset {
}
}//package
Section 159
//Buttons_c_leveleditorbuttondown (Buttons_c_leveleditorbuttondown)
package {
import mx.core.*;
public class Buttons_c_leveleditorbuttondown extends BitmapAsset {
}
}//package
Section 160
//Buttons_c_levelselectbutton (Buttons_c_levelselectbutton)
package {
import mx.core.*;
public class Buttons_c_levelselectbutton extends BitmapAsset {
}
}//package
Section 161
//Buttons_c_levelselectbuttondown (Buttons_c_levelselectbuttondown)
package {
import mx.core.*;
public class Buttons_c_levelselectbuttondown extends BitmapAsset {
}
}//package
Section 162
//Buttons_c_loadbutton (Buttons_c_loadbutton)
package {
import mx.core.*;
public class Buttons_c_loadbutton extends BitmapAsset {
}
}//package
Section 163
//Buttons_c_loadbuttondown (Buttons_c_loadbuttondown)
package {
import mx.core.*;
public class Buttons_c_loadbuttondown extends BitmapAsset {
}
}//package
Section 164
//Buttons_c_loadcustombutton (Buttons_c_loadcustombutton)
package {
import mx.core.*;
public class Buttons_c_loadcustombutton extends BitmapAsset {
}
}//package
Section 165
//Buttons_c_loadcustombuttondown (Buttons_c_loadcustombuttondown)
package {
import mx.core.*;
public class Buttons_c_loadcustombuttondown extends BitmapAsset {
}
}//package
Section 166
//Buttons_c_loadlevelbutton (Buttons_c_loadlevelbutton)
package {
import mx.core.*;
public class Buttons_c_loadlevelbutton extends BitmapAsset {
}
}//package
Section 167
//Buttons_c_loadlevelbuttondown (Buttons_c_loadlevelbuttondown)
package {
import mx.core.*;
public class Buttons_c_loadlevelbuttondown extends BitmapAsset {
}
}//package
Section 168
//Buttons_c_makestaticbutton (Buttons_c_makestaticbutton)
package {
import mx.core.*;
public class Buttons_c_makestaticbutton extends BitmapAsset {
}
}//package
Section 169
//Buttons_c_makestaticbuttondown (Buttons_c_makestaticbuttondown)
package {
import mx.core.*;
public class Buttons_c_makestaticbuttondown extends BitmapAsset {
}
}//package
Section 170
//Buttons_c_menubutton (Buttons_c_menubutton)
package {
import mx.core.*;
public class Buttons_c_menubutton extends BitmapAsset {
}
}//package
Section 171
//Buttons_c_menubuttondown (Buttons_c_menubuttondown)
package {
import mx.core.*;
public class Buttons_c_menubuttondown extends BitmapAsset {
}
}//package
Section 172
//Buttons_c_movetocirclebutton (Buttons_c_movetocirclebutton)
package {
import mx.core.*;
public class Buttons_c_movetocirclebutton extends BitmapAsset {
}
}//package
Section 173
//Buttons_c_movetocirclebuttondown (Buttons_c_movetocirclebuttondown)
package {
import mx.core.*;
public class Buttons_c_movetocirclebuttondown extends BitmapAsset {
}
}//package
Section 174
//Buttons_c_movetopointbutton (Buttons_c_movetopointbutton)
package {
import mx.core.*;
public class Buttons_c_movetopointbutton extends BitmapAsset {
}
}//package
Section 175
//Buttons_c_movetopointbuttondown (Buttons_c_movetopointbuttondown)
package {
import mx.core.*;
public class Buttons_c_movetopointbuttondown extends BitmapAsset {
}
}//package
Section 176
//Buttons_c_nextlevelbutton (Buttons_c_nextlevelbutton)
package {
import mx.core.*;
public class Buttons_c_nextlevelbutton extends BitmapAsset {
}
}//package
Section 177
//Buttons_c_nextlevelbuttondown (Buttons_c_nextlevelbuttondown)
package {
import mx.core.*;
public class Buttons_c_nextlevelbuttondown extends BitmapAsset {
}
}//package
Section 178
//Buttons_c_okbutton (Buttons_c_okbutton)
package {
import mx.core.*;
public class Buttons_c_okbutton extends BitmapAsset {
}
}//package
Section 179
//Buttons_c_okbuttondown (Buttons_c_okbuttondown)
package {
import mx.core.*;
public class Buttons_c_okbuttondown extends BitmapAsset {
}
}//package
Section 180
//Buttons_c_polinkolinkbutton (Buttons_c_polinkolinkbutton)
package {
import mx.core.*;
public class Buttons_c_polinkolinkbutton extends BitmapAsset {
}
}//package
Section 181
//Buttons_c_polinkolinkbuttondown (Buttons_c_polinkolinkbuttondown)
package {
import mx.core.*;
public class Buttons_c_polinkolinkbuttondown extends BitmapAsset {
}
}//package
Section 182
//Buttons_c_propsbutton (Buttons_c_propsbutton)
package {
import mx.core.*;
public class Buttons_c_propsbutton extends BitmapAsset {
}
}//package
Section 183
//Buttons_c_propsbuttondown (Buttons_c_propsbuttondown)
package {
import mx.core.*;
public class Buttons_c_propsbuttondown extends BitmapAsset {
}
}//package
Section 184
//Buttons_c_restartlevelbutton (Buttons_c_restartlevelbutton)
package {
import mx.core.*;
public class Buttons_c_restartlevelbutton extends BitmapAsset {
}
}//package
Section 185
//Buttons_c_restartlevelbuttondown (Buttons_c_restartlevelbuttondown)
package {
import mx.core.*;
public class Buttons_c_restartlevelbuttondown extends BitmapAsset {
}
}//package
Section 186
//Buttons_c_savebutton (Buttons_c_savebutton)
package {
import mx.core.*;
public class Buttons_c_savebutton extends BitmapAsset {
}
}//package
Section 187
//Buttons_c_savebuttondown (Buttons_c_savebuttondown)
package {
import mx.core.*;
public class Buttons_c_savebuttondown extends BitmapAsset {
}
}//package
Section 188
//Buttons_c_testbutton (Buttons_c_testbutton)
package {
import mx.core.*;
public class Buttons_c_testbutton extends BitmapAsset {
}
}//package
Section 189
//Buttons_c_testbuttondown (Buttons_c_testbuttondown)
package {
import mx.core.*;
public class Buttons_c_testbuttondown extends BitmapAsset {
}
}//package
Section 190
//Buttons_c_undobutton (Buttons_c_undobutton)
package {
import mx.core.*;
public class Buttons_c_undobutton extends BitmapAsset {
}
}//package
Section 191
//Buttons_c_undobuttondown (Buttons_c_undobuttondown)
package {
import mx.core.*;
public class Buttons_c_undobuttondown extends BitmapAsset {
}
}//package
Section 192
//Capsule (Capsule)
package {
import flash.display.*;
import Box2D.Dynamics.*;
import Box2D.Common.Math.*;
import Box2D.Collision.Shapes.*;
import flash.geom.*;
public class Capsule {
public var lastX:Number;// = 0
public var lastY:Number;// = 0
public var xSame:int;// = 0
private var reShootBall:Boolean;
private var alive:Boolean;// = false
public var BALL_VELOCITY:int;// = 300
public var shared:SharedData;
public var screen:Bitmap;
private var tempBall:b2Body;
private var gameData:GameData;
public var ball:b2Body;
public function Capsule(fm_world:b2World, fscreen:Bitmap, shared2:SharedData){
gameData = GameData.getInstance();
super();
screen = fscreen;
shared = shared2;
var bodyDefC:b2BodyDef = new b2BodyDef();
var circDef:b2CircleDef = new b2CircleDef();
circDef.density = 1;
circDef.radius = (6 / gameData.m_physScale);
circDef.friction = 0.3;
circDef.restitution = 0.8;
bodyDefC.position.Set(((337 + 7) / gameData.m_physScale), ((28 + 7) / gameData.m_physScale));
bodyDefC.angle = (Math.random() * Math.PI);
ball = gameData.m_world.CreateDynamicBody(bodyDefC);
ball.CreateShape(circDef);
bodyDefC = new b2BodyDef();
tempBall = new b2Body(new b2BodyDef(), 0, fm_world);
tempBall.CreateShape(circDef);
ball.SetBullet(true);
ball.Freeze();
gameData.newBall = 2;
ball.SetMassFromShapes();
}
public function setupNewBall(){
ball.SetXForm(new b2Vec2(((337 + 7) / gameData.m_physScale), ((28 + 7) / gameData.m_physScale)), 0);
}
public function restart(fm_world:b2World, fscreen:Bitmap, shared2:SharedData){
alive = false;
screen = fscreen;
shared = shared2;
var bodyDefC:b2BodyDef = new b2BodyDef();
var circDef:b2CircleDef = new b2CircleDef();
circDef.density = 1;
circDef.radius = (6 / gameData.m_physScale);
circDef.friction = 0.3;
circDef.restitution = 0.8;
bodyDefC.position.Set(((337 + 7) / gameData.m_physScale), ((28 + 7) / gameData.m_physScale));
bodyDefC.angle = (Math.random() * Math.PI);
bodyDefC.isBullet = true;
ball = gameData.m_world.CreateDynamicBody(bodyDefC);
ball.CreateShape(circDef);
bodyDefC = new b2BodyDef();
tempBall = new b2Body(new b2BodyDef(), 0, fm_world);
tempBall.CreateShape(circDef);
ball.SetAngularVelocity(0);
ball.Freeze();
gameData.newBall = 2;
ball.SetMassFromShapes();
}
public function deleteAimDevice(){
var i:int;
while (i < 10) {
gameData.aimingDevice[i] = null;
i++;
};
}
public function aimDevice(){
var j:int;
tempBall.SetXForm(new b2Vec2((ball.GetPosition().x * gameData.m_physScale), (ball.GetPosition().y * gameData.m_physScale)), 0);
var adjustVelocity:Number = 0;
var v:b2Vec2 = new b2Vec2(0, 0);
v.x = 0;
v.y = 0;
v.y = (shared.input.mousey - (28 + 7));
v.x = (shared.input.mousex - (337 + 7));
var length:Number = v.Length();
if (length == 0){
length = 1;
};
v.y = (v.y / length);
v.x = (v.x / length);
v.x = (v.x * BALL_VELOCITY);
v.y = (v.y * BALL_VELOCITY);
gameData.destination_x = shared.input.mousex;
gameData.destination_y = shared.input.mousey;
tempBall.GetLinearVelocity().x = v.x;
tempBall.GetLinearVelocity().y = v.y;
tempBall.GetPosition().x = 337;
tempBall.GetPosition().y = 28;
var i:Number = 0;
var ballHasArrived:Boolean;
var current_x:Number = (337 + 7);
var current_y:Number = (28 + 7);
while (ballHasArrived) {
if (tempBall.GetLinearVelocity().x > 0){
if (current_x > gameData.destination_x){
ballHasArrived = false;
};
} else {
if (tempBall.GetLinearVelocity().x < 0){
if (current_x < gameData.destination_x){
ballHasArrived = false;
};
} else {
if (current_y > gameData.destination_y){
ballHasArrived = false;
};
};
};
current_x = (current_x + (tempBall.GetLinearVelocity().x / 30));
current_y = (current_y + (tempBall.GetLinearVelocity().y / 30));
i++;
if (i == 1000){
ballHasArrived = false;
i = 1;
};
};
ballHasArrived = false;
var gravity_y:Number = 0;
var gravity_x:Number = 0;
var velocity_with_gravityX:Number = (tempBall.GetLinearVelocity().x / 30);
var velocity_with_gravity:Number = (tempBall.GetLinearVelocity().y / 30);
gravity_y = (28 + 7);
gravity_x = (337 + 7);
j = 0;
while (j < i) {
velocity_with_gravity = (velocity_with_gravity + (BALL_VELOCITY / (BALL_VELOCITY / 10)));
gravity_y = (gravity_y + velocity_with_gravity);
gravity_x = (gravity_x + velocity_with_gravityX);
j++;
};
if (i == 0){
i = 1;
};
adjustVelocity = ((gravity_y - current_y) / i);
var adjustVelocityX:* = ((gravity_x - current_x) / i);
var new_vx:Number = tempBall.GetLinearVelocity().x;
var new_vy:Number = tempBall.GetLinearVelocity().y;
v.x = new_vx;
v.y = (new_vy - adjustVelocity);
var tempP:Point = new Point((337 + 7), (28 + 7));
j = 0;
while (j < 10) {
tempP.x = (tempP.x + (v.x / 30));
tempP.y = (tempP.y + (v.y / 30));
v.y = (v.y + 10);
gameData.aimingDevice[j] = new Point(tempP.x, tempP.y);
j++;
};
}
public function aimDevice2(){
var j:int;
tempBall.SetXForm(new b2Vec2((ball.GetPosition().x * gameData.m_physScale), (ball.GetPosition().y * gameData.m_physScale)), 0);
var adjustVelocity:Number = 0;
var v:b2Vec2 = new b2Vec2(0, 0);
v.x = 0;
v.y = 0;
v.y = (shared.input.mousey - ((ball.GetPosition().y * gameData.m_physScale) + 7));
v.x = (shared.input.mousex - ((ball.GetPosition().x * gameData.m_physScale) + 7));
var length:Number = v.Length();
if (length == 0){
length = 1;
};
v.y = (v.y / length);
v.x = (v.x / length);
v.x = (v.x * BALL_VELOCITY);
v.y = (v.y * BALL_VELOCITY);
gameData.destination_x = shared.input.mousex;
gameData.destination_y = shared.input.mousey;
tempBall.GetLinearVelocity().x = v.x;
tempBall.GetLinearVelocity().y = v.y;
tempBall.GetPosition().x = (ball.GetPosition().x * gameData.m_physScale);
tempBall.GetPosition().y = (ball.GetPosition().y * gameData.m_physScale);
var i:Number = 0;
var ballHasArrived:Boolean;
var current_x:Number = ((ball.GetPosition().x * gameData.m_physScale) + 7);
var current_y:Number = ((ball.GetPosition().y * gameData.m_physScale) + 7);
while (ballHasArrived) {
if (tempBall.GetLinearVelocity().x > 0){
if (current_x > gameData.destination_x){
ballHasArrived = false;
};
} else {
if (tempBall.GetLinearVelocity().x < 0){
if (current_x < gameData.destination_x){
ballHasArrived = false;
};
} else {
if (current_y > gameData.destination_y){
ballHasArrived = false;
};
};
};
current_x = (current_x + (tempBall.GetLinearVelocity().x / 30));
current_y = (current_y + (tempBall.GetLinearVelocity().y / 30));
i++;
if (i == 1000){
ballHasArrived = false;
i = 1;
};
};
ballHasArrived = false;
var gravity_y:Number = 0;
var gravity_x:Number = 0;
var velocity_with_gravityX:Number = (tempBall.GetLinearVelocity().x / 30);
var velocity_with_gravity:Number = (tempBall.GetLinearVelocity().y / 30);
gravity_y = ((ball.GetPosition().y * gameData.m_physScale) + 7);
gravity_x = ((ball.GetPosition().x * gameData.m_physScale) + 7);
j = 0;
while (j < i) {
velocity_with_gravity = (velocity_with_gravity + (BALL_VELOCITY / (BALL_VELOCITY / 10)));
gravity_y = (gravity_y + velocity_with_gravity);
gravity_x = (gravity_x + velocity_with_gravityX);
j++;
};
if (i == 0){
i = 1;
};
adjustVelocity = ((gravity_y - current_y) / i);
var adjustVelocityX:* = ((gravity_x - current_x) / i);
var new_vx:Number = tempBall.GetLinearVelocity().x;
var new_vy:Number = tempBall.GetLinearVelocity().y;
v.x = new_vx;
v.y = (new_vy - adjustVelocity);
var tempP:Point = new Point((ball.GetPosition().x * gameData.m_physScale), (ball.GetPosition().y * gameData.m_physScale));
j = 0;
while (j < 10) {
tempP.x = (tempP.x + (v.x / 30));
tempP.y = (tempP.y + (v.y / 30));
v.y = (v.y + 10);
gameData.aimingDevice[j] = new Point(tempP.x, tempP.y);
j++;
};
}
public function paint():void{
shared.images.i_ball.render(null, true, new Matrix(1, 0, 0, 1, ((ball.GetPosition().x * 10) - 8), ((ball.GetPosition().y * 10) - 7)));
}
public function shootBall(){
ball.Unfreeze();
tempBall.SetXForm(new b2Vec2((ball.GetPosition().x * gameData.m_physScale), (ball.GetPosition().y * gameData.m_physScale)), 0);
var adjustVelocity:Number = 0;
var v:b2Vec2 = new b2Vec2(0, 0);
v.x = 0;
v.y = 0;
v.y = (gameData.shoot.y - (28 + 7));
v.x = (gameData.shoot.x - (337 + 7));
var length:Number = v.Length();
if (length == 0){
length = 1;
};
v.y = (v.y / length);
v.x = (v.x / length);
v.x = (v.x * BALL_VELOCITY);
v.y = (v.y * BALL_VELOCITY);
ball.SetLinearVelocity(v);
gameData.destination_x = gameData.shoot.x;
gameData.destination_y = gameData.shoot.y;
gameData.shoot.x = -1;
gameData.shoot.y = -1;
tempBall.GetLinearVelocity().x = v.x;
tempBall.GetLinearVelocity().y = v.y;
tempBall.GetPosition().x = 337;
tempBall.GetPosition().y = 28;
var i:Number = 0;
var ballHasArrived:Boolean;
var current_x:Number = (337 + 7);
var current_y:Number = (28 + 7);
while (ballHasArrived) {
if (tempBall.GetLinearVelocity().x > 0){
if (current_x > gameData.destination_x){
ballHasArrived = false;
};
} else {
if (tempBall.GetLinearVelocity().x < 0){
if (current_x < gameData.destination_x){
ballHasArrived = false;
};
} else {
if (current_y > gameData.destination_y){
ballHasArrived = false;
};
};
};
current_x = (current_x + (tempBall.GetLinearVelocity().x / 30));
current_y = (current_y + (tempBall.GetLinearVelocity().y / 30));
i++;
if (i == 1000){
ballHasArrived = false;
i = 1;
};
};
ballHasArrived = false;
var gravity_y:Number = 0;
var gravity_x:Number = 0;
var velocity_with_gravityX:Number = (tempBall.GetLinearVelocity().x / 30);
var velocity_with_gravity:Number = (tempBall.GetLinearVelocity().y / 30);
gravity_y = (28 + 7);
gravity_x = (337 + 7);
var j:int;
while (j < i) {
velocity_with_gravity = (velocity_with_gravity + (BALL_VELOCITY / (BALL_VELOCITY / 10)));
gravity_y = (gravity_y + velocity_with_gravity);
gravity_x = (gravity_x + velocity_with_gravityX);
j++;
};
if (i == 0){
i = 1;
};
adjustVelocity = ((gravity_y - current_y) / i);
var adjustVelocityX:* = ((gravity_x - current_x) / i);
var new_vx:Number = tempBall.GetLinearVelocity().x;
var new_vy:Number = tempBall.GetLinearVelocity().y;
v.x = new_vx;
v.y = (new_vy - adjustVelocity);
var d:b2Vec2 = new b2Vec2();
d.x = -30;
d.y = 2;
v.Multiply((1 / gameData.m_physScale));
ball.SetLinearVelocity(v);
}
public function reshootBall(){
ball.Unfreeze();
tempBall.SetXForm(new b2Vec2((ball.GetPosition().x * gameData.m_physScale), (ball.GetPosition().y * gameData.m_physScale)), 0);
var adjustVelocity:Number = 0;
var v:b2Vec2 = new b2Vec2(0, 0);
v.x = 0;
v.y = 0;
v.y = (gameData.shoot.y - ((ball.GetPosition().y * gameData.m_physScale) + 7));
v.x = (gameData.shoot.x - ((ball.GetPosition().x * gameData.m_physScale) + 7));
var length:Number = v.Length();
if (length == 0){
length = 1;
};
v.y = (v.y / length);
v.x = (v.x / length);
v.x = (v.x * BALL_VELOCITY);
v.y = (v.y * BALL_VELOCITY);
ball.SetLinearVelocity(v);
gameData.destination_x = gameData.shoot.x;
gameData.destination_y = gameData.shoot.y;
gameData.shoot.x = -1;
gameData.shoot.y = -1;
tempBall.GetLinearVelocity().x = v.x;
tempBall.GetLinearVelocity().y = v.y;
tempBall.GetPosition().x = (ball.GetPosition().x * gameData.m_physScale);
tempBall.GetPosition().y = (ball.GetPosition().y * gameData.m_physScale);
var i:Number = 0;
var ballHasArrived:Boolean;
var current_x:Number = ((ball.GetPosition().x * gameData.m_physScale) + 7);
var current_y:Number = ((ball.GetPosition().y * gameData.m_physScale) + 7);
while (ballHasArrived) {
if (tempBall.GetLinearVelocity().x > 0){
if (current_x > gameData.destination_x){
ballHasArrived = false;
};
} else {
if (tempBall.GetLinearVelocity().x < 0){
if (current_x < gameData.destination_x){
ballHasArrived = false;
};
} else {
if (current_y > gameData.destination_y){
ballHasArrived = false;
};
};
};
current_x = (current_x + (tempBall.GetLinearVelocity().x / 30));
current_y = (current_y + (tempBall.GetLinearVelocity().y / 30));
i++;
if (i == 1000){
ballHasArrived = false;
i = 1;
};
};
ballHasArrived = false;
var gravity_y:Number = 0;
var gravity_x:Number = 0;
var velocity_with_gravityX:Number = (tempBall.GetLinearVelocity().x / 30);
var velocity_with_gravity:Number = (tempBall.GetLinearVelocity().y / 30);
gravity_y = ((ball.GetPosition().y * gameData.m_physScale) + 7);
gravity_x = ((ball.GetPosition().x * gameData.m_physScale) + 7);
var j:int;
while (j < i) {
velocity_with_gravity = (velocity_with_gravity + (BALL_VELOCITY / (BALL_VELOCITY / 10)));
gravity_y = (gravity_y + velocity_with_gravity);
gravity_x = (gravity_x + velocity_with_gravityX);
j++;
};
if (i == 0){
i = 1;
};
adjustVelocity = ((gravity_y - current_y) / i);
var adjustVelocityX:* = ((gravity_x - current_x) / i);
var new_vx:Number = tempBall.GetLinearVelocity().x;
var new_vy:Number = tempBall.GetLinearVelocity().y;
v.x = new_vx;
v.y = (new_vy - adjustVelocity);
v.Multiply((1 / gameData.m_physScale));
ball.SetLinearVelocity(v);
}
public function process(){
if ((((((((Math.abs((lastX - ball.GetXForm().position.x)) < 0.3)) && ((Math.abs((lastY - ball.GetXForm().position.y)) < 0.3)))) && (!((ball.GetXForm().position.y == 3.5))))) && (!(reShootBall)))){
xSame++;
} else {
xSame = 0;
};
lastX = ball.GetXForm().position.x;
lastY = ball.GetXForm().position.y;
if (((shared.input.mouseToggle) && ((gameData.newBall == 2)))){
if ((((((gameData.shoot.x == -1)) && ((shared.input.mousey > 50)))) && ((shared.input.mousex > 80)))){
gameData.shoot.x = shared.input.mousex;
gameData.shoot.y = shared.input.mousey;
gameData.newBall = 0;
gameData.livesLeft--;
};
} else {
if (((shared.input.mouseToggle) && (reShootBall))){
if (gameData.shoot.x == -1){
gameData.shoot.x = shared.input.mousex;
gameData.shoot.y = shared.input.mousey;
};
};
};
if (((((ball.GetXForm().position.y * gameData.m_physScale) > 500)) || ((xSame > 240)))){
reShootBall = false;
gameData.newBall = 1;
setupNewBall();
ball.Freeze();
};
if (((!((gameData.shoot.x == -1))) && (!(reShootBall)))){
ball.SetXForm(new b2Vec2(((337 + 7) / gameData.m_physScale), ((28 + 7) / gameData.m_physScale)), 0);
shootBall();
} else {
if (gameData.shoot.x != -1){
reshootBall();
reShootBall = false;
};
};
if ((((((shared.input.mousey > 50)) && ((gameData.newBall == 2)))) && ((shared.input.mousex > 80)))){
aimDevice();
} else {
if (((reShootBall) && ((shared.input.mousex > 80)))){
aimDevice2();
} else {
deleteAimDevice();
};
};
}
public function reShoot(){
ball.Freeze();
reShootBall = true;
}
}
}//package
Section 193
//FPS (FPS)
package {
import flash.events.*;
import flash.text.*;
import flash.utils.*;
public class FPS extends TextField {
private var numFrames:Number;
private var ms:int;
private var fs:int;
private var startTick:Number;
public function FPS(){
super();
var format:TextFormat = new TextFormat();
format.color = 0xFF00FF;
format.size = 20;
format.bold = true;
format.font = "Verdana";
textColor = 0xCECECE;
autoSize = "left";
defaultTextFormat = format;
ms = getTimer();
fs = 0;
numFrames = 0;
startTick = getTimer();
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
public function onEnterFrame(event:Event):void{
numFrames++;
var t:Number = ((getTimer() - startTick) * 0.001);
if (t > 0.1){
text = ("FPS: " + (Math.floor(((numFrames / t) * 10)) / 10));
};
}
}
}//package
Section 194
//Game (Game)
package {
import flash.display.*;
import org.flintparticles.emitters.*;
import flash.geom.*;
import org.flintparticles.initializers.*;
import org.flintparticles.actions.*;
import org.flintparticles.counters.*;
import de.polygonal.ds.*;
import mochi.*;
import com.electrotank.util.*;
import de.polygonal.motor2.collision.shapes.*;
import de.polygonal.motor2.collision.shapes.data.*;
import de.polygonal.motor2.dynamics.*;
import de.polygonal.motor2.dynamics.contact.*;
import org.flintparticles.displayObjects.*;
import org.flintparticles.zones.*;
public class Game extends Module {
public var physicsGame:PhysicsGame;
public var gameData:GameData;
private var saveData:SaveData;
var imgClass:ImageClass;
public var particleCounter:int;// = 0
public var menuX:int;// = 800
public var showMenu:Boolean;
var scoreName:String;// = "score"
public function Game(){
super();
}
public function getSprite():Sprite{
return (physicsGame.getSprite());
}
override public function Render(){
shared.images.i_sky.render(null, true, new Matrix(1, 0, 0, 1, 87, 6));
if (!gameData.ending){
shared.images.i_player.render(null, true, new Matrix(1, 0, 0, 1, 328, 15));
gameData.capsule.paint();
};
shared.images.i_interface.render(null, true);
physicsGame.Render();
if (gameData.ending){
if (gameData.congratsY < 200){
gameData.congratsY = (gameData.congratsY + 2);
} else {
gameData.congratsY = 200;
};
if (gameData.thanksY > 240){
gameData.thanksY = (gameData.thanksY - 3);
} else {
gameData.thanksY = 240;
};
shared.images.i_congrats.render(null, true, new Matrix(1, 0, 0, 1, 107, gameData.congratsY));
shared.textTyper.drawText("thanks for playing!", 276, gameData.thanksY, shared.textTyper.BRIT12);
shared.images.i_thanks.render(null, true, new Matrix(1, 0, 0, 1, 483, 313));
shared.images.i_blob1.render(null, true, new Matrix(1, 0, 0, 1, 338, 267));
};
if (gameData.ending){
shared.sounds.PlaySound(shared.sounds.s_space);
shared.sounds.StopOthers(shared.sounds.s_space);
};
if (showMenu){
shared.images.i_menu.render(null, true, new Matrix(1, 0, 0, 1, menuX, 135));
shared.buttons.b_ok2.getRect().x = (menuX + 171);
shared.buttons.b_ok2.render();
shared.buttons.b_restartlevelbutton2.getRect().x = (menuX + 53);
shared.buttons.b_restartlevelbutton2.render();
shared.buttons.b_levelselectbutton.getRect().x = (menuX + 53);
shared.buttons.b_levelselectbutton.render();
if (menuX <= 231){
menuX = 231;
if (gameData.musicOn){
shared.images.i_checkmark.render(null, true, new Matrix(1, 0, 0, 1, 270, 258));
};
if (gameData.soundOn){
shared.images.i_checkmark.render(null, true, new Matrix(1, 0, 0, 1, 270, 274));
};
} else {
menuX = (menuX - 20);
};
} else {
if (menuX < 800){
menuX = (menuX + 20);
shared.images.i_menu.render(null, true, new Matrix(1, 0, 0, 1, menuX, 135));
shared.buttons.b_ok2.getRect().x = (menuX + 171);
shared.buttons.b_ok2.render();
shared.buttons.b_restartlevelbutton2.getRect().x = (menuX + 53);
shared.buttons.b_restartlevelbutton2.render();
shared.buttons.b_levelselectbutton.getRect().x = (menuX + 53);
shared.buttons.b_levelselectbutton.render();
};
};
}
override public function Process(){
if (((!(showMenu)) && (!(gameData.ending)))){
physicsGame.Process();
};
if (gameData.ending){
particleCounter++;
if (particleCounter > 110){
shared.particleS.Ending();
particleCounter = 0;
};
};
if (gameData.testing){
shared.buttons.b_back.process(shared);
if (shared.buttons.b_back.isClicked()){
shared.nextGamestate = shared.LEVELEDITOR;
gameData.testing = false;
if (gameData.customLevel){
shared.nextGamestate = shared.LOADLEVEL;
gameData.customLevel = false;
};
};
} else {
shared.buttons.b_menu.process(shared);
if (shared.buttons.b_menu.isClicked()){
showMenu = !(showMenu);
if (showMenu){
menuX = 800;
};
physicsGame.getSprite().visible = false;
};
if (showMenu){
if (((shared.input.mouseToggle) && (new Rectangle(270, 258, 11, 11).contains(shared.input.mousex, shared.input.mousey)))){
gameData.musicOn = !(gameData.musicOn);
};
if (((shared.input.mouseToggle) && (new Rectangle(270, 274, 11, 11).contains(shared.input.mousex, shared.input.mousey)))){
gameData.soundOn = !(gameData.soundOn);
};
shared.buttons.b_levelselectbutton.process(shared);
if (shared.buttons.b_levelselectbutton.isClicked()){
showMenu = false;
shared.nextGamestate = shared.LOADLEVEL;
gameData.ending = false;
shared.gamestate[shared.LOADLEVEL].UpdateScores();
};
shared.buttons.b_ok2.process(shared);
if (shared.buttons.b_ok2.isClicked()){
showMenu = false;
};
shared.buttons.b_restartlevelbutton2.process(shared);
if (shared.buttons.b_restartlevelbutton2.isClicked()){
gameData.initNewGame();
gameData.gameOver = false;
physicsGame.gameoverX = 800;
showMenu = false;
gameData.ending = false;
};
};
};
}
override public function Init(){
showMenu = false;
gameData = GameData.getInstance();
saveData = new SaveData();
MemoryCrypto.setValue(scoreName, 0);
physicsGame = new PhysicsGame(shared.screen, shared);
}
override public function onNextFrame(delta:Number):void{
Process();
Render();
}
}
}//package
Section 195
//GameData (GameData)
package {
import flash.display.*;
import Box2D.Dynamics.*;
import Box2D.Common.Math.*;
import Box2D.Collision.*;
import Box2D.Dynamics.Joints.*;
import Box2D.Collision.Shapes.*;
import Box2D.Common.*;
import Box2D.Dynamics.Contacts.*;
import flash.geom.*;
import com.hexagonstar.util.debug.*;
import mochi.*;
import com.electrotank.util.*;
public class GameData {
public var pegsMemory:Array;
public var m_physScale:Number;// = 10
public var freeBallHit:Boolean;// = false
public var shoot:Point;
public var whatLevel:int;// = 1
public var ending:Boolean;// = false
public var testing:Boolean;// = false
public var capsule:Capsule;
public var level2:Array;
public var pegsHit:Array;
public var aimingDevice:Array;
public var bonusPercent:int;// = 0
public var winner:Boolean;// = false
public var bonusMultiplier:int;// = 1
public var highscores:HighScores;
public var m_world:b2World;
public var countingBallsLeft:Boolean;// = false
public var lvl1Array:Array;
public var congratsY:int;// = 0
public var balls:Array;
public var soundOn:Boolean;// = true
public var threeBlueHit:Boolean;// = false
public var pegsHitInt:Array;
public var shared:SharedData;
public var freeBallHitPoint:Point;
public var leaderboardIsOpen;// = false
public var longshot:Boolean;// = false
public var custom:Boolean;// = false
public var level:Level;
public var destination_x:Number;
public var destination_y:Number;
public var freeBall:Peg;
public var threeRedHit:Boolean;// = false
public var score:String;// = ""
public var customLevel:Boolean;// = false
public var hitFree:Boolean;// = false
public var savedata:SaveData;
public var livesLeft:int;// = 0
public var pitchToPlay:int;// = 0
public var thanksY:int;// = 500
public var lvlPreviewArray:Array;
public var longshotPoint:Point;
public var newBall:int;
public var frontLayer:Sprite;
public var step:Boolean;// = false
public var contactlistener:MyContactListener;
public var physicsGame:PhysicsGame;
public var leaderboardClosedBool:Boolean;// = false
public var musicOn:Boolean;// = true
public var gameOver:Boolean;// = false
public var immovables:Array;
public var threeBlueHitPoint:Point;
public var threeRedHitPoint:Point;
private static var allowInstantiation:Boolean;
private static var instance:GameData;
public function GameData():void{
contactlistener = new MyContactListener();
level2 = new Array();
frontLayer = new Sprite();
pegsMemory = new Array();
pegsHitInt = new Array();
highscores = new HighScores();
super();
if (!allowInstantiation){
throw (new Error("Error: Instantiation failed: Use SingletonDemo.getInstance() instead of new."));
};
}
public function init(){
var i:int;
var randomPeg:int;
var fortyPercent:Number;
pegsHit = new Array();
newBall = 0;
aimingDevice = new Array();
shoot = new Point(-1, -1);
lvl1Array = new Array();
lvlPreviewArray = new Array();
i = 0;
while (i < level2.length) {
lvl1Array[i] = new Peg(null, level2[i].x, level2[i].y, 0, level2[i].type, level2[i].x2, level2[i].y2);
lvl1Array[i].moveType = level2[i].moveType;
if (lvl1Array[i].moveType == 2){
lvl1Array[i].isCircling = true;
};
i++;
};
var redCount:int;
var pegCount:int;
i = 0;
while (i < lvl1Array.length) {
if (lvl1Array[i].type <= 2){
pegCount++;
};
i++;
};
if (pegCount > 20){
while (redCount <= 20) {
randomPeg = (Math.random() * lvl1Array.length);
if (lvl1Array[randomPeg].type <= 2){
if (lvl1Array[randomPeg].color == 0){
lvl1Array[randomPeg].color = 1;
redCount++;
};
};
};
} else {
fortyPercent = (pegCount * 0.4);
while (redCount < fortyPercent) {
randomPeg = (Math.random() * lvl1Array.length);
if (lvl1Array[randomPeg].type <= 2){
if (lvl1Array[randomPeg].color == 0){
lvl1Array[randomPeg].color = 1;
redCount++;
};
};
};
};
balls = new Array();
}
public function leaderboardClosed(){
leaderboardClosedBool = true;
leaderboardIsOpen = false;
}
public function setWorld(fm_world:b2World):void{
m_world = fm_world;
}
public function Winner():void{
countingBallsLeft = true;
}
public function closeLeaderboard():void{
MochiScores.closeLeaderboard();
}
public function initNewGame(){
congratsY = 0;
thanksY = 500;
pitchToPlay = 0;
bonusPercent = 0;
bonusMultiplier = 1;
resetWorld();
physicsGame.resetlevel();
physicsGame.resetLevel2();
physicsGame.resetNewLevel();
level.DestroyFreeBall();
level.pegs = new Array();
level.freeBallGoingRight = true;
level.freeBallGoingUp = true;
level.destroyFreeBall = true;
level.props = new Array();
level.restart();
livesLeft = 12;
capsule = new Capsule(m_world, shared.screen, shared);
step = false;
MemoryCrypto.setValue(score, 0);
gameOver = false;
winner = false;
freeBallHit = false;
threeBlueHit = false;
threeRedHit = false;
longshot = false;
}
public function resetWorld(){
var body:b2Body = m_world.GetBodyList();
while (body) {
m_world.DestroyBody(body);
body = body.GetNext();
};
var worldAABB:b2AABB = new b2AABB();
worldAABB.lowerBound.Set(-1000, -1000);
worldAABB.upperBound.Set(1000, 1000);
var gravity:b2Vec2 = new b2Vec2(0, 30);
var doSleep:Boolean;
m_world = new b2World(worldAABB, gravity, doSleep);
var dbgDraw:b2DebugDraw = new b2DebugDraw();
dbgDraw.m_sprite = shared.frontLayer;
dbgDraw.m_drawScale = 10;
dbgDraw.m_fillAlpha = 0.3;
dbgDraw.m_drawFlags = (b2DebugDraw.e_shapeBit | b2DebugDraw.e_jointBit);
if (shared.debug){
m_world.SetDebugDraw(dbgDraw);
};
m_world.SetListener(contactlistener);
}
public function setLeaderBoard(string:String){
MochiScores.setBoardID(string);
}
public function Winner2():void{
winner = true;
if (whatLevel == 0){
return;
};
MochiScores.setBoardID(highscores.getLevelCode((whatLevel - 1)));
MochiScores.showLeaderboard({score:MemoryCrypto.getValue(score)});
leaderboardIsOpen = true;
MochiScores.onCloseHandler = leaderboardClosed;
}
public function openLeaderboard():void{
if (whatLevel == 0){
return;
};
leaderboardIsOpen = true;
MochiScores.setBoardID(highscores.getLevelCode((whatLevel - 1)));
MochiScores.showLeaderboard({preloaderDisplay:true});
MochiScores.onCloseHandler = leaderboardClosed;
}
public static function getInstance():GameData{
if (instance == null){
allowInstantiation = true;
instance = new (GameData);
allowInstantiation = false;
};
return (instance);
}
}
}//package
Section 196
//HighScores (HighScores)
package {
public class HighScores {
public var levelCodes:Array;
public function HighScores(){
super();
levelCodes = new Array();
levelCodes[0] = "4a2dfab9c9969770";
levelCodes[1] = "897942d0dd926b8e";
levelCodes[2] = "504a57a05fd43e74";
levelCodes[3] = "2749e88c58ce531b";
levelCodes[4] = "77298fd5a9a55f3e";
levelCodes[5] = "6e80d2b85d6e2475";
levelCodes[6] = "08ac261b03bf3ece";
levelCodes[7] = "2b3e0e95e8b2941d";
levelCodes[8] = "7cdc210782efd66c";
levelCodes[9] = "f7f3af0587a82ecc";
levelCodes[10] = "a652e974daa52c4e";
levelCodes[11] = "32e5f0700ada676d";
levelCodes[12] = "39af55f6ef7a8bae";
levelCodes[13] = "1b508cc8109dd8fb";
levelCodes[14] = "c2f98b495d9c1c75";
levelCodes[15] = "27c1270516fbe721";
levelCodes[16] = "5beac1ce6021ffe9";
levelCodes[17] = "c02ad84cd04bfa78";
levelCodes[18] = "96b147c1a96080b5";
levelCodes[19] = "46c32557072a7d73";
levelCodes[20] = "be9cf37f8ba02611";
levelCodes[21] = "6da70f569d48096a";
levelCodes[22] = "8d452764062ad521";
levelCodes[23] = "88ea4ec9d8159290";
levelCodes[24] = "3e9c335945fb046d";
levelCodes[25] = "4b94026ea67dd073";
levelCodes[26] = "66fe07a60e5a86af";
levelCodes[27] = "57368e0cc28a4cc2";
levelCodes[28] = "051c8bf75f5e1291";
levelCodes[29] = "f1fa59c370340a84";
levelCodes[30] = "834c32aae994e433";
levelCodes[31] = "3fc142a17acddd7b";
levelCodes[32] = "05cb1e75460c91ec";
levelCodes[33] = "e07b85ae7173f9f9";
levelCodes[34] = "73cee16c005e280a";
levelCodes[35] = "1a51e45fbed4b5b4";
levelCodes[36] = "a0d49388b6889093";
levelCodes[37] = "23e678c3b2b3f06c";
levelCodes[38] = "c235b91b36a27967";
levelCodes[39] = "70f431b978531839";
levelCodes[40] = "b8a252b6b8f832b3";
levelCodes[41] = "e922f8532c49641a";
levelCodes[42] = "ea0a0643f820208c";
levelCodes[43] = "cf1db48ad314b282";
levelCodes[44] = "91de9842f06d8661";
}
public function getLevelCode(i:int):String{
return (levelCodes[i]);
}
}
}//package
Section 197
//Image (Image)
package {
import flash.display.*;
import flash.geom.*;
public class Image {
public var bitmap:Bitmap;
public var screen:Bitmap;
public var y:int;
public var x:int;
public function Image(screen:Bitmap, what:Class){
super();
bitmap = (new (what) as Bitmap);
this.screen = screen;
}
public function renderToBitmap(bmpdest:Bitmap, srcRect:Rectangle=null, source:Boolean=false, matrix:Matrix=null, colorTransform:ColorTransform=null, blendMode:String=null, clipRect:Rectangle=null, smoothing:Boolean=false):void{
if (source){
bmpdest.bitmapData.draw(bitmap.bitmapData, matrix, colorTransform, blendMode, clipRect, smoothing);
} else {
if (srcRect != null){
} else {
srcRect = new Rectangle(0, 0, bitmap.width, bitmap.height);
};
bmpdest.bitmapData.copyPixels(bitmap.bitmapData, srcRect, new Point(x, y));
};
}
public function getBitmapData():BitmapData{
return (bitmap.bitmapData);
}
public function move(fx:int, fy:int):void{
x = fx;
y = fy;
}
public function render(srcRect:Rectangle=null, source:Boolean=false, matrix:Matrix=null, colorTransform:ColorTransform=null, blendMode:String=null, clipRect:Rectangle=null, smoothing:Boolean=false):void{
if (source){
screen.bitmapData.draw(bitmap.bitmapData, matrix, colorTransform, blendMode, clipRect, smoothing);
} else {
if (srcRect != null){
} else {
srcRect = new Rectangle(0, 0, bitmap.width, bitmap.height);
};
screen.bitmapData.copyPixels(bitmap.bitmapData, srcRect, new Point(x, y));
};
}
public function getWidth():int{
return (bitmap.width);
}
public function getHeight():int{
return (bitmap.height);
}
}
}//package
Section 198
//Images (Images)
package {
import flash.display.*;
public class Images {
public var i_1x:Image;
public var i_ballsleft:Image;
public var i_fillblack:Image;
public var c_congrats:Class;
public var i_loadlevel:Image;
public var i_filler:Image;
public var i_smallsquare:Image;
public var c_anchor:Class;
public var i_clicktoshoot:Image;
public var i_magicbox:Image;
public var i_ball:Image;
public var c_bluerectpeghighlighted:Class;
public var c_magicbox2:Class;
public var c_4x:Class;
public var c_scrollbarBox:Class;
public var c_gameover:Class;
public var i_2x:Image;
public var c_thanks:Class;
public var c_bigbox:Class;
public var i_freeballtext:Image;
public var c_scrollbarBox2:Class;
public var c_tocomplete:Class;
public var c_bluepeghighlighted:Class;
public var c_player:Class;
public var i_bluerectpeg:Image;
public var i_hittingthis:Image;
public var i_tocomplete:Image;
public var c_redpeg:Class;
public var i_redrectpeghighlighted2:Image;
public var i_clicktostart:Image;
public var c_clicktoshoot:Class;
public var c_redrectpeg:Class;
public var c_redrectpeghighlighted:Class;
public var c_ball:Class;
public var c_interface:Class;
public var i_highlight:Image;
public var c_slider:Class;
public var i_4x:Image;
public var c_3blues:Class;
public var i_plus50:Image;
public var c_triangle:Class;
public var i_sky:Image;
public var i_speedball:Image;
public var i_bluepeghighlighted:Image;
public var c_freeballtext:Class;
public var i_rotating:Image;
public var i_missedallpegs:Image;
public var i_redpeghighlighted:Image;
public var i_bigrectangle:Image;
public var c_level1:Class;
public var i_longshot:Image;
public var i_rotatingcross:Image;
public var i_redrectpeg:Image;
public var i_bonusbarfiller:Image;
public var c_clicktostart:Class;
public var c_bluepeg:Class;
public var i_magicbox2:Image;
public var i_bluepeg:Image;
public var c_8x:Class;
public var i_congrats:Image;
public var c_selection:Class;
public var i_bonusbar:Image;
public var c_trianglerotate:Class;
public var i_dotted:Image;
public var c_freeball:Class;
public var c_bigrectangle:Class;
public var c_filler:Class;
public var i_winner:Image;
public var i_8x:Image;
public var i_blob1:Image;
public var i_interface:Image;
public var c_titlescreen:Class;
public var c_missedallpegs:Class;
public var i_bonuspoints:Image;
public var c_bonustext:Class;
public var i_gameover:Image;
public var c_redrectpeg2:Class;
public var c_smallsquare:Class;
public var c_rotatingcross:Class;
public var c_redrectpeghighlighted2:Class;
public var c_checkmark:Class;
public var i_triangle:Image;
public var c_plus50:Class;
public var i_eraser:Image;
public var c_dropmenu:Class;
public var i_selection:Image;
public var c_bluerectpeg:Class;
public var c_hittingthis:Class;
public var c_ballchain:Class;
public var i_anchor:Image;
public var c_sky:Class;
public var i_bluerectpeghighlighted:Image;
public var c_blob1:Class;
public var c_magicbox:Class;
public var i_3reds:Image;
public var i_bigbox:Image;
public var i_thanks:Image;
public var c_bonusbarfiller:Class;
public var i_menu:Image;
public var i_bonustext:Image;
public var c_bluerectpeghighlighted2:Class;
public var i_bluerectpeghighlighted2:Image;
public var i_player:Image;
public var c_ballsleft:Class;
public var i_freeball:Image;
public var c_loadlevel:Class;
public var i_scrollbartop:Image;
public var c_dotted:Class;
public var c_fillblack:Class;
public var i_redpeg:Image;
public var c_slider2:Class;
public var i_checkmark:Image;
public var i_slider:Image;
public var c_winner:Class;
public var i_3blues:Image;
public var i_slider2:Image;
public var levelPreview:Image;
public var i_bluerectpeg2:Image;
public var i_scrollbarBox2:Image;
public var c_rotating:Class;
public var c_menu:Class;
public var c_1x:Class;
public var c_scrollbartop:Class;
public var c_longshot:Class;
public var i_ballchain:Image;
public var c_3reds:Class;
public var i_scrollbarBox:Image;
public var c_highlight:Class;
public var i_redrectpeghighlighted:Image;
public var c_2x:Class;
public var i_dropmenu:Image;
public var c_bonuspoints:Class;
public var c_eraser:Class;
public var c_speedball:Class;
public var i_titlescreen:Image;
public var c_bonusbar:Class;
public var c_scrollbarbottom:Class;
public var i_trianglerotate:Image;
public var c_bluerectpeg2:Class;
public var i_scrollbarbottom:Image;
public var c_redpeghighlighted:Class;
public var i_redrectpeg2:Image;
public function Images(){
c_redpeg = Images_c_redpeg;
c_selection = Images_c_selection;
c_redpeghighlighted = Images_c_redpeghighlighted;
c_level1 = Images_c_level1;
c_dropmenu = Images_c_dropmenu;
c_bluepeghighlighted = Images_c_bluepeghighlighted;
c_bluepeg = Images_c_bluepeg;
c_eraser = Images_c_eraser;
c_bluerectpeg = Images_c_bluerectpeg;
c_bluerectpeg2 = Images_c_bluerectpeg2;
c_redrectpeg = Images_c_redrectpeg;
c_redrectpeg2 = Images_c_redrectpeg2;
c_player = Images_c_player;
c_interface = Images_c_interface;
c_dotted = Images_c_dotted;
c_freeball = Images_c_freeball;
c_speedball = Images_c_speedball;
c_bluerectpeghighlighted = Images_c_bluerectpeghighlighted;
c_bluerectpeghighlighted2 = Images_c_bluerectpeghighlighted2;
c_redrectpeghighlighted = Images_c_redrectpeghighlighted;
c_redrectpeghighlighted2 = Images_c_redrectpeghighlighted2;
c_ball = Images_c_ball;
c_triangle = Images_c_triangle;
c_titlescreen = Images_c_titlescreen;
c_clicktostart = Images_c_clicktostart;
c_ballsleft = Images_c_ballsleft;
c_gameover = Images_c_gameover;
c_winner = Images_c_winner;
c_3reds = Images_c_3reds;
c_longshot = Images_c_longshot;
c_3blues = Images_c_3blues;
c_fillblack = Images_c_fillblack;
c_freeballtext = Images_c_freeballtext;
c_loadlevel = Images_c_loadlevel;
c_highlight = Images_c_highlight;
c_scrollbarBox = Images_c_scrollbarBox;
c_scrollbarBox2 = Images_c_scrollbarBox2;
c_missedallpegs = Images_c_missedallpegs;
c_scrollbartop = Images_c_scrollbartop;
c_scrollbarbottom = Images_c_scrollbarbottom;
c_bonuspoints = Images_c_bonuspoints;
c_plus50 = Images_c_plus50;
c_slider = Images_c_slider;
c_slider2 = Images_c_slider2;
c_bigbox = Images_c_bigbox;
c_trianglerotate = Images_c_trianglerotate;
c_rotating = Images_c_rotating;
c_rotatingcross = Images_c_rotatingcross;
c_ballchain = Images_c_ballchain;
c_anchor = Images_c_anchor;
c_bigrectangle = Images_c_bigrectangle;
c_smallsquare = Images_c_smallsquare;
c_magicbox = Images_c_magicbox;
c_magicbox2 = Images_c_magicbox2;
c_bonustext = Images_c_bonustext;
c_bonusbar = Images_c_bonusbar;
c_bonusbarfiller = Images_c_bonusbarfiller;
c_1x = Images_c_1x;
c_2x = Images_c_2x;
c_4x = Images_c_4x;
c_8x = Images_c_8x;
c_menu = Images_c_menu;
c_checkmark = Images_c_checkmark;
c_sky = Images_c_sky;
c_tocomplete = Images_c_tocomplete;
c_clicktoshoot = Images_c_clicktoshoot;
c_hittingthis = Images_c_hittingthis;
c_congrats = Images_c_congrats;
c_thanks = Images_c_thanks;
c_blob1 = Images_c_blob1;
c_filler = Images_c_filler;
super();
}
public function init(screen:Bitmap){
i_filler = new Image(screen, c_filler);
i_blob1 = new Image(screen, c_blob1);
i_thanks = new Image(screen, c_thanks);
i_congrats = new Image(screen, c_congrats);
i_hittingthis = new Image(screen, c_hittingthis);
i_clicktoshoot = new Image(screen, c_clicktoshoot);
i_tocomplete = new Image(screen, c_tocomplete);
i_sky = new Image(screen, c_sky);
i_checkmark = new Image(screen, c_checkmark);
i_menu = new Image(screen, c_menu);
i_8x = new Image(screen, c_8x);
i_4x = new Image(screen, c_4x);
i_2x = new Image(screen, c_2x);
i_1x = new Image(screen, c_1x);
i_bonustext = new Image(screen, c_bonustext);
i_bonusbarfiller = new Image(screen, c_bonusbarfiller);
i_bonusbar = new Image(screen, c_bonusbar);
i_magicbox = new Image(screen, c_magicbox);
i_magicbox2 = new Image(screen, c_magicbox2);
i_smallsquare = new Image(screen, c_smallsquare);
i_bigrectangle = new Image(screen, c_bigrectangle);
i_anchor = new Image(screen, c_anchor);
i_ballchain = new Image(screen, c_ballchain);
i_rotatingcross = new Image(screen, c_rotatingcross);
i_rotating = new Image(screen, c_rotating);
i_trianglerotate = new Image(screen, c_trianglerotate);
i_bigbox = new Image(screen, c_bigbox);
i_slider2 = new Image(screen, c_slider2);
i_slider = new Image(screen, c_slider);
i_bonuspoints = new Image(screen, c_bonuspoints);
i_plus50 = new Image(screen, c_plus50);
i_interface = new Image(screen, c_interface);
i_player = new Image(screen, c_player);
i_dotted = new Image(screen, c_dotted);
i_eraser = new Image(screen, c_eraser);
i_dropmenu = new Image(screen, c_dropmenu);
i_bluepeg = new Image(screen, c_bluepeg);
i_bluepeghighlighted = new Image(screen, c_bluepeghighlighted);
i_redpeg = new Image(screen, c_redpeg);
i_redpeghighlighted = new Image(screen, c_redpeghighlighted);
i_bluerectpeg = new Image(screen, c_bluerectpeg);
i_bluerectpeghighlighted = new Image(screen, c_bluerectpeghighlighted);
i_redrectpeg = new Image(screen, c_redrectpeg);
i_redrectpeghighlighted = new Image(screen, c_redrectpeghighlighted);
i_bluerectpeg2 = new Image(screen, c_bluerectpeg2);
i_bluerectpeghighlighted2 = new Image(screen, c_bluerectpeghighlighted2);
i_redrectpeg2 = new Image(screen, c_redrectpeg2);
i_redrectpeghighlighted2 = new Image(screen, c_redrectpeghighlighted2);
i_titlescreen = new Image(screen, c_titlescreen);
i_clicktostart = new Image(screen, c_clicktostart);
i_speedball = new Image(screen, c_speedball);
i_freeball = new Image(screen, c_freeball);
i_ballsleft = new Image(screen, c_ballsleft);
i_ball = new Image(screen, c_ball);
i_triangle = new Image(screen, c_triangle);
i_selection = new Image(screen, c_selection);
i_gameover = new Image(screen, c_gameover);
i_winner = new Image(screen, c_winner);
i_fillblack = new Image(screen, c_fillblack);
i_freeballtext = new Image(screen, c_freeballtext);
i_3reds = new Image(screen, c_3reds);
i_3blues = new Image(screen, c_3blues);
i_loadlevel = new Image(screen, c_loadlevel);
i_highlight = new Image(screen, c_highlight);
i_scrollbarBox = new Image(screen, c_scrollbarBox);
i_scrollbarBox2 = new Image(screen, c_scrollbarBox2);
i_scrollbartop = new Image(screen, c_scrollbartop);
i_scrollbarbottom = new Image(screen, c_scrollbarbottom);
levelPreview = new Image(screen, c_sky);
i_missedallpegs = new Image(screen, c_missedallpegs);
i_longshot = new Image(screen, c_longshot);
}
}
}//package
Section 199
//Images_c_1x (Images_c_1x)
package {
import mx.core.*;
public class Images_c_1x extends BitmapAsset {
}
}//package
Section 200
//Images_c_2x (Images_c_2x)
package {
import mx.core.*;
public class Images_c_2x extends BitmapAsset {
}
}//package
Section 201
//Images_c_3blues (Images_c_3blues)
package {
import mx.core.*;
public class Images_c_3blues extends BitmapAsset {
}
}//package
Section 202
//Images_c_3reds (Images_c_3reds)
package {
import mx.core.*;
public class Images_c_3reds extends BitmapAsset {
}
}//package
Section 203
//Images_c_4x (Images_c_4x)
package {
import mx.core.*;
public class Images_c_4x extends BitmapAsset {
}
}//package
Section 204
//Images_c_8x (Images_c_8x)
package {
import mx.core.*;
public class Images_c_8x extends BitmapAsset {
}
}//package
Section 205
//Images_c_anchor (Images_c_anchor)
package {
import mx.core.*;
public class Images_c_anchor extends BitmapAsset {
}
}//package
Section 206
//Images_c_ball (Images_c_ball)
package {
import mx.core.*;
public class Images_c_ball extends BitmapAsset {
}
}//package
Section 207
//Images_c_ballchain (Images_c_ballchain)
package {
import mx.core.*;
public class Images_c_ballchain extends BitmapAsset {
}
}//package
Section 208
//Images_c_ballsleft (Images_c_ballsleft)
package {
import mx.core.*;
public class Images_c_ballsleft extends BitmapAsset {
}
}//package
Section 209
//Images_c_bigbox (Images_c_bigbox)
package {
import mx.core.*;
public class Images_c_bigbox extends BitmapAsset {
}
}//package
Section 210
//Images_c_bigrectangle (Images_c_bigrectangle)
package {
import mx.core.*;
public class Images_c_bigrectangle extends BitmapAsset {
}
}//package
Section 211
//Images_c_blob1 (Images_c_blob1)
package {
import mx.core.*;
public class Images_c_blob1 extends BitmapAsset {
}
}//package
Section 212
//Images_c_bluepeg (Images_c_bluepeg)
package {
import mx.core.*;
public class Images_c_bluepeg extends BitmapAsset {
}
}//package
Section 213
//Images_c_bluepeghighlighted (Images_c_bluepeghighlighted)
package {
import mx.core.*;
public class Images_c_bluepeghighlighted extends BitmapAsset {
}
}//package
Section 214
//Images_c_bluerectpeg (Images_c_bluerectpeg)
package {
import mx.core.*;
public class Images_c_bluerectpeg extends BitmapAsset {
}
}//package
Section 215
//Images_c_bluerectpeg2 (Images_c_bluerectpeg2)
package {
import mx.core.*;
public class Images_c_bluerectpeg2 extends BitmapAsset {
}
}//package
Section 216
//Images_c_bluerectpeghighlighted (Images_c_bluerectpeghighlighted)
package {
import mx.core.*;
public class Images_c_bluerectpeghighlighted extends BitmapAsset {
}
}//package
Section 217
//Images_c_bluerectpeghighlighted2 (Images_c_bluerectpeghighlighted2)
package {
import mx.core.*;
public class Images_c_bluerectpeghighlighted2 extends BitmapAsset {
}
}//package
Section 218
//Images_c_bonusbar (Images_c_bonusbar)
package {
import mx.core.*;
public class Images_c_bonusbar extends BitmapAsset {
}
}//package
Section 219
//Images_c_bonusbarfiller (Images_c_bonusbarfiller)
package {
import mx.core.*;
public class Images_c_bonusbarfiller extends BitmapAsset {
}
}//package
Section 220
//Images_c_bonuspoints (Images_c_bonuspoints)
package {
import mx.core.*;
public class Images_c_bonuspoints extends BitmapAsset {
}
}//package
Section 221
//Images_c_bonustext (Images_c_bonustext)
package {
import mx.core.*;
public class Images_c_bonustext extends BitmapAsset {
}
}//package
Section 222
//Images_c_checkmark (Images_c_checkmark)
package {
import mx.core.*;
public class Images_c_checkmark extends BitmapAsset {
}
}//package
Section 223
//Images_c_clicktoshoot (Images_c_clicktoshoot)
package {
import mx.core.*;
public class Images_c_clicktoshoot extends BitmapAsset {
}
}//package
Section 224
//Images_c_clicktostart (Images_c_clicktostart)
package {
import mx.core.*;
public class Images_c_clicktostart extends BitmapAsset {
}
}//package
Section 225
//Images_c_congrats (Images_c_congrats)
package {
import mx.core.*;
public class Images_c_congrats extends BitmapAsset {
}
}//package
Section 226
//Images_c_dotted (Images_c_dotted)
package {
import mx.core.*;
public class Images_c_dotted extends BitmapAsset {
}
}//package
Section 227
//Images_c_dropmenu (Images_c_dropmenu)
package {
import mx.core.*;
public class Images_c_dropmenu extends BitmapAsset {
}
}//package
Section 228
//Images_c_eraser (Images_c_eraser)
package {
import mx.core.*;
public class Images_c_eraser extends BitmapAsset {
}
}//package
Section 229
//Images_c_fillblack (Images_c_fillblack)
package {
import mx.core.*;
public class Images_c_fillblack extends BitmapAsset {
}
}//package
Section 230
//Images_c_filler (Images_c_filler)
package {
import mx.core.*;
public class Images_c_filler extends BitmapAsset {
}
}//package
Section 231
//Images_c_freeball (Images_c_freeball)
package {
import mx.core.*;
public class Images_c_freeball extends BitmapAsset {
}
}//package
Section 232
//Images_c_freeballtext (Images_c_freeballtext)
package {
import mx.core.*;
public class Images_c_freeballtext extends BitmapAsset {
}
}//package
Section 233
//Images_c_gameover (Images_c_gameover)
package {
import mx.core.*;
public class Images_c_gameover extends BitmapAsset {
}
}//package
Section 234
//Images_c_highlight (Images_c_highlight)
package {
import mx.core.*;
public class Images_c_highlight extends BitmapAsset {
}
}//package
Section 235
//Images_c_hittingthis (Images_c_hittingthis)
package {
import mx.core.*;
public class Images_c_hittingthis extends BitmapAsset {
}
}//package
Section 236
//Images_c_interface (Images_c_interface)
package {
import mx.core.*;
public class Images_c_interface extends BitmapAsset {
}
}//package
Section 237
//Images_c_level1 (Images_c_level1)
package {
import mx.core.*;
public class Images_c_level1 extends BitmapAsset {
}
}//package
Section 238
//Images_c_loadlevel (Images_c_loadlevel)
package {
import mx.core.*;
public class Images_c_loadlevel extends BitmapAsset {
}
}//package
Section 239
//Images_c_longshot (Images_c_longshot)
package {
import mx.core.*;
public class Images_c_longshot extends BitmapAsset {
}
}//package
Section 240
//Images_c_magicbox (Images_c_magicbox)
package {
import mx.core.*;
public class Images_c_magicbox extends BitmapAsset {
}
}//package
Section 241
//Images_c_magicbox2 (Images_c_magicbox2)
package {
import mx.core.*;
public class Images_c_magicbox2 extends BitmapAsset {
}
}//package
Section 242
//Images_c_menu (Images_c_menu)
package {
import mx.core.*;
public class Images_c_menu extends BitmapAsset {
}
}//package
Section 243
//Images_c_missedallpegs (Images_c_missedallpegs)
package {
import mx.core.*;
public class Images_c_missedallpegs extends BitmapAsset {
}
}//package
Section 244
//Images_c_player (Images_c_player)
package {
import mx.core.*;
public class Images_c_player extends BitmapAsset {
}
}//package
Section 245
//Images_c_plus50 (Images_c_plus50)
package {
import mx.core.*;
public class Images_c_plus50 extends BitmapAsset {
}
}//package
Section 246
//Images_c_redpeg (Images_c_redpeg)
package {
import mx.core.*;
public class Images_c_redpeg extends BitmapAsset {
}
}//package
Section 247
//Images_c_redpeghighlighted (Images_c_redpeghighlighted)
package {
import mx.core.*;
public class Images_c_redpeghighlighted extends BitmapAsset {
}
}//package
Section 248
//Images_c_redrectpeg (Images_c_redrectpeg)
package {
import mx.core.*;
public class Images_c_redrectpeg extends BitmapAsset {
}
}//package
Section 249
//Images_c_redrectpeg2 (Images_c_redrectpeg2)
package {
import mx.core.*;
public class Images_c_redrectpeg2 extends BitmapAsset {
}
}//package
Section 250
//Images_c_redrectpeghighlighted (Images_c_redrectpeghighlighted)
package {
import mx.core.*;
public class Images_c_redrectpeghighlighted extends BitmapAsset {
}
}//package
Section 251
//Images_c_redrectpeghighlighted2 (Images_c_redrectpeghighlighted2)
package {
import mx.core.*;
public class Images_c_redrectpeghighlighted2 extends BitmapAsset {
}
}//package
Section 252
//Images_c_rotating (Images_c_rotating)
package {
import mx.core.*;
public class Images_c_rotating extends BitmapAsset {
}
}//package
Section 253
//Images_c_rotatingcross (Images_c_rotatingcross)
package {
import mx.core.*;
public class Images_c_rotatingcross extends BitmapAsset {
}
}//package
Section 254
//Images_c_scrollbarbottom (Images_c_scrollbarbottom)
package {
import mx.core.*;
public class Images_c_scrollbarbottom extends BitmapAsset {
}
}//package
Section 255
//Images_c_scrollbarBox (Images_c_scrollbarBox)
package {
import mx.core.*;
public class Images_c_scrollbarBox extends BitmapAsset {
}
}//package
Section 256
//Images_c_scrollbarBox2 (Images_c_scrollbarBox2)
package {
import mx.core.*;
public class Images_c_scrollbarBox2 extends BitmapAsset {
}
}//package
Section 257
//Images_c_scrollbartop (Images_c_scrollbartop)
package {
import mx.core.*;
public class Images_c_scrollbartop extends BitmapAsset {
}
}//package
Section 258
//Images_c_selection (Images_c_selection)
package {
import mx.core.*;
public class Images_c_selection extends BitmapAsset {
}
}//package
Section 259
//Images_c_sky (Images_c_sky)
package {
import mx.core.*;
public class Images_c_sky extends BitmapAsset {
}
}//package
Section 260
//Images_c_slider (Images_c_slider)
package {
import mx.core.*;
public class Images_c_slider extends BitmapAsset {
}
}//package
Section 261
//Images_c_slider2 (Images_c_slider2)
package {
import mx.core.*;
public class Images_c_slider2 extends BitmapAsset {
}
}//package
Section 262
//Images_c_smallsquare (Images_c_smallsquare)
package {
import mx.core.*;
public class Images_c_smallsquare extends BitmapAsset {
}
}//package
Section 263
//Images_c_speedball (Images_c_speedball)
package {
import mx.core.*;
public class Images_c_speedball extends BitmapAsset {
}
}//package
Section 264
//Images_c_thanks (Images_c_thanks)
package {
import mx.core.*;
public class Images_c_thanks extends BitmapAsset {
}
}//package
Section 265
//Images_c_titlescreen (Images_c_titlescreen)
package {
import mx.core.*;
public class Images_c_titlescreen extends BitmapAsset {
}
}//package
Section 266
//Images_c_tocomplete (Images_c_tocomplete)
package {
import mx.core.*;
public class Images_c_tocomplete extends BitmapAsset {
}
}//package
Section 267
//Images_c_triangle (Images_c_triangle)
package {
import mx.core.*;
public class Images_c_triangle extends BitmapAsset {
}
}//package
Section 268
//Images_c_trianglerotate (Images_c_trianglerotate)
package {
import mx.core.*;
public class Images_c_trianglerotate extends BitmapAsset {
}
}//package
Section 269
//Images_c_winner (Images_c_winner)
package {
import mx.core.*;
public class Images_c_winner extends BitmapAsset {
}
}//package
Section 270
//Input (Input)
package {
import flash.events.*;
import flash.display.*;
public class Input {
public var keyPressed:Array;
public var mouseInsideGame:Boolean;// = true
public var mouseMove:Boolean;// = false
public var mouseToggle:Boolean;// = false
public var keyToggle:Array;
public var mouseDown:Boolean;
public var lastmouseX:int;
public var lastmouseY:int;
public var mousex:int;
public var mousey:int;
public var mouseWheel:int;// = 0
public var mouseWheelProcessed:Boolean;// = true
public var mousePressed:Boolean;// = false
public function Input(){
super();
}
private function onStageMouseUp(event:MouseEvent):void{
mousex = event.stageX;
mousey = event.stageY;
mouseDown = false;
}
private function onMouseDown(event:MouseEvent):void{
mousex = event.stageX;
mousey = event.stageY;
mouseDown = true;
}
public function init(stage:Stage):void{
Key.initialize(stage);
keyPressed = new Array(0x0100);
keyToggle = new Array(0x0100);
var i:int;
while (i < 0x0100) {
keyPressed[i] = new Boolean(false);
keyToggle[i] = new Boolean(false);
i++;
};
stage.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
stage.addEventListener(MouseEvent.MOUSE_UP, onStageMouseUp);
stage.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
stage.addEventListener(Event.MOUSE_LEAVE, onMouseOut);
stage.addEventListener(MouseEvent.MOUSE_WHEEL, onMouseWheel);
}
public function process(){
if (!mouseWheelProcessed){
mouseWheelProcessed = true;
} else {
mouseWheel = 0;
};
var i:int;
while (i < 0x0100) {
keyToggle[i] = false;
if (Key.isDown(i)){
if (!keyPressed[i]){
keyToggle[i] = (keyPressed[i] = true);
};
} else {
keyPressed[i] = false;
};
i++;
};
mouseToggle = false;
if (mouseDown){
if (!mousePressed){
mouseToggle = (mousePressed = true);
};
} else {
mousePressed = false;
};
}
private function onMouseOut(event:Event):void{
mouseInsideGame = false;
}
private function onMouseWheel(event:MouseEvent):void{
mouseWheel = event.delta;
mouseWheelProcessed = false;
}
private function onMouseMove(event:MouseEvent):void{
lastmouseX = mousex;
lastmouseY = mousey;
mousex = event.stageX;
mousey = event.stageY;
mouseInsideGame = true;
mouseMove = true;
}
}
}//package
Section 271
//Key (Key)
package {
import flash.events.*;
import flash.display.*;
public class Key {
private static var initialized:Boolean = false;
private static var keysDown:Object = new Object();
public function Key(){
super();
}
public static function initialize(stage:Stage){
if (!initialized){
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyPressed);
stage.addEventListener(KeyboardEvent.KEY_UP, keyReleased);
stage.addEventListener(Event.DEACTIVATE, clearKeys);
initialized = true;
};
}
private static function clearKeys(event:Event):void{
keysDown = new Object();
}
public static function isDown(keyCode:uint):Boolean{
if (!initialized){
throw (new Error("Key class has yet been initialized."));
};
return (Boolean((keyCode in keysDown)));
}
private static function keyPressed(event:KeyboardEvent):void{
keysDown[event.keyCode] = true;
}
private static function keyReleased(event:KeyboardEvent):void{
if ((event.keyCode in keysDown)){
delete keysDown[event.keyCode];
};
}
}
}//package
Section 272
//Level (Level)
package {
import flash.display.*;
import Box2D.Dynamics.*;
import Box2D.Common.Math.*;
import Box2D.Collision.*;
import Box2D.Dynamics.Joints.*;
import Box2D.Collision.Shapes.*;
import Box2D.Common.*;
import Box2D.Dynamics.Contacts.*;
import flash.geom.*;
import flash.media.*;
import com.hexagonstar.util.debug.*;
import mochi.*;
import com.electrotank.util.*;
public class Level {
public var testRotate:Number;// = 0
public var testLevel:String;// = ""
public var s_test2:Class;
public var s_test3:Class;
public var s_test4:Class;
public var s_test5:Class;
public var s_test6:Class;
public var s_test7:Class;
public var pegs:Array;
public var destroyFreeBall:Boolean;// = false
public var freeBallGoingUp:Boolean;// = true
public var freeBallGoingRight:Boolean;// = true
public var niceSound:Array;
public var magicFlip:Boolean;// = true
public var gameData:GameData;
public var s_test:Class;
private var shared:SharedData;
public var walls:Array;
public var screen:Bitmap;
public var props:Array;
public var magicFlipCount:int;// = 0
public var levelsCode:Array;
public function Level(fscreen:Bitmap){
gameData = GameData.getInstance();
pegs = new Array();
props = new Array();
s_test = Level_s_test;
s_test2 = Level_s_test2;
s_test3 = Level_s_test3;
s_test4 = Level_s_test4;
s_test5 = Level_s_test5;
s_test6 = Level_s_test6;
s_test7 = Level_s_test7;
super();
niceSound = new Array();
niceSound[0] = (new s_test() as Sound);
niceSound[1] = (new s_test2() as Sound);
niceSound[2] = (new s_test3() as Sound);
niceSound[3] = (new s_test4() as Sound);
niceSound[4] = (new s_test5() as Sound);
niceSound[5] = (new s_test6() as Sound);
niceSound[6] = (new s_test7() as Sound);
screen = fscreen;
levelsCode = new Array();
levelsCode[0] = "mq3amjVaqrvat43aurUa$$";
levelsCode[1] = "bWsabWMabW6abXoabXIabX2abYkabYEaeqsaeqMaeq6aeroaerIaer2aeskaesEagWsagWMagW6agXoagXIagX2agYkagYEajqsajqMajq6ajroajrIajr2ajskajsEalWsalWMalW6alXoalXIalX2alYkalYEaoqsaoqMaoq6aoroaorIaor2aoskaosEaqWsaqWMaqW6aqXoaqXIaqX2aqYkaqYEatqsatqMatq6atroatrIatr2atskatsEavWsavWMavW6avXoavXIavX2avYkavYEayqsayqMayq6ayroayrIayr2ayskaysEaAWsaAWMaAW6aAXoaAXIaAX2aAYkaAYEaDqsaDqMaDq6aDroaDrIaDr2aDskaDsEaFWsaFWMaFW6aFXoaFXIaFX2aFYkaFYEa$$";
levelsCode[2] = "eCMaCmMaeMxaCExamDiauLianv1avD2amHBHvrAHqHfHrj2HqyNIrsxIeHFICPDIiS4ay86ayUhajogaq9Bak8qav8qaei#HDa@HCX9Her#HeynICWqImmOavuPaiTEazvzanExavwxa$$";
levelsCode[3] = "ceDaeS#adv2adgqahEIad1QabLqaf13afEuaf1uacKOahCsafKSae0DahC@aogFaq2xapT3anvpaoKNap8wasC2aou8as9Sap9DaqeRasmIaonJanv5aowgaqDdatvlarEdatEsaz8saBUsaEoBaE9VaDTcaCSUaCnxaBD5aAnraAm1aFuqaE9yaFCTaADdaweNnj0On$$";
levelsCode[4] = "bW6aeqMaeq6aeroagWsagWMagW6agXoagXIajqsajqMajq6ajroajrIajr2ajskalWMalW6alXoalXIalX2alYkalYEaoq6aoroaorIaor2aoskaosEatq6atroatrIatr2atskatsEavWMavW6avXoavXIavX2avYkavYEayqsayqMayq6ayroayrIayr2ayskaAWsaAWMaAW6aAXoaAXIaDqMaDq6aDroaFW6az5rgbbrhpHqe$$";
levelsCode[5] = "pOKTjAaMzAaMh9wGg8MGlTqGk8YGiDaGdnaGfS8GdSKGd9@Gk@cGfDAGhEmGlTSGh9QGcnMGiD6GeTOGcDqGbmWGnDaGmCMGjC0GoDGGknEGfnmGn90GkosGeUmGf94GbD2GsT8GrTyGBmSGD96GyUaGxDEGxTaGATQGBTmGETmGFCOGFTKGDCYGDDIGzS@GzDAGwDkGuSSGsm4Gu9QGwEoGsTSGu9sGtncGv88Gx8UGCTaGFC6GDmMGsCIGynWGvD@GA@oGBT8GBTAGy9qGa5@NqAaNeSWGnCWGj9mG$$";
levelsCode[6] = "h6oQxAoQqjsRfOIRAyIRdTaGjTyGoSoGhSwGmC8GmmuGb8oGfnGGh98Gp96GB98GEDuGw9cGq8QGkCOGyCaGE8sGC9cGDCAGBmiGumAGGC@GEC2Gz82GAnMGwTOGvDeGu82GsDeGt9UGnnQGkD2GqowGsT8Gy98GFoiGE9MGEUsGB@wGb96Gd9EGc9iGp88GynuGfDgGiS4GcmWGbCyGa9WGbUAGdUEGdTOGi9QGlDAGjDkGtnwGv9wGADsGw8KGwSmGqmEGnSOGiCiG$$";
levelsCode[7] = "fOQpuiQpeOQqkOQqtiQqziQqfPkpujkpgC4ajC4ah88agTeai9eau84awm6ax88avncaw9gaj90atEkaGDUaCSQaqCwaqnEay@eay9Iao9aam8uafSuacnSakEIaoUaagDOafooacTcajCqaAmqaumwaomUamnGarDkauD0au9KaCDqaGmSaCSoaxCCawSkaETkaCT6azn4arDUamTYapnqajnEacmAahSEahmgalmgalCEad9CabnuabmYaekaGjAgGfzYGnkuGrQGGAACGFAoGg6yGc6wGbP6GeQIGxQKGwQwGEQEGC6qGAQgGCzUGE5GG$$";
levelsCode[8] = "gHFaky2alQjaqXFav42axIjalfFawTFabLFaG9FaB1FabMlaGEmaF8YabeYaov0atf0as1hanvga$$dOYae4ZGd4Tae4ZGd44ae4ZGecmafsnGesgafsnGessafsnGeOQae4ZGeO7ae4ZGfceafsnGfcuafsnGfqSae4ZGfy4ae4ZGfOZae4ZGfQgafsnGfYsafsnGgcmafsnGpiYaqCZGpyTaqCZGpy4aqCZGp6marklaqiQaqCZGqi7aqCZGqkgarklaqksarklaqWSaqCZGq44aqCZGq6earklaq6uarklariZaqCZGrIgarklarQsarklar6marklaBaYaCqZGBqTaCqZGBq4aCqZGBYmaDcmGCaQaCqZGCa7aCqZGCcgaDcmGCcsaDcmGCOSaCqZGCW4aCqZGCYeaDcmGCYuaDcmGDaZaCqZGDAgaDcmGDIsaDcmGDYmaDcmG";
levelsCode[9] = "duBOwmAOwDROdvZOm1fO$$zGtGzCZazbrGzu0aviVGzC0aDy0GzCZaCqBGzC0awzgGzC0awGAGzCZaCjiGzCZagGsGgK1agHuGgK1acy0GgS1akO1GgK1ajyCGgK1adHkGgK1adOBGgK1ajHkGgK1anb0Gp9FGqf9GqfDGl9GGqfFGp89GqfEGm1iGqfEGs91GqfDGufGGp9EGs1iGqfFGzTJazUfazEKazUfavEfazUgaDUgazMfaCLUazMgawwCazMfawLTazUgaCEBazMfagnQGgMnGgMRGgMmGcEnGgMmGkUnGgEnGjnZGgMmGd2KGgUmGdv1GgMmGjMHGgMmG";
levelsCode[10] = "f8wghSMggnolbXgacrEaeX2agX0aebuadH0acYgafsAabH2abrQagbKagIiafceaeckadcyacskadbSaerMabbsacbuabckabIEaeIMaisKaiIiavT2kz9yilnCisYEazsGawcIauqIauq8azXeaEGOaDWkaErgaGawaBWAawqIawq4azmymuGWauaqaBWUawGoaxrwawXuavrkatHkaxHgaCbmaEbaaHG0a$$";
levelsCode[11] = "kKIVpKIVjKIWjLkWuKIWuLkWkLQVpLQVA06SeK8SmO2GnzuGrjmGqy2GpPgGs4@Goi2GnzkGp5CGsPCGtzmGnjIGl5mGyOEGCyuGFOWGDj8GyQeGw5iGDiSGEzAGzPWGyO6GjiyGdOqGb4EGcjWGgQmGizyGii4Ge4KGcjeGfP0GhzIGk6gGqQyGtQeGoj@GnAEGxkGGE6AGFzUGCkAGA5OGw4KGc6oGgQOGjACGF4kGxPIGbjwGiz6GbkIGtAEGFQiGwQoGqQkGm6qGciYGgiuGD5gG$$";
levelsCode[12] = "euBIfKBIg0BIieBIjuBIkKBIl0BIneBIouBIpKBIq0BIseBItuBIuKBIv0BIxeBIyuBIzKBIA0BICeBIev#IfL#Ig1#Iif#Ijv#IkL#Il1#Inf#Iov#IpL#Iq1#Isf#Itv#IuL#Iv1#Ixf#Iyv#IzL#IA1#ICf#Iii0Osy1OpbdKejdKzPfKgGUbmyUbrGUby4UbC5Wbw5YbqjXbkjXbg5VbcklbeIIbrsPbnQrbwAKbGICbGi1bEODbyylbrykbkihbeOhbbGSbaHAbb53be5HbcXjbnOnbGPHbBcLbu6obiACbhQnbm6Hb$$";
levelsCode[13] = "$eqsagWMaeq6agXoaerIagX2aeskagYEagWsajqMagW6ajroagXIajr2agYkajsEajqsalWMajq6alXoajrIalX2ajskalYEalWsaoqMalW6aoroalXIaor2alYkaosEaoqsaqWMaoq6aqXoaorIaqX2aoskaqYEaqWsatqMaqW6atroaqXIatr2aqYkatsEatqsavWMatq6avXoatrIavX2atskavYEavWsayqMavW6ayroavXIayr2avYkaysEayqsaAWMayq6aAXoayrIaAX2ayskaAYEaAWsaDqMaAW6aDroaAXIaDr2aAYkaDsEaDqsaFWMaDq6aFXoaDrIaFX2aDskaFYEa$daMadORadboadPtadb2adP7adcEadQJafGMagiRafHoagjtafH2agj7afIEagkJaiaMaiORaiboaiPtaib2aiP7aicEaiQJakGMaliRakHoaljtakH2alj7akIEalkJanaManORanboanPtanb2anP7ancEanQJapGMaqiRapHoaqjtapH2aqj7apIEaqkJasaMasORasboasPtasb2asP7ascEasQJauGMaviRauHoavjtauH2avj7auIEavkJaxaMaxORaxboaxPtaxb2axP7axcEaxQJazGMaAiRazHoaAjtazH2aAj7azIEaAkJaCaMaCORaCboaCPtaCb2aCP7aCcEaCQJa";
levelsCode[14] = "fjamp5amAPamj48oj5tovi7ovjqofSEaxCyaEKzap8rajmIakMgaxUbav1kakDmarT0ar9haqmMamSRamnPahLSah9pacuGacvxaeUqaEohaCTvaB19aFfoaC0Saz8LaxnSauEbapgHanL5akUKaf2Dah2gadL3abMwaugGaqwhawUGaywuaeCWagTxan1yar9BayDtaxuXatmEarKUao8Zam8wakujaaYOIgIOIdIOIjAOImAOIo6OIrIOIucOIwIOIzcOIBsOIDQOIF6OI$$";
levelsCode[15] = "$$AbHaqPHaz5SaqPHazL3aqPHazgbGqPHaywlaqPHaxEuaqPHawEBGqPHavsIaqPHaucMGqPHasQQaqPHarsRGqPHap6RGqPHaoEQaqPHankMGqPHal6HGqPHakUBaqPHajUtGqPHai2kGqPHaikbaqPHahP2GqPHahvRGqPHahrGaqPHahvvaqPHahTkaqPHaim#GqPHai42aqPHaj0TaqPHak0LGqPHamaFGqPHanqAGqPHaoOxGqPHaqawaqPHarCwaqPHas0yaqPHauiBGqPHavyGGqPHawKNaqPHaxKUGqPHayC3GqPHazjbGqPHazPmaqPHaz5xaqPHa";
levelsCode[16] = "FiiSbOjSaYwKEQwKbu6Gb9DGcD5GFwfGFnIGF0#GzerGruqGleqGg@uGogsGs2uGAMwGf8oGze0GAfGGfSZGhDIGnD2Gsv2GjmOGt8OGgf4GkwcGw2cGAT8GdWBcebocCaBcCHpcekmcDkkcjcwKvQxKkbsKuPqKkiDMpq@Mkq7NpyHN$$";
levelsCode[17] = "$biCahyCab4HGiiHGcOLai4LadyLGjOLGeiIGkyIGe4DaliDafOxGl4xGgytamOtahisanysah4uaoiuaiOzao4zajuFapOFakeJGqyJGk0LGriLGlOKGr4KGmyGasOGaneAatuAan0vauevaoKsau0sapusGvKsGqewGwuwGq0CaxeCarKHGx0HGsuLayKLateLGzuLGt0IGAeIGuKDaA0DavuxaBKxawetaCytaw4saDisaxOuaD4uayyzGEOzGhzoabjoaijtGb5tGi5xacPxajPxGdzxGkzuGejuGljpae5pal5jGfPjGmPfagzfanzeahjeaojgah5gao5laiPlapPrajzraqzvGkjvGrjxGk5xGr5wGlPwGsPsamzsatvmanfmaufhan1hau1eaoLeavLeGpveGwviGqfiGxfoaq1oax1tGrLtGyLxasvxazvxGtfxGAfuGt1uGA1pauLpaBLjavvjaCzfawjfaDjeaw5eaD5gaxPgaEPlGyzlGbkaahAaab6fGikfGcQjai6jadAjGjQjGekgGkAgGe6balkbafP7Gl57Ggz3amP3ahj2anz2ah54aoj4aiP9ao59ajwdapQdakghGqAhGk2jGrkjGlQiGr6iGmAeasQeanf@atv@an15auf5aoL2au12apv2GvL2Gqf6Gwv6Gq2aaxgaarMfGx2fGswjayMjatgjGzwjGt2gGAggGuMbaA2bavv7aBL7awf3aCz3aw52aDj2axP4aD54ayz9GEP9G$";
levelsCode[18] = "q5MhjjMgeyueAiwefnKarSUayToaE98aFniaB9SaA9say8WavCKawDEazUgawngapTcah9kaeT@abnoagCYaomGalSwalDsahn@ahnCadTgalmYai8CajC8anDmaj90ajDIas9IatnmaBC6aGmWadoKabTQadDuac8KaeC@aEnCazTSawTWauSYap9wamTKaCowaCD8aFDIaFoIaDS0aE8yawmsak8Kaom2aboiacDUahEuaeUqaz@Eay@oaGooaCUkaxEaabS4alniafTgaxS4aC9iaDnwasS@a$$";
levelsCode[19] = "jSUljT@lu8Ulu9@loDkefrkaizDamOSanWqaxjpaDaRavGoaDbWawsvanQyapbXaccsacqsGdG1GiOsGBYxGzXNGCHqGyqXGEWnGryqGrG0GubEGkXhGdjJGgsxGdsIGdb7GaPBGbi3GjsJGtIHGGYIGEH6azGpaFraaAG#aeGvapiXapyJaqsaazkfalXKagGQaAiHalqiatrgagjYansearYtasjNaCqoaFGQaFHGahXea$$";
levelsCode[20] = "cHHgsXGggUfaxwianb2eBX0exuPaDSuao0jai0yafnlaqvBaDfxaB8Uaxesap81ak0UamCyagfeaovwat0AavfuazDoax8@aqvbakm@akuEaiCgaeeIah1sar9fazK4aDCQaBewaq0IaaAJpfAJpkAJppAJpuAJpzAJpdnuabTVagnMaevCasLYav1JaGvramnMalfnaou3ag00abvcad8qa$$";
levelsCode[21] = "yDnayvwayfFaxPOaxfWawv3GvD9GuIdatEhaswjGrklaqclao2jGnUhamQcGlT9Gk13akjVGjHNGjjEGi5vGi1mai5daji6ajKXakmPak8Ial0BGmWwGn0sGo8pGqioGrqoGsCqatKtauOxavKCGwyJaxiQGxSYGyi7GyveGtXnatLuatnBasLGGrXKaq1LGp5LapbIGovDGnXxGnHqGnHjan1bGou7Gpe3ap80Gq40arW1GsK5Gtm#atPgabvlGcLlGd1lGfflGgvlGhLlGkflGlvlGmLlGAz4MaGbMAWaNaX@N$$";
levelsCode[22] = "A99MagaNg8XUwKXUpT9U$$kG1ahy1ainnahy1aeTbGhy1afeJGhy1ai0EGhy1ame1ahy1aiPzahy1adviahy1ad8Bahy1ajKtGhy1ai81ahy1ahXbahy1aga7ahy1agmSahy1aiePGhy1aAi1axa1ax1naxa1auvbGxa1auSJGxa1ayCEGxa1aBS1axa1ayrzaxa1as9iaxa1atKBaxa1azmtGxa1ayK1axa1axzbaxa1avO7axa1av0Saxa1axSPGxa1atsaaqkaaq@yaqkaanEmGqkaan1UGqkaarLPGqkaau2aaqkaarAKaqkaamgtaqkaamTMaqkaasvEGqkaarUaaqkaaqImaqkaaoYgaqkaao93aqkaaq10Gqkaa";
levelsCode[23] = "eqIHeqSHeq2HeqyHfqxIgGxIfq5IgG5IfqPIgGPIsCycsCEcsCKcrmKctSKcrmQctSQcByaMvOKMp5iMkjSMb92Gc9kGeDOGgnuGkncGp9yGlzmQyCOGj@cGlD6Gm9YGoDQGqnGG$iaHIfGHIiaXIfGXIjqXIgWXIjqHIgWHIpS4cqaQcpS@cqaWcq8@crqWcsm@csGWctC@ctWWcuS@cvaWcsq4csGQcuW4cvaQc$";
levelsCode[24] = "qPsRgOSRAiORz6kRgQcRuCqGp8CGmSsGtC8GmCWGqm4GC8kGEC6GET8GzoEGr94GnEiGsEyGk9KGj@CGbnqGhnsGe92Gc9iGd9GGcSEGg8eGzTkGvDWGtTuGDnIGyDMGk9gGw8WGsCMGkUaGoTQGi8yGnEGGwEkGgoGGa9SGymkGpSiG$cEuGcmmGbmiGboIGGmAGGUIGFUEGFSgGi84GonmGiD2GoTCGymQGsDiGyEaGsnCG$";
levelsCode[25] = "$DiIGBO1akToGiy7GmTtGl5kat0xGryoaEi3aGiMGkSBGjaSafLaGgvlagzyafLwaBfmGADjaluLal4SaffBGc9lauSXGty6GzLhaA9zaC0KGEevGsodGp59ap9lGrfDGu9OawD3GuP9GvfZaxquGxmoGs5XGtrJauODauaFauyGGvqxalbTGlnzGBitGyOxaA5MaBrSGnWxapaKGtaQat8Xakr1aj5Pair9Gg2cGkggamguGtjpasG#anqIanGDaePEGenwaqHZGob2apGyGpeNGvTJGw53aluAGjuzak0LGkeyagbTGhvLGBL6aBcnajHoGjPtahzvahHvGpwgGosrapuEan8AaiC7ajHoGefzGfPRauWIasq1ajGCahuKamqCGlCHakLrak5mGfYbahbUGqrmGsvxGk8xGiCeaqiKGoOIGg5DairWGk4MGk8zajCOGheUGfPbGea4GzS7GxG3GBDmaCnuamDJGnDVGEjkGFe3aqsfaqYkGecbadMdGdGFaeOramu1Gm0MGdEbGdwpaoLRaqXKatTLauHyaoGOGpyEaAiHaAKUawLdGyHbGBWJGzGyGCPJGFbCavy3Gt87acW8abrkakO2GlvbGp9tarXaaAP5aDbNGtyXGs0LGDPzaEPgGdiSGaO2ao9ganrhazfnGzC5Gi5Oah97Goa7GnXeGmGpGlWnahXHaf9tGhGLGhiPasQeGqwjGjm#Gkq7Gz4rGBWkGiiGahmKakuRGjSQGivZakHZaqj3asvNGxogGxP9acKzGfahGDkhaB12akj0ajwga$";
levelsCode[26] = "rzlhmrmgr5fkg8zalKxaAKwaC1qag9Cag8VapbHih87al0#aneSaxuxaADSaDn4aueSadfuaiT8aiMmaifwaen4adC#adeDacSrabu8aaTJafwuaEMEaf2HazvKaxDhaAuOaEKDaC8maumxavClaeSOaeSsakmRaDS7aCmLaF1CazDlazS4axeVawuDaC9JaGL@aEgpaBwoasmPakSkajmFah0fabeJadKZalnMainfaffIagvVal9tac@pabD#a$$";
levelsCode[27] = "q5GQaAwKEAuKlCQGC8UGBCsGo8OGd9oGtSCGCC8GxEkGhUoGf9cGeCsGbCMGg92Gq@eGDosGCDMGv82GlS@GinIGnEqGw@oGz9sGzCoGmCkGdCKGiCOGd9qGb9WGuEIGA96GEDmGE8IGD8kGxSGGpSEGjSUGj9UGw@wGDn4GFDAGpC@GhDAGv9qGyUAGmoeGoDUGADoGimoGdSWGvDwGsnaGpC6GdnEGhEgGvEoGw@cGqD6GinwGnS6GF9gGq96Gf94GcD0Gd9aGiDcG$$";
levelsCode[28] = "aOmUaPmUaQCUF4kUF5oUF6yUF4QUF50UaP2UaOSU$eqsaeqEGdaMaeqYGeq6aergGdboaerAGerIaerUGdb2aescGeskaeswGdcEaesQGgWsagWEGfGMagWYGgW6agXgGfHoagXAGgXIagXUGfH2agYcGgYkagYwGfIEagYQGjqsajqEGiaMajqYGjq6ajrgGiboajrAGjrIajrUGib2ajscGjskajswGicEajsQGlWsalWEGkGMalWYGlW6alXgGkHoalXAGlXIalXUGkH2alYcGlYkalYwGkIEalYQGoqsaoqEGnaMaoqYGoq6aorgGnboaorAGorIaorUGnb2aoscGoskaoswGncEaosQGqWsaqWEGpGMaqWYGqW6aqXgGpHoaqXAGqXIaqXUGpH2aqYcGqYkaqYwGpIEaqYQGtqsatqEGsaMatqYGtq6atrgGsboatrAGtrIatrUGsb2atscGtskatswGscEatsQGvWsavWEGuGMavWYGvW6avXgGuHoavXAGvXIavXUGuH2avYcGvYkavYwGuIEavYQGyqsayqEGxaMayqYGyq6ayrgGxboayrAGyrIayrUGxb2ayscGyskayswGxcEaysQGAWsaAWEGzGMaAWYGAW6aAXgGzHoaAXAGAXIaAXUGzH2aAYcGAYkaAYwGzIEaAYQGDqsaDqEGCaMaDqYGDq6aDrgGCboaDrAGDrIaDrUGCb2aDscGDskaDswGCcEaDsQG$";
levelsCode[29] = "jaROqPFOqnCGnnUGt1jGnemGhKPGcTTGhUFGlUAGjvPGgDlGeuXGeCoGwmQGCSHGE14GAMSGs2EGB9GGA08GpSMGt0tGACdGdDiGcmIGiSlGf0CGfLUGffxGbTBGbS3Ge2jGhTzGh18GjUrGmEbGsKTGqTbGxndGEDfGF8OGG0tGFmnGFvyGBTqGynsGA2dGywAGyoaGzLNGEgBGBUvGEgkGFoXGC@NGzKOGxmuGpwoGqoRGeUIGcwgGkSFG$$";
levelsCode[30] = "euBIfKBIg0BIieBIjuBIkKBIl0BIneBIouBIpKBIq0BIseBItuBIuKBIv0BIxeBIyuBIzKBIA0BICeBIeeMHeeWHee6HefeHefoHefyHefIHefSHef2HegaHegkHCKMHCKWHCK6HCLeHCLoHCLyHCLIHCLSHCL2HCMaHCMkHjvnIkLnIl1nInfnIovnIpLnIq1nIsfnItvnIuLnIv1nIxfnIjfyHjfIHjfSHjf2HjgaHxLyHxLIHxLSHxL2HxMaHov#IpL#Iq1#Isf#Iochbsshb$$";
levelsCode[31] = "e5qQm5qQu5qQC5qQiCuGxmuGCmwGmCIGeCEGc8QGmD4GeD2GwD@GEUeGF9WGy@wGpEiGrTQGgTKGfEkGmEAGuUuGBEgGA92Gj@iGin0GgEgGeEOGoUKGv@KGGUIGt@GGpUsGt9@GEDQGzomGqoaGfCqGcmqGA8sGF8sGD8AGu8kGumqGtSKGmSCGj8qGgmeGcmyGESMGCmKGdn0GfUIGkUgGj9YG$$";
levelsCode[32] = "dkkKi6kKoIkKuAkKAIkKz8TGlKNGknDGyTPGym6Gr8UGnDhGh02GuLjGDDwGFKKGy1oGs9IGpnYGrDjGpe0GjncGc9pGiD4GnDzGf9oGeCBGun5GB15GDnmGB01GFe#GGn0GweSGBTFGvDzGqvtGf1NGdf7GdymUjqmUDymUxqmUpWmU$$";
levelsCode[33] = "zrlczrrcAzlcAHrcy4Acy4GcxWGcwOGcfG0cfGVcfGQcfGKcgWKcrHhcrHncrHtcrHzccrKccrQcdzQcdzVckXmcjHmckXgcjHscmjWcmj2clb2cnr2cmCLGwfVGECWGDSxGDnSGtTdGqSjGonfGfLOGdvfGb0cGhmjGewgGnEyGq93GBExGuEDGvEfGE2pGyT@Gg@qG$$";
levelsCode[34] = "kLGGmvGGovGGlnxGnvjGoTrGqLCGsLtGu1kGtTdGqfeGoDcGr1dGwfwGxfFGoe2GuK7Gv02GmK1Gpu1GxeVGvKPGar8Njj@Nrb7Nzr5NeH6Nnz7Nvz6N$$zzHaw5Hay9Saw5HaxXZGw5Hawr0aw5HavbUGw5HauzJGw5HauPyaw5HavPpGw5Haxfnaw5HayDrGw5HazrBaw5Ham5HakzHamDSakzHalrZGkzHajX0akzHaiHUGkzHah5JGkzHaijyakzHajjpGkzHakLnakzHal9rGkzHamXBakzHa";
levelsCode[35] = "dOAVnyAVwyAVcOIWiOIWmyIWsyIWvyIWByIWdPkVnzkVwzkVeqPbibdbgq3bhGTbeXbboqPbqGTboHdbqG#bxGTbyW9bzWTbAq#bxHbbdPUViP2WcP2WdQEVnzUVmz2Wsz2WnAEVwzUVvz2WBz2WwAEVfb@cgskcfswchIacqsqcpIicpcucpYaczsccyYucxImcxX@cmnIGg9AGb9KGqDIGuTyGz9GGC9GGFCWGEEmGlC0GuC4Ga8SGaUkGkUkGuUiGuUKGk@MGD@OGboOGcCqGBCuG$$";
levelsCode[36] = "cEiGk9uGgDSGpnAGv94GAoqGD@oGGT6Gc8kGcCuGcSGGd8KGfmIGf8yGfSoGe8iGd8gGeD8GiTCGm9wGsTOGx@eGCEuGFEgGq9JGuDTGCsibCH8bCbUbCXGbCbubCXkbBHabCG2bArdcyrfcxrncvXrcErdcFHjcGXpcBGWbzGObxqGbAGQbyGKbDqWbEWObGqGbHqwbFWEbEaMbCqMbCGwbCGgbaQxUdkxUgkxUjkxUmkxUpAxUskxUu6xUxQxUAQxUDAxUFQxUeyxRi5IO$$";
levelsCode[37] = "dSkGhSAGeSWGcTWGe@EGh9UGensGz8cGt8mGCm2GE8sGyCCGDDUGzEyGFUAGBDsGF9qGj@GGfn@GcoAGbm6GnmmGiSaGgTcGB@iGhUmG$$yjHaqPHax9SGqPHaxH4aqPHaw2cGqPHav2maqPHauQtaqPHatwyGqPHar6CaqPHaqACGqPHao6BaqPHanIxGqPHamorGqPHalgjGqPHakn#GqPHajH1aqPHajnPaqPHajjDaqPHajvrGqPHaj5gaqPHakS8aqPHalSZGqPHam8SGqPHaouNGqPHapWLaqPHarqLaqPHasWNaqPHauiRGqPHavyYGqPHawC7aqPHaxrfaqPHax1qaqPHayfCaqPHaq4XGqPHaq47GqPHaq5fGqPHaq5pGqPHaq5TGqPHaq53GqPHaq6bGqPHaq6lGqPHalbGaqPHamrGaqPHanHGaqPHaoXGaqPHasHGaqPHatXGaqPHavbGaqPHawrGaqPHa";
levelsCode[38] = "bjiacziadPiae5iagjiahziaiPiaj5ialjiamzianPiao5iaqjiarziasPiat5iavjiawziaxPiay5iaAjiaBziaCPiaD5iaFjiaGziabjEGczEGdPEGe5EGgjEGhzEGiPEGj5EGljEGmzEGnPEGo5EGqjEGrzEGsPEGt5EGvjEGwzEGxPEGy5EGAjEGBzEGCPEGD5EGFjEGGzEGakaNBh@NgQKVlQKVqQKVvQKVAQKV$j4RawyRajC2av82aiq9GuW9GgW@atq@afG4Gsa4Ge4TGryTGfiIarOIagizGsOzGhKxauexai8BGvCBGjWLawqLaCQaaqkaaColapUlaBcsGoIsGzItanctaysnGlYnGxQcGlkcGx53alz3ay5UGmzUGAvSan1SaBTWGpnWGCH6aqb6a$";
levelsCode[39] = "nLYia0iemgmlmf2lhCQaukchF5gnF4enB4GmxiGmpPgkakIpfkApakspfkkpakcpfj6pkPcqtPcqgEOai@Qad9oadSKapmsaAmoaB92aAooawTEaDT2aBUMaCECazDQaBnkaznaajDMaiTkaf82agnMabDQavCkaECkaC9aaxoaakSsasSGagCsab82ahnoad9EaqTSazUaaDnEazDwaHEKa$$";
levelsCode[40] = "cwHpl@HpvUHpbwHohwHok@Hoq@HouUHoAUHoFuAnbeDn$EqKbweKbD0QHw8QHDuXbxWXbCW3byK3bCi8Hzy8HBHcbAjcbA1hHA1hHAjmbBHmbzzqHCjqHyLvbCXvbxXyHDvyHw9CbD1CbwfFbErFbvnHHETHHuvJHFbJHtzLbFvLbsDMbFLMbrHNbFXNbqLNbF9NbpPNbGbNboTMHGbMHnXLHGbLHm5KbF9Kbl9IbF1IblfFHFLFHknDbFvDbjvzHFfzHiHwbETwbhXsbErsbg9obD1obgrjbDvjbfLebCXebe4@HCm@Heq5bBG5bdSZbA4ZbdmTbAiTbcSMHzyMHEHvch9vcEfBIhnBIDLIcgDIcDbOcfXOcCzTIfjTIBXZceHZcBf4Id94IAz9cdD9czQbIc@bIy2gccIgcycjIckjIxoncb2ncwwqcbMqcvEsIbwsIuMuIbouItQwcbgwcsUxcbgxcrYycbgycq2ycbkycp6ycbsyco@xIbExIocwIbQwInkvcb@vcmotccstclwqIcQqIkEocdkocjMkIdMkIiYhcekhcicdceUdchn#cfv#cgH6cgb6cf11cgT1cfjVIhDVIeHQcinQcd9KcjbKcdDEcj5Ecc9xIkTxI$";
levelsCode[41] = "d0opc0oqi0oqd0UpxUApwT6qCT6qxX6pcXeocXyocXSocYaocYzofYzoi6zomczopkzosIzogDoafLVakotas1Qan1samobakLJahgjaiT6as2haoTXaqwman2parLBanvHalfuainIaxS@ah0Iae0CagSBae0KaguOazEqay2haBUhaAMhaBosaw9yap1AaqL0avv8ayfMaB9QaCu8aBKGaxmFareIak8Oaqfhatu9aumSap80aoSuan0Yal8@atfpauvJajflainaawKOaz84aAnAau9dawe4azSMatuzanuFal0uaz9UaDfwayTia$$";
levelsCode[42] = "euBIfKBIg0BIieBIjuBIeeIHeeSHee2HefaHjGIHjGSHjG2HjHaHevjIfLjIg1jIifjIjvjIq0BIseBItuBIuKBIv0BIqKIHqKSHqK2HqLaHwaIHwaSHwa2HwbaHq1jIsfjItvjIuLjIv1jIkLWIl1WInfWIovWIpLWIkv3HkwbHkwlHkwvHpX3HpYbHpYlHpYvHkMEIl2EIngEIowEIpMEIxfWIyvWIzLWIA1WICfWIw13Hw2bHw2lHw2vHCr3HCsbHCslHCsvHxgEIywEIzMEIA2EICgEInmCHnmMHnmWHnm6HnneHzSCHzSMHzSWHzS6HzTeHgT0HgT@HgUiHgUsHgUCHtT0HtT@HtUiHtUsHtUCHFAyUEAyUDAyUbkyUckyUdkyUekyU$$";
levelsCode[43] = "i40kvXjkmHFku5#kkIvkbGpHbzeHckjHFIHHFzRHFyNHCyqHCXmHvjLHmreHh4CHxWFHrOPHpqpHi5@HpsfHwcKHDj3HgzBHcOLHwakHArcHvq3Hoy#HkGCHhPiHubrHnrVHAXIHuQsHmQGHdz7HbXpHejjHprfeoHLejrQeysmed6ieCQged4ne$$";
levelsCode[44] = "c9mGdSEGtCKGyEbGlnpGkSEGsDsGB04GBChGq0MGg03Gh@mGxv6Gy9gGGwcGr@KGnDTGp9pGn89GgnRGqosGtTTGynEGEfKGyKDGGeEGCgCGCfNGGfaGw1hGsm0Gn2xGj99Gh9IGgfcGj0YGf0tGdS1GbmvGcoFGc9TGbDJGgwtGcoeGg@iGjTZGkDHGhLpGp9TGvUrGtohGCEaGuTwGwmYGE9sGDvqGrDiGpmZGlCmGnTlGnfDGmgmGj@xGlbaPwjaPpX5K$$";
levelsCode[45] = "$xCGHxEQbhqIchqjccbpccajcbq0HbsQbCWlaCWjGlMLblKkbrjaGrkPGtb3cHT3chghbhekbCfMIbnMIvr6cvqjcwQcbHEcbFnJbFmkbEsLcHULcGqlIHSlIxq5ba85ben6aHP6ahAsHHEsHdTEcdSjcsTbcHTbcF9IabjIaFaBba8Bba8Eba8EbGYJcboJckEwGbkwGgv3ba93bCwAGHQAGzsaHzsQbyK9Ha89HGqSIbmSIb8qcb@Pck5PabjPak6oGHQoGBWNIBYPcG1oHG0kbe0XGbiXGfr9cbn9cDmRaDmjGorraoqjGCknIbonIr8Dba8DbEIDbEGkbFIocHUocCXNaHPNaG6HcG4jcuqlGHOlGFsabFsQbxHVHa9VHFflbFekbqYJHHEJHuCKcuCjcc55cc6Pce0Cbe0kbfuNcfwPczTsabjsabHhGHPhGc82bHC2bw0IabiIasqzIbmzIjkBcjkPclPzGHPzGBiNGHONGtsMabkMagwKbgwQbuLtbuMQbjaHHa8HHe8qGe@PGk49bHC9bnO@HnQQbEkAHa@AHxmSGHOSGlPmblOkbHPxcHOjcuGUaHOUakq1IHS1IFsFGbkFGcXoGbjoGHuDbHukbrAKcboKcnopanoPGBSrGbirGpYacboacm5IaHPIaCiLHHCLHwWTba8TbkXxbkYQbFfPaFgPGzznIbnnIuwEbuwQbB8GabiGazcDHHEDHnSCInSjcwfuGbjuGhGGahGjGGniaHPiaya9aHO9ajQkGjOjGji@aHO@awsOGwqjGjW0aHO0a$";
addWalls();
LoadLevel();
gameData.level = this;
}
public function insertCircle(i:int){
var bodyDefC:b2BodyDef = new b2BodyDef();
var circDef:b2CircleDef = new b2CircleDef();
circDef.density = 0;
circDef.radius = (8 / gameData.m_physScale);
circDef.friction = 0.3;
circDef.restitution = 0.9;
bodyDefC.position.Set((gameData.lvl1Array[i].x / gameData.m_physScale), (gameData.lvl1Array[i].y / gameData.m_physScale));
bodyDefC.angle = (Math.random() * Math.PI);
pegs[i] = gameData.m_world.CreateStaticBody(bodyDefC);
pegs[i].CreateShape(circDef);
pegs[i].AllowSleeping(true);
pegs[i].m_userData = gameData.lvl1Array[i];
pegs[i].SetMassFromShapes();
}
public function setupNewBall(){
}
public function DestroyFreeBall(){
gameData.m_world.DestroyBody(pegs[(pegs.length - 1)]);
gameData.freeBall.alive = 2;
destroyFreeBall = false;
}
public function linkShared(s:SharedData){
shared = s;
}
public function insertSlider2(i:int){
var bodyDefP:b2BodyDef = new b2BodyDef();
var polyDef:b2PolygonDef = new b2PolygonDef();
polyDef.vertexCount = 4;
polyDef.vertices[3].Set((0 / gameData.m_physScale), (13 / gameData.m_physScale));
polyDef.vertices[2].Set((93 / gameData.m_physScale), (87 / gameData.m_physScale));
polyDef.vertices[1].Set((103 / gameData.m_physScale), (74 / gameData.m_physScale));
polyDef.vertices[0].Set((9 / gameData.m_physScale), (1 / gameData.m_physScale));
polyDef.density = 0;
polyDef.friction = 0.3;
polyDef.restitution = 0.1;
bodyDefP.position.Set((gameData.lvl1Array[i].x / gameData.m_physScale), (gameData.lvl1Array[i].y / gameData.m_physScale));
pegs[i] = gameData.m_world.CreateStaticBody(bodyDefP);
pegs[i].CreateShape(polyDef);
pegs[i].SetMassFromShapes();
}
public function drawSpeedBall(i:int){
if (gameData.lvl1Array[i].alive != 2){
shared.images.i_speedball.render(null, true, new Matrix(1, 0, 0, 1, ((pegs[i].GetXForm().position.x * gameData.m_physScale) - 20), ((pegs[i].GetXForm().position.y * gameData.m_physScale) - 20)));
};
}
public function insertSmallSquare(i:int){
var bodyDefC:b2BodyDef = new b2BodyDef();
var circDef:b2PolygonDef = new b2PolygonDef();
circDef.SetAsBox((8 / gameData.m_physScale), (8 / gameData.m_physScale));
circDef.density = 0;
circDef.friction = 0.3;
circDef.restitution = 0.9;
bodyDefC.position.Set(((gameData.lvl1Array[i].x + 8) / gameData.m_physScale), ((gameData.lvl1Array[i].y + 8) / gameData.m_physScale));
pegs[i] = gameData.m_world.CreateStaticBody(bodyDefC);
pegs[i].CreateShape(circDef);
pegs[i].AllowSleeping(true);
pegs[i].m_userData = gameData.lvl1Array[i];
pegs[i].SetMassFromShapes();
}
public function drawSlider1(i:int){
if (gameData.lvl1Array[i].alive != 2){
shared.images.i_slider.render(null, true, new Matrix(1, 0, 0, 1, (pegs[i].GetXForm().position.x * gameData.m_physScale), (pegs[i].GetXForm().position.y * gameData.m_physScale)));
};
}
public function convertCodeToItem(code:String):Peg{
var decimalCode = (convertLetterTo6BitCode(code.charAt(0)) << 18);
decimalCode = (decimalCode + (convertLetterTo6BitCode(code.charAt(1)) << 12));
decimalCode = (decimalCode + (convertLetterTo6BitCode(code.charAt(2)) << 6));
decimalCode = (decimalCode + (convertLetterTo6BitCode(code.charAt(3)) << 0));
var peg:Peg = new Peg(null, 100, 100, 0);
peg.x = ((decimalCode >> 14) + 91);
peg.y = (((decimalCode - ((decimalCode >> 14) << 14)) >> 5) + 52);
peg.type = (decimalCode - ((decimalCode >> 5) << 5));
return (peg);
}
public function restart(){
pegs = new Array();
addWalls();
LoadLevel();
gameData.contactlistener.clean();
}
public function insertRect1(i:int){
var bodyDefC:b2BodyDef = new b2BodyDef();
var boxDef:b2PolygonDef = new b2PolygonDef();
boxDef.density = 0;
boxDef.SetAsBox((6 / gameData.m_physScale), (10 / gameData.m_physScale));
boxDef.friction = 0.3;
boxDef.restitution = 0.9;
bodyDefC.position.Set((gameData.lvl1Array[i].x / gameData.m_physScale), (gameData.lvl1Array[i].y / gameData.m_physScale));
pegs[i] = gameData.m_world.CreateStaticBody(bodyDefC);
pegs[i].CreateShape(boxDef);
pegs[i].AllowSleeping(true);
pegs[i].m_userData = gameData.lvl1Array[i];
}
public function insertTriangleRotate(i:int){
var bodyDefP:b2BodyDef = new b2BodyDef();
var polyDef:b2PolygonDef = new b2PolygonDef();
polyDef.vertexCount = 3;
polyDef.vertices[1].Set((0 / gameData.m_physScale), (94 / gameData.m_physScale));
polyDef.vertices[0].Set((38 / gameData.m_physScale), (92 / gameData.m_physScale));
polyDef.vertices[2].Set((0 / gameData.m_physScale), (0 / gameData.m_physScale));
polyDef.density = 0;
polyDef.friction = 0.3;
polyDef.restitution = 0.1;
bodyDefP.position.Set((gameData.lvl1Array[i].x / gameData.m_physScale), (gameData.lvl1Array[i].y / gameData.m_physScale));
pegs[i] = gameData.m_world.CreateStaticBody(bodyDefP);
pegs[i].CreateShape(polyDef);
pegs[i].SetBullet(true);
pegs[i].SetMassFromShapes();
}
public function LoadLevel(){
var i:int;
destroyFreeBall = false;
var level:Array = new Array();
gameData.level2 = LoadLevel2();
gameData.init();
i = 0;
while (i < gameData.lvl1Array.length) {
switch (gameData.lvl1Array[i].type){
case 0:
insertCircle(i);
break;
case 1:
insertRect1(i);
break;
case 2:
insertRect2(i);
break;
case 4:
insertSpeedBall(i);
break;
case 6:
insertSlider1(i);
break;
case 7:
insertSlider2(i);
break;
case 8:
insertBigBox(i);
break;
case 9:
insertTriangleRotate(i);
break;
case 10:
insertRotating(i);
break;
case 11:
insertStar(i);
break;
case 12:
insertBells(i);
break;
case 13:
insertBigRectangle(i);
break;
case 14:
insertSmallSquare(i);
break;
case 15:
insertMagicBox1(i);
break;
case 16:
insertMagicBox2(i);
break;
};
gameData.lvl1Array[i].updateRef(pegs[i]);
i++;
};
i = 0;
while (i < gameData.lvl1Array.length) {
if (gameData.lvl1Array[i].x2 != -1){
gameData.lvl1Array[i].isMoving();
};
i++;
};
insertFreeBall();
}
public function convertLetterTo6BitCode(char:String):int{
if (char.charCodeAt(0) == new String("#").charCodeAt(0)){
return (63);
};
if (char.charCodeAt(0) == new String("@").charCodeAt(0)){
return (62);
};
if (char.charCodeAt(0) >= 97){
return ((char.charCodeAt(0) - 97));
};
if (char.charCodeAt(0) >= 65){
return (((char.charCodeAt(0) - 65) + 26));
};
if (char.charCodeAt(0) >= 48){
return (((char.charCodeAt(0) - 48) + 52));
};
return (0);
}
public function destroyBall(i:int){
gameData.m_world.DestroyBody(pegs[i]);
gameData.lvl1Array[i].alive = 2;
}
public function insertBells(i:int){
var bodyDefC:b2BodyDef;
var body:b2Body;
bodyDefC = new b2BodyDef();
var circDef:b2CircleDef = new b2CircleDef();
circDef.density = 1;
circDef.radius = (15 / gameData.m_physScale);
circDef.friction = 0.3;
circDef.restitution = 0.9;
bodyDefC.position.Set(((gameData.lvl1Array[i].x + 0) / gameData.m_physScale), ((gameData.lvl1Array[i].y + 45) / gameData.m_physScale));
bodyDefC.angle = (Math.random() * Math.PI);
pegs[i] = gameData.m_world.CreateDynamicBody(bodyDefC);
pegs[i].CreateShape(circDef);
pegs[i].AllowSleeping(true);
pegs[i].m_userData = gameData.lvl1Array[i];
pegs[i].SetMassFromShapes();
bodyDefC = new b2BodyDef();
var boxDef:b2PolygonDef = new b2PolygonDef();
boxDef.density = 1;
boxDef.SetAsBox((5 / gameData.m_physScale), (5 / gameData.m_physScale));
boxDef.friction = 0.3;
boxDef.restitution = 0.9;
bodyDefC.position.Set((gameData.lvl1Array[i].x / gameData.m_physScale), (gameData.lvl1Array[i].y / gameData.m_physScale));
body = gameData.m_world.CreateStaticBody(bodyDefC);
body.CreateShape(boxDef);
body.AllowSleeping(true);
body.SetMassFromShapes();
var joint:b2DistanceJointDef = new b2DistanceJointDef();
var anchor:b2Vec2 = new b2Vec2();
anchor.Set((gameData.lvl1Array[i].x / gameData.m_physScale), (gameData.lvl1Array[i].y / gameData.m_physScale));
var anchor2:b2Vec2 = new b2Vec2();
anchor2.Set((gameData.lvl1Array[i].x / gameData.m_physScale), ((gameData.lvl1Array[i].y + 45) / gameData.m_physScale));
joint.Initialize(body, pegs[i], anchor, anchor2);
gameData.m_world.CreateJoint(joint);
gameData.lvl1Array[i].anchorX = (body.GetPosition().x * gameData.m_physScale);
gameData.lvl1Array[i].anchorY = (body.GetPosition().y * gameData.m_physScale);
}
public function drawBigBox(i:int){
if (gameData.lvl1Array[i].alive != 2){
shared.images.i_bigbox.render(null, true, new Matrix(1, 0, 0, 1, ((pegs[i].GetXForm().position.x * gameData.m_physScale) - 50), ((pegs[i].GetXForm().position.y * gameData.m_physScale) - 50)));
};
}
public function processFreeBall(){
var newX:Number = 0;
var newY:Number = 0;
if (freeBallGoingRight){
newX = (pegs[(pegs.length - 1)].GetXForm().position.x + (3 / gameData.m_physScale));
} else {
newX = (pegs[(pegs.length - 1)].GetXForm().position.x - (3 / gameData.m_physScale));
};
if (freeBallGoingUp){
newY = (pegs[(pegs.length - 1)].GetXForm().position.y - (1 / gameData.m_physScale));
} else {
newY = (pegs[(pegs.length - 1)].GetXForm().position.y + (1 / gameData.m_physScale));
};
if (newY <= (430 / gameData.m_physScale)){
freeBallGoingUp = false;
};
if (newY >= (450 / gameData.m_physScale)){
freeBallGoingUp = true;
};
if (newX >= (600 / gameData.m_physScale)){
freeBallGoingRight = false;
};
if (newX <= (115 / gameData.m_physScale)){
freeBallGoingRight = true;
};
pegs[(pegs.length - 1)].SetXForm(new b2Vec2(newX, newY), 0);
gameData.freeBall.x = newX;
gameData.freeBall.y = newY;
}
public function insertStar(i:int){
var bodyDefC:b2BodyDef = new b2BodyDef();
var boxDef:b2PolygonDef = new b2PolygonDef();
var boxDef2:b2PolygonDef = new b2PolygonDef();
boxDef.density = 0;
boxDef.SetAsBox((5 / gameData.m_physScale), (20 / gameData.m_physScale));
boxDef.friction = 0.3;
boxDef.restitution = 0.9;
bodyDefC.position.Set((gameData.lvl1Array[i].x / gameData.m_physScale), (gameData.lvl1Array[i].y / gameData.m_physScale));
boxDef2.SetAsOrientedBox((5 / gameData.m_physScale), (20 / gameData.m_physScale), new b2Vec2(0, 0), (0.5 * Math.PI));
pegs[i] = gameData.m_world.CreateStaticBody(bodyDefC);
pegs[i].CreateShape(boxDef);
pegs[i].CreateShape(boxDef2);
pegs[i].AllowSleeping(true);
pegs[i].m_userData = gameData.lvl1Array[i];
pegs[i].SetMassFromShapes();
}
public function insertBigRectangle(i:int){
var bodyDefC:b2BodyDef = new b2BodyDef();
var circDef:b2PolygonDef = new b2PolygonDef();
circDef.SetAsBox((8 / gameData.m_physScale), (100 / gameData.m_physScale));
circDef.density = 0;
circDef.friction = 0.3;
circDef.restitution = 0.9;
bodyDefC.position.Set(((gameData.lvl1Array[i].x + 8) / gameData.m_physScale), ((gameData.lvl1Array[i].y + 100) / gameData.m_physScale));
pegs[i] = gameData.m_world.CreateStaticBody(bodyDefC);
pegs[i].CreateShape(circDef);
pegs[i].AllowSleeping(true);
pegs[i].m_userData = gameData.lvl1Array[i];
pegs[i].SetMassFromShapes();
}
public function insertSpeedBall(i:int){
var bodyDefC:b2BodyDef = new b2BodyDef();
var circDef:b2CircleDef = new b2CircleDef();
circDef.density = 0;
circDef.radius = (20 / gameData.m_physScale);
circDef.friction = 0.3;
circDef.restitution = 0.9;
bodyDefC.position.Set(((gameData.lvl1Array[i].x + 20) / gameData.m_physScale), ((gameData.lvl1Array[i].y + 20) / gameData.m_physScale));
bodyDefC.angle = (Math.random() * Math.PI);
pegs[i] = gameData.m_world.CreateStaticBody(bodyDefC);
pegs[i].CreateShape(circDef);
pegs[i].AllowSleeping(true);
pegs[i].m_userData = gameData.lvl1Array[i];
}
public function insertTeeter(i:int){
var body:b2Body;
var j:b2RevoluteJoint;
var bodyDefC:b2BodyDef = new b2BodyDef();
var boxDef:b2PolygonDef = new b2PolygonDef();
boxDef.density = 1;
boxDef.SetAsBox((60 / gameData.m_physScale), (5 / gameData.m_physScale));
boxDef.friction = 0.3;
boxDef.restitution = 0.9;
bodyDefC.position.Set((gameData.lvl1Array[i].x / gameData.m_physScale), (gameData.lvl1Array[i].y / gameData.m_physScale));
pegs[i] = gameData.m_world.CreateDynamicBody(bodyDefC);
pegs[i].CreateShape(boxDef);
pegs[i].AllowSleeping(true);
pegs[i].SetMassFromShapes();
boxDef.density = 1;
boxDef.SetAsBox((15 / gameData.m_physScale), (15 / gameData.m_physScale));
boxDef.friction = 0.3;
boxDef.restitution = 0.9;
bodyDefC.position.Set((gameData.lvl1Array[i].x / gameData.m_physScale), ((gameData.lvl1Array[i].y / gameData.m_physScale) + 1));
body = gameData.m_world.CreateStaticBody(bodyDefC);
body.CreateShape(boxDef);
body.AllowSleeping(true);
body.SetMassFromShapes();
var joint:b2RevoluteJointDef = new b2RevoluteJointDef();
var anchor:b2Vec2 = new b2Vec2();
anchor.Set((gameData.lvl1Array[i].x / gameData.m_physScale), (gameData.lvl1Array[i].y / gameData.m_physScale));
joint.Initialize(pegs[i], body, anchor);
gameData.m_world.CreateJoint(joint);
}
public function drawStar(i:int){
var propMatrix:Matrix;
if (gameData.lvl1Array[i].alive != 2){
propMatrix = new Matrix(1, 0, 0, 1, 0, 0);
propMatrix.rotate(pegs[i].GetAngle());
propMatrix.translate((((Math.sin(pegs[i].GetAngle()) * 21) + ((-1 * 21) * Math.cos(pegs[i].GetAngle()))) + (pegs[i].GetXForm().position.x * gameData.m_physScale)), ((((-1 * 21) * Math.sin(pegs[i].GetAngle())) + (pegs[i].GetXForm().position.y * gameData.m_physScale)) - (Math.cos(pegs[i].GetAngle()) * 21)));
shared.images.i_rotatingcross.render(null, true, propMatrix);
};
}
public function insertRect2(i:int){
var bodyDefC:b2BodyDef = new b2BodyDef();
var boxDef:b2PolygonDef = new b2PolygonDef();
boxDef.density = 0;
boxDef.SetAsBox((10 / gameData.m_physScale), (6 / gameData.m_physScale));
boxDef.friction = 0.3;
boxDef.restitution = 0.9;
bodyDefC.position.Set((gameData.lvl1Array[i].x / gameData.m_physScale), (gameData.lvl1Array[i].y / gameData.m_physScale));
pegs[i] = gameData.m_world.CreateStaticBody(bodyDefC);
pegs[i].CreateShape(boxDef);
pegs[i].AllowSleeping(true);
pegs[i].m_userData = gameData.lvl1Array[i];
}
public function insertRotating(i:int){
var body:b2Body;
var j:b2RevoluteJoint;
var bodyDefC:b2BodyDef = new b2BodyDef();
var boxDef:b2PolygonDef = new b2PolygonDef();
boxDef.density = 1;
boxDef.SetAsBox((60 / gameData.m_physScale), (5 / gameData.m_physScale));
boxDef.friction = 0.3;
boxDef.restitution = 0.9;
bodyDefC.position.Set((gameData.lvl1Array[i].x / gameData.m_physScale), (gameData.lvl1Array[i].y / gameData.m_physScale));
pegs[i] = gameData.m_world.CreateDynamicBody(bodyDefC);
pegs[i].CreateShape(boxDef);
pegs[i].AllowSleeping(true);
pegs[i].SetMassFromShapes();
boxDef.density = 1;
boxDef.SetAsBox((5 / gameData.m_physScale), (5 / gameData.m_physScale));
boxDef.friction = 0.3;
boxDef.restitution = 0.9;
bodyDefC.position.Set((gameData.lvl1Array[i].x / gameData.m_physScale), (gameData.lvl1Array[i].y / gameData.m_physScale));
body = gameData.m_world.CreateStaticBody(bodyDefC);
body.CreateShape(boxDef);
body.AllowSleeping(true);
body.SetMassFromShapes();
var joint:b2RevoluteJointDef = new b2RevoluteJointDef();
var anchor:b2Vec2 = new b2Vec2();
anchor.Set((gameData.lvl1Array[i].x / gameData.m_physScale), (gameData.lvl1Array[i].y / gameData.m_physScale));
joint.Initialize(pegs[i], body, anchor);
gameData.m_world.CreateJoint(joint);
}
public function drawCirclePeg(i:int){
if (gameData.lvl1Array[i].color == 0){
if (gameData.lvl1Array[i].alive == 1){
shared.images.i_bluepeg.render(null, true, new Matrix(1, 0, 0, 1, ((pegs[i].GetXForm().position.x * gameData.m_physScale) - 9), ((pegs[i].GetXForm().position.y * gameData.m_physScale) - 8)));
} else {
if (gameData.lvl1Array[i].alive == 0){
shared.images.i_bluepeghighlighted.render(null, true, new Matrix(1, 0, 0, 1, (((pegs[i].GetXForm().position.x * gameData.m_physScale) - 9) - 4), (((pegs[i].GetXForm().position.y * gameData.m_physScale) - 4) - 8)));
};
};
} else {
if (gameData.lvl1Array[i].alive == 1){
shared.images.i_redpeg.render(null, true, new Matrix(1, 0, 0, 1, ((pegs[i].GetXForm().position.x * gameData.m_physScale) - 8), ((pegs[i].GetXForm().position.y * gameData.m_physScale) - 7)));
} else {
if (gameData.lvl1Array[i].alive == 0){
shared.images.i_redpeghighlighted.render(null, true, new Matrix(1, 0, 0, 1, (((pegs[i].GetXForm().position.x * gameData.m_physScale) - 8) - 5), (((pegs[i].GetXForm().position.y * gameData.m_physScale) - 5) - 7)));
};
};
};
}
public function drawMagicBox2(i:int){
if (gameData.lvl1Array[i].alive != 2){
shared.images.i_magicbox2.render(null, true, new Matrix(1, 0, 0, 1, ((pegs[i].GetXForm().position.x * gameData.m_physScale) - 8), ((pegs[i].GetXForm().position.y * gameData.m_physScale) - 40)));
};
}
public function insertBigBox(i:int){
var bodyDefC:b2BodyDef = new b2BodyDef();
var circDef:b2CircleDef = new b2CircleDef();
circDef.density = 0;
circDef.radius = (50 / gameData.m_physScale);
circDef.friction = 0.3;
circDef.restitution = 0.9;
bodyDefC.position.Set(((gameData.lvl1Array[i].x + 50) / gameData.m_physScale), ((gameData.lvl1Array[i].y + 50) / gameData.m_physScale));
bodyDefC.angle = (Math.random() * Math.PI);
pegs[i] = gameData.m_world.CreateStaticBody(bodyDefC);
pegs[i].CreateShape(circDef);
pegs[i].AllowSleeping(true);
pegs[i].m_userData = gameData.lvl1Array[i];
pegs[i].SetMassFromShapes();
}
public function drawSlider2(i:int){
if (gameData.lvl1Array[i].alive != 2){
shared.images.i_slider2.render(null, true, new Matrix(1, 0, 0, 1, (pegs[i].GetXForm().position.x * gameData.m_physScale), (pegs[i].GetXForm().position.y * gameData.m_physScale)));
};
}
public function drawMagicBox1(i:int){
if (gameData.lvl1Array[i].alive != 2){
shared.images.i_magicbox.render(null, true, new Matrix(1, 0, 0, 1, ((pegs[i].GetXForm().position.x * gameData.m_physScale) - 40), ((pegs[i].GetXForm().position.y * gameData.m_physScale) - 8)));
};
}
public function addWalls(){
var wallB:b2Body;
var wallSd:b2PolygonDef = new b2PolygonDef();
var wallBd:b2BodyDef = new b2BodyDef();
walls = new Array();
wallBd.position.Set(((-50 + 85) / gameData.m_physScale), (0 / gameData.m_physScale));
wallSd.SetAsBox((50 / gameData.m_physScale), (580 / gameData.m_physScale));
walls[0] = gameData.m_world.CreateStaticBody(wallBd);
walls[0].CreateShape(wallSd);
walls[0].SetMassFromShapes();
wallBd.position.Set((690 / gameData.m_physScale), (580 / gameData.m_physScale));
walls[1] = gameData.m_world.CreateStaticBody(wallBd);
walls[1].CreateShape(wallSd);
walls[1].SetMassFromShapes();
wallBd.position.Set((-100 / gameData.m_physScale), (-50 / gameData.m_physScale));
wallSd.SetAsBox((840 / gameData.m_physScale), (50 / gameData.m_physScale));
walls[2] = gameData.m_world.CreateStaticBody(wallBd);
walls[2].CreateShape(wallSd);
walls[2].SetMassFromShapes();
wallBd.position.Set((-100 / gameData.m_physScale), ((580 + 50) / gameData.m_physScale));
walls[3] = gameData.m_world.CreateStaticBody(wallBd);
walls[3].CreateShape(wallSd);
walls[3].SetMassFromShapes();
}
public function drawRotating(i:int){
var propMatrix:Matrix;
if (gameData.lvl1Array[i].alive != 2){
propMatrix = new Matrix(1, 0, 0, 1, 0, 0);
propMatrix.rotate(pegs[i].GetAngle());
propMatrix.translate((((-1 * 60) * Math.cos((pegs[i].GetAngle() + 0.1))) + (pegs[i].GetXForm().position.x * gameData.m_physScale)), (((-1 * 60) * Math.sin((pegs[i].GetAngle() + 0.1))) + (pegs[i].GetXForm().position.y * gameData.m_physScale)));
shared.images.i_rotating.render(null, true, propMatrix);
};
}
public function drawRectPeg(i:int){
if (gameData.lvl1Array[i].color == 0){
if (gameData.lvl1Array[i].alive == 1){
shared.images.i_bluerectpeg.render(null, true, new Matrix(1, 0, 0, 1, (((pegs[i].GetXForm().position.x * gameData.m_physScale) - 8) + 2), (((pegs[i].GetXForm().position.y * gameData.m_physScale) - 7) - 2)));
} else {
if (gameData.lvl1Array[i].alive == 0){
shared.images.i_bluerectpeghighlighted.render(null, true, new Matrix(1, 0, 0, 1, (((pegs[i].GetXForm().position.x * gameData.m_physScale) - 8) - 3), ((((pegs[i].GetXForm().position.y * gameData.m_physScale) - 4) - 7) - 3)));
};
};
} else {
if (gameData.lvl1Array[i].alive == 1){
shared.images.i_redrectpeg.render(null, true, new Matrix(1, 0, 0, 1, (((pegs[i].GetXForm().position.x * gameData.m_physScale) - 8) + 2), (((pegs[i].GetXForm().position.y * gameData.m_physScale) - 7) - 2)));
} else {
if (gameData.lvl1Array[i].alive == 0){
shared.images.i_redrectpeghighlighted.render(null, true, new Matrix(1, 0, 0, 1, (((pegs[i].GetXForm().position.x * gameData.m_physScale) - 8) - 3), ((((pegs[i].GetXForm().position.y * gameData.m_physScale) - 4) - 7) - 3)));
};
};
};
}
public function drawSmallSquare(i:int){
if (gameData.lvl1Array[i].alive != 2){
shared.images.i_smallsquare.render(null, true, new Matrix(1, 0, 0, 1, ((pegs[i].GetXForm().position.x * gameData.m_physScale) - 8), ((pegs[i].GetXForm().position.y * gameData.m_physScale) - 8)));
};
}
public function drawRectPeg2(i:int){
if (gameData.lvl1Array[i].color == 0){
if (gameData.lvl1Array[i].alive == 1){
shared.images.i_bluerectpeg2.render(null, true, new Matrix(1, 0, 0, 1, (((pegs[i].GetXForm().position.x * gameData.m_physScale) - 8) - 2), ((pegs[i].GetXForm().position.y * gameData.m_physScale) - 7)));
} else {
if (gameData.lvl1Array[i].alive == 0){
shared.images.i_bluerectpeghighlighted2.render(null, true, new Matrix(1, 0, 0, 1, (((pegs[i].GetXForm().position.x * gameData.m_physScale) - 8) - 4), (((pegs[i].GetXForm().position.y * gameData.m_physScale) - 4) - 12)));
};
};
} else {
if (gameData.lvl1Array[i].alive == 1){
shared.images.i_redrectpeg2.render(null, true, new Matrix(1, 0, 0, 1, (((pegs[i].GetXForm().position.x * gameData.m_physScale) - 8) - 2), ((pegs[i].GetXForm().position.y * gameData.m_physScale) - 7)));
} else {
if (gameData.lvl1Array[i].alive == 0){
shared.images.i_redrectpeghighlighted2.render(null, true, new Matrix(1, 0, 0, 1, ((((pegs[i].GetXForm().position.x * gameData.m_physScale) - 8) - 4) - 4), (((pegs[i].GetXForm().position.y * gameData.m_physScale) - 4) - 8)));
};
};
};
}
public function drawBigRectangle(i:int){
if (gameData.lvl1Array[i].alive != 2){
shared.images.i_bigrectangle.render(null, true, new Matrix(1, 0, 0, 1, ((pegs[i].GetXForm().position.x * gameData.m_physScale) - 8), ((pegs[i].GetXForm().position.y * gameData.m_physScale) - 100)));
};
}
public function LoadLevel2():Array{
var codeToLoad:String;
var i:int;
var codeString:String;
var firstPeg:Peg;
var secondPeg:Peg;
var level:Array = new Array();
codeToLoad = levelsCode[gameData.whatLevel];
if (gameData.testing){
codeToLoad = testLevel;
};
var levelcode2:String = codeToLoad.substring(0, codeToLoad.search("\\$"));
var pegs:int = (levelcode2.length / 4);
i = 0;
while (i < pegs) {
codeString = levelcode2.slice(0, 4);
levelcode2 = levelcode2.slice(4, levelcode2.length);
level[i] = convertCodeToItem(codeString);
i++;
};
var sideToSidePegs:String = codeToLoad.substring((codeToLoad.search("\\$") + 1));
sideToSidePegs = sideToSidePegs.substring(0, sideToSidePegs.search("\\$"));
var sidePegsCount:int = (sideToSidePegs.length / 8);
i = 0;
while (i < sidePegsCount) {
codeString = sideToSidePegs.slice(0, 4);
sideToSidePegs = sideToSidePegs.slice(4, sideToSidePegs.length);
firstPeg = convertCodeToItem(codeString);
codeString = sideToSidePegs.slice(0, 4);
sideToSidePegs = sideToSidePegs.slice(4, sideToSidePegs.length);
secondPeg = convertCodeToItem(codeString);
level[(i + pegs)] = new Peg(null, firstPeg.x, firstPeg.y, 0, firstPeg.type, secondPeg.x, secondPeg.y);
level[(i + pegs)].moveType = 1;
i++;
};
var circlingPegs:String = codeToLoad.substring((codeToLoad.search("\\$") + 1));
circlingPegs = circlingPegs.substring((circlingPegs.search("\\$") + 1));
var circlingPegsCount:int = (circlingPegs.length / 8);
i = 0;
while (i < circlingPegsCount) {
codeString = circlingPegs.slice(0, 4);
circlingPegs = circlingPegs.slice(4, circlingPegs.length);
firstPeg = convertCodeToItem(codeString);
codeString = circlingPegs.slice(0, 4);
circlingPegs = circlingPegs.slice(4, circlingPegs.length);
secondPeg = convertCodeToItem(codeString);
level[((sidePegsCount + i) + pegs)] = new Peg(null, firstPeg.x, firstPeg.y, 0, firstPeg.type, secondPeg.x, secondPeg.y);
level[((sidePegsCount + i) + pegs)].moveType = 2;
i++;
};
destroyFreeBall = false;
return (level);
}
public function insertMagicBox1(i:int){
var bodyDefC:b2BodyDef = new b2BodyDef();
var circDef:b2PolygonDef = new b2PolygonDef();
circDef.SetAsBox((40 / gameData.m_physScale), (8 / gameData.m_physScale));
circDef.density = 0;
circDef.friction = 0.3;
circDef.restitution = 0.9;
bodyDefC.position.Set(((gameData.lvl1Array[i].x + 40) / gameData.m_physScale), ((gameData.lvl1Array[i].y + 8) / gameData.m_physScale));
pegs[i] = gameData.m_world.CreateStaticBody(bodyDefC);
pegs[i].CreateShape(circDef);
pegs[i].AllowSleeping(true);
pegs[i].m_userData = gameData.lvl1Array[i];
pegs[i].SetMassFromShapes();
}
public function insertMagicBox2(i:int){
var bodyDefC:b2BodyDef = new b2BodyDef();
var circDef:b2PolygonDef = new b2PolygonDef();
circDef.SetAsBox((8 / gameData.m_physScale), (40 / gameData.m_physScale));
circDef.density = 0;
circDef.friction = 0.3;
circDef.restitution = 0.9;
bodyDefC.position.Set(((gameData.lvl1Array[i].x + 8) / gameData.m_physScale), ((gameData.lvl1Array[i].y + 40) / gameData.m_physScale));
pegs[i] = gameData.m_world.CreateStaticBody(bodyDefC);
pegs[i].CreateShape(circDef);
pegs[i].AllowSleeping(true);
pegs[i].m_userData = gameData.lvl1Array[i];
pegs[i].SetMassFromShapes();
}
public function drawTriangleRotate(i:int){
var propMatrix:Matrix;
if (gameData.lvl1Array[i].alive != 2){
propMatrix = new Matrix(1, 0, 0, 1, 0, 0);
propMatrix.rotate((-1 * (testRotate - 0.075)));
propMatrix.translate((pegs[i].GetXForm().position.x * gameData.m_physScale), (pegs[i].GetXForm().position.y * gameData.m_physScale));
shared.images.i_trianglerotate.render(null, true, propMatrix);
};
}
public function insertFreeBall(){
gameData.freeBall = new Peg(null, 115, 425, 0, 3, -1, -1);
var bodyDefC:b2BodyDef = new b2BodyDef();
var circDef:b2CircleDef = new b2CircleDef();
circDef.density = 0;
circDef.radius = (20 / gameData.m_physScale);
circDef.friction = 0.3;
circDef.restitution = 0.9;
bodyDefC.position.Set((115 / gameData.m_physScale), (425 / gameData.m_physScale));
bodyDefC.angle = (Math.random() * Math.PI);
pegs[pegs.length] = gameData.m_world.CreateDynamicBody(bodyDefC);
pegs[(pegs.length - 1)].CreateShape(circDef);
pegs[(pegs.length - 1)].AllowSleeping(true);
pegs[(pegs.length - 1)].m_userData = gameData.freeBall;
pegs[(pegs.length - 1)].SetBullet(true);
gameData.freeBall = new Peg(null, (pegs[(pegs.length - 1)].GetXForm().position.x * gameData.m_physScale), (pegs[(pegs.length - 1)].GetXForm().position.y * gameData.m_physScale), 0, 3, -1, -1);
gameData.freeBall.alive = 1;
}
public function paint():void{
var i:int;
var propMatrix:Matrix;
i = 0;
while (i < gameData.lvl1Array.length) {
switch (gameData.lvl1Array[i].type){
case 0:
drawCirclePeg(i);
break;
case 1:
drawRectPeg(i);
break;
case 2:
drawRectPeg2(i);
break;
case 4:
drawSpeedBall(i);
break;
case 6:
drawSlider1(i);
break;
case 7:
drawSlider2(i);
break;
case 8:
drawBigBox(i);
break;
case 9:
drawTriangleRotate(i);
break;
case 10:
drawRotating(i);
break;
case 11:
drawStar(i);
break;
case 12:
drawBells(i);
break;
case 13:
drawBigRectangle(i);
break;
case 14:
drawSmallSquare(i);
break;
case 15:
drawMagicBox1(i);
break;
case 16:
drawMagicBox2(i);
break;
};
i++;
};
i = 0;
while (i < props.length) {
propMatrix = new Matrix(1, 0, 0, 1, 0, 0);
i++;
};
var freeBallPosition:int = (pegs.length - 1);
if (gameData.freeBall.alive == 1){
shared.images.i_freeball.render(null, true, new Matrix(1, 0, 0, 1, ((pegs[freeBallPosition].GetXForm().position.x * gameData.m_physScale) - 20), ((pegs[freeBallPosition].GetXForm().position.y * gameData.m_physScale) - 20)));
};
}
public function process():void{
var i:int;
var redpegFound:Boolean;
var whatPeg:int;
var contacts:Array;
var j:int;
if (gameData.winner == false){
redpegFound = false;
i = 0;
while (i < gameData.lvl1Array.length) {
if (gameData.lvl1Array[i].alive != 2){
if (gameData.lvl1Array[i].color == 1){
redpegFound = true;
break;
};
};
i++;
};
if (!redpegFound){
gameData.Winner();
};
};
i = 0;
while (i < gameData.lvl1Array.length) {
if (gameData.lvl1Array[i].alive != 2){
gameData.lvl1Array[i].process();
};
i++;
};
if (destroyFreeBall){
if (gameData.freeBall.alive == 1){
gameData.livesLeft++;
shared.particleS.emitStars((13 + (16 * ((gameData.livesLeft - 1) % 4))), (182 + (Math.floor(((gameData.livesLeft - 1) / 4)) * 16)), 5, shared.particleS.star1);
};
gameData.m_world.DestroyBody(pegs[(pegs.length - 1)]);
gameData.freeBall.alive = 2;
destroyFreeBall = false;
};
i = 0;
while (i < gameData.lvl1Array.length) {
if ((((gameData.lvl1Array[i].alive == 0)) && ((gameData.lvl1Array[i].type == 4)))){
gameData.m_world.DestroyBody(pegs[i]);
gameData.lvl1Array[i].alive = 2;
gameData.capsule.reShoot();
};
i++;
};
testRotate = (testRotate + 0.075);
if (testRotate >= (2 * Math.PI)){
testRotate = 0;
};
magicFlipCount++;
if (magicFlipCount > 40){
magicFlipCount = 0;
magicFlip = !(magicFlip);
};
i = 0;
while (i < gameData.lvl1Array.length) {
if (gameData.lvl1Array[i].type == 9){
pegs[i].SetXForm(pegs[i].GetPosition(), (-1 * testRotate));
};
if (gameData.lvl1Array[i].type == 11){
pegs[i].SetXForm(pegs[i].GetPosition(), (-1 * testRotate));
};
if ((((gameData.lvl1Array[i].type == 15)) || ((gameData.lvl1Array[i].type == 16)))){
if (magicFlip){
if (gameData.lvl1Array[i].type == 15){
pegs[i].SetXForm(new b2Vec2(((gameData.lvl1Array[i].x + 40) / gameData.m_physScale), ((gameData.lvl1Array[i].y + 8) / gameData.m_physScale)), 0);
} else {
pegs[i].SetXForm(new b2Vec2(((gameData.lvl1Array[i].x + 8) / gameData.m_physScale), ((gameData.lvl1Array[i].y + 40) / gameData.m_physScale)), 0);
};
};
if (magicFlip == false){
pegs[i].SetXForm(new b2Vec2(-100, -100), 0);
};
};
i++;
};
if (gameData.contactlistener.contacts.length > 0){
whatPeg = -1;
contacts = gameData.contactlistener.contacts;
i = 0;
while (i < contacts.length) {
if (contacts[i] == pegs[(pegs.length - 1)]){
if (gameData.soundOn){
shared.sounds.s_freeball.play(0, 0);
};
destroyFreeBall = true;
gameData.freeBallHit = true;
gameData.hitFree = true;
gameData.freeBallHitPoint = new Point();
if (gameData.freeBall.x > 495){
gameData.freeBallHitPoint.x = (gameData.freeBall.x - 120);
} else {
gameData.freeBallHitPoint.x = gameData.freeBall.x;
};
gameData.freeBallHitPoint.y = gameData.freeBall.y;
} else {
if ((((((contacts[i] == walls[0])) || ((contacts[i] == walls[1])))) || ((contacts[i] == walls[2])))){
if (gameData.soundOn){
shared.sounds.s_minimalist.play(0, 0);
};
};
j = 0;
while (j < gameData.lvl1Array.length) {
if (contacts[i] == pegs[j]){
whatPeg = j;
if ((((gameData.lvl1Array[whatPeg].type > 2)) && (!((gameData.lvl1Array[whatPeg].type == 4))))){
if (gameData.soundOn){
shared.sounds.s_minimalist.play(0, 0);
};
break;
};
if (gameData.lvl1Array[whatPeg].alive == 2){
break;
};
if (gameData.lvl1Array[whatPeg].hitCounter > 5){
destroyBall(whatPeg);
return;
};
if (whatPeg != -1){
if (gameData.lvl1Array[whatPeg].hitCounter == 0){
if (gameData.soundOn){
niceSound[Math.floor((gameData.pitchToPlay / 4))].play(0, 0);
};
gameData.pitchToPlay++;
if (gameData.pitchToPlay == 28){
gameData.pitchToPlay = 27;
};
if (gameData.pegsHit.length >= 1){
if (Math.abs((gameData.pegsHit[(gameData.pegsHit.length - 1)].x - gameData.lvl1Array[whatPeg].x)) > 300){
gameData.longshot = true;
MemoryCrypto.incrementValue(gameData.score, 50);
gameData.longshotPoint = new Point(gameData.lvl1Array[whatPeg].x, gameData.lvl1Array[whatPeg].y);
};
};
if ((((gameData.pegsHit.length >= 2)) && ((gameData.lvl1Array[whatPeg].color == 1)))){
if ((((((gameData.pegsHit[(gameData.pegsHit.length - 1)].usedInBonus == false)) && ((gameData.pegsHit[(gameData.pegsHit.length - 1)].color == 1)))) && ((gameData.pegsHit[(gameData.pegsHit.length - 2)].color == 1)))){
gameData.threeRedHit = true;
MemoryCrypto.incrementValue(gameData.score, 500);
gameData.lvl1Array[whatPeg].usedInBonus = true;
if (gameData.lvl1Array[whatPeg].x > 490){
gameData.threeRedHitPoint = new Point((gameData.lvl1Array[whatPeg].x - 150), gameData.lvl1Array[whatPeg].y);
} else {
gameData.threeRedHitPoint = new Point(gameData.lvl1Array[whatPeg].x, gameData.lvl1Array[whatPeg].y);
};
};
};
if ((((gameData.pegsHit.length >= 2)) && ((gameData.lvl1Array[whatPeg].color == 0)))){
if ((((((gameData.pegsHit[(gameData.pegsHit.length - 1)].usedInBonus == false)) && ((gameData.pegsHit[(gameData.pegsHit.length - 1)].color == 0)))) && ((gameData.pegsHit[(gameData.pegsHit.length - 2)].color == 0)))){
gameData.threeBlueHit = true;
MemoryCrypto.incrementValue(gameData.score, 50);
gameData.lvl1Array[whatPeg].usedInBonus = true;
if (gameData.lvl1Array[whatPeg].x > 490){
gameData.threeBlueHitPoint = new Point((gameData.lvl1Array[whatPeg].x - 150), gameData.lvl1Array[whatPeg].y);
} else {
gameData.threeBlueHitPoint = new Point(gameData.lvl1Array[whatPeg].x, gameData.lvl1Array[whatPeg].y);
};
};
};
shared.particleS.emitStars(gameData.lvl1Array[whatPeg].x, gameData.lvl1Array[whatPeg].y, 5, shared.particleS.snowflake);
gameData.pegsHitInt.push(whatPeg);
gameData.pegsHit.push(gameData.lvl1Array[whatPeg]);
};
gameData.lvl1Array[whatPeg].alive = 0;
gameData.lvl1Array[whatPeg].hitCounter++;
};
break;
};
j++;
};
};
i++;
};
gameData.contactlistener.clean();
};
if (gameData.freeBall.alive == 1){
processFreeBall();
};
}
public function drawBells(i:int){
if (gameData.lvl1Array[i].alive != 2){
shared.images.i_anchor.render(null, true, new Matrix(1, 0, 0, 1, (gameData.lvl1Array[i].anchorX - 6), (gameData.lvl1Array[i].anchorY - 6)));
shared.drawDottedLine(gameData.lvl1Array[i].anchorX, gameData.lvl1Array[i].anchorY, (pegs[i].GetXForm().position.x * gameData.m_physScale), (pegs[i].GetXForm().position.y * gameData.m_physScale));
shared.images.i_ballchain.render(null, true, new Matrix(1, 0, 0, 1, ((pegs[i].GetXForm().position.x * gameData.m_physScale) - 15), ((pegs[i].GetXForm().position.y * gameData.m_physScale) - 15)));
};
}
public function insertSlider1(i:int){
var bodyDefP:b2BodyDef = new b2BodyDef();
var polyDef:b2PolygonDef = new b2PolygonDef();
polyDef.vertexCount = 4;
polyDef.vertices[3].Set((0 / gameData.m_physScale), (74 / gameData.m_physScale));
polyDef.vertices[2].Set((9 / gameData.m_physScale), (87 / gameData.m_physScale));
polyDef.vertices[1].Set((103 / gameData.m_physScale), (13 / gameData.m_physScale));
polyDef.vertices[0].Set((93 / gameData.m_physScale), (1 / gameData.m_physScale));
polyDef.density = 0;
polyDef.friction = 0.3;
polyDef.restitution = 0.1;
bodyDefP.position.Set((gameData.lvl1Array[i].x / gameData.m_physScale), (gameData.lvl1Array[i].y / gameData.m_physScale));
pegs[i] = gameData.m_world.CreateStaticBody(bodyDefP);
pegs[i].CreateShape(polyDef);
pegs[i].SetMassFromShapes();
}
}
}//package
Section 273
//Level_s_test (Level_s_test)
package {
import mx.core.*;
public class Level_s_test extends SoundAsset {
}
}//package
Section 274
//Level_s_test2 (Level_s_test2)
package {
import mx.core.*;
public class Level_s_test2 extends SoundAsset {
}
}//package
Section 275
//Level_s_test3 (Level_s_test3)
package {
import mx.core.*;
public class Level_s_test3 extends SoundAsset {
}
}//package
Section 276
//Level_s_test4 (Level_s_test4)
package {
import mx.core.*;
public class Level_s_test4 extends SoundAsset {
}
}//package
Section 277
//Level_s_test5 (Level_s_test5)
package {
import mx.core.*;
public class Level_s_test5 extends SoundAsset {
}
}//package
Section 278
//Level_s_test6 (Level_s_test6)
package {
import mx.core.*;
public class Level_s_test6 extends SoundAsset {
}
}//package
Section 279
//Level_s_test7 (Level_s_test7)
package {
import mx.core.*;
public class Level_s_test7 extends SoundAsset {
}
}//package
Section 280
//LevelEditor (LevelEditor)
package {
import Box2D.Common.Math.*;
import flash.geom.*;
import flash.text.*;
import com.hexagonstar.util.debug.*;
import flash.system.*;
import flash.ui.*;
public class LevelEditor extends Module {
private var moveCircle:Boolean;
public var gameData:GameData;
private var level:Array;
private var undoCount:int;// = 0
private var levelProps:Array;
private var levelCode:String;
private var cursor:int;// = 0
public var selected:int;// = -1
private var undo:Array;
private var loadMenu:int;// = 0
private var propCount;
private var text:TextField;
private var propsMenu:int;// = 0
private var pegCount;
private var saveMenu:int;// = 0
private var movePoint:Boolean;
public function LevelEditor(){
super();
gameData = GameData.getInstance();
level = new Array();
levelProps = new Array();
undo = new Array();
levelCode = "";
movePoint = (moveCircle = false);
}
public function LoadLevel(){
var i:int;
var codeString:String;
var firstPeg:Peg;
var secondPeg:Peg;
level = new Array();
levelProps = new Array();
undo = new Array();
var codeToLoad:String = text.text;
var levelcode2:String = codeToLoad.substring(0, codeToLoad.search("\\$"));
var pegs:int = (levelcode2.length / 4);
i = 0;
while (i < pegs) {
codeString = levelcode2.slice(0, 4);
levelcode2 = levelcode2.slice(4, levelcode2.length);
level[i] = convertCodeToItem(codeString);
SetBoxes(i);
i++;
};
var sideToSidePegs:String = codeToLoad.substring((codeToLoad.search("\\$") + 1));
sideToSidePegs = sideToSidePegs.substring(0, sideToSidePegs.search("\\$"));
var sidePegsCount:int = (sideToSidePegs.length / 8);
i = 0;
while (i < sidePegsCount) {
codeString = sideToSidePegs.slice(0, 4);
sideToSidePegs = sideToSidePegs.slice(4, sideToSidePegs.length);
firstPeg = convertCodeToItem(codeString);
codeString = sideToSidePegs.slice(0, 4);
sideToSidePegs = sideToSidePegs.slice(4, sideToSidePegs.length);
secondPeg = convertCodeToItem(codeString);
level[(i + pegs)] = new Peg(null, firstPeg.x, firstPeg.y, 0, firstPeg.type, secondPeg.x, secondPeg.y);
level[(i + pegs)].moveType = 1;
i++;
};
var circlingPegs:String = codeToLoad.substring((codeToLoad.search("\\$") + 1));
circlingPegs = circlingPegs.substring((circlingPegs.search("\\$") + 1));
var circlingPegsCount:int = (circlingPegs.length / 8);
i = 0;
while (i < circlingPegsCount) {
codeString = circlingPegs.slice(0, 4);
circlingPegs = circlingPegs.slice(4, circlingPegs.length);
firstPeg = convertCodeToItem(codeString);
codeString = circlingPegs.slice(0, 4);
circlingPegs = circlingPegs.slice(4, circlingPegs.length);
secondPeg = convertCodeToItem(codeString);
level[((sidePegsCount + i) + pegs)] = new Peg(null, firstPeg.x, firstPeg.y, 0, firstPeg.type, secondPeg.x, secondPeg.y);
level[((sidePegsCount + i) + pegs)].moveType = 2;
i++;
};
pegCount = ((sidePegsCount + pegs) + circlingPegsCount);
}
public function convertLetterTo6BitCode(char:String):int{
if (char.charCodeAt(0) == new String("#").charCodeAt(0)){
return (63);
};
if (char.charCodeAt(0) == new String("@").charCodeAt(0)){
return (62);
};
if (char.charCodeAt(0) >= 97){
return ((char.charCodeAt(0) - 97));
};
if (char.charCodeAt(0) >= 65){
return (((char.charCodeAt(0) - 65) + 26));
};
if (char.charCodeAt(0) >= 48){
return (((char.charCodeAt(0) - 48) + 52));
};
return (0);
}
public function convertCodeToItem(code:String):Peg{
var decimalCode = (convertLetterTo6BitCode(code.charAt(0)) << 18);
decimalCode = (decimalCode + (convertLetterTo6BitCode(code.charAt(1)) << 12));
decimalCode = (decimalCode + (convertLetterTo6BitCode(code.charAt(2)) << 6));
decimalCode = (decimalCode + (convertLetterTo6BitCode(code.charAt(3)) << 0));
var peg:Peg = new Peg(null, 100, 100, 0);
peg.type = (decimalCode - ((decimalCode >> 5) << 5));
peg.x = ((decimalCode >> 14) + 91);
peg.y = (((decimalCode - ((decimalCode >> 14) << 14)) >> 5) + 52);
switch (peg.type){
case 0:
peg.x = (peg.x - 9);
peg.y = (peg.y - 8);
break;
case 1:
peg.x = (peg.x - 6);
peg.y = (peg.y - 9);
break;
case 2:
peg.x = (peg.x - 10);
peg.y = (peg.y - 7);
break;
};
return (peg);
}
public function DrawCursorSymbol(){
switch (cursor){
case 0:
shared.screen.bitmapData.setPixel(18, 72, 0xFF0000);
shared.screen.bitmapData.setPixel(19, 73, 0xFF0000);
shared.screen.bitmapData.setPixel(19, 72, 0xFF0000);
shared.screen.bitmapData.setPixel(18, 73, 0xFF0000);
break;
case 1:
shared.screen.bitmapData.setPixel((18 + 23), 72, 0xFF0000);
shared.screen.bitmapData.setPixel((19 + 23), 73, 0xFF0000);
shared.screen.bitmapData.setPixel((19 + 23), 72, 0xFF0000);
shared.screen.bitmapData.setPixel((18 + 23), 73, 0xFF0000);
break;
case 2:
shared.screen.bitmapData.setPixel(((18 + 23) + 23), 72, 0xFF0000);
shared.screen.bitmapData.setPixel(((19 + 23) + 23), 73, 0xFF0000);
shared.screen.bitmapData.setPixel(((19 + 23) + 23), 72, 0xFF0000);
shared.screen.bitmapData.setPixel(((18 + 23) + 23), 73, 0xFF0000);
break;
case 3:
shared.screen.bitmapData.setPixel((40 + 20), 113, 0xFF0000);
shared.screen.bitmapData.setPixel(((40 + 20) + 1), 113, 0xFF0000);
shared.screen.bitmapData.setPixel((40 + 20), (113 + 1), 0xFF0000);
shared.screen.bitmapData.setPixel(((40 + 20) + 1), (113 + 1), 0xFF0000);
break;
case 5:
shared.screen.bitmapData.setPixel(((40 + 20) - 38), 113, 0xFF0000);
shared.screen.bitmapData.setPixel((((40 + 20) + 1) - 38), 113, 0xFF0000);
shared.screen.bitmapData.setPixel(((40 + 20) - 38), (113 + 1), 0xFF0000);
shared.screen.bitmapData.setPixel((((40 + 20) + 1) - 38), (113 + 1), 0xFF0000);
break;
};
}
public function SetBoxes(pegCount:int){
if (cursor == 4){
level[pegCount].SetBox(40, 40);
};
if ((((cursor == 6)) || ((cursor == 7)))){
level[pegCount].SetBox(100, 90);
};
if (cursor == 8){
level[pegCount].SetBox(100, 100);
};
if (cursor == 9){
level[pegCount].SetBox(54, 94);
};
if (cursor == 10){
level[pegCount].SetBox(120, 10);
};
if (cursor == 11){
level[pegCount].SetBox(42, 42);
};
if (cursor == 12){
level[pegCount].SetBox(49, 71);
};
if (cursor == 13){
level[pegCount].SetBox(16, 200);
};
if (cursor == 14){
level[pegCount].SetBox(16, 16);
};
if (cursor == 15){
level[pegCount].SetBox(40, 8);
};
if (cursor == 16){
level[pegCount].SetBox(8, 40);
};
}
public function convertToLetterCode(number:int):String{
if (number <= 25){
return (String.fromCharCode((97 + number)));
};
if (number <= 51){
return (String.fromCharCode((65 + (number - 26))));
};
if (number <= 61){
return (new Number((number - 52)).toString());
};
if (number == 62){
return ("@");
};
if (number == 63){
return ("#");
};
return ("");
}
public function convertToDecimal(binary:Number):int{
var inString:String = binary.toString();
var code:int;
var i:int = (inString.length - 1);
while (i >= 0) {
if (inString.charAt(i) == "1"){
code = (code + Math.pow(2, ((inString.length - 1) - i)));
};
i--;
};
return (code);
}
override public function Process(){
var i:int;
var rect2:Rectangle;
var segment:b2Vec2;
var radius:Number;
var rect:Rectangle;
shared.sounds.StopMusic();
if (loadMenu > 0){
loadMenu = (loadMenu - 25);
if (loadMenu <= 97){
loadMenu = 97;
shared.buttons.b_cancelbutton2.process(shared);
if (shared.buttons.b_cancelbutton2.isClicked()){
loadMenu = 0;
text.visible = false;
};
shared.buttons.b_load.process(shared);
if (shared.buttons.b_load.isClicked()){
loadMenu = 0;
text.visible = false;
};
shared.buttons.b_ok.process(shared);
if (shared.buttons.b_ok.isClicked()){
loadMenu = 0;
text.visible = false;
LoadLevel();
};
};
return;
};
if (saveMenu > 0){
saveMenu = (saveMenu - 25);
if (saveMenu <= 97){
saveMenu = 97;
shared.buttons.b_copy.process(shared);
shared.buttons.b_ok.process(shared);
shared.buttons.b_cancelbutton2.process(shared);
if (shared.buttons.b_cancelbutton2.isClicked()){
saveMenu = 0;
text.visible = false;
};
if (shared.buttons.b_copy.isClicked()){
System.setClipboard(levelCode);
};
if (shared.buttons.b_ok.isClicked()){
saveMenu = 0;
text.visible = false;
};
};
shared.buttons.b_save.process(shared);
if (shared.buttons.b_save.isClicked()){
saveMenu = 0;
text.visible = false;
};
return;
};
if (propsMenu > 0){
propsMenu = (propsMenu - 25);
if (propsMenu <= 97){
propsMenu = 97;
if (shared.input.mouseToggle){
if ((((shared.input.mousey > 83)) && ((shared.input.mousey < (83 + 50))))){
if ((((shared.input.mousex > 119)) && ((shared.input.mousex < (119 + 40))))){
cursor = 4;
propsMenu = 0;
};
};
if ((((shared.input.mousey > 91)) && ((shared.input.mousey < 159)))){
if ((((shared.input.mousex > 173)) && ((shared.input.mousex < 267)))){
cursor = 6;
propsMenu = 0;
};
};
if ((((shared.input.mousey > 88)) && ((shared.input.mousey < 161)))){
if ((((shared.input.mousex > 300)) && ((shared.input.mousex < 400)))){
cursor = 7;
propsMenu = 0;
};
};
if ((((shared.input.mousey > 83)) && ((shared.input.mousey < (83 + 100))))){
if ((((shared.input.mousex > 450)) && ((shared.input.mousex < (450 + 100))))){
cursor = 8;
propsMenu = 0;
};
};
if ((((shared.input.mousey > 183)) && ((shared.input.mousey < (183 + 94))))){
if ((((shared.input.mousex > 119)) && ((shared.input.mousex < (119 + 54))))){
cursor = 9;
propsMenu = 0;
};
};
if ((((shared.input.mousey > 200)) && ((shared.input.mousey < (200 + 11))))){
if ((((shared.input.mousex > 200)) && ((shared.input.mousex < (200 + 121))))){
cursor = 10;
propsMenu = 0;
};
};
if ((((shared.input.mousey > 231)) && ((shared.input.mousey < (231 + 42))))){
if ((((shared.input.mousex > 390)) && ((shared.input.mousex < (390 + 42))))){
cursor = 11;
propsMenu = 0;
};
};
if ((((shared.input.mousey > 250)) && ((shared.input.mousey < (250 + 71))))){
if ((((shared.input.mousex > 450)) && ((shared.input.mousex < (500 + 49))))){
cursor = 12;
propsMenu = 0;
};
};
if ((((shared.input.mousey > 227)) && ((shared.input.mousey < (227 + 200))))){
if ((((shared.input.mousex > 540)) && ((shared.input.mousex < (540 + 16))))){
cursor = 13;
propsMenu = 0;
};
};
if ((((shared.input.mousey > 300)) && ((shared.input.mousey < (300 + 16))))){
if ((((shared.input.mousex > 119)) && ((shared.input.mousex < (119 + 16))))){
cursor = 14;
propsMenu = 0;
};
};
if ((((shared.input.mousey > 300)) && ((shared.input.mousey < (300 + 17))))){
if ((((shared.input.mousex > 200)) && ((shared.input.mousex < (200 + 81))))){
cursor = 15;
propsMenu = 0;
};
};
if ((((shared.input.mousey > 300)) && ((shared.input.mousey < (300 + 81))))){
if ((((shared.input.mousex > 300)) && ((shared.input.mousex < (300 + 17))))){
cursor = 16;
propsMenu = 0;
};
};
};
shared.buttons.b_cancelbutton2.process(shared);
if (shared.buttons.b_cancelbutton2.isClicked()){
propsMenu = 0;
};
};
shared.buttons.b_props.process(shared);
if (shared.buttons.b_props.isClicked()){
propsMenu = 0;
};
return;
};
if (shared.input.mouseToggle){
if ((((shared.input.mousey > 50)) && ((shared.input.mousey < (413 - 20))))){
if ((((shared.input.mousex > 98)) && ((shared.input.mousex < (538 + 88))))){
if (cursor == 3){
i = (level.length - 1);
for (;i >= 0;i--) {
rect2 = new Rectangle(level[i].x, level[i].y, level[i].rect.width, level[i].rect.height);
if (rect2.contains(shared.input.mousex, shared.input.mousey)){
switch (level[i].type){
case 6:
if (shared.images.i_slider.getBitmapData().getPixel((shared.input.mousex - level[i].x), (shared.input.mousey - level[i].y)) == 0){
continue;
};
break;
case 7:
if (shared.images.i_slider.getBitmapData().getPixel((shared.input.mousex - level[i].x), (shared.input.mousey - level[i].y)) == 0){
continue;
};
break;
case 8:
if (shared.images.i_bigbox.getBitmapData().getPixel((shared.input.mousex - level[i].x), (shared.input.mousey - level[i].y)) == 0){
continue;
};
break;
case 9:
if (shared.images.i_trianglerotate.getBitmapData().getPixel((shared.input.mousex - level[i].x), (shared.input.mousey - level[i].y)) == 0){
continue;
};
break;
case 10:
break;
case 11:
if (shared.images.i_rotatingcross.getBitmapData().getPixel(((shared.input.mousex - level[i].x) - 21), ((shared.input.mousey - level[i].y) - 21)) == 0){
continue;
};
break;
case 12:
break;
case 13:
break;
};
level.splice(i, 1);
pegCount--;
break;
};
};
} else {
if (cursor == 5){
if (movePoint){
level[selected].x2 = (shared.input.mousex - 7);
level[selected].y2 = (shared.input.mousey - 7);
movePoint = false;
level[selected].moveType = 1;
return;
};
if (moveCircle){
segment = new b2Vec2();
segment.x = ((shared.input.mousex - 7) - level[selected].x);
segment.y = ((shared.input.mousey - 7) - level[selected].y);
radius = segment.Length();
if (((shared.input.mousey - 7) - radius) < 43){
return;
};
if (((shared.input.mousey - 7) + radius) > (413 - 20)){
return;
};
if (((shared.input.mousex - 7) - radius) < (91 - 7)){
return;
};
if (((shared.input.mousex - 7) + radius) > (627 - 7)){
return;
};
level[selected].x2 = (shared.input.mousex - 7);
level[selected].y2 = (shared.input.mousey - 7);
level[selected].moveType = 2;
moveCircle = false;
return;
};
i = 0;
for (;i < level.length;i++) {
rect = new Rectangle(level[i].x, level[i].y, 15, 15);
if (rect.contains(shared.input.mousex, shared.input.mousey)){
if (level[i].type <= 2){
selected = i;
} else {
continue;
};
break;
};
};
} else {
level[pegCount] = new Peg(null, (shared.input.mousex - 7), (shared.input.mousey - 7), 0);
SetBoxes(pegCount);
level[pegCount].changeType(cursor);
pegCount++;
};
};
};
};
};
shared.buttons.b_undo.process(shared);
if (((shared.buttons.b_undo.isClicked()) || (shared.input.keyToggle[85]))){
if (level.length > 0){
level.pop();
pegCount--;
};
};
shared.buttons.b_testbutton.process(shared);
if (shared.buttons.b_testbutton.isClicked()){
SaveLevel();
gameData.physicsGame.level.testLevel = levelCode;
gameData.testing = true;
gameData.initNewGame();
Mouse.show();
shared.nextGamestate = shared.GAME;
return;
};
shared.buttons.b_save.process(shared);
if (shared.buttons.b_save.isClicked()){
saveMenu = 600;
SaveLevel();
};
shared.buttons.b_load.process(shared);
if (shared.buttons.b_load.isClicked()){
loadMenu = 600;
text.text = "";
};
shared.buttons.b_props.process(shared);
if (shared.buttons.b_props.isClicked()){
propsMenu = 600;
};
shared.buttons.b_back.process(shared);
if (shared.buttons.b_back.isClicked()){
Mouse.show();
shared.nextGamestate = shared.LOADLEVEL;
return;
};
shared.buttons.b_clear.process(shared);
if (shared.buttons.b_clear.isClicked()){
shared.sounds.s_lightawoken.play(0, 9999);
pegCount = 0;
level = new Array();
};
if ((((((movePoint == false)) && ((moveCircle == false)))) && ((cursor == 5)))){
shared.buttons.b_movetocircle.process(shared);
shared.buttons.b_movetopoint.process(shared);
shared.buttons.b_makestaticbutton.process(shared);
if (shared.buttons.b_makestaticbutton.isClicked()){
level[selected].x2 = -1;
level[selected].y2 = -1;
level[selected].moveType = 0;
return;
};
if (shared.buttons.b_movetocircle.isClicked()){
moveCircle = true;
return;
};
if (shared.buttons.b_movetopoint.isClicked()){
movePoint = true;
return;
};
};
if (((movePoint) || (moveCircle))){
shared.buttons.b_cancelbutton.process(shared);
if (shared.buttons.b_cancelbutton.isClicked()){
movePoint = false;
moveCircle = false;
};
};
if (shared.input.mouseToggle){
if ((((shared.input.mousey > 50)) && ((shared.input.mousey < (50 + 20))))){
if ((((shared.input.mousex > 10)) && ((shared.input.mousex < (10 + 20))))){
cursor = 0;
};
};
if ((((shared.input.mousey > 45)) && ((shared.input.mousey < (45 + 24))))){
if ((((shared.input.mousex > 35)) && ((shared.input.mousex < (35 + 20))))){
cursor = 1;
};
};
if ((((shared.input.mousey > 52)) && ((shared.input.mousey < (52 + 20))))){
if ((((shared.input.mousex > 55)) && ((shared.input.mousex < (55 + 27))))){
cursor = 2;
};
};
if ((((shared.input.mousey > 90)) && ((shared.input.mousey < (90 + 20))))){
if ((((shared.input.mousex > (27 + 20))) && ((shared.input.mousex < ((27 + 20) + 40))))){
cursor = 3;
};
};
if ((((shared.input.mousey > 90)) && ((shared.input.mousey < (90 + 40))))){
if ((((shared.input.mousex > ((27 + 20) - 38))) && ((shared.input.mousex < (((27 + 20) + 40) - 38))))){
cursor = 5;
};
};
};
}
public function convertToCode(numericCode:int):String{
var code:String = "";
var binaryString:String = numericCode.toString(2);
if (binaryString.length < 18){
binaryString = ("000000" + binaryString);
};
var firstCode:Number = new Number(binaryString.slice(0, (binaryString.length - 18)));
var secondCode:Number = new Number(binaryString.slice((binaryString.length - 18), (binaryString.length - 12)));
var thirdCode:Number = new Number(binaryString.slice((binaryString.length - 12), (binaryString.length - 6)));
var fourthCode:Number = new Number(binaryString.slice((binaryString.length - 6), binaryString.length));
code = (((convertToLetterCode(convertToDecimal(firstCode)) + convertToLetterCode(convertToDecimal(secondCode))) + convertToLetterCode(convertToDecimal(thirdCode))) + convertToLetterCode(convertToDecimal(fourthCode)));
return (code);
}
public function SaveLevel(){
var i:int;
var x:int;
var y:int;
var item:int;
var code:int;
var x2:int;
var y2:int;
var code2:int;
levelCode = "";
i = 0;
while (i < level.length) {
if (level[i].x2 != -1){
} else {
x = (level[i].x - 91);
y = (level[i].y - 52);
switch (level[i].type){
case 0:
x = (x + 9);
y = (y + 8);
break;
case 1:
x = (x + 6);
y = (y + 9);
break;
case 2:
x = (x + 10);
y = (y + 7);
break;
};
item = level[i].type;
code = item;
y = (y << 5);
x = (x << (5 + 9));
code = (code + (y + x));
levelCode = (levelCode + convertToCode(code));
};
i++;
};
levelCode = (levelCode + "$");
i = 0;
while (i < level.length) {
if ((((level[i].x2 == -1)) || ((level[i].moveType == 2)))){
} else {
x = (level[i].x - 91);
y = (level[i].y - 52);
x2 = (level[i].x2 - 91);
y2 = (level[i].y2 - 52);
switch (level[i].type){
case 0:
x = (x + 9);
y = (y + 8);
x2 = (x2 + 9);
y2 = (y2 + 8);
break;
case 1:
x = (x + 6);
y = (y + 9);
x2 = (x2 + 6);
y2 = (y2 + 9);
break;
case 2:
x = (x + 10);
y = (y + 7);
x2 = (x2 + 10);
y2 = (y2 + 7);
break;
};
item = level[i].type;
code = item;
y = (y << 5);
x = (x << (5 + 9));
code = (code + (y + x));
levelCode = (levelCode + convertToCode(code));
code2 = item;
y2 = (y2 << 5);
x2 = (x2 << (5 + 9));
code2 = (code2 + (x2 + y2));
levelCode = (levelCode + convertToCode(code2));
};
i++;
};
levelCode = (levelCode + "$");
i = 0;
while (i < level.length) {
if ((((level[i].x2 == -1)) || ((level[i].moveType == 1)))){
} else {
x = (level[i].x - 91);
y = (level[i].y - 52);
x2 = (level[i].x2 - 91);
y2 = (level[i].y2 - 52);
switch (level[i].type){
case 0:
x = (x + 9);
y = (y + 8);
x2 = (x2 + 9);
y2 = (y2 + 8);
break;
case 1:
x = (x + 6);
y = (y + 9);
x2 = (x2 + 6);
y2 = (y2 + 9);
break;
case 2:
x = (x + 10);
y = (y + 7);
x2 = (x2 + 10);
y2 = (y2 + 7);
break;
};
item = level[i].type;
code = item;
y = (y << 5);
x = (x << (5 + 9));
code = (code + (y + x));
levelCode = (levelCode + convertToCode(code));
code2 = item;
y2 = (y2 << 5);
x2 = (x2 << (5 + 9));
code2 = (code2 + (x2 + y2));
levelCode = (levelCode + convertToCode(code2));
};
i++;
};
}
override public function Init(){
pegCount = (propCount = 0);
text = new TextField();
text.text = "paste level code here";
text.background = true;
text.border = true;
text.x = (99 + 10);
text.y = (75 + 10);
text.width = (523 - 20);
text.height = (337 - 20);
shared.frontLayer.addChild(text);
text.type = TextFieldType.INPUT;
text.wordWrap = true;
text.visible = false;
}
public function DrawPegs(){
var i:int;
while (i < level.length) {
switch (level[i].type){
case 0:
shared.images.i_bluepeg.render(null, true, new Matrix(1, 0, 0, 1, level[i].x, level[i].y));
if (((!((level[i].x2 == -1))) && ((cursor == 5)))){
if (level[i].moveType == 1){
shared.images.i_bluepeg.render(null, true, new Matrix(1, 0, 0, 1, level[i].x2, level[i].y2), new ColorTransform(1, 0, 0, 1));
shared.drawDottedLine((level[i].x + 7), (level[i].y + 7), (level[i].x2 + 7), (level[i].y2 + 7));
} else {
shared.drawCircle((level[i].x + 7), (level[i].y + 7), (level[i].x2 + 7), (level[i].y2 + 7));
};
};
break;
case 1:
shared.images.i_bluerectpeg.render(null, true, new Matrix(1, 0, 0, 1, level[i].x, level[i].y));
if (((!((level[i].x2 == -1))) && ((cursor == 5)))){
if (level[i].moveType == 1){
shared.images.i_bluerectpeg.render(null, true, new Matrix(1, 0, 0, 1, level[i].x2, level[i].y2), new ColorTransform(1, 0, 0, 1));
shared.drawDottedLine((level[i].x + 7), (level[i].y + 7), (level[i].x2 + 7), (level[i].y2 + 7));
} else {
shared.drawCircle((level[i].x + 7), (level[i].y + 7), (level[i].x2 + 7), (level[i].y2 + 7));
};
};
break;
case 2:
shared.images.i_bluerectpeg2.render(null, true, new Matrix(1, 0, 0, 1, level[i].x, level[i].y));
if (((!((level[i].x2 == -1))) && ((cursor == 5)))){
if (level[i].moveType == 1){
shared.images.i_bluerectpeg2.render(null, true, new Matrix(1, 0, 0, 1, level[i].x2, level[i].y2), new ColorTransform(1, 0, 0, 1));
shared.drawDottedLine((level[i].x + 7), (level[i].y + 7), (level[i].x2 + 7), (level[i].y2 + 7));
} else {
shared.drawCircle((level[i].x + 7), (level[i].y + 7), (level[i].x2 + 7), (level[i].y2 + 7));
};
};
break;
case 4:
shared.images.i_speedball.render(null, true, new Matrix(1, 0, 0, 1, level[i].x, level[i].y));
break;
case 6:
shared.images.i_slider.render(null, true, new Matrix(1, 0, 0, 1, level[i].x, level[i].y));
break;
case 7:
shared.images.i_slider2.render(null, true, new Matrix(1, 0, 0, 1, level[i].x, level[i].y));
break;
case 8:
shared.images.i_bigbox.render(null, true, new Matrix(1, 0, 0, 1, level[i].x, level[i].y));
break;
case 9:
shared.images.i_trianglerotate.render(null, true, new Matrix(1, 0, 0, 1, level[i].x, level[i].y));
break;
case 10:
shared.images.i_rotating.render(null, true, new Matrix(1, 0, 0, 1, (level[i].x - 60), (level[i].y - 6)));
break;
case 11:
shared.images.i_rotatingcross.render(null, true, new Matrix(1, 0, 0, 1, (level[i].x - 21), (level[i].y - 21)));
break;
case 12:
shared.images.i_anchor.render(null, true, new Matrix(1, 0, 0, 1, (level[i].x - 6), (level[i].y - 6)), new ColorTransform(1, 1, 1, 0.75));
shared.drawDottedLine(level[i].x, level[i].y, level[i].x, (level[i].y + 45));
shared.images.i_ballchain.render(null, true, new Matrix(1, 0, 0, 1, (level[i].x - 15), ((level[i].y + 45) - 15)), new ColorTransform(1, 1, 1, 0.75));
break;
case 13:
shared.images.i_bigrectangle.render(null, true, new Matrix(1, 0, 0, 1, level[i].x, level[i].y));
break;
case 14:
shared.images.i_smallsquare.render(null, true, new Matrix(1, 0, 0, 1, level[i].x, level[i].y));
break;
case 15:
shared.images.i_magicbox.render(null, true, new Matrix(1, 0, 0, 1, level[i].x, level[i].y));
break;
case 16:
shared.images.i_magicbox2.render(null, true, new Matrix(1, 0, 0, 1, level[i].x, level[i].y));
break;
};
if ((((i == selected)) && ((cursor == 5)))){
switch (level[i].type){
case 0:
shared.images.i_bluepeg.render(null, true, new Matrix(1, 0, 0, 1, level[i].x, level[i].y), new ColorTransform(0, 1, 1, 1));
break;
case 1:
shared.images.i_bluerectpeg.render(null, true, new Matrix(1, 0, 0, 1, level[i].x, level[i].y), new ColorTransform(0, 1, 1, 1));
break;
case 2:
shared.images.i_bluerectpeg2.render(null, true, new Matrix(1, 0, 0, 1, level[i].x, level[i].y), new ColorTransform(0, 1, 1, 1));
break;
};
if ((((movePoint == false)) && ((moveCircle == false)))){
shared.buttons.b_movetocircle.render();
shared.buttons.b_movetopoint.render();
shared.buttons.b_makestaticbutton.render();
};
if (movePoint){
shared.buttons.b_cancelbutton.render();
shared.textTyper.drawText("SELECT SPOT FOR PEG TO MOVE TO", 210, 67, shared.textTyper.MICRO16);
};
if (moveCircle){
shared.buttons.b_cancelbutton.render();
shared.textTyper.drawText("SELECT SPOT FOR PEG TO ROTATE AROUND", 180, 67, shared.textTyper.MICRO16);
};
};
i++;
};
}
public function loadCustom():void{
var coordinate:Number;
level = new Array();
levelProps = new Array();
undo = new Array();
var dddcount:int;
coordinate = 0;
var flipper:int;
coordinate = 0;
}
override public function Render(){
shared.images.i_sky.render(null, true, new Matrix(1, 0, 0, 1, 87, 6));
shared.images.i_player.render(null, true, new Matrix(1, 0, 0, 1, 328, 15));
shared.images.i_interface.render(null, true);
shared.images.i_dotted.render(null, true, new Matrix(1, 0, 0, 1, 90, 50));
shared.images.i_bluepeg.render(null, true, new Matrix(1, 0, 0, 1, 10, 50));
shared.images.i_bluerectpeg.render(null, true, new Matrix(1, 0, 0, 1, 35, 45));
shared.images.i_bluerectpeg2.render(null, true, new Matrix(1, 0, 0, 1, 55, 52));
DrawPegs();
shared.buttons.b_save.render();
shared.buttons.b_load.render();
shared.buttons.b_back.render();
if (cursor != 5){
shared.buttons.b_undo.render();
};
shared.buttons.b_clear.render();
shared.buttons.b_props.render();
shared.images.i_eraser.render(null, true, new Matrix(1, 0, 0, 1, 50, 92));
shared.images.i_selection.render(null, true, new Matrix(1, 0, 0, 1, 12, 86));
shared.buttons.b_testbutton.render();
DrawCursorSymbol();
if (loadMenu > 0){
shared.buttons.b_load.renderDownImage();
shared.images.i_dropmenu.render(null, true, new Matrix(1, 0, 0, 1, loadMenu, 57), new ColorTransform(1, 1, 1, (1 - ((1 / 697) * (loadMenu - 97)))));
if (loadMenu == 97){
text.visible = true;
shared.buttons.b_cancelbutton2.render();
shared.buttons.b_ok.render();
shared.textTyper.ChangeColor(0xFFFFFF);
shared.textTyper.drawText("PASTE LEVEL CODE HERE", 112, 66, shared.textTyper.MICRO16);
};
return;
};
if (propsMenu > 0){
shared.images.i_dropmenu.render(null, true, new Matrix(1, 0, 0, 1, propsMenu, 57), new ColorTransform(1, 1, 1, (1 - ((1 / 697) * (propsMenu - 97)))));
if (propsMenu == 97){
shared.buttons.b_cancelbutton2.render();
shared.images.i_trianglerotate.render(null, true, new Matrix(1, 0, 0, 1, 119, 183));
shared.images.i_speedball.render(null, true, new Matrix(1, 0, 0, 1, 119, 83));
shared.images.i_slider.render(null, true, new Matrix(1, 0, 0, 1, 175, 83));
shared.images.i_slider2.render(null, true, new Matrix(1, 0, 0, 1, 300, 83));
shared.images.i_bigbox.render(null, true, new Matrix(1, 0, 0, 1, 450, 83));
shared.images.i_rotating.render(null, true, new Matrix(1, 0, 0, 1, 200, 200));
shared.images.i_rotatingcross.render(null, true, new Matrix(1, 0, 0, 1, 390, 230));
shared.images.i_anchor.render(null, true, new Matrix(1, 0, 0, 1, (500 - 6), (250 - 6)), new ColorTransform(1, 1, 1, 0.75));
shared.drawDottedLine(500, 250, 500, (250 + 45));
shared.images.i_ballchain.render(null, true, new Matrix(1, 0, 0, 1, (500 - 15), ((250 + 45) - 15)), new ColorTransform(1, 1, 1, 0.75));
shared.images.i_bigrectangle.render(null, true, new Matrix(1, 0, 0, 1, 540, 227), new ColorTransform(1, 1, 1, 0.75));
shared.images.i_smallsquare.render(null, true, new Matrix(1, 0, 0, 1, 119, 300), new ColorTransform(1, 1, 1, 0.75));
shared.images.i_magicbox.render(null, true, new Matrix(1, 0, 0, 1, 200, 300), new ColorTransform(1, 1, 1, 0.75));
shared.images.i_magicbox2.render(null, true, new Matrix(1, 0, 0, 1, 300, 300), new ColorTransform(1, 1, 1, 0.75));
};
return;
};
if (saveMenu > 0){
shared.images.i_dropmenu.render(null, true, new Matrix(1, 0, 0, 1, saveMenu, 57), new ColorTransform(1, 1, 1, (1 - ((1 / 697) * (saveMenu - 97)))));
shared.buttons.b_save.renderDownImage();
if (saveMenu == 97){
shared.buttons.b_cancelbutton2.render();
shared.buttons.b_ok.render();
text.visible = true;
text.text = levelCode;
shared.buttons.b_copy.render();
shared.textTyper.ChangeColor(0xFFFFFF);
shared.textTyper.drawText("COPY THE LEVEL CODE", 112, 66, shared.textTyper.MICRO16);
};
return;
};
if ((((shared.input.mousey > 50)) && ((shared.input.mousey < (413 - 20))))){
if ((((shared.input.mousex > 98)) && ((shared.input.mousex < (538 + 88))))){
switch (cursor){
case 0:
shared.images.i_bluepeg.render(null, true, new Matrix(1, 0, 0, 1, (shared.input.mousex - 7), (shared.input.mousey - 7)), new ColorTransform(1, 1, 1, 0.75));
break;
case 1:
shared.images.i_bluerectpeg.render(null, true, new Matrix(1, 0, 0, 1, (shared.input.mousex - 7), (shared.input.mousey - 7)), new ColorTransform(1, 1, 1, 0.75));
break;
case 2:
shared.images.i_bluerectpeg2.render(null, true, new Matrix(1, 0, 0, 1, (shared.input.mousex - 7), (shared.input.mousey - 7)), new ColorTransform(1, 1, 1, 0.75));
break;
case 3:
Mouse.hide();
if (shared.nextGamestate == shared.GAME){
Mouse.show();
};
shared.images.i_eraser.render(null, true, new Matrix(1, 0, 0, 1, shared.input.mousex, shared.input.mousey));
break;
case 4:
shared.images.i_speedball.render(null, true, new Matrix(1, 0, 0, 1, (shared.input.mousex - 7), (shared.input.mousey - 7)), new ColorTransform(1, 1, 1, 0.75));
break;
case 5:
if (movePoint){
shared.drawDottedLine((level[selected].x + 7), (level[selected].y + 7), shared.input.mousex, shared.input.mousey);
switch (level[selected].type){
case 0:
shared.images.i_bluepeg.render(null, true, new Matrix(1, 0, 0, 1, (shared.input.mousex - 7), (shared.input.mousey - 7)), new ColorTransform(1, 1, 1, 0.75));
break;
case 1:
shared.images.i_bluerectpeg.render(null, true, new Matrix(1, 0, 0, 1, (shared.input.mousex - 7), (shared.input.mousey - 7)), new ColorTransform(1, 1, 1, 0.75));
break;
case 2:
shared.images.i_bluerectpeg2.render(null, true, new Matrix(1, 0, 0, 1, (shared.input.mousex - 7), (shared.input.mousey - 7)), new ColorTransform(1, 1, 1, 0.75));
break;
};
};
if (moveCircle){
shared.drawCircle((level[selected].x + 7), (level[selected].y + 7), shared.input.mousex, shared.input.mousey);
shared.drawDottedLine((level[selected].x + 7), (level[selected].y + 7), shared.input.mousex, shared.input.mousey);
};
break;
case 6:
shared.images.i_slider.render(null, true, new Matrix(1, 0, 0, 1, (shared.input.mousex - 7), (shared.input.mousey - 7)), new ColorTransform(1, 1, 1, 0.75));
break;
case 7:
shared.images.i_slider2.render(null, true, new Matrix(1, 0, 0, 1, (shared.input.mousex - 7), (shared.input.mousey - 7)), new ColorTransform(1, 1, 1, 0.75));
break;
case 8:
shared.images.i_bigbox.render(null, true, new Matrix(1, 0, 0, 1, (shared.input.mousex - 7), (shared.input.mousey - 7)), new ColorTransform(1, 1, 1, 0.75));
break;
case 9:
shared.images.i_trianglerotate.render(null, true, new Matrix(1, 0, 0, 1, (shared.input.mousex - 7), (shared.input.mousey - 7)), new ColorTransform(1, 1, 1, 0.75));
break;
case 10:
shared.images.i_rotating.render(null, true, new Matrix(1, 0, 0, 1, ((shared.input.mousex - 7) - 60), ((shared.input.mousey - 6) - 7)), new ColorTransform(1, 1, 1, 0.75));
break;
case 11:
shared.images.i_rotatingcross.render(null, true, new Matrix(1, 0, 0, 1, ((shared.input.mousex - 7) - 21), ((shared.input.mousey - 21) - 7)), new ColorTransform(1, 1, 1, 0.75));
break;
case 12:
shared.images.i_anchor.render(null, true, new Matrix(1, 0, 0, 1, ((shared.input.mousex - 7) - 6), ((shared.input.mousey - 6) - 7)), new ColorTransform(1, 1, 1, 0.75));
shared.drawDottedLine((shared.input.mousex - 7), (shared.input.mousey - 7), (shared.input.mousex - 7), ((shared.input.mousey - 7) + 45));
shared.images.i_ballchain.render(null, true, new Matrix(1, 0, 0, 1, ((shared.input.mousex - 7) - 15), (((shared.input.mousey - 7) + 45) - 15)), new ColorTransform(1, 1, 1, 0.75));
break;
case 13:
shared.images.i_bigrectangle.render(null, true, new Matrix(1, 0, 0, 1, (shared.input.mousex - 7), (shared.input.mousey - 7)), new ColorTransform(1, 1, 1, 0.75));
break;
case 14:
shared.images.i_smallsquare.render(null, true, new Matrix(1, 0, 0, 1, (shared.input.mousex - 7), (shared.input.mousey - 7)), new ColorTransform(1, 1, 1, 0.75));
break;
case 15:
shared.images.i_magicbox.render(null, true, new Matrix(1, 0, 0, 1, (shared.input.mousex - 7), (shared.input.mousey - 7)), new ColorTransform(1, 1, 1, 0.75));
break;
case 16:
shared.images.i_magicbox2.render(null, true, new Matrix(1, 0, 0, 1, (shared.input.mousex - 7), (shared.input.mousey - 7)), new ColorTransform(1, 1, 1, 0.75));
break;
};
shared.textTyper.drawText(((("x:" + shared.input.mousex.toString()) + " y:") + shared.input.mousey.toString()), (574 - 50), (461 - 25), shared.textTyper.MICRO16);
};
};
if (!(((((((shared.input.mousey > 50)) && ((shared.input.mousey < (413 - 20))))) && ((shared.input.mousex > 98)))) && ((shared.input.mousex < (538 + 88))))){
Mouse.show();
};
shared.textTyper.ChangeColor(0);
}
}
}//package
Section 281
//LevelPreviewer (LevelPreviewer)
package {
import flash.display.*;
import flash.geom.*;
public class LevelPreviewer {
public var gameData:GameData;
public var previewBitmap:Bitmap;
public var pegs:Array;
private var shared:SharedData;
public var props:Array;
public function LevelPreviewer(){
gameData = GameData.getInstance();
pegs = new Array();
props = new Array();
super();
previewBitmap = new Bitmap();
previewBitmap.bitmapData = new BitmapData(640, 480, true);
}
public function drawRectPeg2(i:int){
if (gameData.lvlPreviewArray[i].color == 0){
if (gameData.lvlPreviewArray[i].alive == 1){
shared.images.i_bluerectpeg2.renderToBitmap(previewBitmap, null, true, new Matrix(1, 0, 0, 1, ((gameData.lvlPreviewArray[i].x - 8) - 2), (gameData.lvlPreviewArray[i].y - 7)));
} else {
if (gameData.lvlPreviewArray[i].alive == 0){
shared.images.i_bluerectpeghighlighted2.renderToBitmap(previewBitmap, null, true, new Matrix(1, 0, 0, 1, ((gameData.lvlPreviewArray[i].x - 8) - 4), ((gameData.lvlPreviewArray[i].y - 4) - 12)));
};
};
} else {
if (gameData.lvlPreviewArray[i].alive == 1){
shared.images.i_redrectpeg2.renderToBitmap(previewBitmap, null, true, new Matrix(1, 0, 0, 1, ((gameData.lvlPreviewArray[i].x - 8) - 2), (gameData.lvlPreviewArray[i].y - 7)));
} else {
if (gameData.lvlPreviewArray[i].alive == 0){
shared.images.i_redrectpeghighlighted2.renderToBitmap(previewBitmap, null, true, new Matrix(1, 0, 0, 1, (((gameData.lvlPreviewArray[i].x - 8) - 4) - 4), ((gameData.lvlPreviewArray[i].y - 4) - 8)));
};
};
};
}
public function drawSpeedBall(i:int){
if (gameData.lvlPreviewArray[i].alive != 2){
shared.images.i_speedball.renderToBitmap(previewBitmap, null, true, new Matrix(1, 0, 0, 1, gameData.lvlPreviewArray[i].x, gameData.lvlPreviewArray[i].y));
};
}
public function drawSlider1(i:int){
if (gameData.lvlPreviewArray[i].alive != 2){
shared.images.i_slider.renderToBitmap(previewBitmap, null, true, new Matrix(1, 0, 0, 1, gameData.lvlPreviewArray[i].x, gameData.lvlPreviewArray[i].y));
};
}
public function drawSmallSquare(i:int){
if (gameData.lvlPreviewArray[i].alive != 2){
shared.images.i_smallsquare.renderToBitmap(previewBitmap, null, true, new Matrix(1, 0, 0, 1, gameData.lvlPreviewArray[i].x, gameData.lvlPreviewArray[i].y));
};
}
public function convertCodeToItem(code:String):Peg{
var decimalCode = (convertLetterTo6BitCode(code.charAt(0)) << 18);
decimalCode = (decimalCode + (convertLetterTo6BitCode(code.charAt(1)) << 12));
decimalCode = (decimalCode + (convertLetterTo6BitCode(code.charAt(2)) << 6));
decimalCode = (decimalCode + (convertLetterTo6BitCode(code.charAt(3)) << 0));
var peg:Peg = new Peg(null, 100, 100, 0);
peg.x = ((decimalCode >> 14) + 91);
peg.y = (((decimalCode - ((decimalCode >> 14) << 14)) >> 5) + 52);
peg.type = (decimalCode - ((decimalCode >> 5) << 5));
return (peg);
}
public function drawBigBox(i:int){
if (gameData.lvlPreviewArray[i].alive != 2){
shared.images.i_bigbox.renderToBitmap(previewBitmap, null, true, new Matrix(1, 0, 0, 1, gameData.lvlPreviewArray[i].x, gameData.lvlPreviewArray[i].y));
};
}
public function drawSlider2(i:int){
if (gameData.lvlPreviewArray[i].alive != 2){
shared.images.i_slider2.renderToBitmap(previewBitmap, null, true, new Matrix(1, 0, 0, 1, gameData.lvlPreviewArray[i].x, gameData.lvlPreviewArray[i].y));
};
}
public function convertLetterTo6BitCode(char:String):int{
if (char.charCodeAt(0) == new String("#").charCodeAt(0)){
return (63);
};
if (char.charCodeAt(0) == new String("@").charCodeAt(0)){
return (62);
};
if (char.charCodeAt(0) >= 97){
return ((char.charCodeAt(0) - 97));
};
if (char.charCodeAt(0) >= 65){
return (((char.charCodeAt(0) - 65) + 26));
};
if (char.charCodeAt(0) >= 48){
return (((char.charCodeAt(0) - 48) + 52));
};
return (0);
}
public function LoadLevel2(chosenLevel:int):Array{
var i:int;
var codeString:String;
var firstPeg:Peg;
var secondPeg:Peg;
var level:Array = new Array();
var codeToLoad:String = shared.gamestate[shared.GAME].physicsGame.level.levelsCode[chosenLevel];
var levelcode2:String = codeToLoad.substring(0, codeToLoad.search("\\$"));
var pegs:int = (levelcode2.length / 4);
i = 0;
while (i < pegs) {
codeString = levelcode2.slice(0, 4);
levelcode2 = levelcode2.slice(4, levelcode2.length);
level[i] = convertCodeToItem(codeString);
i++;
};
var sideToSidePegs:String = codeToLoad.substring((codeToLoad.search("\\$") + 1));
sideToSidePegs = sideToSidePegs.substring(0, sideToSidePegs.search("\\$"));
var sidePegsCount:int = (sideToSidePegs.length / 8);
i = 0;
while (i < sidePegsCount) {
codeString = sideToSidePegs.slice(0, 4);
sideToSidePegs = sideToSidePegs.slice(4, sideToSidePegs.length);
firstPeg = convertCodeToItem(codeString);
codeString = sideToSidePegs.slice(0, 4);
sideToSidePegs = sideToSidePegs.slice(4, sideToSidePegs.length);
secondPeg = convertCodeToItem(codeString);
level[(i + pegs)] = new Peg(null, firstPeg.x, firstPeg.y, 0, firstPeg.type, secondPeg.x, secondPeg.y);
level[(i + pegs)].moveType = 1;
i++;
};
var circlingPegs:String = codeToLoad.substring((codeToLoad.search("\\$") + 1));
circlingPegs = circlingPegs.substring((circlingPegs.search("\\$") + 1));
var circlingPegsCount:int = (circlingPegs.length / 8);
i = 0;
while (i < circlingPegsCount) {
codeString = circlingPegs.slice(0, 4);
circlingPegs = circlingPegs.slice(4, circlingPegs.length);
firstPeg = convertCodeToItem(codeString);
codeString = circlingPegs.slice(0, 4);
circlingPegs = circlingPegs.slice(4, circlingPegs.length);
secondPeg = convertCodeToItem(codeString);
level[((sidePegsCount + i) + pegs)] = new Peg(null, firstPeg.x, firstPeg.y, 0, firstPeg.type, secondPeg.x, secondPeg.y);
level[((sidePegsCount + i) + pegs)].moveType = 2;
i++;
};
return (level);
}
public function LoadLevel(chosenLevel:int){
var level:Array = new Array();
gameData.lvlPreviewArray = LoadLevel2(chosenLevel);
var i:int;
while (i < gameData.lvlPreviewArray.length) {
gameData.lvlPreviewArray[i].updateRef(pegs[i]);
i++;
};
}
public function load(chosenLevel:int){
LoadLevel(chosenLevel);
}
public function drawTriangleRotate(i:int){
var propMatrix:Matrix;
if (gameData.lvlPreviewArray[i].alive != 2){
propMatrix = new Matrix(1, 0, 0, 1, 0, 0);
shared.images.i_trianglerotate.renderToBitmap(previewBitmap, null, true, new Matrix(1, 0, 0, 1, gameData.lvlPreviewArray[i].x, gameData.lvlPreviewArray[i].y));
};
}
public function drawRectPeg(i:int){
if (gameData.lvlPreviewArray[i].color == 0){
if (gameData.lvlPreviewArray[i].alive == 1){
shared.images.i_bluerectpeg.renderToBitmap(previewBitmap, null, true, new Matrix(1, 0, 0, 1, ((gameData.lvlPreviewArray[i].x - 8) + 2), ((gameData.lvlPreviewArray[i].y - 7) - 2)));
} else {
if (gameData.lvlPreviewArray[i].alive == 0){
shared.images.i_bluerectpeghighlighted.renderToBitmap(previewBitmap, null, true, new Matrix(1, 0, 0, 1, ((gameData.lvlPreviewArray[i].x - 8) - 3), (((gameData.lvlPreviewArray[i].y - 4) - 7) - 3)));
};
};
} else {
if (gameData.lvlPreviewArray[i].alive == 1){
shared.images.i_redrectpeg.renderToBitmap(previewBitmap, null, true, new Matrix(1, 0, 0, 1, ((gameData.lvlPreviewArray[i].x - 8) + 2), ((gameData.lvlPreviewArray[i].y - 7) - 2)));
} else {
if (gameData.lvlPreviewArray[i].alive == 0){
shared.images.i_redrectpeghighlighted.renderToBitmap(previewBitmap, null, true, new Matrix(1, 0, 0, 1, ((gameData.lvlPreviewArray[i].x - 8) - 3), (((gameData.lvlPreviewArray[i].y - 4) - 7) - 3)));
};
};
};
}
public function drawBells(i:int){
if (gameData.lvlPreviewArray[i].alive != 2){
shared.images.i_anchor.renderToBitmap(previewBitmap, null, true, new Matrix(1, 0, 0, 1, (gameData.lvlPreviewArray[i].x + 7), (gameData.lvlPreviewArray[i].y - 25)));
shared.drawDottedLine((gameData.lvlPreviewArray[i].x + 7), (gameData.lvlPreviewArray[i].y - 25), gameData.lvlPreviewArray[i].x, gameData.lvlPreviewArray[i].y);
shared.images.i_ballchain.renderToBitmap(previewBitmap, null, true, new Matrix(1, 0, 0, 1, gameData.lvlPreviewArray[i].x, gameData.lvlPreviewArray[i].y));
};
}
public function paint():void{
var i:int;
var propMatrix:Matrix;
previewBitmap = new Bitmap();
previewBitmap.bitmapData = new BitmapData(640, 480, true);
shared.images.i_sky.renderToBitmap(previewBitmap, null, true, new Matrix((640 / 547), 0, 0, (480 / 467), 0, 0));
i = 0;
while (i < gameData.lvlPreviewArray.length) {
switch (gameData.lvlPreviewArray[i].type){
case 0:
drawCirclePeg(i);
break;
case 1:
drawRectPeg(i);
break;
case 2:
drawRectPeg2(i);
break;
case 4:
drawSpeedBall(i);
break;
case 6:
drawSlider1(i);
break;
case 7:
drawSlider2(i);
break;
case 8:
drawBigBox(i);
break;
case 9:
drawTriangleRotate(i);
break;
case 10:
drawRotating(i);
break;
case 11:
drawStar(i);
break;
case 12:
drawBells(i);
break;
case 13:
drawBigRectangle(i);
break;
case 14:
drawSmallSquare(i);
break;
case 15:
drawMagicBox1(i);
break;
case 16:
drawMagicBox2(i);
break;
};
i++;
};
i = 0;
while (i < props.length) {
propMatrix = new Matrix(1, 0, 0, 1, 0, 0);
propMatrix.rotate(props[i].m_rotation);
propMatrix.translate(props[i].m_position.x, props[i].m_position.y);
shared.images.i_triangle.renderToBitmap(previewBitmap, null, true, propMatrix);
i++;
};
}
public function drawMagicBox1(i:int){
if (gameData.lvlPreviewArray[i].alive != 2){
shared.images.i_magicbox.renderToBitmap(previewBitmap, null, true, new Matrix(1, 0, 0, 1, gameData.lvlPreviewArray[i].x, gameData.lvlPreviewArray[i].y));
};
}
public function drawStar(i:int){
if (gameData.lvlPreviewArray[i].alive != 2){
shared.images.i_rotatingcross.renderToBitmap(previewBitmap, null, true, new Matrix(1, 0, 0, 1, (gameData.lvlPreviewArray[i].x - 21), (gameData.lvlPreviewArray[i].y - 21)));
};
}
public function drawMagicBox2(i:int){
if (gameData.lvlPreviewArray[i].alive != 2){
shared.images.i_magicbox2.renderToBitmap(previewBitmap, null, true, new Matrix(1, 0, 0, 1, gameData.lvlPreviewArray[i].x, gameData.lvlPreviewArray[i].y));
};
}
public function drawBigRectangle(i:int){
if (gameData.lvlPreviewArray[i].alive != 2){
shared.images.i_bigrectangle.renderToBitmap(previewBitmap, null, true, new Matrix(1, 0, 0, 1, gameData.lvlPreviewArray[i].x, gameData.lvlPreviewArray[i].y));
};
}
public function drawRotating(i:int){
var propMatrix:Matrix;
if (gameData.lvlPreviewArray[i].alive != 2){
propMatrix = new Matrix(1, 0, 0, 1, 0, 0);
shared.images.i_rotating.renderToBitmap(previewBitmap, null, true, new Matrix(1, 0, 0, 1, (gameData.lvlPreviewArray[i].x - 60), gameData.lvlPreviewArray[i].y));
};
}
public function drawCirclePeg(i:int){
if (gameData.lvlPreviewArray[i].color == 0){
if (gameData.lvlPreviewArray[i].alive == 1){
shared.images.i_bluepeg.renderToBitmap(previewBitmap, null, true, new Matrix(1, 0, 0, 1, (gameData.lvlPreviewArray[i].x - 8), (gameData.lvlPreviewArray[i].y - 7)));
} else {
if (gameData.lvlPreviewArray[i].alive == 0){
shared.images.i_bluepeghighlighted.renderToBitmap(previewBitmap, null, true, new Matrix(1, 0, 0, 1, ((gameData.lvlPreviewArray[i].x - 8) - 4), ((gameData.lvlPreviewArray[i].y - 4) - 7)));
};
};
} else {
if (gameData.lvlPreviewArray[i].alive == 1){
shared.images.i_redpeg.renderToBitmap(previewBitmap, null, true, new Matrix(1, 0, 0, 1, (gameData.lvlPreviewArray[i].x - 8), (gameData.lvlPreviewArray[i].y - 7)));
} else {
if (gameData.lvlPreviewArray[i].alive == 0){
shared.images.i_redpeghighlighted.renderToBitmap(previewBitmap, null, true, new Matrix(1, 0, 0, 1, ((gameData.lvlPreviewArray[i].x - 8) - 5), ((gameData.lvlPreviewArray[i].y - 5) - 7)));
};
};
};
}
public function linkShared(s:SharedData){
shared = s;
}
}
}//package
Section 282
//LoadLevel (LoadLevel)
package {
import flash.geom.*;
import flash.text.*;
import com.hexagonstar.util.debug.*;
import mochi.*;
public class LoadLevel extends Module {
public var boxPoint:int;// = 0
public var scrollbarBoxRect:Rectangle;
public var pageUpRect:Rectangle;
public var scrollDown:Number;// = 0
public var highscoresText:Array;
public var levelPreviewer:LevelPreviewer;
public var pageDownRect:Rectangle;
public var highscoresTextScores:Array;
public var scrollbarBoxHeld:Boolean;// = false
private var list:Object;
public var bottomScrollBarRect:Rectangle;
private var loadMenu:int;// = 0
public var scrollbar:int;// = 0
public var drawBox1:int;// = 0
public var drawBox2:int;// = 0
private var text:TextField;
public var chosenLevel:int;// = 0
public var topScrollBarRect:Rectangle;
public var gameData:GameData;
public function LoadLevel(){
gameData = GameData.getInstance();
super();
}
public function UpdateScores(){
if (chosenLevel != 0){
MochiScores.setBoardID(gameData.highscores.getLevelCode((chosenLevel - 1)));
MochiScores.requestList(this, "DoneLoading");
} else {
highscoresText = new Array();
highscoresTextScores = new Array();
};
}
override public function onNextFrame(delta:Number):void{
Process();
Render();
}
override public function Process(){
var i:int;
scrollDown = (scrollDown - 1);
shared.sounds.StopMusic();
scrollbarBoxRect.y = (52 + scrollbar);
pageDownRect.y = ((52 + scrollbar) + 88);
pageDownRect.height = ((353 - 88) - scrollbar);
pageUpRect.y = 52;
pageUpRect.height = scrollbar;
if (loadMenu > 0){
loadMenu = (loadMenu - 25);
if (loadMenu <= 97){
loadMenu = 97;
shared.buttons.b_cancelbutton2.process(shared);
if (shared.buttons.b_cancelbutton2.isClicked()){
loadMenu = 0;
text.visible = false;
};
shared.buttons.b_ok.process(shared);
if (shared.buttons.b_ok.isClicked()){
loadMenu = 0;
text.visible = false;
gameData.physicsGame.level.testLevel = text.text;
gameData.testing = true;
gameData.customLevel = true;
gameData.whatLevel = 0;
gameData.initNewGame();
shared.nextGamestate = shared.GAME;
};
};
return;
};
if (shared.input.mouseWheel > 0){
i = 0;
while (i < (shared.input.mouseWheel / 3)) {
if (scrollbar >= 5){
scrollbar = (scrollbar - 5);
} else {
scrollbar = 0;
};
i++;
};
};
if (shared.input.mouseWheel < 0){
i = 0;
while (i < (Math.abs(shared.input.mouseWheel) / 3)) {
if (scrollbar <= ((353 - 88) - 5)){
scrollbar = (scrollbar + 5);
} else {
scrollbar = (353 - 88);
};
i++;
};
};
if (((shared.input.mouseToggle) && (topScrollBarRect.contains(shared.input.mousex, shared.input.mousey)))){
if (scrollbar >= 5){
scrollbar = (scrollbar - 5);
} else {
scrollbar = 0;
};
};
if (((shared.input.mouseToggle) && (bottomScrollBarRect.contains(shared.input.mousex, shared.input.mousey)))){
if (scrollbar <= ((353 - 88) - 5)){
scrollbar = (scrollbar + 5);
} else {
scrollbar = (353 - 88);
};
};
if (((shared.input.mouseToggle) && (pageDownRect.contains(shared.input.mousex, shared.input.mousey)))){
if (scrollbar <= (253 - 88)){
scrollbar = (scrollbar + 100);
} else {
if (scrollbar <= (353 - 88)){
scrollbar = (353 - 88);
};
};
};
if (((shared.input.mouseToggle) && (pageUpRect.contains(shared.input.mousex, shared.input.mousey)))){
if (scrollbar >= 100){
scrollbar = (scrollbar - 100);
} else {
if (scrollbar >= 0){
scrollbar = 0;
};
};
};
if (((shared.input.mouseToggle) && (scrollbarBoxRect.contains(shared.input.mousex, shared.input.mousey)))){
scrollbarBoxHeld = true;
boxPoint = ((shared.input.mousey - scrollbar) - 52);
};
if (!shared.input.mouseDown){
scrollbarBoxHeld = false;
};
if (scrollbarBoxHeld){
if (shared.input.mouseDown){
scrollbar = ((shared.input.mousey - 52) - boxPoint);
if (scrollbar < 0){
scrollbar = 0;
};
if (scrollbar > (353 - 88)){
scrollbar = (353 - 88);
};
};
};
if (((shared.input.mouseToggle) && (pageUpRect.contains(shared.input.mousex, shared.input.mousey)))){
drawBox1 = 2;
};
if (((shared.input.mouseToggle) && (pageDownRect.contains(shared.input.mousex, shared.input.mousey)))){
drawBox2 = 2;
};
shared.buttons.b_leveleditorbutton.process(shared);
if (shared.buttons.b_leveleditorbutton.isClicked()){
shared.nextGamestate = shared.LEVELEDITOR;
};
shared.buttons.b_loadcustombutton.process(shared);
if (shared.buttons.b_loadcustombutton.isClicked()){
loadMenu = 600;
text.text = "";
};
shared.buttons.b_loadlevelbutton.process(shared);
if (((shared.buttons.b_loadlevelbutton.isClicked()) && (gameData.savedata.completedLevels[chosenLevel]))){
gameData.whatLevel = chosenLevel;
gameData.initNewGame();
shared.nextGamestate = shared.GAME;
};
if (shared.input.mouseToggle){
i = 0;
while (i < 46) {
if (new Rectangle(31, (((39 + (i * 20)) - (scrollbar * 3)) - 2), 122, 19).contains(shared.input.mousex, shared.input.mousey)){
chosenLevel = i;
levelPreviewer.load(chosenLevel);
levelPreviewer.paint();
shared.images.levelPreview.bitmap = levelPreviewer.previewBitmap;
UpdateScores();
};
i++;
};
};
}
override public function Init(){
highscoresText = new Array();
highscoresTextScores = new Array();
list = new Object();
text = new TextField();
text.text = "paste level code here";
text.background = true;
text.border = true;
text.x = (99 + 10);
text.y = (75 + 10);
text.width = (523 - 20);
text.height = (337 - 20);
shared.frontLayer.addChild(text);
text.type = TextFieldType.INPUT;
text.wordWrap = true;
text.visible = false;
levelPreviewer = new LevelPreviewer();
levelPreviewer.linkShared(shared);
levelPreviewer.load(0);
levelPreviewer.paint();
shared.images.levelPreview.bitmap = levelPreviewer.previewBitmap;
topScrollBarRect = new Rectangle(154, 29, 23, 23);
bottomScrollBarRect = new Rectangle(154, 407, 23, 23);
scrollbarBoxRect = new Rectangle(153, 52, 23, 88);
pageDownRect = new Rectangle(153, (52 + 23), 23, (351 - 88));
pageUpRect = new Rectangle(153, 52, 23, 0);
}
public function DoneLoading(args:Object){
scrollDown = 150;
var newScores:Object = MochiScores.scoresArrayToObjects(args.scores);
highscoresText = new Array();
highscoresTextScores = new Array();
var i:int;
while (i < newScores.daily.length) {
highscoresText[i] = new String(newScores.daily[i].name);
highscoresTextScores[i] = new String(newScores.daily[i].score);
i++;
};
}
override public function Render(){
var i:int;
shared.images.i_loadlevel.render(null, true, new Matrix(1, 0, 0, 1, 0, 0));
shared.images.i_scrollbarBox2.render(null, true, new Matrix(1, 0, 0, 1, 154, (52 + scrollbar)));
i = 0;
while (i < 46) {
if ((((((39 + (i * 20)) - (scrollbar * 3)) > 480)) || ((((39 + (i * 20)) - (scrollbar * 3)) < 0)))){
} else {
if (chosenLevel == i){
shared.images.i_highlight.render(null, false);
shared.images.i_highlight.x = 31;
shared.images.i_highlight.y = ((39 + (i * 20)) - (scrollbar * 3));
};
if (i == 0){
shared.textTyper.drawText("TUTORIAL", 47, ((39 + (i * 20)) - (scrollbar * 3)), shared.textTyper.MICRO16);
} else {
if (gameData.savedata.completedLevels[i]){
shared.textTyper.drawText(("LEVEL " + i.toString()), 47, ((39 + (i * 20)) - (scrollbar * 3)), shared.textTyper.MICRO16);
} else {
shared.textTyper.ChangeColor(0);
shared.textTyper.drawText(("LEVEL " + i.toString()), 47, ((39 + (i * 20)) - (scrollbar * 3)), shared.textTyper.MICRO16);
shared.textTyper.ChangeColor(0xFFFFFF);
};
};
};
i++;
};
if (drawBox1 > 0){
drawBox1--;
shared.screen.bitmapData.fillRect(new Rectangle(155, 53, 21, (scrollbar - 2)), 4288059051);
};
if (drawBox2 > 0){
drawBox2--;
shared.screen.bitmapData.fillRect(new Rectangle(155, ((53 + 88) + scrollbar), 21, ((353 - 88) - scrollbar)), 4288059051);
};
shared.images.i_scrollbarbottom.render(null, true, new Matrix(1, 0, 0, 1, 31, 430));
shared.images.i_scrollbartop.render(null, true, new Matrix(1, 0, 0, 1, 31, 0));
shared.buttons.b_leveleditorbutton.render();
shared.buttons.b_loadcustombutton.render();
shared.buttons.b_loadlevelbutton.render();
shared.textTyper.ChangeColor(15592959);
shared.textTyper.drawText("CHOOSE LEVEL", 264, 5, shared.textTyper.MICRO16);
shared.textTyper.ChangeColor(0xFFFFFF);
if (chosenLevel == 0){
shared.images.i_filler.render(null, true, new Matrix(1, 0, 0, 1, 180, 285));
};
if ((((highscoresText.length == 0)) && (!((chosenLevel == 0))))){
shared.textTyper.drawText2("NONE", 200, 313, shared.textTyper.LEVELFONT, 5);
};
i = 0;
while (i < highscoresText.length) {
if (((313 + (i * 20)) + scrollDown) < 311){
} else {
if (((313 + (i * 20)) + scrollDown) > 420){
} else {
shared.textTyper.drawText2(((i + 1).toString() + "."), 200, ((313 + (i * 20)) + scrollDown), shared.textTyper.LEVELFONT, 5);
shared.textTyper.drawText2(highscoresText[i], (200 + 20), ((313 + (i * 20)) + scrollDown), shared.textTyper.LEVELFONT, 5);
shared.textTyper.drawText2(highscoresTextScores[i], (200 + 300), ((313 + (i * 20)) + scrollDown), shared.textTyper.LEVELFONT, 5);
};
};
i++;
};
if (((313 + ((highscoresText.length - 1) * 20)) + scrollDown) < 300){
scrollDown = 150;
};
shared.images.levelPreview.render(null, true, new Matrix((320 / 640), 0, 0, (240 / 480), (267 - 45), 39), null, null, new Rectangle(267, 0, (640 - 91), 480));
if (loadMenu > 0){
shared.images.i_dropmenu.render(null, true, new Matrix(1, 0, 0, 1, loadMenu, 57), new ColorTransform(1, 1, 1, (1 - ((1 / 697) * (loadMenu - 97)))));
if (loadMenu == 97){
text.visible = true;
shared.buttons.b_cancelbutton2.render();
shared.buttons.b_ok.render();
shared.textTyper.ChangeColor(0xFFFFFF);
shared.textTyper.drawText("PASTE LEVEL CODE HERE", 112, 66, shared.textTyper.MICRO16);
};
};
}
}
}//package
Section 283
//MainMenu (MainMenu)
package {
public class MainMenu extends Module {
public function MainMenu(){
super();
}
override public function Init(){
}
override public function onNextFrame(delta:Number):void{
Process();
Render();
}
override public function Render(){
}
override public function Process(){
}
}
}//package
Section 284
//MochiAd (MochiAd)
package {
import flash.events.*;
import flash.display.*;
import flash.utils.*;
import flash.system.*;
import flash.net.*;
public class MochiAd {
public function MochiAd(){
super();
}
public static function getVersion():String{
return ("2.3");
}
public static function showTimedAd(options:Object):void{
trace("[MochiAd] DEPRECATED: showTimedAd was renamed to showInterLevelAd in 2.0");
MochiAd.showInterLevelAd(options);
}
public static function _allowDomains(server:String):String{
var hostname:String = server.split("/")[2].split(":")[0];
Security.allowDomain("*");
Security.allowDomain(hostname);
Security.allowInsecureDomain("*");
Security.allowInsecureDomain(hostname);
return (hostname);
}
public static function load(options:Object):MovieClip{
var clip:Object;
var mc:MovieClip;
var k:String;
var server:String;
var hostname:String;
var lc:LocalConnection;
var name:String;
var loader:Loader;
var f:Function;
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;
mc = 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;
};
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;
lv.lc = name;
lv.st = getTimer();
loader = new Loader();
f = function (ev:Object):void{
ev.target.removeEventListener(ev.type, arguments.callee);
mc._mochiad_ctr_failed = true;
};
loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, f);
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"));
req.contentType = "application/x-www-form-urlencoded";
req.method = URLRequestMethod.POST;
req.data = lv;
loader.load(req);
mc.addChild(loader);
mc._mochiad_ctr = loader;
return (mc);
}
public static function sendHighScore(options:Object, callbackObj:Object, callbackMethod:Object=null):Boolean{
var lc:MovieClip = MochiAd._loadCommunicator({clip:options.clip, id:options.id});
if (!lc){
return (false);
};
lc.doSend(["sendHighScore", options], callbackObj, callbackMethod);
return (true);
}
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 _isNetworkAvailable():Boolean{
return (!((Security.sandboxType == "localWithFile")));
}
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 unload(clip:Object):Boolean{
if (((clip.clip) && (clip.clip._mochiad))){
clip = clip.clip;
};
if (!clip._mochiad){
return (false);
};
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");
}};
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.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);
};
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 = ad_clip.loaderInfo.bytesTotal;
if ((((total > 0)) || (("number" == "undefined")))){
chk.showing = true;
chk.started = getTimer();
} else {
if (elapsed > chk.ad_timeout){
options.ad_failed();
finished = true;
};
};
};
if (this.parent._mochiad_ctr_failed){
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 _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 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 _loadCommunicator(options:Object):MovieClip{
var mc:MovieClip;
var k:String;
var lc:LocalConnection;
var name:String;
var req:URLRequest;
var loader:Loader;
var options = options;
var DEFAULTS:Object = {com_server:"http://x.mochiads.com/com/1/", method:"loadCommunicator", depth:10337, id:"_UNKNOWN_"};
options = MochiAd._parseOptions(options, DEFAULTS);
options.swfv = 9;
options.mav = MochiAd.getVersion();
var clip:Object = options.clip;
var clipname:String = ("_mochiad_com_" + options.id);
if (!MochiAd._isNetworkAvailable()){
return (null);
};
if (clip[clipname]){
return (clip[clipname]);
};
var server:String = (options.com_server + options.id);
MochiAd._allowDomains(server);
delete options.id;
delete options.com_server;
var depth:Number = options.depth;
delete options.depth;
mc = createEmptyMovieClip(clip, clipname, depth);
var lv:URLVariables = new URLVariables();
for (k in options) {
lv[k] = options[k];
};
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.name = name;
mc.lc = lc;
lv.lc = name;
mc._id = 0;
mc._queue = [];
mc.rpcResult = function (cb:Object):void{
cb = parseInt(cb.toString());
var cblst:Array = mc._callbacks[cb];
if (typeof(cblst) == "undefined"){
return;
};
delete mc._callbacks[cb];
var args:Array = [];
var i:Number = 2;
while (i < cblst.length) {
args.push(cblst[i]);
i++;
};
i = 1;
while (i < arguments.length) {
args.push(arguments[i]);
i++;
};
var method:Object = cblst[1];
var obj:Object = cblst[0];
if (((obj) && ((typeof(method) == "string")))){
method = obj[method];
};
if (typeof(method) == "function"){
method.apply(obj, args);
};
};
mc._didConnect = function (endpoint:String):void{
var item:Array;
mc._endpoint = endpoint;
var q:Array = mc._queue;
delete mc._queue;
var ds:Function = mc.doSend;
var i:Number = 0;
while (i < q.length) {
item = q[i];
ds.apply(this, item);
i++;
};
};
mc.doSend = function (args:Array, cbobj:Object, cbfn:Object):void{
var qargs:Array;
var i:Number;
if (mc._endpoint == null){
qargs = [];
i = 0;
while (i < arguments.length) {
qargs.push(arguments[i]);
i++;
};
mc._queue.push(qargs);
return;
};
mc._id = (mc._id + 1);
var id:Number = mc._id;
mc._callbacks[id] = [cbobj, ((cbfn) || (cbobj))];
var slc:LocalConnection = new LocalConnection();
slc.send(mc._endpoint, "rpc", id, args);
};
mc._callbacks = {};
mc._callbacks[0] = [mc, "_didConnect"];
lv.st = getTimer();
req = new URLRequest((server + ".swf"));
req.contentType = "application/x-www-form-urlencoded";
req.method = URLRequestMethod.POST;
req.data = lv;
loader = new Loader();
loader.load(req);
mc.addChild(loader);
mc._mochiad_com = loader;
return (mc);
}
public static function showPreGameAd(options:Object):void{
var clip:Object;
var mc:MovieClip;
var chk:MovieClip;
var complete:Boolean;
var unloaded:Boolean;
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, 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");
}};
options = MochiAd._parseOptions(options, DEFAULTS);
if ("5cc6f7dfb67f2f08341c831480f7c2a7".length == 0){
options.ad_started();
options.ad_finished();
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);
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.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;
};
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);
if (!chk.showing){
total = ad_clip.loaderInfo.bytesTotal;
if ((((total > 0)) || (("number" == "undefined")))){
chk.showing = true;
chk.started = getTimer();
} else {
if (elapsed > chk.ad_timeout){
options.ad_failed();
finished = true;
};
};
};
if (this.parent._mochiad_ctr_failed){
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 fetchHighScores(options:Object, callbackObj:Object, callbackMethod:Object=null):Boolean{
var lc:MovieClip = MochiAd._loadCommunicator({clip:options.clip, id:options.id});
if (!lc){
return (false);
};
lc.doSend(["fetchHighScores", options], callbackObj, callbackMethod);
return (true);
}
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
Section 285
//MochiBot (MochiBot)
package {
import flash.display.*;
import flash.net.*;
import flash.system.*;
public dynamic class MochiBot extends Sprite {
public function MochiBot(){
super();
}
public static function track(parent:Sprite, tag:String):MochiBot{
if (Security.sandboxType == "localWithFile"){
return (null);
};
var self:MochiBot = new (MochiBot);
parent.addChild(self);
Security.allowDomain("*");
Security.allowInsecureDomain("*");
var server:String = "http://core.mochibot.com/my/core.swf";
var lv:URLVariables = new URLVariables();
lv["sb"] = Security.sandboxType;
lv["v"] = Capabilities.version;
lv["swfid"] = tag;
lv["mv"] = "8";
lv["fv"] = "9";
var url:String = self.root.loaderInfo.loaderURL;
if (url.indexOf("http") == 0){
lv["url"] = url;
} else {
lv["url"] = "local";
};
var req:URLRequest = new URLRequest(server);
req.contentType = "application/x-www-form-urlencoded";
req.method = URLRequestMethod.POST;
req.data = lv;
var loader:Loader = new Loader();
self.addChild(loader);
loader.load(req);
return (self);
}
}
}//package
Section 286
//Module (Module)
package {
public class Module {
protected var modulestate:int;
protected var shared:SharedData;
public function Module():void{
super();
}
public function Init(){
}
public function Process(){
}
public function onNextFrame(delta:Number):void{
}
public function Render(){
}
public function linkShared(s:SharedData):void{
shared = s;
}
}
}//package
Section 287
//MyContactListener (MyContactListener)
package {
import Box2D.Dynamics.*;
import Box2D.Collision.*;
public class MyContactListener extends b2ContactListener {
public var contacts:Array;
public var contacts2:Array;
public function MyContactListener(){
super();
contacts = new Array();
contacts2 = new Array();
}
override public function Add(point:b2ContactPoint):void{
contacts.push(point.shape1.GetBody());
contacts2.push(point.shape2.GetBody());
}
override public function Persist(point:b2ContactPoint):void{
}
public function clean(){
contacts = new Array();
contacts2 = new Array();
}
override public function Remove(point:b2ContactPoint):void{
}
}
}//package
Section 288
//pachinko (pachinko)
package {
import flash.events.*;
import flash.display.*;
import flash.geom.*;
import com.hexagonstar.util.debug.*;
import General.*;
import flash.utils.*;
import flash.filters.*;
import valve.gfx.*;
public dynamic class pachinko extends MovieClip {
public var fps:FPS;
public var input:Input;
public var screen:Bitmap;
public var framebuffer:Bitmap;
private var background:Sprite;
private var nowTimer:uint;
public var s:SharedData;
private var previousTimer:uint;
public function pachinko(){
super();
if (stage != null){
init(false);
};
}
public function init(did_load:Boolean):void{
MochiBot.track(this, "f7d66f33");
Debug.fpsStart(stage);
this.mouseEnabled = false;
background = new Sprite();
nowTimer = 0;
previousTimer = 0;
screen = new Bitmap(new BitmapData(640, 480, true, 4278190080));
s = new SharedData();
s.screen = screen;
framebuffer = new Bitmap(new BitmapData(640, 480, true, 4278190080));
s.init(stage, root);
s.gamestate = new Array();
s.gamestate[s.MAINMENU] = new MainMenu();
s.gamestate[s.GAME] = new Game();
s.gamestate[s.LOADLEVEL] = new LoadLevel();
s.gamestate[3] = new MainMenu();
s.gamestate[s.TITLESCREEN] = new TitleScreen();
s.gamestate[s.TRANSITION] = new Transition();
s.gamestate[s.LEVELEDITOR] = new LevelEditor();
s.gamestate[s.WINNER] = new TitleScreen();
s.currentGamestate = s.TITLESCREEN;
s.nextGamestate = s.TITLESCREEN;
var i:int;
while (i < s.gamestate.length) {
s.gamestate[i].linkShared(s);
s.gamestate[i].Init();
i++;
};
addChild(framebuffer);
fps = new FPS();
addChild(fps);
fps.visible = false;
stage.addEventListener(Event.ENTER_FRAME, onEnterFrame);
addChild(s.gamestate[s.GAME].getSprite());
addChild(GameData.getInstance().frontLayer);
addChild(s.highscoresLayer);
addChild(s.frontLayer);
previousTimer = 0;
nowTimer = getTimer();
}
private function onEnterFrame(event:Event):void{
previousTimer = nowTimer;
nowTimer = getTimer();
s.input.process();
if (s.input.keyToggle[70]){
fps.visible = !(fps.visible);
};
s.gameTick = (nowTimer - previousTimer);
s.gamestate[s.currentGamestate].Process();
s.gamestate[s.currentGamestate].Render();
if (((((!((s.nextGamestate == s.currentGamestate))) && (!((s.currentGamestate == s.TRANSITION))))) || (s.transitionNow))){
s.previousGamestate = s.currentGamestate;
s.currentGamestate = s.TRANSITION;
s.gamestate[s.currentGamestate].Process();
s.gamestate[s.currentGamestate].Render();
s.transitionNow = false;
};
if (((!((s.nextGamestate == s.currentGamestate))) && (s.transitionFinished))){
s.currentGamestate = s.nextGamestate;
s.transitionFinished = false;
s.gamestate[s.TRANSITION].Reset();
};
framebuffer.bitmapData.copyPixels(s.screen.bitmapData, new Rectangle(0, 0, 640, 480), new Point(0, 0));
FRateLimiter.limitFrame(40);
}
}
}//package
Section 289
//Peg (Peg)
package {
import Box2D.Dynamics.*;
import Box2D.Common.Math.*;
import flash.geom.*;
public class Peg {
public var y:Number;
public var radius:Number;// = 100
public var pegRef:b2Body;
public var moveType:int;// = 0
public var x1:Number;
public var x2:Number;
public var type:int;// = 0
public var anchorX:Number;
public var anchorY:Number;
public var alive:int;// = 0
public var time:Number;// = 0
public var isCircling:Boolean;// = false
public var y1:Number;
public var y2:Number;
public var color:int;
public var rect:Rectangle;
public var hitCounter;// = 0
public var velocity1:b2Vec2;
public var velocity2:b2Vec2;
public var goingToTwo:Boolean;
public var x:Number;
public var moveTimer:int;// = 0
public var usedInBonus:Boolean;// = false
public function Peg(pegref:b2Body, fx:int, fy:int, fcolor:int, ftype:int=0, fx2:int=-1, fy2:int=-1){
rect = new Rectangle();
super();
pegRef = pegref;
x = fx;
y = fy;
alive = 1;
color = fcolor;
hitCounter = 0;
type = ftype;
x2 = fx2;
y2 = fy2;
x1 = x;
y1 = y;
goingToTwo = true;
rect.x = fx;
rect.y = fy;
rect.width = 17;
rect.height = 17;
}
public function updateRef(x:b2Body){
pegRef = x;
}
public function changeType(whatType:int){
type = whatType;
}
public function isMoving(){
var length:Number;
var vector:b2Vec2;
if (x2 != -1){
velocity2 = new b2Vec2();
velocity1 = new b2Vec2(0, 0);
velocity1.x = 0;
velocity1.y = 0;
velocity1.y = (y2 - y1);
velocity1.x = (x2 - x1);
length = velocity1.Length();
if (length == 0){
length = 1;
};
velocity1.y = (velocity1.y / 100);
velocity1.x = (velocity1.x / 100);
velocity2 = velocity1.Negative();
vector = new b2Vec2();
vector.x = (x2 - x1);
vector.y = (y2 - y1);
radius = vector.Length();
if (((((x - x2) >= 0)) && (((y - y2) >= 0)))){
time = Math.asin(((x - x2) / radius));
time = Math.acos(((y - y2) / radius));
} else {
if (((((x - x2) <= 0)) && (((y - y2) >= 0)))){
time = Math.asin(((x - x2) / radius));
time = ((2 * Math.PI) - Math.acos(((y - y2) / radius)));
} else {
if (((((x - x2) <= 0)) && (((y - y2) <= 0)))){
time = (Math.PI - Math.asin(((x - x2) / radius)));
time = ((2 * Math.PI) - Math.acos(((y - y2) / radius)));
} else {
if (((((x - x2) >= 0)) && (((y - y2) <= 0)))){
time = (Math.PI - Math.asin(((x - x2) / radius)));
time = Math.acos(((y - y2) / radius));
};
};
};
};
};
}
public function SetBox(fwidth:int, fheight:int){
rect.width = fwidth;
rect.height = fheight;
}
public function circle(){
time = (time + 0.05);
if (time >= (2 * Math.PI)){
time = 0;
};
if (pegRef != null){
if ((Math.PI - Math.asin(((x - x2) / radius))) == ((2 * Math.PI) - Math.acos(((y - y2) / radius)))){
};
pegRef.SetXForm(new b2Vec2((((radius * Math.sin(time)) + x2) / 10), (((radius * Math.cos(time)) + y2) / 10)), 0);
x = (pegRef.GetPosition().x * 10);
y = (pegRef.GetPosition().y * 10);
};
}
public function process(){
if (isCircling){
circle();
return;
};
if (x2 != -1){
if (pegRef != null){
if (goingToTwo){
pegRef.SetXForm(new b2Vec2(((x + velocity1.x) / 10), ((y + velocity1.y) / 10)), 0);
x = (pegRef.GetPosition().x * 10);
y = (pegRef.GetPosition().y * 10);
moveTimer++;
if (moveTimer == 100){
moveTimer = 0;
goingToTwo = false;
};
} else {
pegRef.SetXForm(new b2Vec2(((x + velocity2.x) / 10), ((y + velocity2.y) / 10)), 0);
x = (pegRef.GetPosition().x * 10);
y = (pegRef.GetPosition().y * 10);
moveTimer++;
if (moveTimer == 100){
moveTimer = 0;
goingToTwo = true;
};
};
};
};
}
}
}//package
Section 290
//PhysicsGame (PhysicsGame)
package {
import flash.display.*;
import Box2D.Dynamics.*;
import Box2D.Common.Math.*;
import Box2D.Collision.*;
import Box2D.Dynamics.Joints.*;
import Box2D.Collision.Shapes.*;
import Box2D.Common.*;
import Box2D.Dynamics.Contacts.*;
import flash.geom.*;
import com.hexagonstar.util.debug.*;
import mochi.*;
import com.electrotank.util.*;
import flash.utils.*;
public class PhysicsGame {
public var showScoreForABit:Boolean;// = false
public var delay:int;// = 0
public var level:Level;
public var m_physScale:Number;// = 1
public var fadeText2:int;// = 0
public var transitioningX:int;// = 0
public var missedPegsX:int;// = 0
public var pegCount:int;
public var particleCounter:int;// = 0
public var physicsDraw:Sprite;
public var swoop:Boolean;// = false
public var showMissed:Boolean;// = false
public var m_bomb:b2Body;
public var countingPegs:Boolean;
public var gameData:GameData;
public var pacer:int;// = 0
public var scoreString:String;// = ""
public var m_iterations:int;// = 10
public var fadeText:int;// = 0
public var m_timeStep:Number;// = 0.0333333333333333
public var swoopx:Number;// = 0
public var swoopy:Number;// = 0
public var swoopVec:b2Vec2;
public var bounceY:Number;// = 0
public var pegshit:int;// = 0
public var pacer2:int;// = 0
public var m_sprite:Sprite;
public var gameoverX:Number;// = 0
public var alternateParticles:Boolean;// = true
public var bounced:Boolean;// = false
public var bounced2:Boolean;// = false
public var screenTemp:Image;
public var screenTemp2:Image;
public var highscoresClicked:Boolean;// = false
public var shared:SharedData;
public var screen:Bitmap;
public var transitioning:Boolean;
public var pegcumalative:int;// = 0
public var totalString:String;// = ""
public var m_mouseJoint:b2MouseJoint;
public var winnerY:Number;// = 0
public var swoopScale:Number;// = 1
private var c_blank:Class;
public function PhysicsGame(fscreen:Bitmap, fshared:SharedData){
c_blank = PhysicsGame_c_blank;
super();
transitioning = false;
shared = fshared;
gameData = GameData.getInstance();
gameData.shared = shared;
gameData.physicsGame = this;
screen = fscreen;
physicsDraw = new Sprite();
gameData.savedata = new SaveData();
gameData.savedata.loadData();
screenTemp = new Image(shared.screen, c_blank);
screenTemp2 = new Image(shared.screen, c_blank);
var worldAABB:b2AABB = new b2AABB();
worldAABB.lowerBound.Set(-1000, -1000);
worldAABB.upperBound.Set(1000, 1000);
var gravity:b2Vec2 = new b2Vec2(0, 30);
var doSleep:Boolean;
gameData.whatLevel = 0;
gameData.m_world = new b2World(worldAABB, gravity, doSleep);
var dbgDraw:b2DebugDraw = new b2DebugDraw();
dbgDraw.m_sprite = shared.frontLayer;
dbgDraw.m_drawScale = 10;
dbgDraw.m_fillAlpha = 0.3;
dbgDraw.m_drawFlags = (b2DebugDraw.e_shapeBit | b2DebugDraw.e_jointBit);
if (shared.debug){
gameData.m_world.SetDebugDraw(dbgDraw);
};
gameData.m_world.SetListener(gameData.contactlistener);
countingPegs = false;
level = new Level(screen);
level.linkShared(shared);
gameData.capsule = new Capsule(gameData.m_world, screen, shared);
swoopVec = new b2Vec2();
swoopVec.x = (38 - 235);
swoopVec.y = (72 - 204);
swoopVec.Normalize();
swoopVec.Multiply(15);
pegCount = 0;
gameData.livesLeft = 12;
gameoverX = 800;
bounceY = 0;
winnerY = 0;
MochiServices.connect("d7374563833eae05", shared.highscoresLayer);
MochiScores.setBoardID("e0c020a3a9061410");
}
public function resetLevel2(){
swoop = false;
pegcumalative = 0;
pegshit = 0;
scoreString = "";
totalString = "";
swoopScale = 1;
}
public function getSprite():Sprite{
return (physicsDraw);
}
public function resetlevel(){
gameData.longshot = false;
gameData.pitchToPlay = 0;
gameData.threeBlueHit = false;
gameData.threeRedHit = false;
gameData.pegsHit = new Array();
gameData.pegsHitInt = new Array();
swoopx = 235;
swoopy = 204;
gameData.newBall = 2;
gameData.hitFree = false;
if (gameData.freeBall.alive == 2){
level.insertFreeBall();
};
pacer = 0;
pacer2 = 0;
countingPegs = false;
delay = 0;
}
public function Render(){
var i:int;
var len:int;
var matrix:Matrix;
if (transitioning){
screenTemp2.render(null, true, new Matrix(1, 0, 0, 1, 0, 0), new ColorTransform(1, 1, 1, (transitioningX / 640), 0, 0, 0, 0));
screenTemp.render(null, true, new Matrix(1, 0, 0, 1, 0, 0), new ColorTransform(1, 1, 1, (1 - (transitioningX / 640)), 0, 0, 0, 0));
return;
};
if (!gameData.ending){
level.paint();
};
if (!gameData.ending){
if (((gameData.testing) && (!(gameData.customLevel)))){
shared.textTyper.drawText2("TESTING", 2, 12, shared.textTyper.LEVELFONT, 5);
} else {
if (gameData.customLevel == false){
if (gameData.whatLevel == 0){
shared.textTyper.drawText2("TUTORIAL", -2, 12, shared.textTyper.LEVELFONT, 5);
} else {
shared.textTyper.drawText2("LEVEL ", 5, 12, shared.textTyper.LEVELFONT, 5);
shared.textTyper.drawText2(gameData.whatLevel.toString(), 36, (12 + 15), shared.textTyper.LEVELFONT, 5);
};
} else {
shared.textTyper.drawText2("CUSTOM", 2, 12, shared.textTyper.LEVELFONT, 5);
};
};
};
if (((((((!(gameData.customLevel)) && (!(gameData.testing)))) && (!((gameData.whatLevel == 0))))) && (!(gameData.ending)))){
shared.buttons.b_highscoresbutton.render();
};
if (!gameData.ending){
shared.images.i_bonustext.render(null, true, new Matrix(1, 0, 0, 1, 15, 258));
shared.images.i_bonusbar.render(null, true, new Matrix(1, 0, 0, 1, 10, 270));
shared.images.i_bonusbarfiller.render(null, true, new Matrix(1, 0, 0, 1, 10, 270), null, null, new Rectangle(10, 270, (65 * (gameData.bonusPercent / 16)), 13));
switch (gameData.bonusMultiplier){
case 1:
shared.images.i_1x.render(null, true, new Matrix(1, 0, 0, 1, 32, 288));
break;
case 2:
shared.images.i_2x.render(null, true, new Matrix(1, 0, 0, 1, 32, 288));
break;
case 4:
shared.images.i_4x.render(null, true, new Matrix(1, 0, 0, 1, 32, 288));
break;
case 8:
shared.images.i_8x.render(null, true, new Matrix(1, 0, 0, 1, 32, 288));
break;
};
};
if (gameData.testing){
shared.buttons.b_back.render();
} else {
shared.buttons.b_menu.render();
};
if (!gameData.ending){
shared.images.i_ballsleft.render(null, true, new Matrix(1, 0, 0, 1, 12, 137));
i = 0;
while (i < gameData.livesLeft) {
shared.images.i_ball.render(null, true, new Matrix(1, 0, 0, 1, (7 + (16 * (i % 4))), (176 + (Math.floor((i / 4)) * 16))));
i++;
};
};
if (!gameData.ending){
shared.textTyper.drawText("SCORE", 16, 72, shared.textTyper.BRIT12);
len = MemoryCrypto.getValue(gameData.score).toString().length;
if (len < 6){
shared.textTyper.drawText(MemoryCrypto.getValue(gameData.score).toString(), (12 + ((6 - len) * 10)), 92, shared.textTyper.BRIT12);
} else {
shared.textTyper.drawText(MemoryCrypto.getValue(gameData.score).toString(), 12, 92, shared.textTyper.BRIT12);
};
i = 0;
while (i < 10) {
if (gameData.aimingDevice[i] != null){
if ((i % 2) == 1){
shared.images.i_ball.render(null, true, new Matrix(1, 0, 0, 1, (gameData.aimingDevice[i].x - 7), (gameData.aimingDevice[i].y - 7)), new ColorTransform(1, 1, 1, 0.5));
};
};
i++;
};
};
if (countingPegs){
shared.textTyper.drawText(scoreString, (224 + 50), 164, shared.textTyper.ARIAL);
shared.textTyper.drawText(totalString, (235 - 30), 204, shared.textTyper.ARIAL);
};
if (swoop){
matrix = new Matrix(swoopScale, 0, 0, swoopScale, swoopx, swoopy);
shared.textTyper.drawTextMatrix(totalString, shared.textTyper.ARIAL, matrix);
};
if (showMissed){
if (missedPegsX < 0xFF){
shared.images.i_missedallpegs.render(null, true, new Matrix(1, 0, 0, 1, 290, 76), new ColorTransform(1, 1, 1, (1 - (missedPegsX / 0xFF))));
missedPegsX = (missedPegsX + 4);
} else {
missedPegsX = 0;
showMissed = false;
};
};
if (!gameData.ending){
if (gameData.gameOver){
shared.images.i_gameover.render(null, true, new Matrix(1, 0, 0, 1, gameoverX, 179));
if (gameoverX <= 204){
shared.buttons.b_restartlevelbutton.render();
};
};
if (gameData.winner){
shared.images.i_fillblack.render(null, true, new Matrix(1, 0, 0, 1, 83, 0));
shared.images.i_winner.render(null, true, new Matrix(1, 0, 0, 1, 228, winnerY));
if (winnerY >= 150){
if (gameData.testing){
shared.buttons.b_restartlevelbutton.render();
} else {
if (gameData.whatLevel == 45){
shared.buttons.b_continuebutton.render();
} else {
shared.buttons.b_nextlevelbutton.render();
};
};
};
};
};
if (gameData.freeBallHit){
if (fadeText < 0xFF){
shared.images.i_freeballtext.render(null, true, new Matrix(1, 0, 0, 1, (gameData.freeBallHitPoint.x * gameData.m_physScale), (gameData.freeBallHitPoint.y * gameData.m_physScale)), new ColorTransform(1, 1, 1, (1 - (fadeText / 0xFF))));
fadeText = (fadeText + 3);
} else {
fadeText = 0;
gameData.freeBallHit = false;
};
};
if (gameData.threeRedHit){
if (fadeText2 < 0xFF){
shared.images.i_3reds.render(null, true, new Matrix(1, 0, 0, 1, gameData.threeRedHitPoint.x, gameData.threeRedHitPoint.y), new ColorTransform(1, 1, 1, (1 - (fadeText2 / 0xFF))));
fadeText2 = (fadeText2 + 3);
} else {
fadeText2 = 0;
gameData.threeRedHit = false;
};
};
if (gameData.longshot){
if (fadeText2 < 0xFF){
shared.images.i_longshot.render(null, true, new Matrix(1, 0, 0, 1, gameData.longshotPoint.x, gameData.longshotPoint.y), new ColorTransform(1, 1, 1, (1 - (fadeText2 / 0xFF))));
fadeText2 = (fadeText2 + 3);
} else {
fadeText2 = 0;
gameData.longshot = false;
};
};
if (gameData.threeBlueHit){
if (fadeText2 < 0xFF){
shared.images.i_3blues.render(null, true, new Matrix(1, 0, 0, 1, gameData.threeBlueHitPoint.x, gameData.threeBlueHitPoint.y), new ColorTransform(1, 1, 1, (1 - (fadeText2 / 0xFF))));
fadeText2 = (fadeText2 + 3);
} else {
fadeText2 = 0;
gameData.threeBlueHit = false;
};
};
if (gameData.countingBallsLeft){
totalString = MemoryCrypto.getValue(gameData.score).toString();
shared.images.i_bonuspoints.render(null, true, new Matrix(1, 0, 0, 1, 103, 181));
shared.images.i_plus50.render(null, true, new Matrix(1, 0, 0, 1, 217, 198));
};
if ((((gameData.whatLevel == 0)) && (!(gameData.testing)))){
shared.images.i_clicktoshoot.render(null, true, new Matrix(1, 0, 0, 1, 109, 25));
shared.images.i_tocomplete.render(null, true, new Matrix(1, 0, 0, 1, 441, 231));
shared.images.i_hittingthis.render(null, true, new Matrix(1, 0, 0, 1, ((gameData.freeBall.x * gameData.m_physScale) + 20), (gameData.freeBall.y * gameData.m_physScale)));
};
}
public function resetNewLevel(){
gameData.countingBallsLeft = false;
shared.buttons.b_nextlevelbutton.getRect().y = 400;
shared.buttons.b_continuebutton.getRect().y = 400;
countingPegs;
pegCount;
pacer = 0;
scoreString = "";
pegshit = 0;
pegcumalative = 0;
totalString = "";
delay = 0;
swoopx = 0;
swoopy = 0;
swoop = false;
swoopScale = 1;
gameoverX = 0;
winnerY = 0;
bounceY = 0;
bounced = false;
bounced2 = false;
alternateParticles = true;
particleCounter = 0;
fadeText = 0;
fadeText2 = 0;
pegCount = 0;
gameoverX = 800;
bounceY = 0;
winnerY = 0;
gameData.leaderboardClosedBool = false;
}
public function Process(){
var next:int;
if (gameData.musicOn){
if (gameData.whatLevel >= 0){
switch ((gameData.whatLevel % 5)){
case 0:
shared.sounds.PlaySound(shared.sounds.s_intotheblue);
shared.sounds.StopOthers(shared.sounds.s_intotheblue);
break;
case 1:
shared.sounds.PlaySound(shared.sounds.s_lightawoken);
shared.sounds.StopOthers(shared.sounds.s_lightawoken);
break;
case 2:
shared.sounds.PlaySound(shared.sounds.s_togetheragain);
shared.sounds.StopOthers(shared.sounds.s_togetheragain);
break;
case 3:
shared.sounds.PlaySound(shared.sounds.s_thelab);
shared.sounds.StopOthers(shared.sounds.s_thelab);
break;
case 4:
shared.sounds.PlaySound(shared.sounds.s_space);
shared.sounds.StopOthers(shared.sounds.s_space);
break;
};
};
} else {
shared.sounds.StopMusic();
};
if (highscoresClicked){
if (shared.highscoresLayer.x > 37){
shared.highscoresLayer.x = 37;
} else {
shared.highscoresLayer.x = 37;
};
shared.buttons.b_highscoresbutton.process(shared);
if (((!(gameData.leaderboardIsOpen)) || (shared.buttons.b_highscoresbutton.isClicked()))){
highscoresClicked = false;
gameData.closeLeaderboard();
shared.highscoresLayer.x = 37;
};
return;
};
if (transitioning){
transitioningX = (transitioningX + 20);
if (transitioningX == 640){
transitioning = false;
};
return;
};
if (((!(gameData.customLevel)) && (!(gameData.testing)))){
shared.buttons.b_highscoresbutton.process(shared);
if (shared.buttons.b_highscoresbutton.isClicked()){
highscoresClicked = true;
shared.highscoresLayer.x = 640;
gameData.openLeaderboard();
};
};
if (showScoreForABit){
if (pacer > 20){
pacer = 0;
showScoreForABit = false;
gameData.Winner2();
if (gameData.soundOn){
shared.sounds.s_winner.play();
};
gameData.savedata.completedLevels[(gameData.whatLevel + 1)] = true;
gameData.savedata.update();
} else {
pacer++;
};
return;
};
if (gameData.countingBallsLeft){
if (gameData.livesLeft == 0){
gameData.countingBallsLeft = false;
showScoreForABit = true;
return;
};
if (pacer > 5){
shared.particleS.emitStars((13 + (16 * ((gameData.livesLeft - 1) % 4))), (182 + (Math.floor(((gameData.livesLeft - 1) / 4)) * 16)), 5, shared.particleS.star1);
gameData.livesLeft--;
MemoryCrypto.incrementValue(gameData.score, 50);
pacer = 0;
if (gameData.soundOn){
shared.sounds.s_bubble.play();
};
} else {
pacer++;
};
return;
};
if (gameData.winner){
if (gameData.leaderboardClosedBool){
if (winnerY > 170){
winnerY = (winnerY - 10);
shared.buttons.b_nextlevelbutton.getRect().y = (shared.buttons.b_nextlevelbutton.getRect().y - 10);
shared.buttons.b_continuebutton.getRect().y = (shared.buttons.b_continuebutton.getRect().y - 10);
};
} else {
if (winnerY < 340){
particleCounter++;
if (particleCounter > 2){
shared.particleS.emitStars((((486 - 185) / 2) + 185), winnerY, 5, shared.particleS.spark);
particleCounter = 0;
};
winnerY = (winnerY + 10);
};
};
particleCounter++;
if (particleCounter > 45){
if ((Math.random() * 2) > 1){
shared.particleS.emitStars((95 + (Math.random() * 50)), (Math.random() * 400), 10, shared.particleS.star2);
} else {
shared.particleS.emitStars((95 + (Math.random() * 50)), (Math.random() * 400), 10, shared.particleS.star3);
};
if ((Math.random() * 2) > 1){
shared.particleS.emitStars((547 + (Math.random() * 80)), (Math.random() * 400), 10, shared.particleS.star1);
} else {
shared.particleS.emitStars((547 + (Math.random() * 80)), (Math.random() * 400), 10, shared.particleS.star2);
};
particleCounter = 0;
};
if (gameData.testing){
shared.buttons.b_restartlevelbutton.process(shared);
if (shared.buttons.b_restartlevelbutton.isClicked()){
gameData.closeLeaderboard();
shared.gamestate[shared.GAME].Render();
screenTemp.bitmap.bitmapData.copyPixels(shared.screen.bitmapData, new Rectangle(0, 0, 640, 480), new Point(0, 0));
resetNewLevel();
gameData.initNewGame();
shared.gamestate[shared.GAME].Render();
screenTemp2.bitmap.bitmapData.copyPixels(shared.screen.bitmapData, new Rectangle(0, 0, 640, 480), new Point(0, 0));
transitioning = true;
transitioningX = 0;
};
} else {
if (gameData.whatLevel == 45){
shared.buttons.b_continuebutton.process(shared);
if (shared.buttons.b_continuebutton.isClicked()){
gameData.closeLeaderboard();
gameData.ending = true;
};
return;
};
shared.buttons.b_nextlevelbutton.process(shared);
if (shared.buttons.b_nextlevelbutton.isClicked()){
gameData.closeLeaderboard();
shared.gamestate[shared.GAME].Render();
screenTemp.bitmap.bitmapData.copyPixels(shared.screen.bitmapData, new Rectangle(0, 0, 640, 480), new Point(0, 0));
resetNewLevel();
gameData.whatLevel = (gameData.whatLevel + 1);
gameData.initNewGame();
shared.gamestate[shared.GAME].Render();
screenTemp2.bitmap.bitmapData.copyPixels(shared.screen.bitmapData, new Rectangle(0, 0, 640, 480), new Point(0, 0));
transitioning = true;
transitioningX = 0;
};
};
return;
};
if (countingPegs){
if (pacer == 3){
if (gameData.pegsHitInt.length > 0){
next = gameData.pegsHitInt[(gameData.pegsHitInt.length - 1)];
level.destroyBall(next);
if (gameData.lvl1Array[next].color == 0){
shared.particleS.emitStars(gameData.lvl1Array[next].x, gameData.lvl1Array[next].y, 5, shared.particleS.fadeblue, 1, 1, 50, 50);
} else {
shared.particleS.emitStars(gameData.lvl1Array[next].x, gameData.lvl1Array[next].y, 5, shared.particleS.fadered, 1, 1, 50, 50);
};
pegcumalative = (pegcumalative + 10);
pegshit++;
if (gameData.bonusMultiplier < 8){
gameData.bonusPercent++;
if (gameData.bonusPercent > 16){
gameData.bonusPercent = 0;
gameData.bonusMultiplier = (gameData.bonusMultiplier * 2);
gameData.livesLeft++;
shared.particleS.emitStars((13 + (16 * ((gameData.livesLeft - 1) % 4))), (182 + (Math.floor(((gameData.livesLeft - 1) / 4)) * 16)), 5, shared.particleS.star1);
};
} else {
gameData.bonusPercent = 16;
};
scoreString = ((pegshit.toString() + " x ") + pegcumalative.toString());
totalString = (((gameData.bonusMultiplier.toString() + " x ") + new int((pegshit * pegcumalative)).toString()) + " points");
gameData.pegsHitInt.pop();
if (gameData.soundOn){
shared.sounds.s_bubble.play(0, 0);
};
} else {
pacer = 0;
if (delay == 12){
resetlevel();
swoop = true;
} else {
delay++;
};
};
pacer = 0;
} else {
pacer++;
};
return;
};
if (swoop){
if (swoopx < 38){
MemoryCrypto.incrementValue(gameData.score, ((pegcumalative * pegshit) * gameData.bonusMultiplier));
resetLevel2();
};
swoopx = (swoopx + swoopVec.x);
swoopy = (swoopy + swoopVec.y);
swoopScale = (swoopScale - 0.01);
return;
};
if (gameData.gameOver){
if (gameoverX > 204){
gameoverX = (gameoverX - 10);
};
shared.buttons.b_restartlevelbutton.process(shared);
if (shared.buttons.b_restartlevelbutton.isClicked()){
gameData.livesLeft = 8;
resetNewLevel();
gameData.initNewGame();
gameData.gameOver = false;
gameoverX = 800;
};
gameData.m_world.Step(m_timeStep, m_iterations);
level.process();
return;
};
var physStart:uint = getTimer();
gameData.m_world.Step(m_timeStep, m_iterations);
gameData.capsule.process();
level.process();
if ((((gameData.newBall == 1)) && (!(gameData.gameOver)))){
if (gameData.pegsHitInt.length > 0){
countingPegs = true;
} else {
if (!gameData.hitFree){
if (gameData.soundOn){
shared.sounds.s_bad.play(0, 0);
};
gameData.hitFree = false;
showMissed = true;
missedPegsX = 0;
gameData.livesLeft++;
shared.particleS.emitStars((13 + (16 * ((gameData.livesLeft - 1) % 4))), (182 + (Math.floor(((gameData.livesLeft - 1) / 4)) * 16)), 5, shared.particleS.star1);
};
resetlevel();
resetLevel2();
};
};
if (gameData.livesLeft > 0){
gameData.gameOver = false;
} else {
if (gameData.newBall == 1){
if (gameData.pegsHit.length > 0){
countingPegs = true;
};
return;
};
};
if ((((gameData.livesLeft == 0)) && ((gameData.newBall == 2)))){
gameData.gameOver = true;
};
gameData.leaderboardClosedBool = false;
}
}
}//package
Section 291
//PhysicsGame_c_blank (PhysicsGame_c_blank)
package {
import mx.core.*;
public class PhysicsGame_c_blank extends BitmapAsset {
}
}//package
Section 292
//Preloader (Preloader)
package {
import flash.events.*;
import flash.display.*;
import flash.utils.*;
import com.hexagonstar.util.debug.*;
public dynamic class Preloader extends MovieClip {
private var did_load:Boolean;
public static var GAME_OPTIONS:Object = {id:"d7374563833eae05", res:"640x480", background:1381676, color:0xFF8A00, outline:13994812, no_bg:true};
public static var MAIN_CLASS:String = "pachinko";
public function Preloader(){
var k:String;
super();
var f:Function = function (ev:IOErrorEvent):void{
};
loaderInfo.addEventListener(IOErrorEvent.IO_ERROR, f);
var opts:Object = {};
for (k in GAME_OPTIONS) {
opts[k] = GAME_OPTIONS[k];
};
opts.ad_started = function ():void{
did_load = true;
};
opts.ad_finished = function ():void{
var mainClass:Class = Class(getDefinitionByName(MAIN_CLASS));
var app:Object = new (mainClass);
parent.addChild((app as DisplayObject));
if (app.init){
app.init(did_load);
};
};
opts.clip = this;
MochiAd.showPreGameAd(opts);
}
}
}//package
Section 293
//PulseParticleSystem (PulseParticleSystem)
package {
import com.roguedevelopment.pulse.emitter.*;
import com.roguedevelopment.pulse.*;
import com.roguedevelopment.pulse.simple.*;
public class PulseParticleSystem {
public var star2:Class;
public var star3:Class;
public var shared:SharedData;
public var emitter:GenericEmitter;
public var snowflake:Class;
public var diamond:Class;
public var fadered:Class;
public var fadeblue:Class;
public var test:Class;
public var spark:Class;
public var star1:Class;
public function PulseParticleSystem(fshared:SharedData){
snowflake = PulseParticleSystem_snowflake;
spark = PulseParticleSystem_spark;
test = PulseParticleSystem_test;
star1 = PulseParticleSystem_star1;
star2 = PulseParticleSystem_star2;
star3 = PulseParticleSystem_star3;
diamond = PulseParticleSystem_diamond;
fadered = PulseParticleSystem_fadered;
fadeblue = PulseParticleSystem_fadeblue;
super();
shared = fshared;
PulseEngine.instance.root = shared.frontLayer;
emitter = new GenericEmitter(20);
emitter.x = 10;
emitter.y = 10;
emitter.particleLimit = 50;
}
public function emitStars(fx:int, fy:int, count:int, type:Class, fscale:Number=0.1, fscale2:Number=0.3, fspeed:int=150, fspeed2:int=150){
emitter = new GenericEmitter(20);
emitter.x = 10;
emitter.y = 10;
emitter.particleLimit = 50;
emitter.particleLimit = count;
SimpleParticles.configureEmitterByObject(emitter, {pps:10, x:fx, y:fy, width:1, height:1, image:type, movement:true, speed:[fspeed, fspeed2], angle:[0, 360], startScale:[fscale, fscale2], gravity:5, fade:650, lifespan:520});
}
public function Ending(){
emitter = new GenericEmitter(20);
emitter.x = 10;
emitter.y = 10;
emitter.particleLimit = 50;
SimpleParticles.configureEmitterByObject(emitter, {image:star1, pps:10, x:87, y:10, width:550, height:1, size:15, color:2588900, movement:true, minSpeed:150, maxSpeed:150, minAngle:0, maxAngle:180.7, minScale:0.5, maxScale:0.5, gravity:1, lifespan:7910});
}
}
}//package
Section 294
//PulseParticleSystem_diamond (PulseParticleSystem_diamond)
package {
import mx.core.*;
public class PulseParticleSystem_diamond extends BitmapAsset {
}
}//package
Section 295
//PulseParticleSystem_fadeblue (PulseParticleSystem_fadeblue)
package {
import mx.core.*;
public class PulseParticleSystem_fadeblue extends BitmapAsset {
}
}//package
Section 296
//PulseParticleSystem_fadered (PulseParticleSystem_fadered)
package {
import mx.core.*;
public class PulseParticleSystem_fadered extends BitmapAsset {
}
}//package
Section 297
//PulseParticleSystem_snowflake (PulseParticleSystem_snowflake)
package {
import mx.core.*;
public class PulseParticleSystem_snowflake extends BitmapAsset {
}
}//package
Section 298
//PulseParticleSystem_spark (PulseParticleSystem_spark)
package {
import mx.core.*;
public class PulseParticleSystem_spark extends BitmapAsset {
}
}//package
Section 299
//PulseParticleSystem_star1 (PulseParticleSystem_star1)
package {
import mx.core.*;
public class PulseParticleSystem_star1 extends BitmapAsset {
}
}//package
Section 300
//PulseParticleSystem_star2 (PulseParticleSystem_star2)
package {
import mx.core.*;
public class PulseParticleSystem_star2 extends BitmapAsset {
}
}//package
Section 301
//PulseParticleSystem_star3 (PulseParticleSystem_star3)
package {
import mx.core.*;
public class PulseParticleSystem_star3 extends BitmapAsset {
}
}//package
Section 302
//PulseParticleSystem_test (PulseParticleSystem_test)
package {
import mx.core.*;
public class PulseParticleSystem_test extends BitmapAsset {
}
}//package
Section 303
//SaveData (SaveData)
package {
import flash.net.*;
public class SaveData {
private var mySo:SharedObject;
public var completedLevels:Array;
public function SaveData(){
super();
completedLevels = new Array(100);
}
public function loadData(){
var i:int;
mySo = SharedObject.getLocal("polinko", "/");
if (mySo.data.completed == null){
completedLevels = new Array();
i = 0;
while (i < 100) {
completedLevels[i] = new Boolean();
completedLevels[i] = false;
i++;
};
completedLevels[0] = true;
} else {
completedLevels = mySo.data.completed;
};
}
public function update(){
mySo.data.completed = completedLevels;
mySo.flush();
}
}
}//package
Section 304
//SharedData (SharedData)
package {
import flash.display.*;
import Box2D.Common.Math.*;
public class SharedData {
public var buttons:Buttons;
public var WARP:int;// = 1
public var particleS:PulseParticleSystem;
public var MAINMENU:int;// = 0
public var TITLESCREEN:int;// = 4
public var previousGamestate:int;// = 0
public var nextGamestate:int;// = 0
public var frontLayer:MovieClip;
public var SCALE:int;// = 2
public var gameTick:Number;
public var WINNER:int;// = 6
public var transitionNow:Boolean;// = false
public var sounds:Sounds;
public var LOADLEVEL:int;// = 2
public var input:Input;
public var textTyper:Text;
public var LEVELEDITOR:int;// = 7
public var TRANSITION:int;// = 5
public var debug:Boolean;// = false
public var transition:int;
public var highscoresLayer:MovieClip;
public var root:DisplayObject;
public var currentGamestate:int;// = 0
public var transitionFinished:Boolean;// = false
public var screen:Bitmap;
public var gamestate:Array;
public var GAME:int;// = 1
public var images:Images;
public var CREDITS:int;// = 3
public var FADE:int;// = 0
public function SharedData(){
transition = FADE;
super();
}
public function init(stage:Stage, froot:DisplayObject){
root = froot;
images = new Images();
buttons = new Buttons();
sounds = new Sounds();
images.init(screen);
buttons.init(screen);
input = new Input();
input.init(stage);
textTyper = new Text();
textTyper.Init(screen);
frontLayer = new MovieClip();
highscoresLayer = new MovieClip();
particleS = new PulseParticleSystem(this);
highscoresLayer.y = -50;
highscoresLayer.x = 37;
}
public function drawDottedLine(x1:int, y1:int, x2:int, y2:int){
var i:int;
var y:Number = y1;
if (x1 < x2){
i = x1;
while (i < x2) {
screen.bitmapData.setPixel(i, y, 0);
y = (y + ((y2 - y1) / (x2 - x1)));
i++;
};
} else {
y = y2;
i = x2;
while (i < x1) {
screen.bitmapData.setPixel(i, y, 0);
y = (y + ((y1 - y2) / (x1 - x2)));
i++;
};
};
var x:Number = x1;
if (y1 < y2){
i = y1;
while (i < y2) {
screen.bitmapData.setPixel(x, i, 0);
x = (x + ((x2 - x1) / (y2 - y1)));
i++;
};
} else {
x = x2;
i = y2;
while (i < y1) {
screen.bitmapData.setPixel(x, i, 0);
x = (x + ((x1 - x2) / (y1 - y2)));
i++;
};
};
}
public function drawCircle(x1:int, y1:int, x2:int, y2:int){
var vector:b2Vec2 = new b2Vec2();
vector.x = (x2 - x1);
vector.y = (y2 - y1);
var radius:Number = vector.Length();
var circumference:Number = (Math.PI * radius);
var x:Number = x1;
var y:Number = y1;
var i:int;
while (i < circumference) {
screen.bitmapData.setPixel(x, y, 0);
x = (x2 + (radius * Math.cos(i)));
y = (y2 + (radius * Math.sin(i)));
i++;
};
}
}
}//package
Section 305
//Sounds (Sounds)
package {
import flash.media.*;
public class Sounds {
public var s_lightawoken:Sound;
public var s_winner:Sound;
public var soundsBeingPlayed:Array;
public var c_intotheblue:Class;
public var c_togetheragain:Class;
public var s_wall:Sound;
public var s_togetheragain:Sound;
public var c_winner:Class;
public var s_minimalist:Sound;
public var s_intotheblue:Sound;
public var c_minimalist:Class;
public var c_wall:Class;
public var c_bad:Class;
public var c_space:Class;
public var s_freeball:Sound;
public var s_bad:Sound;
public var s_space:Sound;
public var c_freeball:Class;
public var s_thelab:Sound;
public var s_bubble:Sound;
public var c_thelab:Class;
public var c_bubble:Class;
public var c_lightawoken:Class;
public var soundChannels:Array;
public function Sounds(){
c_bubble = Sounds_c_bubble;
c_freeball = Sounds_c_freeball;
c_wall = Sounds_c_wall;
c_bad = Sounds_c_bad;
c_minimalist = Sounds_c_minimalist;
c_lightawoken = Sounds_c_lightawoken;
c_intotheblue = Sounds_c_intotheblue;
c_togetheragain = Sounds_c_togetheragain;
c_thelab = Sounds_c_thelab;
c_space = Sounds_c_space;
c_winner = Sounds_c_winner;
super();
soundsBeingPlayed = new Array();
soundChannels = new Array();
s_winner = (new c_winner() as Sound);
s_lightawoken = (new c_lightawoken() as Sound);
s_togetheragain = (new c_togetheragain() as Sound);
s_intotheblue = (new c_intotheblue() as Sound);
s_space = (new c_space() as Sound);
s_thelab = (new c_thelab() as Sound);
s_minimalist = (new c_minimalist() as Sound);
s_bubble = (new c_bubble() as Sound);
s_wall = (new c_wall() as Sound);
s_freeball = (new c_freeball() as Sound);
s_bad = (new c_bad() as Sound);
soundsBeingPlayed[s_lightawoken] = false;
soundsBeingPlayed[s_intotheblue] = false;
soundsBeingPlayed[s_togetheragain] = false;
soundsBeingPlayed[s_thelab] = false;
soundsBeingPlayed[s_space] = false;
}
public function Stop(element, index:int, arr:Array){
element.close();
soundsBeingPlayed[element] = false;
}
public function StopMusic(){
if (soundsBeingPlayed[s_lightawoken]){
soundChannels[s_lightawoken].stop();
};
if (soundsBeingPlayed[s_togetheragain]){
soundChannels[s_togetheragain].stop();
};
if (soundsBeingPlayed[s_intotheblue]){
soundChannels[s_intotheblue].stop();
};
if (soundsBeingPlayed[s_thelab]){
soundChannels[s_thelab].stop();
};
if (soundsBeingPlayed[s_space]){
soundChannels[s_space].stop();
};
soundsBeingPlayed[s_lightawoken] = false;
soundsBeingPlayed[s_togetheragain] = false;
soundsBeingPlayed[s_intotheblue] = false;
soundsBeingPlayed[s_space] = false;
soundsBeingPlayed[s_thelab] = false;
}
public function PlaySound(whichSound:Sound){
if (soundsBeingPlayed[whichSound]){
return;
};
soundChannels[whichSound] = whichSound.play(0, 999);
soundsBeingPlayed[whichSound] = true;
}
public function StopOthers(which:Sound){
if (((soundsBeingPlayed[s_lightawoken]) && (!((which == s_lightawoken))))){
soundChannels[s_lightawoken].stop();
soundsBeingPlayed[s_lightawoken] = false;
};
if (((soundsBeingPlayed[s_togetheragain]) && (!((which == s_togetheragain))))){
soundChannels[s_togetheragain].stop();
soundsBeingPlayed[s_togetheragain] = false;
};
if (((soundsBeingPlayed[s_intotheblue]) && (!((which == s_intotheblue))))){
soundChannels[s_intotheblue].stop();
soundsBeingPlayed[s_intotheblue] = false;
};
if (((soundsBeingPlayed[s_thelab]) && (!((which == s_thelab))))){
soundChannels[s_thelab].stop();
soundsBeingPlayed[s_thelab] = false;
};
if (((soundsBeingPlayed[s_space]) && (!((which == s_space))))){
soundChannels[s_space].stop();
soundsBeingPlayed[s_space] = false;
};
}
}
}//package
Section 306
//Sounds_c_bad (Sounds_c_bad)
package {
import mx.core.*;
public class Sounds_c_bad extends SoundAsset {
}
}//package
Section 307
//Sounds_c_bubble (Sounds_c_bubble)
package {
import mx.core.*;
public class Sounds_c_bubble extends SoundAsset {
}
}//package
Section 308
//Sounds_c_freeball (Sounds_c_freeball)
package {
import mx.core.*;
public class Sounds_c_freeball extends SoundAsset {
}
}//package
Section 309
//Sounds_c_intotheblue (Sounds_c_intotheblue)
package {
import mx.core.*;
public class Sounds_c_intotheblue extends SoundAsset {
}
}//package
Section 310
//Sounds_c_lightawoken (Sounds_c_lightawoken)
package {
import mx.core.*;
public class Sounds_c_lightawoken extends SoundAsset {
}
}//package
Section 311
//Sounds_c_minimalist (Sounds_c_minimalist)
package {
import mx.core.*;
public class Sounds_c_minimalist extends SoundAsset {
}
}//package
Section 312
//Sounds_c_space (Sounds_c_space)
package {
import mx.core.*;
public class Sounds_c_space extends SoundAsset {
}
}//package
Section 313
//Sounds_c_thelab (Sounds_c_thelab)
package {
import mx.core.*;
public class Sounds_c_thelab extends SoundAsset {
}
}//package
Section 314
//Sounds_c_togetheragain (Sounds_c_togetheragain)
package {
import mx.core.*;
public class Sounds_c_togetheragain extends SoundAsset {
}
}//package
Section 315
//Sounds_c_wall (Sounds_c_wall)
package {
import mx.core.*;
public class Sounds_c_wall extends SoundAsset {
}
}//package
Section 316
//Sounds_c_winner (Sounds_c_winner)
package {
import mx.core.*;
public class Sounds_c_winner extends SoundAsset {
}
}//package
Section 317
//Text (Text)
package {
import flash.display.*;
import flash.geom.*;
import de.polygonal.ds.*;
public class Text {
private var arialWidth:Array;
private var c_erasbold:Class;
public var FANDANGO:int;// = 3
private var c_micro16:Class;
private var letters:Array;
public var MICRO:int;// = 0
public var LEVELFONT:int;// = 5
private var c_brit12:Class;
private var levelfontWidth:Array;
private var i_text:Image;
public var MICRO16:int;// = 1
private var brit12Width:Array;
public var BRIT12:int;// = 2
private var micro16Width:Array;
private var fandangoWidth:Array;
private var c_fandango:Class;
private var color:ColorTransform;
private var i_font:Array;
private var c_micro:Class;
private var microWidth:Array;
public var ARIAL:int;// = 4
private var microMap:Array;
private var c_levelfont:Class;
public function Text(){
var i:int;
var cursor:int;
c_levelfont = Text_c_levelfont;
c_brit12 = Text_c_brit12;
c_micro = Text_c_micro;
c_micro16 = Text_c_micro16;
c_fandango = Text_c_fandango;
c_erasbold = Text_c_erasbold;
super();
letters = new Array("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "~", "`", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "-", "_", "=", "+", "[", "{", "]", "}", ";", ":", "'", "\"", ",", "<", ".", ">", "/", "?", "¡", "¢", "£", "¥", "§", "©", "®", "¿", "À", "Á", "Â", "Ã", "Ä", "Å", "Æ", "Ç", "È", "É", "Ê", "Ë", "Ì", "Í", "Î", "Ï", "Ð", "Ñ", "Ò", "Ó", "Ô", "Õ", "Ö", "Ø", "Ù", "Ú", "Û", "Ü", "Ý", "ß", "à", "á", "â", "ã", "ä", "å", "æ", "ç", "è", "é", "ê", "ë", "ì", "í", "î", "ï", "ð", "ñ", "ò", "ó", "ô", "õ", "ö", "ø", "ù", "ú", "û", "ü", "ý", "ÿ");
microWidth = new Array(6, 6, 6, 6, 6, 6, 6, 6, 2, 5, 6, 5, 8, 6, 6, 6, 6, 6, 6, 6, 6, 6, 8, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 2, 5, 6, 5, 8, 6, 6, 6, 6, 6, 6, 6, 6, 6, 8, 6, 6, 6, 6, 3, 6, 6, 6, 6, 6, 5, 6, 6, 5, 3, 2, 6, 6, 6, 6, 4, 7, 6, 3, 3, 4, 6, 5, 4, 3, 4, 3, 4, 2, 2, 2, 4, 2, 4, 2, 4, 4, 6, 2, 6, 5, 6, 4, 6, 6, 6, 6, 6, 6, 6, 6, 6, 8, 6, 6, 6, 6, 6, 2, 2, 2, 2, 8, 8, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 8, 6, 6, 6, 6, 6, 2, 2, 2, 2, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6);
micro16Width = new Array(10, 10, 10, 10, 10, 10, 10, 10, 2, 8, 10, 8, 14, 10, 10, 10, 10, 10, 10, 10, 10, 10, 14, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 2, 8, 10, 8, 14, 10, 10, 10, 10, 10, 10, 10, 10, 10, 14, 10, 10, 10, 10, 4, 10, 10, 10, 10, 10, 8, 10, 10, 8, 4, 2, 10, 10, 10, 10, 6, 12, 10, 4, 4, 6, 10, 8, 6, 4, 5, 4, 6, 2, 2, 2, 6, 2, 6, 2, 6, 6, 10, 4, 14, 12, 14, 6, 10, 10, 14, 14, 14, 14, 14, 14, 14, 20, 14, 14, 14, 14, 14, 4, 4, 4, 4, 20, 20, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 20, 14, 14, 14, 14, 14, 4, 4, 4, 4, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14);
brit12Width = new Array(19, 19, 19, 19, 17, 17, 19, 19, 13, 16, 19, 17, 20, 18, 20, 18, 20, 18, 18, 18, 18, 18, 22, 19, 18, 19, 18, 18, 18, 18, 18, 15, 19, 17, 13, 14, 18, 13, 21, 17, 18, 18, 18, 16, 17, 15, 17, 17, 21, 17, 17, 17, 19, 15, 18, 18, 18, 18, 18, 18, 18, 18, 18, 12, 14, 21, 19, 18, 22, 18, 20, 15, 15, 15, 14, 18, 18, 18, 14, 15, 13, 15, 13, 13, 12, 15, 12, 17, 13, 17, 16, 16, 14, 18, 17, 18, 18, 21, 21, 16, 19, 19, 19, 19, 19, 19, 23, 19, 17, 17, 17, 17, 13, 13, 14, 17, 20, 18, 20, 20, 20, 20, 20, 20, 18, 18, 18, 18, 18, 17, 18, 18, 18, 18, 18, 18, 21, 17, 18, 18, 18, 18, 14, 13, 14, 17, 18, 17, 18, 18, 18, 18, 18, 18, 17, 17, 17, 17, 17, 17);
fandangoWidth = new Array(39, 37, 36, 35, 38, 39, 40, 39, 20, 34, 36, 34, 48, 35, 38, 39, 40, 42, 33, 39, 37, 40, 50, 38, 42, 37, 39, 37, 36, 35, 38, 39, 39, 39, 19, 34, 36, 34, 48, 35, 39, 39, 40, 42, 33, 39, 37, 39, 49, 37, 42, 37, 35, 27, 34, 33, 34, 34, 35, 33, 40, 35, 28, 28, 19, 39, 42, 31, 42, 28, 38, 31, 27, 26, 27, 28, 32, 28, 31, 31, 31, 31, 21, 19, 28, 23, 19, 28, 19, 28, 37, 36, 31, 31, 31, 31, 31, 16, 28, 31, 28, 28, 31, 28, 28, 28, 28, 28, 31, 28, 28, 31, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 50, 28, 31, 28, 28, 28, 28, 28, 38, 28, 31, 28, 28, 28, 28, 28, 50, 28, 28, 28, 28, 28, 28, 38, 28, 31, 31, 31, 31);
arialWidth = new Array(37, 30, 29, 32, 28, 28, 33, 33, 18, 27, 32, 28, 37, 33, 36, 28, 36, 29, 25, 30, 32, 36, 43, 34, 31, 30, 27, 29, 24, 30, 27, 22, 29, 29, 17, 23, 28, 18, 37, 29, 29, 29, 28, 23, 23, 22, 28, 29, 40, 30, 30, 25, 29, 21, 28, 27, 30, 27, 28, 26, 29, 28, 26, 17, 18, 35, 30, 25, 37, 27, 34, 22, 18, 18, 19, 26, 29, 29, 20, 20, 20, 20, 19, 16, 15, 21, 19, 24, 16, 24, 29, 26, 18, 24, 28, 31, 26, 34, 34, 26, 37, 37, 37, 37, 37, 37, 41, 29, 28, 28, 28, 28, 18, 19, 19, 20, 34, 33, 36, 36, 36, 36, 36, 35, 32, 32, 32, 32, 31, 29, 27, 27, 27, 27, 27, 27, 36, 24, 27, 27, 27, 27, 17, 19, 19, 20, 29, 29, 29, 29, 29, 29, 29, 29, 28, 28, 28, 28, 30, 30);
levelfontWidth = new Array(20, 20, 20, 20, 20, 20, 20, 20, 12, 18, 20, 18, 24, 20, 20, 20, 20, 20, 20, 20, 20, 20, 24, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 12, 18, 20, 18, 24, 20, 20, 20, 20, 20, 20, 20, 20, 20, 24, 20, 20, 20, 20, 14, 20, 20, 20, 20, 20, 18, 20, 20, 18, 14, 12, 20, 20, 20, 20, 16, 22, 20, 14, 14, 16, 20, 18, 16, 14, 15, 14, 16, 12, 12, 12, 16, 12, 16, 12, 16, 16, 20, 14, 24, 22, 24, 16, 20, 20, 24, 24, 24, 24, 24, 24, 24, 30, 24, 24, 24, 24, 24, 14, 14, 14, 14, 30, 30, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 30, 24, 24, 24, 24, 24, 14, 14, 14, 14, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24);
microMap = new Array();
microMap[0] = new HashMap();
microMap[1] = new HashMap();
microMap[2] = new HashMap();
microMap[3] = new HashMap();
microMap[4] = new HashMap();
microMap[5] = new HashMap();
cursor = 0;
i = 0;
while (i < micro16Width.length) {
microMap[1].insert(letters[i], new Rectangle(cursor, 0, (micro16Width[i] + 1), 16));
cursor = (cursor + micro16Width[i]);
cursor++;
i++;
};
cursor = 0;
i = 0;
while (i < microWidth.length) {
microMap[0].insert(letters[i], new Rectangle(cursor, 0, microWidth[i], 8));
cursor = (cursor + microWidth[i]);
i++;
};
cursor = 4;
i = 0;
while (i < brit12Width.length) {
microMap[2].insert(letters[i], new Rectangle(cursor, 0, ((brit12Width[i] + 2) - 10), 26));
cursor = (cursor + (brit12Width[i] - 10));
cursor++;
cursor = (cursor + 10);
i++;
};
cursor = 0;
i = 0;
while (i < fandangoWidth.length) {
microMap[3].insert(letters[i], new Rectangle(cursor, 0, ((fandangoWidth[i] + 7) - 10), 70));
cursor = (cursor + (fandangoWidth[i] - 10));
cursor++;
cursor = (cursor + 10);
i++;
};
cursor = 0;
i = 0;
while (i < arialWidth.length) {
microMap[4].insert(letters[i], new Rectangle(cursor, 0, ((arialWidth[i] + 9) - 10), 70));
cursor = (cursor + (arialWidth[i] - 10));
cursor++;
cursor = (cursor + 10);
i++;
};
cursor = 0;
i = 0;
while (i < levelfontWidth.length) {
microMap[5].insert(letters[i], new Rectangle(cursor, 0, ((levelfontWidth[i] + 7) - 10), 26));
cursor = (cursor + (levelfontWidth[i] - 10));
cursor++;
cursor = (cursor + 10);
i++;
};
}
public function drawText(text:String, x:int, y:int, font:int){
var letter:Rectangle;
i_text.bitmap.bitmapData.fillRect(i_text.bitmap.bitmapData.rect, 0);
var cursor:int;
var i:int;
while (i < text.length) {
if (text.charAt(i) == " "){
cursor = (cursor + 6);
} else {
letter = microMap[font].find(text.charAt(i));
i_text.bitmap.bitmapData.copyPixels(i_font[font].bitmap.bitmapData, letter, new Point(cursor, 0), null, null, true);
cursor = (cursor + letter.width);
};
i++;
};
if (((((((!((font == LEVELFONT))) && (!((font == BRIT12))))) && (!((font == FANDANGO))))) && (!((font == ARIAL))))){
i_text.render(null, true, new Matrix(1, 0, 0, 1, x, y), color);
} else {
i_text.render(null, true, new Matrix(1, 0, 0, 1, x, y));
};
}
public function changeColorTransform(c:ColorTransform){
color = c;
}
public function Init(screen:Bitmap){
color = new ColorTransform();
i_font = new Array();
i_font[MICRO] = new Image(screen, c_micro);
i_font[MICRO16] = new Image(screen, c_micro16);
i_font[BRIT12] = new Image(screen, c_brit12);
i_font[FANDANGO] = new Image(screen, c_fandango);
i_font[ARIAL] = new Image(screen, c_erasbold);
i_font[LEVELFONT] = new Image(screen, c_levelfont);
i_text = new Image(screen, c_micro);
i_text.bitmap.bitmapData = new BitmapData(640, 480, true, 0);
}
public function drawTextMatrix(text:String, font:int, matrix:Matrix){
var letter:Rectangle;
i_text.bitmap.bitmapData.fillRect(i_text.bitmap.bitmapData.rect, 0);
var cursor:int;
var i:int;
while (i < text.length) {
if (text.charAt(i) == " "){
cursor = (cursor + 6);
} else {
letter = microMap[font].find(text.charAt(i));
i_text.bitmap.bitmapData.copyPixels(i_font[font].bitmap.bitmapData, letter, new Point(cursor, 0), null, null, true);
cursor = (cursor + letter.width);
};
i++;
};
if (((((((!((font == LEVELFONT))) && (!((font == BRIT12))))) && (!((font == FANDANGO))))) && (!((font == ARIAL))))){
i_text.render(null, true, matrix, color);
} else {
i_text.render(null, true, matrix);
};
}
public function drawText2(text:String, x:int, y:int, font:int, minusWidth:int){
var letter:Rectangle;
i_text.bitmap.bitmapData.fillRect(i_text.bitmap.bitmapData.rect, 0);
var cursor:int;
var i:int;
while (i < text.length) {
if (text.charAt(i) == " "){
cursor = (cursor + 6);
} else {
letter = microMap[font].find(text.charAt(i));
i_text.bitmap.bitmapData.copyPixels(i_font[font].bitmap.bitmapData, letter, new Point(cursor, 0), null, null, true);
cursor = (cursor + (letter.width - minusWidth));
};
i++;
};
if (((((((!((font == LEVELFONT))) && (!((font == BRIT12))))) && (!((font == FANDANGO))))) && (!((font == ARIAL))))){
i_text.render(null, true, new Matrix(1, 0, 0, 1, x, y), color);
} else {
i_text.render(null, true, new Matrix(1, 0, 0, 1, x, y));
};
}
public function drawTextCustom(text:String, x:int, y:int, font:int, minusWidth:int){
var letter:Rectangle;
i_text.bitmap.bitmapData.fillRect(i_text.bitmap.bitmapData.rect, 0);
var cursor:int;
var i:int;
while (i < text.length) {
if (text.charAt(i) == " "){
cursor = (cursor + 6);
} else {
letter = microMap[font].find(text.charAt(i));
i_text.bitmap.bitmapData.copyPixels(i_font[font].bitmap.bitmapData, letter, new Point(cursor, 0), null, null, true);
cursor = (cursor + (letter.width - minusWidth));
};
i++;
};
i_text.render(null, true, new Matrix(1, 0, 0, 1, x, y), color);
}
public function ChangeColor(fcolor:uint){
color.color = fcolor;
}
public function drawTextFixWidth(text:String, x:int, y:int, width:int, font:int){
var letter:Rectangle;
i_text.bitmap.bitmapData.fillRect(i_text.bitmap.bitmapData.rect, 0);
var cursor:int;
var cursor2:int;
var cursor_y:int;
var i:int;
while (i < text.length) {
if (text.charAt(i) == " "){
cursor = (cursor + 6);
cursor2++;
} else {
letter = microMap[font].find(text.charAt(i));
i_text.bitmap.bitmapData.copyPixels(i_font[font].bitmap.bitmapData, letter, new Point(cursor, cursor_y), null, null, true);
cursor = (cursor + letter.width);
cursor2++;
if (cursor2 > width){
cursor2 = 0;
cursor = cursor2;
cursor_y = (cursor_y + (letter.height + 2));
};
};
i++;
};
if (((((((!((font == LEVELFONT))) && (!((font == BRIT12))))) && (!((font == FANDANGO))))) && (!((font == ARIAL))))){
i_text.render(null, true, new Matrix(1, 0, 0, 1, x, y), color);
} else {
i_text.render(null, true, new Matrix(1, 0, 0, 1, x, y));
};
}
}
}//package
Section 318
//Text_c_brit12 (Text_c_brit12)
package {
import mx.core.*;
public class Text_c_brit12 extends BitmapAsset {
}
}//package
Section 319
//Text_c_erasbold (Text_c_erasbold)
package {
import mx.core.*;
public class Text_c_erasbold extends BitmapAsset {
}
}//package
Section 320
//Text_c_fandango (Text_c_fandango)
package {
import mx.core.*;
public class Text_c_fandango extends BitmapAsset {
}
}//package
Section 321
//Text_c_levelfont (Text_c_levelfont)
package {
import mx.core.*;
public class Text_c_levelfont extends BitmapAsset {
}
}//package
Section 322
//Text_c_micro (Text_c_micro)
package {
import mx.core.*;
public class Text_c_micro extends BitmapAsset {
}
}//package
Section 323
//Text_c_micro16 (Text_c_micro16)
package {
import mx.core.*;
public class Text_c_micro16 extends BitmapAsset {
}
}//package
Section 324
//TitleScreen (TitleScreen)
package {
import flash.geom.*;
import mochi.*;
import flash.net.*;
public class TitleScreen extends Module {
private var alphaClickFlip:Boolean;
private var alphaClick:Number;
public function TitleScreen(){
super();
alphaClick = 0;
alphaClickFlip = true;
}
override public function Init(){
}
override public function Render(){
shared.images.i_titlescreen.render();
shared.images.i_clicktostart.render(null, true, new Matrix(1, 0, 0, 1, 242, 240), new ColorTransform(1, 1, 1, alphaClick, 0, 0, 0, 0));
shared.buttons.b_polinkolink.render();
}
public function callLink():void{
var url = "http://www.polinko.com";
var request:URLRequest = new URLRequest(url);
navigateToURL(request, "_blank");
//unresolved jump
var _slot1 = e;
trace("Error occurred!");
}
override public function onNextFrame(delta:Number):void{
Process();
Render();
}
override public function Process(){
shared.buttons.b_polinkolink.process(shared);
if (shared.buttons.b_polinkolink.isClicked()){
callLink();
shared.input.mousePressed = false;
shared.input.mouseToggle = false;
shared.input.mouseDown = false;
};
if (((shared.input.mousePressed) && (!(shared.buttons.b_polinkolink.getRect().contains(shared.input.mousex, shared.input.mousey))))){
shared.nextGamestate = shared.LOADLEVEL;
};
if (alphaClick >= 1){
alphaClickFlip = false;
} else {
if (alphaClick <= 0){
alphaClickFlip = true;
};
};
if (alphaClickFlip){
alphaClick = (alphaClick + 0.04);
} else {
alphaClick = (alphaClick - 0.04);
};
}
}
}//package
Section 325
//Transition (Transition)
package {
import flash.geom.*;
public class Transition extends Module {
public var screenTemp:Image;
private var warpValue:Number;
private var nextRender:Image;
private var previousRender:Image;
public var screenTemp2:Image;
private var fadeValue:Number;
private var c_blank:Class;
public function Transition(){
c_blank = Transition_c_blank;
super();
}
override public function Process(){
shared.gamestate[shared.previousGamestate].Render();
screenTemp.bitmap.bitmapData.copyPixels(shared.screen.bitmapData, new Rectangle(0, 0, 640, 480), new Point(0, 0));
shared.gamestate[shared.nextGamestate].Render();
screenTemp2.bitmap.bitmapData.copyPixels(shared.screen.bitmapData, new Rectangle(0, 0, 640, 480), new Point(0, 0));
switch (shared.transition){
case shared.FADE:
if (fadeValue > 0){
fadeValue = (fadeValue - 0.05);
};
if (fadeValue <= 0){
shared.transitionFinished = true;
return;
};
break;
case shared.WARP:
if (warpValue > 0){
warpValue = (warpValue - 0.05);
};
if (warpValue <= 0){
shared.transitionFinished = true;
return;
};
break;
case shared.SCALE:
if (warpValue > 0){
warpValue = (warpValue - 0.05);
};
if (warpValue <= 0){
shared.transitionFinished = true;
return;
};
break;
};
}
public function Reset(){
fadeValue = 1;
warpValue = 1;
}
override public function Init(){
fadeValue = 1;
warpValue = 1;
screenTemp = new Image(shared.screen, c_blank);
screenTemp2 = new Image(shared.screen, c_blank);
}
override public function onNextFrame(delta:Number):void{
Process();
Render();
}
override public function Render(){
shared.screen.bitmapData.fillRect(new Rectangle(0, 0, 640, 480), 0);
switch (shared.transition){
case shared.FADE:
screenTemp.render(null, true, new Matrix(1, 0, 0, 1, 0, 0), new ColorTransform(1, 1, 1, fadeValue, 0, 0, 0, 0));
screenTemp2.render(null, true, new Matrix(1, 0, 0, 1, 0, 0), new ColorTransform(1, 1, 1, (1 - fadeValue), 0, 0, 0, 0));
break;
case shared.WARP:
screenTemp.render(null, true, new Matrix(1, (1 - warpValue), (1 - warpValue), 1, 0, 0));
screenTemp2.render(null, true, new Matrix(1, warpValue, warpValue, 1, 0, 0));
break;
case shared.SCALE:
screenTemp.render(null, true, new Matrix(1, 0, 0, 1, 0, 0));
screenTemp2.render(null, true, new Matrix((1 - warpValue), 0, 0, (1 - warpValue), 0, 0));
break;
};
}
}
}//package
Section 326
//Transition_c_blank (Transition_c_blank)
package {
import mx.core.*;
public class Transition_c_blank extends BitmapAsset {
}
}//package