Section 1
//KongregateEvent (com.kongregate.as3.client.events.KongregateEvent)
package com.kongregate.as3.client.events {
import flash.events.*;
public class KongregateEvent extends Event {
public static const COMPLETE:String = "component_api_available";
public function KongregateEvent(_arg1:String){
super(_arg1);
}
}
}//package com.kongregate.as3.client.events
Section 2
//AbstractShadowService (com.kongregate.as3.client.services.AbstractShadowService)
package com.kongregate.as3.client.services {
import flash.events.*;
public class AbstractShadowService extends EventDispatcher {
protected function alert(_arg1:String, _arg2:String, _arg3="", _arg4:String=""):void{
trace(((((((("Kongregate API: " + _arg1) + ".") + _arg2) + "(") + _arg3) + ") ") + _arg4));
}
}
}//package com.kongregate.as3.client.services
Section 3
//HighScoreServiceShadow (com.kongregate.as3.client.services.HighScoreServiceShadow)
package com.kongregate.as3.client.services {
public class HighScoreServiceShadow extends AbstractShadowService implements IHighScoreServices {
private var mode:String;
public function HighScoreServiceShadow(){
mode = "";
}
public function submit(_arg1:Number, _arg2:String=null):void{
alert("IHighScoreServices", "submit", arguments);
}
public function connect():Boolean{
alert("IKongregateServices", "connect");
return (true);
}
public function requestList(_arg1:Function):void{
alert("IHighScoreServices", "requestList", "", (("[Mode: " + mode) + "]"));
_arg1({success:false});
}
public function setMode(_arg1:String):void{
alert("IHighScoreServices", "setMode", arguments);
this.mode = _arg1;
}
}
}//package com.kongregate.as3.client.services
Section 4
//IHighScoreServices (com.kongregate.as3.client.services.IHighScoreServices)
package com.kongregate.as3.client.services {
public interface IHighScoreServices {
function setMode(_arg1:String):void;
function submit(_arg1:Number, _arg2:String=null):void;
function requestList(_arg1:Function):void;
}
}//package com.kongregate.as3.client.services
Section 5
//IKongregateServices (com.kongregate.as3.client.services.IKongregateServices)
package com.kongregate.as3.client.services {
import flash.events.*;
public interface IKongregateServices extends IEventDispatcher {
function getPlayerInfo(_arg1:Function):void;
function connect(_arg1:Number=-1):Boolean;
}
}//package com.kongregate.as3.client.services
Section 6
//IStatServices (com.kongregate.as3.client.services.IStatServices)
package com.kongregate.as3.client.services {
public interface IStatServices {
function submitArray(_arg1:Array):void;
function submit(_arg1:String, _arg2:Number):void;
}
}//package com.kongregate.as3.client.services
Section 7
//IUserServices (com.kongregate.as3.client.services.IUserServices)
package com.kongregate.as3.client.services {
public interface IUserServices {
function getName():String;
function getPlayerInfo(_arg1:Function):void;
}
}//package com.kongregate.as3.client.services
Section 8
//KongregateServiceShadow (com.kongregate.as3.client.services.KongregateServiceShadow)
package com.kongregate.as3.client.services {
public class KongregateServiceShadow extends AbstractShadowService implements IKongregateServices {
public function getName():String{
alert("IKongregateServices", "getName");
return ("Guest");
}
public function connect(_arg1:Number=-1):Boolean{
alert("IKongregateServices", "connect", arguments);
return (true);
}
public function getPlayerInfo(_arg1:Function):void{
alert("IKongregateServices", "getPlayerInfo");
_arg1(new Object());
}
}
}//package com.kongregate.as3.client.services
Section 9
//StatServiceShadow (com.kongregate.as3.client.services.StatServiceShadow)
package com.kongregate.as3.client.services {
public class StatServiceShadow extends AbstractShadowService implements IStatServices {
public function submitArray(_arg1:Array):void{
alert("IStatServices", "submitArray", arguments);
}
public function submit(_arg1:String, _arg2:Number):void{
alert("IStatServices", "submitStat", arguments);
}
}
}//package com.kongregate.as3.client.services
Section 10
//UserServiceShadow (com.kongregate.as3.client.services.UserServiceShadow)
package com.kongregate.as3.client.services {
public class UserServiceShadow extends AbstractShadowService implements IUserServices {
public function getName():String{
alert("UserService", "getName");
return ("Guest");
}
public function getPlayerInfo(_arg1:Function):void{
alert("UserService", "getPlayerInfo");
_arg1({isGuest:true, name:"Guest", points:0, level:0, isMode:false, isAdmin:false, isDeveloper:false, avatarPath:"", chatAvatarPath:""});
}
}
}//package com.kongregate.as3.client.services
Section 11
//IAPIBootstrap (com.kongregate.as3.client.IAPIBootstrap)
package com.kongregate.as3.client {
import flash.events.*;
import flash.display.*;
public interface IAPIBootstrap {
function init(_arg1:Event=null, _arg2:Stage=null):void;
function hideLog():void;
function showLog(_arg1:int=0):void;
}
}//package com.kongregate.as3.client
Section 12
//KongregateAPI (com.kongregate.as3.client.KongregateAPI)
package com.kongregate.as3.client {
import flash.errors.*;
import flash.events.*;
import flash.net.*;
import flash.system.*;
import flash.display.*;
import flash.utils.*;
import com.kongregate.as3.client.services.*;
import com.kongregate.as3.client.events.*;
public class KongregateAPI extends Sprite {
private const VERSION:Number = 1;
private var loader:Loader;
private var loadedDomain:ApplicationDomain;
private static const CLASS_USER:String = "com.kongregate.as3.client.services.UserServices";
private static const CLASS_STATS:String = "com.kongregate.as3.client.services.StatServices";
private static const CLASS_SERVICES:String = "com.kongregate.as3.client.services.KongregateServices";
private static const CLASS_SCORES:String = "com.kongregate.as3.client.services.HighScoreServices";
private static const DEBUG_API_URL:String = "//Linuxpc/kongregate/public/flash/API_AS3.swf";
private static var _connected:Boolean;
private static var kUser:IUserServices;
private static var _loaded:Boolean;
private static var kServices:IKongregateServices;
private static var kScores:IHighScoreServices;
private static var mInstance:KongregateAPI;
private static var kStats:IStatServices;
private static var kAPI:IAPIBootstrap;
public function KongregateAPI(){
if (mInstance != null){
throw (new Error("Warning: KongregateAPI has been added to stage more than once or accessed improperly. Use getInstance() or a stage reference to access."));
};
mInstance = this;
this.addEventListener(Event.ADDED_TO_STAGE, init, false, 0, true);
}
public function get loaded():Boolean{
return (_loaded);
}
public function get connected():Boolean{
return (_connected);
}
private function alertConnected(_arg1:TimerEvent=null):void{
var _local2:KongregateEvent;
var _local3:Boolean;
_local2 = new KongregateEvent(KongregateEvent.COMPLETE);
_local3 = this.dispatchEvent(_local2);
}
private function init(_arg1:Event):void{
var _local2:Object;
var _local3:String;
var _local4:URLRequest;
var _local5:LoaderContext;
this.removeEventListener(Event.ADDED_TO_STAGE, init);
_loaded = false;
_connected = false;
_local2 = LoaderInfo(root.loaderInfo).parameters;
_local3 = _local2.api_path;
if (_local3 == null){
trace("Alert: Kongregate API could not be loaded, due to local testing. API will load when the game is uploaded.");
createShadowServices();
return;
};
Security.allowDomain("*.kongregate.com");
Security.allowDomain("kongregatetrunk.com");
_local4 = new URLRequest(_local3);
_local5 = new LoaderContext(false);
_local5.applicationDomain = ApplicationDomain.currentDomain;
_local5.securityDomain = SecurityDomain.currentDomain;
loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete);
loader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
loader.load(_local4, _local5);
}
public function get api():IAPIBootstrap{
return (kAPI);
}
private function loadComplete(_arg1:Event):void{
getServices();
}
public function get scores():IHighScoreServices{
return (kScores);
}
private function ioErrorHandler(_arg1:IOErrorEvent):void{
throw (new IOError(("API file not found. " + _arg1)));
}
public function get services():IKongregateServices{
return (kServices);
}
public function get stats():IStatServices{
return (kStats);
}
private function createShadowServices():void{
var _local1:Timer;
trace(">>> Kongregate Shadow Services instantiated for local development..");
kServices = new KongregateServiceShadow();
kScores = new HighScoreServiceShadow();
kStats = new StatServiceShadow();
kUser = new UserServiceShadow();
_local1 = new Timer(200, 1);
_local1.addEventListener(TimerEvent.TIMER_COMPLETE, alertConnected);
_local1.start();
_connected = true;
}
public function get user():IUserServices{
return (kUser);
}
private function getServices():void{
var _local1:ApplicationDomain;
var _local2:*;
var _local3:*;
var _local4:*;
var _local5:*;
_local1 = ApplicationDomain.currentDomain;
kAPI = IAPIBootstrap(loader.getChildAt(0));
this.addChild(loader);
_local2 = _local1.getDefinition(CLASS_SERVICES);
trace(_local2);
kServices = _local2.getInstance();
_local3 = _local1.getDefinition(CLASS_SCORES);
kScores = _local3.getInstance();
_local4 = _local1.getDefinition(CLASS_STATS);
kStats = _local4.getInstance();
_local5 = _local1.getDefinition(CLASS_USER);
kUser = _local5.getInstance();
kServices.connect(VERSION);
_loaded = true;
_connected = true;
alertConnected();
}
public static function getInstance():KongregateAPI{
if (!(mInstance)){
throw (new IllegalOperationError("You must add the Kongregate API component to the stage before attempting to access it."));
};
return (mInstance);
}
}
}//package com.kongregate.as3.client
Section 13
//b2BoxDef (Engine.Collision.Shapes.b2BoxDef)
package Engine.Collision.Shapes {
import Engine.Common.Math.*;
public class b2BoxDef extends b2ShapeDef {
public var extents:b2Vec2;
public function b2BoxDef(){
super();
type = b2Shape.e_boxShape;
extents = new b2Vec2(1, 1);
}
}
}//package Engine.Collision.Shapes
Section 14
//b2CircleDef (Engine.Collision.Shapes.b2CircleDef)
package Engine.Collision.Shapes {
public class b2CircleDef extends b2ShapeDef {
public var radius:Number;
public function b2CircleDef(){
super();
type = b2Shape.e_circleShape;
radius = 1;
}
}
}//package Engine.Collision.Shapes
Section 15
//b2CircleShape (Engine.Collision.Shapes.b2CircleShape)
package Engine.Collision.Shapes {
import Engine.Common.Math.*;
import Engine.Collision.*;
import Engine.Dynamics.*;
public class b2CircleShape extends b2Shape {
public var m_localPosition:b2Vec2;
public var m_radius:Number;
public function b2CircleShape(def:b2ShapeDef, body:b2Body, localCenter:b2Vec2){
var circle:b2CircleDef;
var aabb:b2AABB;
var broadPhase:b2BroadPhase;
m_localPosition = new b2Vec2();
super(def, body);
circle = (def as b2CircleDef);
m_localPosition.Set((def.localPosition.x - localCenter.x), (def.localPosition.y - localCenter.y));
m_type = b2Shape.e_circleShape;
m_radius = circle.radius;
m_R.SetM(m_body.m_R);
m_position.SetV(m_localPosition);
m_position.MulM(m_R);
m_position.Add(m_body.m_position);
aabb = new b2AABB();
aabb.minVertex.Set((m_position.x - m_radius), (m_position.y - m_radius));
aabb.maxVertex.Set((m_position.x + m_radius), (m_position.y + m_radius));
broadPhase = m_body.m_world.m_broadPhase;
if (broadPhase.InRange(aabb)){
m_proxyId = broadPhase.CreateProxy(aabb, def.groupIndex, def.categoryBits, def.maskBits, this);
} else {
m_proxyId = b2Pair.b2_nullProxy;
};
if (m_proxyId == b2Pair.b2_nullProxy){
m_body.Freeze();
};
}
override public function ResetProxy(broadPhase:b2BroadPhase):void{
var proxy:b2Proxy;
var groupIndex:int;
var categoryBits:uint;
var maskBits:uint;
var aabb:b2AABB;
if (m_proxyId == b2Pair.b2_nullProxy){
return;
};
proxy = broadPhase.GetProxy(m_proxyId);
groupIndex = proxy.groupIndex;
categoryBits = proxy.categoryBits;
maskBits = proxy.maskBits;
broadPhase.DestroyProxy(m_proxyId);
proxy = null;
aabb = new b2AABB();
aabb.minVertex.Set((m_position.x - m_radius), (m_position.y - m_radius));
aabb.maxVertex.Set((m_position.x + m_radius), (m_position.y + m_radius));
if (broadPhase.InRange(aabb)){
m_proxyId = broadPhase.CreateProxy(aabb, groupIndex, categoryBits, maskBits, this);
} else {
m_proxyId = b2Pair.b2_nullProxy;
};
if (m_proxyId == b2Pair.b2_nullProxy){
m_body.Freeze();
};
}
override public function Support(dX:Number, dY:Number):b2Vec2{
var len:Number;
len = Math.sqrt(((dX * dX) + (dY * dY)));
dX = (dX / len);
dY = (dY / len);
return (new b2Vec2((m_position.x + (m_radius * dX)), (m_position.y + (m_radius * dY))));
}
override public function Synchronize(position:b2Vec2, R:b2Mat22):void{
var aabb:b2AABB;
var broadPhase:b2BroadPhase;
m_R.SetM(R);
m_position.SetV(m_localPosition);
m_position.MulM(R);
m_position.Add(position);
if (m_proxyId == b2Pair.b2_nullProxy){
return;
};
aabb = new b2AABB();
aabb.minVertex.Set((m_position.x - m_radius), (m_position.y - m_radius));
aabb.maxVertex.Set((m_position.x + m_radius), (m_position.y + m_radius));
broadPhase = m_body.m_world.m_broadPhase;
if (broadPhase.InRange(aabb)){
broadPhase.MoveProxy(m_proxyId, aabb);
} else {
broadPhase.DestroyProxy(m_proxyId);
m_proxyId = b2Pair.b2_nullProxy;
m_body.Freeze();
};
}
override public function TestPoint(p:b2Vec2):Boolean{
var d:b2Vec2;
d = new b2Vec2();
d.SetV(p);
d.Subtract(m_position);
return ((b2Math.b2Dot(d, d) <= (m_radius * m_radius)));
}
}
}//package Engine.Collision.Shapes
Section 16
//b2MassData (Engine.Collision.Shapes.b2MassData)
package Engine.Collision.Shapes {
import Engine.Common.Math.*;
public class b2MassData {
public var mass:Number;// = 0
public var center:b2Vec2;
public var I:Number;// = 0
public function b2MassData(){
mass = 0;
center = new b2Vec2(0, 0);
I = 0;
super();
}
}
}//package Engine.Collision.Shapes
Section 17
//b2PolyDef (Engine.Collision.Shapes.b2PolyDef)
package Engine.Collision.Shapes {
import Engine.Common.*;
import Engine.Common.Math.*;
public class b2PolyDef extends b2ShapeDef {
public var vertexCount:int;
public var vertices:Array;
public function b2PolyDef(){
var i:int;
vertices = new Array(b2Settings.b2_maxPolyVertices);
super();
type = b2Shape.e_polyShape;
vertexCount = 0;
i = 0;
while (i < b2Settings.b2_maxPolyVertices) {
vertices[i] = new b2Vec2();
i++;
};
}
}
}//package Engine.Collision.Shapes
Section 18
//b2PolyShape (Engine.Collision.Shapes.b2PolyShape)
package Engine.Collision.Shapes {
import Engine.Common.Math.*;
import Engine.Collision.*;
import Engine.Common.*;
import Engine.Dynamics.*;
public class b2PolyShape extends b2Shape {
public var m_vertices:Array;
public var m_normals:Array;
public var m_nextVert:Array;
public var m_localOBB:b2OBB;
public var m_vertexCount:int;
public function b2PolyShape(def:b2ShapeDef, body:b2Body, localCenter:b2Vec2):void{
var i:int;
var h:b2Vec2;
var tVec:b2Vec2;
var aabb:b2AABB;
var localR:b2Mat22;
var localPositionX:Number;
var localPositionY:Number;
var minVertex:b2Vec2;
var maxVertex:b2Vec2;
var R:b2Mat22;
var absR:b2Mat22;
var position:b2Vec2;
var broadPhase:b2BroadPhase;
var box:b2BoxDef;
var poly:b2PolyDef;
var edge:b2Vec2;
m_localOBB = new b2OBB();
super(def, body);
aabb = new b2AABB();
m_vertices = new Array(b2Settings.b2_maxPolyVertices);
m_nextVert = new Array();
m_normals = new Array(b2Settings.b2_maxPolyVertices);
m_type = b2Shape.e_polyShape;
localR = new b2Mat22(def.localRotation);
localPositionX = (def.localPosition.x - localCenter.x);
localPositionY = (def.localPosition.y - localCenter.y);
if (def.type === b2Shape.e_boxShape){
box = (def as b2BoxDef);
m_vertexCount = 4;
h = box.extents;
m_vertices[0] = new b2Vec2(h.x, h.y);
tVec = m_vertices[0];
tVec.MulM(localR);
tVec.x = (tVec.x + localPositionX);
tVec.y = (tVec.y + localPositionY);
m_vertices[1] = new b2Vec2(-(h.x), h.y);
tVec = m_vertices[1];
tVec.MulM(localR);
tVec.x = (tVec.x + localPositionX);
tVec.y = (tVec.y + localPositionY);
m_vertices[2] = new b2Vec2(-(h.x), -(h.y));
tVec = m_vertices[2];
tVec.MulM(localR);
tVec.x = (tVec.x + localPositionX);
tVec.y = (tVec.y + localPositionY);
m_vertices[3] = new b2Vec2(h.x, -(h.y));
tVec = m_vertices[3];
tVec.MulM(localR);
tVec.x = (tVec.x + localPositionX);
tVec.y = (tVec.y + localPositionY);
} else {
poly = (def as b2PolyDef);
m_vertexCount = poly.vertexCount;
i = 0;
while (i < m_vertexCount) {
m_vertices[i] = poly.vertices[i].Copy();
tVec = m_vertices[i];
tVec.MulM(localR);
tVec.x = (tVec.x + localPositionX);
tVec.y = (tVec.y + localPositionY);
i++;
};
};
minVertex = new b2Vec2(Number.MAX_VALUE, Number.MAX_VALUE);
maxVertex = new b2Vec2(-(Number.MAX_VALUE), -(Number.MAX_VALUE));
i = 0;
while (i < m_vertexCount) {
minVertex = b2Math.b2MinV(minVertex, m_vertices[i]);
maxVertex = b2Math.b2MaxV(maxVertex, m_vertices[i]);
i++;
};
m_localOBB.R.SetIdentity();
m_localOBB.center.Set(((minVertex.x + maxVertex.x) * 0.5), ((minVertex.y + maxVertex.y) * 0.5));
m_localOBB.extents.Set(((maxVertex.x - minVertex.x) * 0.5), ((maxVertex.y - minVertex.y) * 0.5));
i = 0;
while (i < m_vertexCount) {
m_nextVert[i] = (((i + 1) < m_vertexCount)) ? (i + 1) : 0;
edge = m_vertices[m_nextVert[i]].Copy();
edge.Subtract(m_vertices[i]);
m_normals[i] = new b2Vec2();
tVec = m_normals[i];
tVec.SetV(edge);
tVec.CrossVF(1);
tVec.Normalize();
i++;
};
i = 0;
while (i < m_vertexCount) {
i++;
};
m_R = m_body.m_R.Copy();
m_position.SetV(m_body.m_position);
R = b2Math.b2MulMM(m_R, m_localOBB.R);
absR = b2Math.b2AbsM(R);
h = b2Math.b2MulMV(absR, m_localOBB.extents);
position = b2Math.b2MulMV(m_R, m_localOBB.center);
position.Add(m_position);
aabb.minVertex.SetV(position);
aabb.minVertex.Subtract(h);
aabb.maxVertex.SetV(position);
aabb.maxVertex.Add(h);
broadPhase = m_body.m_world.m_broadPhase;
if (broadPhase.InRange(aabb)){
m_proxyId = broadPhase.CreateProxy(aabb, def.groupIndex, def.categoryBits, def.maskBits, this);
} else {
m_proxyId = b2Pair.b2_nullProxy;
};
if (m_proxyId == b2Pair.b2_nullProxy){
m_body.Freeze();
};
}
override public function ResetProxy(broadPhase:b2BroadPhase):void{
var proxy:b2Proxy;
var groupIndex:int;
var categoryBits:uint;
var maskBits:uint;
var R:b2Mat22;
var absR:b2Mat22;
var h:b2Vec2;
var position:b2Vec2;
var aabb:b2AABB;
if (m_proxyId == b2Pair.b2_nullProxy){
return;
};
proxy = broadPhase.GetProxy(m_proxyId);
groupIndex = proxy.groupIndex;
categoryBits = proxy.categoryBits;
maskBits = proxy.maskBits;
broadPhase.DestroyProxy(m_proxyId);
proxy = null;
R = b2Math.b2MulMM(m_R, m_localOBB.R);
absR = b2Math.b2AbsM(R);
h = b2Math.b2MulMV(absR, m_localOBB.extents);
position = b2Math.b2MulMV(m_R, m_localOBB.center);
position.Add(m_position);
aabb = new b2AABB();
aabb.minVertex.SetV(position);
aabb.minVertex.Subtract(h);
aabb.maxVertex.SetV(position);
aabb.maxVertex.Add(h);
if (broadPhase.InRange(aabb)){
m_proxyId = broadPhase.CreateProxy(aabb, groupIndex, categoryBits, maskBits, this);
} else {
m_proxyId = b2Pair.b2_nullProxy;
};
if (m_proxyId == b2Pair.b2_nullProxy){
m_body.Freeze();
};
}
override public function Support(dX:Number, dY:Number):b2Vec2{
var dLocalX:Number;
var dLocalY:Number;
var bestIndex:int;
var bestValue:Number;
var i:int;
var value:Number;
dLocalX = ((dX * m_R.col1.x) + (dY * m_R.col1.y));
dLocalY = ((dX * m_R.col2.x) + (dY * m_R.col2.y));
bestIndex = 0;
bestValue = ((m_vertices[0].x * dLocalX) + (m_vertices[0].y * dLocalY));
i = 1;
while (i < m_vertexCount) {
value = ((m_vertices[i].x * dLocalX) + (m_vertices[i].y * dLocalY));
if (value > bestValue){
bestIndex = i;
bestValue = value;
};
i++;
};
return (new b2Vec2((m_position.x + ((m_R.col1.x * m_vertices[bestIndex].x) + (m_R.col2.x * m_vertices[bestIndex].y))), (m_position.y + ((m_R.col1.y * m_vertices[bestIndex].x) + (m_R.col2.y * m_vertices[bestIndex].y)))));
}
override public function Synchronize(position:b2Vec2, R:b2Mat22):void{
var obbR:b2Mat22;
var absR:b2Mat22;
var h:b2Vec2;
var center:b2Vec2;
var aabb:b2AABB;
var broadPhase:b2BroadPhase;
m_R.SetM(R);
m_position.SetV(position);
if (m_proxyId == b2Pair.b2_nullProxy){
return;
};
obbR = b2Math.b2MulMM(m_R, m_localOBB.R);
absR = b2Math.b2AbsM(obbR);
h = b2Math.b2MulMV(absR, m_localOBB.extents);
center = b2Math.b2MulMV(m_R, m_localOBB.center);
center.Add(m_position);
aabb = new b2AABB();
aabb.minVertex.SetV(center);
aabb.minVertex.Subtract(h);
aabb.maxVertex.SetV(center);
aabb.maxVertex.Add(h);
broadPhase = m_body.m_world.m_broadPhase;
if (broadPhase.InRange(aabb)){
broadPhase.MoveProxy(m_proxyId, aabb);
} else {
broadPhase.DestroyProxy(m_proxyId);
m_proxyId = b2Pair.b2_nullProxy;
m_body.Freeze();
};
}
override public function TestPoint(p:b2Vec2):Boolean{
var pLocal:b2Vec2;
var i:int;
var tVec:b2Vec2;
var dot:Number;
pLocal = new b2Vec2();
pLocal.SetV(p);
pLocal.Subtract(m_position);
pLocal.MulTM(m_R);
i = 0;
while (i < m_vertexCount) {
tVec = new b2Vec2();
tVec.SetV(pLocal);
tVec.Subtract(m_vertices[i]);
dot = b2Math.b2Dot(m_normals[i], tVec);
if (dot > 0){
return (false);
};
i++;
};
return (true);
}
}
}//package Engine.Collision.Shapes
Section 19
//b2Shape (Engine.Collision.Shapes.b2Shape)
package Engine.Collision.Shapes {
import Engine.Dynamics.*;
import Engine.Common.Math.*;
import Engine.Collision.*;
public class b2Shape {
public var m_R:b2Mat22;
public var m_next:b2Shape;
public var m_type:int;
public var m_friction:Number;
public var m_proxyId:int;
public var m_userData;// = null
public var m_body:b2Body;
public var m_restitution:Number;
public var m_position:b2Vec2;
public static const e_boxShape:int = 1;
public static const e_unknownShape:int = -1;
public static const e_shapeTypeCount:int = 4;
public static const e_circleShape:int = 0;
public static const e_meshShape:int = 3;
public static const e_polyShape:int = 2;
public function b2Shape(def:b2ShapeDef, body:b2Body):void{
m_userData = null;
m_position = new b2Vec2();
m_R = new b2Mat22();
super();
m_userData = def.userData;
m_friction = def.friction;
m_restitution = def.restitution;
m_body = body;
m_proxyId = b2Pair.b2_nullProxy;
}
public function GetPosition():b2Vec2{
return (m_position);
}
public function GetNext():b2Shape{
return (m_next);
}
public function GetType():int{
return (m_type);
}
public function GetUserData(){
return (m_userData);
}
public function Support(dX:Number, dY:Number):b2Vec2{
return (null);
}
public function Synchronize(position:b2Vec2, R:b2Mat22):void{
}
public function GetRotationMatrix():b2Mat22{
return (m_R);
}
public function GetBody():b2Body{
return (m_body);
}
public function TestPoint(p:b2Vec2):Boolean{
return (false);
}
public function ResetProxy(broadPhase:b2BroadPhase):void{
}
public static function Destroy(shape:b2Shape):void{
if (shape.m_proxyId !== b2Pair.b2_nullProxy){
shape.m_body.m_world.m_broadPhase.DestroyProxy(shape.m_proxyId);
};
}
public static function PolyMass(massData:b2MassData, vs:Array, count:int, rho:Number):void{
var center:b2Vec2;
var area:Number;
var I:Number;
var pRef:b2Vec2;
var inv3:Number;
var i:int;
var p1:b2Vec2;
var p2:b2Vec2;
var p3:b2Vec2;
var e1:b2Vec2;
var e2:b2Vec2;
var D:Number;
var triangleArea:Number;
var tVec:b2Vec2;
var px:Number;
var py:Number;
var ex1:Number;
var ey1:Number;
var ex2:Number;
var ey2:Number;
var intx2:Number;
var inty2:Number;
center = new b2Vec2();
center.SetZero();
area = 0;
I = 0;
pRef = new b2Vec2(0, 0);
inv3 = (1 / 3);
i = 0;
while (i < count) {
p1 = pRef;
p2 = vs[i];
p3 = (((i + 1) < count)) ? vs[(i + 1)] : vs[0];
e1 = b2Math.SubtractVV(p2, p1);
e2 = b2Math.SubtractVV(p3, p1);
D = b2Math.b2CrossVV(e1, e2);
triangleArea = (0.5 * D);
area = (area + triangleArea);
tVec = new b2Vec2();
tVec.SetV(p1);
tVec.Add(p2);
tVec.Add(p3);
tVec.Multiply((inv3 * triangleArea));
center.Add(tVec);
px = p1.x;
py = p1.y;
ex1 = e1.x;
ey1 = e1.y;
ex2 = e2.x;
ey2 = e2.y;
intx2 = ((inv3 * ((0.25 * (((ex1 * ex1) + (ex2 * ex1)) + (ex2 * ex2))) + ((px * ex1) + (px * ex2)))) + ((0.5 * px) * px));
inty2 = ((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 = (rho * area);
center.Multiply((1 / area));
massData.center = center;
I = (rho * (I - (area * b2Math.b2Dot(center, center))));
massData.I = I;
}
public static function Create(def:b2ShapeDef, body:b2Body, center:b2Vec2):b2Shape{
switch (def.type){
case e_circleShape:
return (new b2CircleShape(def, body, center));
case e_boxShape:
case e_polyShape:
return (new b2PolyShape(def, body, center));
};
return (null);
}
}
}//package Engine.Collision.Shapes
Section 20
//b2ShapeDef (Engine.Collision.Shapes.b2ShapeDef)
package Engine.Collision.Shapes {
import Engine.Common.Math.*;
import Engine.Common.*;
public class b2ShapeDef {
public var groupIndex:int;
public var categoryBits:int;
public var localRotation:Number;
public var restitution:Number;
public var userData;// = null
public var density:Number;
public var maskBits:int;
public var type:int;
public var localPosition:b2Vec2;
public var friction:Number;
public function b2ShapeDef(){
userData = null;
super();
type = b2Shape.e_unknownShape;
userData = null;
localPosition = new b2Vec2(0, 0);
localRotation = 0;
friction = 0.2;
restitution = 0;
density = 0;
categoryBits = 1;
maskBits = 0xFFFF;
groupIndex = 0;
}
public function ComputeMass(massData:b2MassData):void{
var circle:b2CircleDef;
var box:b2BoxDef;
var poly:b2PolyDef;
massData.center = new b2Vec2(0, 0);
if (density === 0){
massData.mass = 0;
massData.center.Set(0, 0);
massData.I = 0;
};
switch (type){
case b2Shape.e_circleShape:
circle = (this as b2CircleDef);
massData.mass = (((density * b2Settings.b2_pi) * circle.radius) * circle.radius);
massData.center.Set(0, 0);
massData.I = (((0.5 * massData.mass) * circle.radius) * circle.radius);
break;
case b2Shape.e_boxShape:
box = (this as b2BoxDef);
massData.mass = (((4 * density) * box.extents.x) * box.extents.y);
massData.center.Set(0, 0);
massData.I = ((massData.mass / 3) * b2Math.b2Dot(box.extents, box.extents));
break;
case b2Shape.e_polyShape:
poly = (this as b2PolyDef);
b2Shape.PolyMass(massData, poly.vertices, poly.vertexCount, density);
break;
default:
massData.mass = 0;
massData.center.Set(0, 0);
massData.I = 0;
break;
};
}
}
}//package Engine.Collision.Shapes
Section 21
//b2AABB (Engine.Collision.b2AABB)
package Engine.Collision {
import Engine.Common.Math.*;
public class b2AABB {
public var minVertex:b2Vec2;
public var maxVertex:b2Vec2;
public function b2AABB(){
minVertex = new b2Vec2();
maxVertex = new b2Vec2();
super();
}
public function IsValid():Boolean{
var dX:Number;
var dY:Number;
var valid:Boolean;
dX = maxVertex.x;
dY = maxVertex.y;
dX = maxVertex.x;
dY = maxVertex.y;
dX = (dX - minVertex.x);
dY = (dY - minVertex.y);
valid = (((dX >= 0)) && ((dY >= 0)));
valid = ((((valid) && (minVertex.IsValid()))) && (maxVertex.IsValid()));
return (valid);
}
}
}//package Engine.Collision
Section 22
//b2Bound (Engine.Collision.b2Bound)
package Engine.Collision {
public class b2Bound {
public var proxyId:uint;
public var stabbingCount:uint;
public var value:uint;
public function b2Bound(){
super();
}
public function Swap(b:b2Bound):void{
var tempValue:uint;
var tempProxyId:uint;
var tempStabbingCount:uint;
tempValue = value;
tempProxyId = proxyId;
tempStabbingCount = 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 Engine.Collision
Section 23
//b2BroadPhase (Engine.Collision.b2BroadPhase)
package Engine.Collision {
import Engine.Common.*;
import Engine.Common.Math.*;
public class b2BroadPhase {
private var maxProxies:int;
public var m_freeProxy:uint;
public var m_pairBuffer:Array;
public var m_worldAABB:b2AABB;
public var m_bounds:Array;
public var m_pairCallback:b2PairCallback;
public var m_proxyCount:int;
private var maxPairs:int;
public var m_quantizationFactor:b2Vec2;
public var m_queryResultCount:int;
public var m_proxyPool:Array;
public var m_pairManager:b2PairManager;
public var m_pairBufferCount:int;
public var m_timeStamp:uint;
public var m_queryResults:Array;
public static const b2_nullEdge:uint = b2Settings.USHRT_MAX;
public static const b2_invalid:uint = b2Settings.USHRT_MAX;
public static var s_validate:Boolean = false;
public function b2BroadPhase(worldAABB:b2AABB, callback:b2PairCallback):void{
var i:int;
var maxProxies2:int;
var dX:Number;
var dY:Number;
var tProxy:b2Proxy;
var j:int;
maxProxies = b2Settings.b2_maxProxies;
maxPairs = b2Settings.b2_maxPairs;
m_pairManager = new b2PairManager();
m_proxyPool = new Array(maxPairs);
m_pairBuffer = new Array(maxPairs);
m_bounds = new Array((2 * maxProxies));
m_queryResults = new Array(maxProxies);
m_quantizationFactor = new b2Vec2();
super();
m_worldAABB = worldAABB;
m_pairCallback = callback;
m_proxyCount = 0;
i = 0;
while (i < maxProxies) {
m_queryResults[i] = 0;
i++;
};
maxProxies2 = (maxProxies * 2);
m_bounds = new Array(2);
i = 0;
while (i < 2) {
m_bounds[i] = new Array(maxProxies2);
j = 0;
while (j < maxProxies2) {
m_bounds[i][j] = new b2Bound();
j++;
};
i++;
};
i = 0;
while (i < maxPairs) {
m_pairBuffer[i] = new b2BufferedPair();
i++;
};
dX = worldAABB.maxVertex.x;
dY = worldAABB.maxVertex.y;
dX = (dX - worldAABB.minVertex.x);
dY = (dY - worldAABB.minVertex.y);
m_quantizationFactor.x = (b2Settings.USHRT_MAX / dX);
m_quantizationFactor.y = (b2Settings.USHRT_MAX / dY);
i = 0;
while (i < (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[(maxProxies - 1)] = tProxy;
tProxy.SetNext(b2Pair.b2_nullProxy);
tProxy.timeStamp = 0;
tProxy.overlapCount = b2_invalid;
tProxy.userData = null;
m_freeProxy = 0;
m_pairBufferCount = 0;
m_timeStamp = 1;
m_queryResultCount = 0;
}
public function ValidatePairs():void{
var pairCount:uint;
var i:int;
var pair:b2Pair;
var proxy1:b2Proxy;
var proxy2:b2Proxy;
pairCount = m_pairManager.GetCount();
m_pairBuffer.sortOn(["proxyId1", "proxyId2"], Array.NUMERIC);
i = 0;
while (i < m_pairBufferCount) {
if (i > 0){
};
pair = m_pairManager.Find(m_pairBuffer[i].proxyId1, m_pairBuffer[i].proxyId2);
proxy1 = m_proxyPool[pair.proxyId1];
proxy2 = m_proxyPool[pair.proxyId2];
i++;
};
}
public function QueryAABB(aabb:b2AABB, userData, maxCount:int):int{
var lowerValues:Array;
var upperValues:Array;
var lowerIndex:uint;
var upperIndex:uint;
var lowerIndexOut:Array;
var upperIndexOut:Array;
var count:int;
var i:int;
var proxy:b2Proxy;
lowerValues = new Array();
upperValues = new Array();
ComputeBounds(lowerValues, upperValues, aabb);
lowerIndexOut = [lowerIndex];
upperIndexOut = [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);
count = 0;
i = 0;
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 GetProxy(proxyId:int):b2Proxy{
if ((((proxyId == b2Pair.b2_nullProxy)) || ((m_proxyPool[proxyId].IsValid() === false)))){
return (null);
};
return (m_proxyPool[proxyId]);
}
private function RemoveBufferedPair(id1:uint, id2:uint):void{
var pair:b2Pair;
pair = m_pairManager.Find(id1, id2);
if (pair == null){
return;
};
if (pair.IsBuffered() === false){
if (m_pairBufferCount < maxPairs){
pair.SetBuffered();
m_pairBuffer[m_pairBufferCount].proxyId1 = pair.proxyId1;
m_pairBuffer[m_pairBufferCount].proxyId2 = pair.proxyId2;
m_pairBufferCount++;
};
};
pair.SetRemoved();
}
public function Flush():void{
var i:int;
var removeCount:int;
var pair:b2Pair;
var proxy1:b2Proxy;
var proxy2:b2Proxy;
removeCount = 0;
i = 0;
while (i < m_pairBufferCount) {
pair = m_pairManager.Find(m_pairBuffer[i].proxyId1, m_pairBuffer[i].proxyId2);
proxy1 = m_proxyPool[pair.proxyId1];
proxy2 = m_proxyPool[pair.proxyId2];
if (pair.IsRemoved()){
if (pair.IsReceived()){
m_pairCallback.PairRemoved(proxy1.userData, proxy2.userData, pair.userData);
};
m_pairBuffer[removeCount].proxyId1 = pair.proxyId1;
m_pairBuffer[removeCount].proxyId2 = pair.proxyId2;
removeCount++;
} else {
pair.ClearBuffered();
if (pair.IsReceived() === false){
pair.userData = m_pairCallback.PairAdded(proxy1.userData, proxy2.userData);
pair.SetReceived();
};
};
i++;
};
i = 0;
while (i < removeCount) {
m_pairManager.Remove(m_pairBuffer[i].proxyId1, m_pairBuffer[i].proxyId2);
i++;
};
m_pairBufferCount = 0;
}
private function IncrementTimeStamp():void{
var i:uint;
if (m_timeStamp == b2Settings.USHRT_MAX){
i = 0;
while (i < 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, edgeCount:uint, axis:int):void{
var lowerQuery:uint;
var upperQuery:uint;
var j:uint;
var i:int;
var s:int;
var proxy:b2Proxy;
lowerQuery = BinarySearch(bounds, edgeCount, lowerValue);
upperQuery = BinarySearch(bounds, edgeCount, upperValue);
j = 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 ComputeBounds(lowerValues:Array, upperValues:Array, aabb:b2AABB):void{
var minVertexX:Number;
var minVertexY:Number;
var maxVertexX:Number;
var maxVertexY:Number;
minVertexX = aabb.minVertex.x;
minVertexY = aabb.minVertex.y;
minVertexX = b2Math.b2Min(minVertexX, m_worldAABB.maxVertex.x);
minVertexY = b2Math.b2Min(minVertexY, m_worldAABB.maxVertex.y);
minVertexX = b2Math.b2Max(minVertexX, m_worldAABB.minVertex.x);
minVertexY = b2Math.b2Max(minVertexY, m_worldAABB.minVertex.y);
maxVertexX = aabb.maxVertex.x;
maxVertexY = aabb.maxVertex.y;
maxVertexX = b2Math.b2Min(maxVertexX, m_worldAABB.maxVertex.x);
maxVertexY = b2Math.b2Min(maxVertexY, m_worldAABB.maxVertex.y);
maxVertexX = b2Math.b2Max(maxVertexX, m_worldAABB.minVertex.x);
maxVertexY = b2Math.b2Max(maxVertexY, m_worldAABB.minVertex.y);
lowerValues[0] = (uint((m_quantizationFactor.x * (minVertexX - m_worldAABB.minVertex.x))) & (b2Settings.USHRT_MAX - 1));
upperValues[0] = ((uint((m_quantizationFactor.x * (maxVertexX - m_worldAABB.minVertex.x))) & 0xFFFF) | 1);
lowerValues[1] = (uint((m_quantizationFactor.y * (minVertexY - m_worldAABB.minVertex.y))) & (b2Settings.USHRT_MAX - 1));
upperValues[1] = ((uint((m_quantizationFactor.y * (maxVertexY - m_worldAABB.minVertex.y))) & 0xFFFF) | 1);
}
public function ShouldCollide(id1:int, id2:int):Boolean{
var p1:b2Proxy;
var p2:b2Proxy;
var doCollide:Boolean;
p1 = m_proxyPool[id1];
p2 = m_proxyPool[id2];
if ((((p1.groupIndex === p2.groupIndex)) && (!((p1.groupIndex === 0))))){
return ((p1.groupIndex > 0));
};
doCollide = ((!(((p1.maskBits & p2.categoryBits) === 0))) && (!(((p1.categoryBits & p2.maskBits) === 0))));
return (doCollide);
}
public function CreateProxy(aabb:b2AABB, groupIndex:int, categoryBits:int, maskBits:int, userData):uint{
var index:uint;
var proxy:b2Proxy;
var proxyId:uint;
var edgeCount:uint;
var lowerValues:Array;
var upperValues:Array;
var axis:int;
var i:int;
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 pair:b2Pair;
if (m_freeProxy == b2Pair.b2_nullProxy){
return (b2Pair.b2_nullProxy);
};
Flush();
proxyId = m_freeProxy;
proxy = m_proxyPool[proxyId];
m_freeProxy = proxy.GetNext();
proxy.overlapCount = 0;
proxy.groupIndex = groupIndex;
proxy.categoryBits = categoryBits;
proxy.maskBits = maskBits;
proxy.userData = userData;
edgeCount = (2 * m_proxyCount);
lowerValues = new Array();
upperValues = new Array();
ComputeBounds(lowerValues, upperValues, aabb);
axis = 0;
while (axis < 2) {
bounds = m_bounds[axis];
lowerIndexOut = [lowerIndex];
upperIndexOut = [upperIndex];
Query(lowerIndexOut, upperIndexOut, lowerValues[axis], upperValues[axis], bounds, edgeCount, axis);
lowerIndex = lowerIndexOut[0];
upperIndex = upperIndexOut[0];
tArr = new Array();
tEnd = (edgeCount - 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 < (edgeCount + 2)) {
proxy2 = m_proxyPool[bounds[index].proxyId];
if (bounds[index].IsLower()){
proxy2.lowerBounds[axis] = index;
} else {
proxy2.upperBounds[axis] = index;
};
index++;
};
axis++;
};
m_proxyCount++;
i = 0;
while (i < m_queryResultCount) {
if (ShouldCollide(proxyId, m_queryResults[i]) === false){
} else {
pair = m_pairManager.Add(proxyId, m_queryResults[i]);
if (pair == null){
} else {
pair.userData = m_pairCallback.PairAdded(proxy.userData, m_proxyPool[m_queryResults[i]].userData);
pair.SetReceived();
};
};
i++;
};
m_queryResultCount = 0;
IncrementTimeStamp();
return (proxyId);
}
public function DestroyProxy(proxyId:uint):void{
var proxy:b2Proxy;
var edgeCount:uint;
var axis:int;
var i:int;
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 other:b2Proxy;
var pairUserData:*;
if (proxyId == b2Pair.b2_nullProxy){
return;
};
Flush();
proxy = m_proxyPool[proxyId];
edgeCount = (2 * m_proxyCount);
axis = 0;
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 = ((edgeCount - 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 = (edgeCount - 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(new Array(), new Array(), lowerValue, upperValue, bounds, (edgeCount - 2), axis);
axis++;
};
i = 0;
while (i < m_queryResultCount) {
other = m_proxyPool[m_queryResults[i]];
pairUserData = m_pairManager.Remove(proxyId, m_queryResults[i]);
m_pairCallback.PairRemoved(proxy.userData, other.userData, pairUserData);
i++;
};
m_queryResultCount = 0;
IncrementTimeStamp();
proxy.userData = null;
proxy.overlapCount = b2_invalid;
proxy.SetNext(m_freeProxy);
m_freeProxy = proxyId;
m_proxyCount--;
}
private function TestOverlap(p1:b2Proxy, p2:b2Proxy):Boolean{
var axis:int;
var bounds:Array;
axis = 0;
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);
}
public function Validate():void{
var pair:b2Pair;
var proxy1:b2Proxy;
var proxy2:b2Proxy;
var overlap:Boolean;
var axis:int;
var pairs:Array;
var pairCount:uint;
var j:int;
var k:int;
var bounds:b2Bound;
var pointCount:uint;
var stabbingCount:uint;
var i:uint;
var bound:b2Bound;
var proxyId:uint;
var proxy:b2Proxy;
var prevEdge:b2Bound;
axis = 0;
while (axis < 2) {
bounds = m_bounds[axis];
pointCount = (2 * m_proxyCount);
stabbingCount = 0;
i = 0;
while (i < pointCount) {
bound = bounds[i];
if (i > 0){
prevEdge = bounds[(i - 1)];
};
proxyId = bound.proxyId;
proxy = m_proxyPool[bound.proxyId];
if (bound.IsLower() === true){
stabbingCount++;
} else {
stabbingCount--;
};
i++;
};
axis++;
};
pairs = m_pairManager.GetPairs();
pairCount = m_pairManager.GetCount();
m_pairBuffer.sortOn(["proxyId1", "proxyId2"], Array.NUMERIC);
j = 0;
while (j < m_pairBufferCount) {
if (j > 0){
};
pair = m_pairManager.Find(m_pairBuffer[j].proxyId1, m_pairBuffer[j].proxyId2);
proxy1 = m_proxyPool[pair.proxyId1];
proxy2 = m_proxyPool[pair.proxyId2];
overlap = TestOverlap(proxy1, proxy2);
if (pair.IsRemoved() === true){
};
j++;
};
k = 0;
while (k < pairCount) {
pair = pairs[k];
proxy1 = m_proxyPool[pair.proxyId1];
proxy2 = m_proxyPool[pair.proxyId2];
overlap = TestOverlap(proxy1, proxy2);
if (pair.IsBuffered()){
if (pair.IsRemoved() === true){
};
};
k++;
};
}
private function IncrementOverlapCount(proxyId:uint):void{
var proxy:b2Proxy;
proxy = 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.minVertex.x;
dY = aabb.minVertex.y;
dX = (dX - m_worldAABB.maxVertex.x);
dY = (dY - m_worldAABB.maxVertex.y);
d2X = m_worldAABB.minVertex.x;
d2Y = m_worldAABB.minVertex.y;
d2X = (d2X - aabb.maxVertex.x);
d2Y = (d2Y - aabb.maxVertex.y);
dX = b2Math.b2Max(dX, d2X);
dY = b2Math.b2Max(dY, d2Y);
return ((b2Math.b2Max(dX, dY) < 0));
}
private function AddBufferedPair(id1:uint, id2:uint):void{
var pair:b2Pair;
if (ShouldCollide(id1, id2) === false){
return;
};
pair = m_pairManager.Add(id1, id2);
if (pair == null){
return;
};
if (pair.IsBuffered() === false){
if (m_pairBufferCount < maxPairs){
pair.SetBuffered();
m_pairBuffer[m_pairBufferCount].proxyId1 = pair.proxyId1;
m_pairBuffer[m_pairBufferCount].proxyId2 = pair.proxyId2;
m_pairBufferCount++;
};
};
pair.ClearRemoved();
}
public function MoveProxy(proxyId:uint, aabb:b2AABB):void{
var index:uint;
var bound:b2Bound;
var prevEdge:b2Bound;
var nextEdge:b2Bound;
var nextProxyId:uint;
var nextProxy:b2Proxy;
var edgeCount:uint;
var proxy:b2Proxy;
var lowerValues:Array;
var upperValues:Array;
var axis:uint;
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)) || ((maxProxies <= proxyId)))){
return;
};
if (aabb.IsValid() === false){
return;
};
edgeCount = (2 * m_proxyCount);
proxy = m_proxyPool[proxyId];
lowerValues = new Array();
upperValues = new Array();
ComputeBounds(lowerValues, upperValues, aabb);
axis = 0;
while (axis < 2) {
bounds = m_bounds[axis];
lowerIndex = proxy.lowerBounds[axis];
upperIndex = proxy.upperBounds[axis];
lowerValue = lowerValues[axis];
upperValue = 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];
prevEdge = bounds[(index - 1)];
prevProxyId = prevEdge.proxyId;
prevProxy = m_proxyPool[prevEdge.proxyId];
prevEdge.stabbingCount++;
if (prevEdge.IsUpper() === true){
if (TestOverlap(proxy, prevProxy)){
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(prevEdge);
index--;
};
};
if (deltaUpper > 0){
index = upperIndex;
while ((((index < (edgeCount - 1))) && ((bounds[(index + 1)].value <= upperValue)))) {
bound = bounds[index];
nextEdge = bounds[(index + 1)];
nextProxyId = nextEdge.proxyId;
nextProxy = m_proxyPool[nextProxyId];
nextEdge.stabbingCount++;
if (nextEdge.IsLower() === true){
if (TestOverlap(proxy, nextProxy)){
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(nextEdge);
index++;
};
};
if (deltaLower > 0){
index = lowerIndex;
while ((((index < (edgeCount - 1))) && ((bounds[(index + 1)].value <= lowerValue)))) {
bound = bounds[index];
nextEdge = bounds[(index + 1)];
nextProxyId = nextEdge.proxyId;
nextProxy = m_proxyPool[nextProxyId];
nextEdge.stabbingCount--;
if (nextEdge.IsUpper()){
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(nextEdge);
index++;
};
};
if (deltaUpper < 0){
index = upperIndex;
while ((((index > 0)) && ((upperValue < bounds[(index - 1)].value)))) {
bound = bounds[index];
prevEdge = bounds[(index - 1)];
prevProxyId = prevEdge.proxyId;
prevProxy = m_proxyPool[prevProxyId];
prevEdge.stabbingCount--;
if (prevEdge.IsLower() === true){
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(prevEdge);
index--;
};
};
axis++;
};
}
public static function BinarySearch(bounds:Array, count:int, value:uint):uint{
var low:int;
var high:int;
var mid:int;
low = 0;
high = (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));
}
public static function Equals(pair1:b2BufferedPair, pair2:b2BufferedPair):Boolean{
if ((((pair1.proxyId1 === pair2.proxyId1)) && ((pair1.proxyId2 === pair2.proxyId2)))){
return (true);
};
return (false);
}
public static function LessThanBP(pair1:b2BufferedPair, pair2:b2BufferedPair):Boolean{
if (pair1.proxyId1 < pair2.proxyId1){
return (true);
};
if (pair1.proxyId1 === pair2.proxyId1){
return ((pair1.proxyId2 < pair2.proxyId2));
};
return (false);
}
}
}//package Engine.Collision
Section 24
//b2BufferedPair (Engine.Collision.b2BufferedPair)
package Engine.Collision {
public class b2BufferedPair {
public var proxyId1:uint;
public var proxyId2:uint;
public function b2BufferedPair(){
super();
}
}
}//package Engine.Collision
Section 25
//b2Collision (Engine.Collision.b2Collision)
package Engine.Collision {
import Engine.Common.Math.*;
import Engine.Common.*;
import Engine.Collision.Shapes.*;
public class b2Collision {
public static const b2_nullFeature:uint = 0xFF;
private static var b2CollidePolyTempVec:b2Vec2 = new b2Vec2();
public function b2Collision(){
super();
}
public static function EdgeSeparation(poly1:b2PolyShape, edge1:int, poly2:b2PolyShape):Number{
var count1:int;
var vert1s:Array;
var count2:int;
var vert2s:Array;
var vertexIndex11:int;
var vertexIndex12:int;
var normalLocal1X:Number;
var normalLocal1Y:Number;
var tX:Number;
var invLength:Number;
var normalX:Number;
var normalY:Number;
var tMat:b2Mat22;
var normalLocal2X:Number;
var normalLocal2Y:Number;
var vertexIndex2:int;
var minDot:Number;
var i:int;
var v1:b2Vec2;
var v2:b2Vec2;
var separation:Number;
var tVec:b2Vec2;
var dot:Number;
count1 = poly1.m_vertexCount;
vert1s = poly1.m_vertices;
count2 = poly2.m_vertexCount;
vert2s = poly2.m_vertices;
vertexIndex11 = edge1;
vertexIndex12 = (((edge1 + 1) == count1)) ? 0 : (edge1 + 1);
normalLocal1X = (vert1s[vertexIndex12].x - vert1s[vertexIndex11].x);
normalLocal1Y = (vert1s[vertexIndex12].y - vert1s[vertexIndex11].y);
tX = normalLocal1X;
normalLocal1X = normalLocal1Y;
normalLocal1Y = -(tX);
invLength = (1 / Math.sqrt(((normalLocal1X * normalLocal1X) + (normalLocal1Y * normalLocal1Y))));
normalLocal1X = (normalLocal1X * invLength);
normalLocal1Y = (normalLocal1Y * invLength);
normalX = normalLocal1X;
normalY = normalLocal1Y;
tX = normalX;
tMat = poly1.m_R;
normalX = ((tMat.col1.x * tX) + (tMat.col2.x * normalY));
normalY = ((tMat.col1.y * tX) + (tMat.col2.y * normalY));
normalLocal2X = normalX;
normalLocal2Y = normalY;
tMat = poly2.m_R;
tX = ((normalLocal2X * tMat.col1.x) + (normalLocal2Y * tMat.col1.y));
normalLocal2Y = ((normalLocal2X * tMat.col2.x) + (normalLocal2Y * tMat.col2.y));
normalLocal2X = tX;
vertexIndex2 = 0;
minDot = Number.MAX_VALUE;
i = 0;
while (i < count2) {
tVec = vert2s[i];
dot = ((tVec.x * normalLocal2X) + (tVec.y * normalLocal2Y));
if (dot < minDot){
minDot = dot;
vertexIndex2 = i;
};
i++;
};
v1 = new b2Vec2();
v1.SetV(vert1s[vertexIndex11]);
v1.MulM(poly1.m_R);
v1.Add(poly1.m_position);
v2 = new b2Vec2();
v2.SetV(vert2s[vertexIndex2]);
v2.MulM(poly2.m_R);
v2.Add(poly2.m_position);
v2.Subtract(v1);
separation = ((v2.x * normalX) + (v2.y * normalY));
return (separation);
}
public static function b2TestOverlap(a:b2AABB, b:b2AABB):Boolean{
var t1:b2Vec2;
var t2:b2Vec2;
var d1X:Number;
var d1Y:Number;
var d2X:Number;
var d2Y:Number;
t1 = b.minVertex;
t2 = a.maxVertex;
d1X = (t1.x - t2.x);
d1Y = (t1.y - t2.y);
t1 = a.minVertex;
t2 = b.maxVertex;
d2X = (t1.x - t2.x);
d2Y = (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:b2PolyShape, edge1:int, poly2:b2PolyShape):void{
var count1:int;
var vert1s:Array;
var count2:int;
var vert2s:Array;
var vertex11:int;
var vertex12:int;
var tVec:b2Vec2;
var normal1Local1X:Number;
var normal1Local1Y:Number;
var tX:Number;
var invLength:Number;
var normal1X:Number;
var normal1Y:Number;
var tMat:b2Mat22;
var normal1Local2X:Number;
var normal1Local2Y:Number;
var vertex21:int;
var vertex22:int;
var minDot:Number;
var i:int;
var tClip:ClipVertex;
var i1:int;
var i2:int;
var normal2Local2X:Number;
var normal2Local2Y:Number;
var dot:Number;
count1 = poly1.m_vertexCount;
vert1s = poly1.m_vertices;
count2 = poly2.m_vertexCount;
vert2s = poly2.m_vertices;
vertex11 = edge1;
vertex12 = (((edge1 + 1) == count1)) ? 0 : (edge1 + 1);
tVec = vert1s[vertex12];
normal1Local1X = tVec.x;
normal1Local1Y = tVec.y;
tVec = vert1s[vertex11];
normal1Local1X = (normal1Local1X - tVec.x);
normal1Local1Y = (normal1Local1Y - tVec.y);
tX = normal1Local1X;
normal1Local1X = normal1Local1Y;
normal1Local1Y = -(tX);
invLength = (1 / Math.sqrt(((normal1Local1X * normal1Local1X) + (normal1Local1Y * normal1Local1Y))));
normal1Local1X = (normal1Local1X * invLength);
normal1Local1Y = (normal1Local1Y * invLength);
normal1X = normal1Local1X;
normal1Y = normal1Local1Y;
tX = normal1X;
tMat = poly1.m_R;
normal1X = ((tMat.col1.x * tX) + (tMat.col2.x * normal1Y));
normal1Y = ((tMat.col1.y * tX) + (tMat.col2.y * normal1Y));
normal1Local2X = normal1X;
normal1Local2Y = normal1Y;
tMat = poly2.m_R;
tX = ((normal1Local2X * tMat.col1.x) + (normal1Local2Y * tMat.col1.y));
normal1Local2Y = ((normal1Local2X * tMat.col2.x) + (normal1Local2Y * tMat.col2.y));
normal1Local2X = tX;
minDot = Number.MAX_VALUE;
i = 0;
while (i < count2) {
i1 = i;
i2 = (((i + 1) < count2)) ? (i + 1) : 0;
tVec = vert2s[i2];
normal2Local2X = tVec.x;
normal2Local2Y = tVec.y;
tVec = vert2s[i1];
normal2Local2X = (normal2Local2X - tVec.x);
normal2Local2Y = (normal2Local2Y - tVec.y);
tX = normal2Local2X;
normal2Local2X = normal2Local2Y;
normal2Local2Y = -(tX);
invLength = (1 / Math.sqrt(((normal2Local2X * normal2Local2X) + (normal2Local2Y * normal2Local2Y))));
normal2Local2X = (normal2Local2X * invLength);
normal2Local2Y = (normal2Local2Y * invLength);
dot = ((normal2Local2X * normal1Local2X) + (normal2Local2Y * normal1Local2Y));
if (dot < minDot){
minDot = dot;
vertex21 = i1;
vertex22 = i2;
};
i++;
};
tClip = c[0];
tVec = tClip.v;
tVec.SetV(vert2s[vertex21]);
tVec.MulM(poly2.m_R);
tVec.Add(poly2.m_position);
tClip.id.features.referenceFace = edge1;
tClip.id.features.incidentEdge = vertex21;
tClip.id.features.incidentVertex = vertex21;
tClip = c[1];
tVec = tClip.v;
tVec.SetV(vert2s[vertex22]);
tVec.MulM(poly2.m_R);
tVec.Add(poly2.m_position);
tClip.id.features.referenceFace = edge1;
tClip.id.features.incidentEdge = vertex21;
tClip.id.features.incidentVertex = vertex22;
}
public static function b2CollidePolyAndCircle(manifold:b2Manifold, poly:b2PolyShape, circle:b2CircleShape):void{
var tPoint:b2ContactPoint;
var dX:Number;
var dY:Number;
var xLocalX:Number;
var xLocalY:Number;
var tMat:b2Mat22;
var tX:Number;
var dist:Number;
var normalIndex:int;
var separation:Number;
var radius:Number;
var i:int;
var vertIndex1:int;
var vertIndex2:int;
var eX:Number;
var eY:Number;
var length:Number;
var u:Number;
var pX:Number;
var pY:Number;
var s:Number;
var tVec:b2Vec2;
manifold.pointCount = 0;
xLocalX = (circle.m_position.x - poly.m_position.x);
xLocalY = (circle.m_position.y - poly.m_position.y);
tMat = poly.m_R;
tX = ((xLocalX * tMat.col1.x) + (xLocalY * tMat.col1.y));
xLocalY = ((xLocalX * tMat.col2.x) + (xLocalY * tMat.col2.y));
xLocalX = tX;
normalIndex = 0;
separation = -(Number.MAX_VALUE);
radius = circle.m_radius;
i = 0;
while (i < poly.m_vertexCount) {
s = ((poly.m_normals[i].x * (xLocalX - poly.m_vertices[i].x)) + (poly.m_normals[i].y * (xLocalY - poly.m_vertices[i].y)));
if (s > radius){
return;
};
if (s > separation){
separation = s;
normalIndex = i;
};
i++;
};
if (separation < Number.MIN_VALUE){
manifold.pointCount = 1;
tVec = poly.m_normals[normalIndex];
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;
tPoint.position.x = (circle.m_position.x - (radius * manifold.normal.x));
tPoint.position.y = (circle.m_position.y - (radius * manifold.normal.y));
tPoint.separation = (separation - radius);
return;
};
vertIndex1 = normalIndex;
vertIndex2 = poly.m_nextVert[vertIndex1];
eX = (poly.m_vertices[vertIndex2].x - poly.m_vertices[vertIndex1].x);
eY = (poly.m_vertices[vertIndex2].y - poly.m_vertices[vertIndex1].y);
length = Math.sqrt(((eX * eX) + (eY * eY)));
eX = (eX / length);
eY = (eY / length);
if (length < Number.MIN_VALUE){
dX = (xLocalX - poly.m_vertices[vertIndex1].x);
dY = (xLocalY - poly.m_vertices[vertIndex1].y);
dist = Math.sqrt(((dX * dX) + (dY * dY)));
dX = (dX / dist);
dY = (dY / dist);
if (dist > radius){
return;
};
manifold.pointCount = 1;
manifold.normal.Set(((tMat.col1.x * dX) + (tMat.col2.x * dY)), ((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;
tPoint.position.x = (circle.m_position.x - (radius * manifold.normal.x));
tPoint.position.y = (circle.m_position.y - (radius * manifold.normal.y));
tPoint.separation = (dist - radius);
return;
};
u = (((xLocalX - poly.m_vertices[vertIndex1].x) * eX) + ((xLocalY - poly.m_vertices[vertIndex1].y) * 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 = poly.m_vertices[vertIndex1].x;
pY = poly.m_vertices[vertIndex1].y;
tPoint.id.features.incidentVertex = vertIndex1;
} else {
if (u >= length){
pX = poly.m_vertices[vertIndex2].x;
pY = poly.m_vertices[vertIndex2].y;
tPoint.id.features.incidentVertex = vertIndex2;
} else {
pX = ((eX * u) + poly.m_vertices[vertIndex1].x);
pY = ((eY * u) + poly.m_vertices[vertIndex1].y);
tPoint.id.features.incidentEdge = vertIndex1;
};
};
dX = (xLocalX - pX);
dY = (xLocalY - pY);
dist = Math.sqrt(((dX * dX) + (dY * dY)));
dX = (dX / dist);
dY = (dY / dist);
if (dist > radius){
return;
};
manifold.pointCount = 1;
manifold.normal.Set(((tMat.col1.x * dX) + (tMat.col2.x * dY)), ((tMat.col1.y * dX) + (tMat.col2.y * dY)));
tPoint.position.x = (circle.m_position.x - (radius * manifold.normal.x));
tPoint.position.y = (circle.m_position.y - (radius * manifold.normal.y));
tPoint.separation = (dist - radius);
}
public static function FindMaxSeparation(edge:Array, poly1:b2PolyShape, poly2:b2PolyShape):Number{
var count1:int;
var vert1s:Array;
var d:b2Vec2;
var dLocal1:b2Vec2;
var vertexIndex1:int;
var maxDot:Number;
var i:int;
var prevFaceIndex:int;
var sPrev:Number;
var nextFaceIndex:int;
var sNext:Number;
var bestFaceIndex:int;
var bestSeparation:Number;
var increment:int;
var dot:Number;
var edgeIndex:int;
var separation:Number;
count1 = poly1.m_vertexCount;
vert1s = poly1.m_vertices;
d = new b2Vec2();
d.SetV(poly2.m_position);
d.Subtract(poly1.m_position);
dLocal1 = new b2Vec2();
dLocal1.SetV(d);
dLocal1.MulTM(poly1.m_R);
vertexIndex1 = 0;
maxDot = -(Number.MAX_VALUE);
i = 0;
while (i < count1) {
dot = b2Math.b2Dot(vert1s[i], dLocal1);
if (dot > maxDot){
maxDot = dot;
vertexIndex1 = i;
};
i++;
};
prevFaceIndex = (((vertexIndex1 - 1) >= 0)) ? (vertexIndex1 - 1) : (count1 - 1);
sPrev = EdgeSeparation(poly1, prevFaceIndex, poly2);
if (sPrev > 0){
return (sPrev);
};
nextFaceIndex = vertexIndex1;
sNext = EdgeSeparation(poly1, nextFaceIndex, poly2);
if (sNext > 0){
return (sNext);
};
if (sPrev > sNext){
increment = -1;
bestFaceIndex = prevFaceIndex;
bestSeparation = sPrev;
} else {
increment = 1;
bestFaceIndex = nextFaceIndex;
bestSeparation = sNext;
};
while (true) {
if (increment === -1){
edgeIndex = (((bestFaceIndex - 1) >= 0)) ? (bestFaceIndex - 1) : (count1 - 1);
} else {
edgeIndex = (((bestFaceIndex + 1) < count1)) ? (bestFaceIndex + 1) : 0;
};
separation = EdgeSeparation(poly1, edgeIndex, poly2);
if (separation > 0){
return (separation);
};
if (separation > bestSeparation){
bestFaceIndex = edgeIndex;
bestSeparation = separation;
} else {
break;
};
};
edge[0] = bestFaceIndex;
return (bestSeparation);
}
public static function ClipSegmentToLine(vOut:Array, vIn:Array, normal:b2Vec2, offset:Number):int{
var numOut:int;
var vIn0:b2Vec2;
var vIn1:b2Vec2;
var distance0:Number;
var distance1:Number;
var interp:Number;
var tVec:b2Vec2;
numOut = 0;
vIn0 = vIn[0].v;
vIn1 = vIn[1].v;
distance0 = (b2Math.b2Dot(normal, vIn[0].v) - offset);
distance1 = (b2Math.b2Dot(normal, vIn[1].v) - 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 b2CollidePoly(manifold:b2Manifold, polyA:b2PolyShape, polyB:b2PolyShape):void{
var edgeA:int;
var edgeAOut:Array;
var separationA:Number;
var edgeB:int;
var edgeBOut:Array;
var separationB:Number;
var poly1:b2PolyShape;
var poly2:b2PolyShape;
var edge1:int;
var flip:int;
var k_relativeTol:Number;
var k_absoluteTol:Number;
var incidentEdge:Array;
var count1:int;
var vert1s:Array;
var v11:b2Vec2;
var v12:b2Vec2;
var dvX:Number;
var dvY:Number;
var sideNormalX:Number;
var sideNormalY:Number;
var tX:Number;
var tMat:b2Mat22;
var invLength:Number;
var frontNormalX:Number;
var frontNormalY:Number;
var v11X:Number;
var v11Y:Number;
var v12X:Number;
var v12Y:Number;
var frontOffset:Number;
var sideOffset1:Number;
var sideOffset2:Number;
var clipPoints1:Array;
var clipPoints2:Array;
var np:int;
var pointCount:int;
var i:int;
var tVec:b2Vec2;
var separation:Number;
var cp:b2ContactPoint;
manifold.pointCount = 0;
edgeA = 0;
edgeAOut = [edgeA];
separationA = FindMaxSeparation(edgeAOut, polyA, polyB);
edgeA = edgeAOut[0];
if (separationA > 0){
return;
};
edgeB = 0;
edgeBOut = [edgeB];
separationB = FindMaxSeparation(edgeBOut, polyB, polyA);
edgeB = edgeBOut[0];
if (separationB > 0){
return;
};
k_relativeTol = 0.98;
k_absoluteTol = 0.001;
if (separationB > ((k_relativeTol * separationA) + k_absoluteTol)){
poly1 = polyB;
poly2 = polyA;
edge1 = edgeB;
flip = 1;
} else {
poly1 = polyA;
poly2 = polyB;
edge1 = edgeA;
flip = 0;
};
incidentEdge = [new ClipVertex(), new ClipVertex()];
FindIncidentEdge(incidentEdge, poly1, edge1, poly2);
count1 = poly1.m_vertexCount;
vert1s = poly1.m_vertices;
v11 = vert1s[edge1];
v12 = (((edge1 + 1) < count1)) ? vert1s[(edge1 + 1)] : vert1s[0];
dvX = (v12.x - v11.x);
dvY = (v12.y - v11.y);
sideNormalX = (v12.x - v11.x);
sideNormalY = (v12.y - v11.y);
tX = sideNormalX;
tMat = poly1.m_R;
sideNormalX = ((tMat.col1.x * tX) + (tMat.col2.x * sideNormalY));
sideNormalY = ((tMat.col1.y * tX) + (tMat.col2.y * sideNormalY));
invLength = (1 / Math.sqrt(((sideNormalX * sideNormalX) + (sideNormalY * sideNormalY))));
sideNormalX = (sideNormalX * invLength);
sideNormalY = (sideNormalY * invLength);
frontNormalX = sideNormalX;
frontNormalY = sideNormalY;
tX = frontNormalX;
frontNormalX = frontNormalY;
frontNormalY = -(tX);
v11X = v11.x;
v11Y = v11.y;
tX = v11X;
tMat = poly1.m_R;
v11X = ((tMat.col1.x * tX) + (tMat.col2.x * v11Y));
v11Y = ((tMat.col1.y * tX) + (tMat.col2.y * v11Y));
v11X = (v11X + poly1.m_position.x);
v11Y = (v11Y + poly1.m_position.y);
v12X = v12.x;
v12Y = v12.y;
tX = v12X;
tMat = poly1.m_R;
v12X = ((tMat.col1.x * tX) + (tMat.col2.x * v12Y));
v12Y = ((tMat.col1.y * tX) + (tMat.col2.y * v12Y));
v12X = (v12X + poly1.m_position.x);
v12Y = (v12Y + poly1.m_position.y);
frontOffset = ((frontNormalX * v11X) + (frontNormalY * v11Y));
sideOffset1 = -(((sideNormalX * v11X) + (sideNormalY * v11Y)));
sideOffset2 = ((sideNormalX * v12X) + (sideNormalY * v12Y));
clipPoints1 = [new ClipVertex(), new ClipVertex()];
clipPoints2 = [new ClipVertex(), new ClipVertex()];
b2CollidePolyTempVec.Set(-(sideNormalX), -(sideNormalY));
np = ClipSegmentToLine(clipPoints1, incidentEdge, b2CollidePolyTempVec, sideOffset1);
if (np < 2){
return;
};
b2CollidePolyTempVec.Set(sideNormalX, sideNormalY);
np = ClipSegmentToLine(clipPoints2, clipPoints1, b2CollidePolyTempVec, sideOffset2);
if (np < 2){
return;
};
if (flip){
manifold.normal.Set(-(frontNormalX), -(frontNormalY));
} else {
manifold.normal.Set(frontNormalX, frontNormalY);
};
pointCount = 0;
i = 0;
while (i < b2Settings.b2_maxManifoldPoints) {
tVec = clipPoints2[i].v;
separation = (((frontNormalX * tVec.x) + (frontNormalY * tVec.y)) - frontOffset);
if (separation <= 0){
cp = manifold.points[pointCount];
cp.separation = separation;
cp.position.SetV(clipPoints2[i].v);
cp.id.Set(clipPoints2[i].id);
cp.id.features.flip = flip;
pointCount++;
};
i++;
};
manifold.pointCount = pointCount;
}
public static function b2CollideCircle(manifold:b2Manifold, circle1:b2CircleShape, circle2:b2CircleShape):void{
var dX:Number;
var dY:Number;
var distSqr:Number;
var radiusSum:Number;
var separation:Number;
var tPoint:b2ContactPoint;
var dist:Number;
var a:Number;
manifold.pointCount = 0;
dX = (circle2.m_position.x - circle1.m_position.x);
dY = (circle2.m_position.y - circle1.m_position.y);
distSqr = ((dX * dX) + (dY * dY));
radiusSum = (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;
tPoint = manifold.points[0];
tPoint.id.key = 0;
tPoint.separation = separation;
tPoint.position.x = (circle2.m_position.x - (circle2.m_radius * manifold.normal.x));
tPoint.position.y = (circle2.m_position.y - (circle2.m_radius * manifold.normal.y));
}
}
}//package Engine.Collision
Section 26
//b2ContactID (Engine.Collision.b2ContactID)
package Engine.Collision {
public class b2ContactID {
public var _key:uint;
public var features:Features;
public function b2ContactID():void{
features = new Features();
super();
features._m_id = this;
}
public function Set(id:b2ContactID):void{
key = id._key;
}
public function Copy():b2ContactID{
var id:b2ContactID;
id = new b2ContactID();
id.key = key;
return (id);
}
public function get key():uint{
return (_key);
}
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);
}
}
}//package Engine.Collision
Section 27
//b2ContactPoint (Engine.Collision.b2ContactPoint)
package Engine.Collision {
import Engine.Common.Math.*;
public class b2ContactPoint {
public var separation:Number;
public var position:b2Vec2;
public var normalImpulse:Number;
public var tangentImpulse:Number;
public var id:b2ContactID;
public function b2ContactPoint(){
position = new b2Vec2();
id = new b2ContactID();
super();
}
}
}//package Engine.Collision
Section 28
//b2Manifold (Engine.Collision.b2Manifold)
package Engine.Collision {
import Engine.Common.*;
import Engine.Common.Math.*;
public class b2Manifold {
public var points:Array;
public var pointCount:int;
public var normal:b2Vec2;
public function b2Manifold():void{
var maxManifoldPoints:int;
var i:int;
super();
maxManifoldPoints = b2Settings.b2_maxManifoldPoints;
points = new Array(maxManifoldPoints);
i = 0;
while (i < maxManifoldPoints) {
points[i] = new b2ContactPoint();
i++;
};
normal = new b2Vec2();
}
}
}//package Engine.Collision
Section 29
//b2OBB (Engine.Collision.b2OBB)
package Engine.Collision {
import Engine.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 Engine.Collision
Section 30
//b2Pair (Engine.Collision.b2Pair)
package Engine.Collision {
import Engine.Common.*;
public class b2Pair {
public var userData;// = null
public var proxyId1:uint;
public var proxyId2:uint;
public var status:uint;
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 e_pairReceived:uint = 4;
public static var b2_nullProxy:uint = b2Settings.USHRT_MAX;
public static var b2_tableCapacity:int = b2Settings.b2_maxPairs;
public function b2Pair(){
userData = null;
super();
}
public function SetBuffered():void{
status = (status | e_pairBuffered);
}
public function SetReceived():void{
status = (status | e_pairReceived);
}
public function IsBuffered():Boolean{
return (((status & e_pairBuffered) == e_pairBuffered));
}
public function IsReceived():Boolean{
return (((status & e_pairReceived) == e_pairReceived));
}
public function ClearBuffered():void{
status = (status & ~(e_pairBuffered));
}
public function ClearRemoved():void{
status = (status & ~(e_pairRemoved));
}
public function IsRemoved():Boolean{
return (((status & e_pairRemoved) == e_pairRemoved));
}
public function SetRemoved():void{
status = (status | e_pairRemoved);
}
}
}//package Engine.Collision
Section 31
//b2PairCallback (Engine.Collision.b2PairCallback)
package Engine.Collision {
public class b2PairCallback {
public function b2PairCallback(){
super();
}
public function PairRemoved(proxyUserData1, proxyUserData2, pairUserData):void{
}
public function PairAdded(proxyUserData1, proxyUserData2){
return (null);
}
}
}//package Engine.Collision
Section 32
//b2PairManager (Engine.Collision.b2PairManager)
package Engine.Collision {
import Engine.Common.*;
import Engine.Common.Math.*;
public class b2PairManager {
public var m_next:Array;
public var m_pairs:Array;
public var m_pairCount:int;
public var m_hashTable:Array;
public function b2PairManager(){
var i:uint;
var maxPairs:int;
super();
maxPairs = b2Settings.b2_maxPairs;
m_hashTable = new Array(b2Pair.b2_tableCapacity);
i = 0;
while (i < b2Pair.b2_tableCapacity) {
m_hashTable[i] = b2Pair.b2_nullPair;
i++;
};
m_next = new Array(maxPairs);
i = 0;
while (i < maxPairs) {
m_next[i] = b2Pair.b2_nullPair;
i++;
};
m_pairs = new Array(maxPairs);
i = 0;
while (i < maxPairs) {
m_pairs[i] = new b2Pair();
i++;
};
m_pairCount = 0;
}
public function Find(proxyId1:uint, proxyId2:uint):b2Pair{
var hash:uint;
var index:uint;
var temp:uint;
if (proxyId1 > proxyId2){
temp = proxyId1;
proxyId1 = proxyId2;
proxyId2 = temp;
};
hash = (Hash(proxyId1, proxyId2) & b2Pair.b2_tableMask);
index = m_hashTable[hash];
while (((!((index === b2Pair.b2_nullPair))) && ((Equals(m_pairs[index], proxyId1, proxyId2) === false)))) {
index = m_next[index];
};
if (index == b2Pair.b2_nullPair){
return (null);
};
return (m_pairs[index]);
}
public function Add(proxyId1:uint, proxyId2:uint):b2Pair{
var hash:uint;
var pairIndex:int;
var pair:b2Pair;
var temp:uint;
if (proxyId1 > proxyId2){
temp = proxyId1;
proxyId1 = proxyId2;
proxyId2 = temp;
};
hash = (Hash(proxyId1, proxyId2) & b2Pair.b2_tableMask);
pairIndex = FindHash(proxyId1, proxyId2, hash);
pair = (!((pairIndex === b2Settings.USHRT_MAX))) ? m_pairs[pairIndex] : null;
if (pair != null){
return (pair);
};
if (m_pairCount === b2Settings.b2_maxPairs){
return (null);
};
pair = m_pairs[m_pairCount];
pair.proxyId1 = proxyId1;
pair.proxyId2 = proxyId2;
pair.status = 0;
pair.userData = null;
m_next[m_pairCount] = m_hashTable[hash];
m_hashTable[hash] = m_pairCount;
m_pairCount++;
return (pair);
}
public function GetPairs():Array{
return (m_pairs);
}
public function Remove(proxyId1:uint, proxyId2:uint){
var hash:uint;
var pairIndex:int;
var pair:b2Pair;
var userData:*;
var index:uint;
var previous:uint;
var lastPairIndex:uint;
var last:b2Pair;
var lastHash:uint;
var temp:uint;
if (proxyId1 > proxyId2){
temp = proxyId1;
proxyId1 = proxyId2;
proxyId2 = temp;
};
hash = (Hash(proxyId1, proxyId2) & b2Pair.b2_tableMask);
pairIndex = FindHash(proxyId1, proxyId2, hash);
pair = (!((pairIndex === b2Settings.USHRT_MAX))) ? m_pairs[pairIndex] : null;
if (pair == null){
return (null);
};
userData = pair.userData;
index = m_hashTable[hash];
previous = b2Pair.b2_nullPair;
while (index !== pairIndex) {
previous = index;
index = m_next[index];
};
if (previous !== b2Pair.b2_nullPair){
m_next[previous] = m_next[pairIndex];
} else {
m_hashTable[hash] = m_next[pairIndex];
};
lastPairIndex = (m_pairCount - 1);
if (lastPairIndex == pairIndex){
m_pairCount--;
return (userData);
};
last = m_pairs[lastPairIndex];
lastHash = (Hash(last.proxyId1, last.proxyId2) & b2Pair.b2_tableMask);
index = m_hashTable[lastHash];
previous = b2Pair.b2_nullPair;
while (index !== lastPairIndex) {
previous = index;
index = m_next[index];
};
if (previous !== b2Pair.b2_nullPair){
m_next[previous] = m_next[lastPairIndex];
} else {
m_hashTable[lastHash] = m_next[lastPairIndex];
};
m_pairs[pairIndex].userData = m_pairs[lastPairIndex].userData;
m_pairs[pairIndex].proxyId1 = m_pairs[lastPairIndex].proxyId1;
m_pairs[pairIndex].proxyId2 = m_pairs[lastPairIndex].proxyId2;
m_pairs[pairIndex].status = m_pairs[lastPairIndex].status;
m_next[pairIndex] = m_hashTable[lastHash];
m_hashTable[lastHash] = pairIndex;
m_pairCount--;
return (userData);
}
public function GetCount():int{
return (m_pairCount);
}
private function FindHash(proxyId1:uint, proxyId2:uint, hash:uint):int{
var index:uint;
index = m_hashTable[hash];
while (((!((index === b2Pair.b2_nullPair))) && ((Equals(m_pairs[index], proxyId1, proxyId2) === false)))) {
index = m_next[index];
};
if (index == b2Pair.b2_nullPair){
return (b2Settings.USHRT_MAX);
};
return (index);
}
public static function Hash(proxyId1:uint, proxyId2:uint):uint{
var key:uint;
key = (((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 Engine.Collision
Section 33
//b2Proxy (Engine.Collision.b2Proxy)
package Engine.Collision {
public class b2Proxy {
public var categoryBits:uint;
public var overlapCount:uint;
public var lowerBounds:Array;
public var upperBounds:Array;
public var maskBits:uint;
public var groupIndex:int;
public var userData;// = null
public var timeStamp:uint;
public function b2Proxy(){
lowerBounds = [uint(0), uint(0)];
upperBounds = [uint(0), uint(0)];
userData = null;
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 Engine.Collision
Section 34
//ClipVertex (Engine.Collision.ClipVertex)
package Engine.Collision {
import Engine.Common.Math.*;
public class ClipVertex {
public var v:b2Vec2;
public var id:b2ContactID;
public function ClipVertex(){
v = new b2Vec2();
id = new b2ContactID();
super();
}
}
}//package Engine.Collision
Section 35
//Features (Engine.Collision.Features)
package Engine.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 set flip(value:int):void{
_flip = value;
_m_id._key = ((_m_id._key & 0xFFFFFF) | ((_flip << 24) & 4278190080));
}
public function get incidentVertex():int{
return (_incidentVertex);
}
public function set incidentEdge(value:int):void{
_incidentEdge = value;
_m_id._key = ((_m_id._key & 4294902015) | ((_incidentEdge << 8) & 0xFF00));
}
}
}//package Engine.Collision
Section 36
//b2Mat22 (Engine.Common.Math.b2Mat22)
package Engine.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):void{
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 Set(angle:Number):void{
var c:Number;
var s:Number;
c = Math.cos(angle);
s = Math.sin(angle);
col1.x = c;
col2.x = -(s);
col1.y = s;
col2.y = c;
}
public function SetVV(c1:b2Vec2, c2:b2Vec2):void{
col1.SetV(c1);
col2.SetV(c2);
}
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 b:Number;
var c:Number;
var d:Number;
var det:Number;
a = col1.x;
b = col2.x;
c = col1.y;
d = 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 Solve(out:b2Vec2, bX:Number, bY:Number):b2Vec2{
var a11:Number;
var a12:Number;
var a21:Number;
var a22:Number;
var det:Number;
a11 = col1.x;
a12 = col2.x;
a21 = col1.y;
a22 = col2.y;
det = ((a11 * a22) - (a12 * a21));
det = (1 / det);
out.x = (det * ((a22 * bX) - (a12 * bY)));
out.y = (det * ((a11 * bY) - (a21 * bX)));
return (out);
}
}
}//package Engine.Common.Math
Section 37
//b2Math (Engine.Common.Math.b2Math)
package Engine.Common.Math {
public class b2Math {
public function b2Math(){
super();
}
public static function b2CrossVF(a:b2Vec2, s:Number):b2Vec2{
var v:b2Vec2;
v = new b2Vec2((s * a.y), (-(s) * a.x));
return (v);
}
public static function AddVV(a:b2Vec2, b:b2Vec2):b2Vec2{
var v:b2Vec2;
v = 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 b2Swap(a:Array, b:Array):void{
var tmp:*;
tmp = a[0];
a[0] = b[0];
b[0] = tmp;
}
public static function b2Abs(a:Number):Number{
return (((a > 0)) ? a : -(a));
}
public static function b2AbsM(A:b2Mat22):b2Mat22{
var B:b2Mat22;
B = new b2Mat22(0, b2AbsV(A.col1), b2AbsV(A.col2));
return (B);
}
public static function SubtractVV(a:b2Vec2, b:b2Vec2):b2Vec2{
var v:b2Vec2;
v = new b2Vec2((a.x - b.x), (a.y - b.y));
return (v);
}
public static function b2CrossVV(a:b2Vec2, b:b2Vec2):Number{
return (((a.x * b.y) - (a.y * b.x)));
}
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;
b = new b2Vec2(b2Abs(a.x), b2Abs(a.y));
return (b);
}
public static function b2MinV(a:b2Vec2, b:b2Vec2):b2Vec2{
var c:b2Vec2;
c = new b2Vec2(b2Min(a.x, b.x), b2Min(a.y, b.y));
return (c);
}
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;
v = new b2Vec2((-(s) * a.y), (s * a.x));
return (v);
}
public static function AddMM(A:b2Mat22, B:b2Mat22):b2Mat22{
var C:b2Mat22;
C = new b2Mat22(0, AddVV(A.col1, B.col1), AddVV(A.col2, B.col2));
return (C);
}
public static function b2MulTMM(A:b2Mat22, B:b2Mat22):b2Mat22{
var c1:b2Vec2;
var c2:b2Vec2;
var C:b2Mat22;
c1 = new b2Vec2(b2Dot(A.col1, B.col1), b2Dot(A.col2, B.col1));
c2 = new b2Vec2(b2Dot(A.col1, B.col2), b2Dot(A.col2, B.col2));
C = new b2Mat22(0, c1, c2);
return (C);
}
public static function b2MaxV(a:b2Vec2, b:b2Vec2):b2Vec2{
var c:b2Vec2;
c = new b2Vec2(b2Max(a.x, b.x), b2Max(a.y, b.y));
return (c);
}
public static function b2IsPowerOfTwo(x:uint):Boolean{
var result:Boolean;
result = (((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 MulFV(s:Number, a:b2Vec2):b2Vec2{
var v:b2Vec2;
v = new b2Vec2((s * a.x), (s * a.y));
return (v);
}
public static function b2MulTMV(A:b2Mat22, v:b2Vec2):b2Vec2{
var u:b2Vec2;
u = 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;
C = 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;
u = 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 Engine.Common.Math
Section 38
//b2Vec2 (Engine.Common.Math.b2Vec2)
package Engine.Common.Math {
public class b2Vec2 {
public var x:Number;
public var y:Number;
public function b2Vec2(x_:Number=0, y_:Number=0){
super();
x = x_;
y = 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 Add(v:b2Vec2):void{
x = (x + v.x);
y = (y + v.y);
}
public function SetZero():void{
x = 0;
y = 0;
}
public function CrossVF(s:Number):void{
var tX:Number;
tX = 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 Abs():void{
x = Math.abs(x);
y = Math.abs(y);
}
public function Copy():b2Vec2{
return (new b2Vec2(x, y));
}
public function MulTM(A:b2Mat22):void{
var tX:Number;
tX = 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 function MinV(b:b2Vec2):void{
x = ((x < b.x)) ? x : b.x;
y = ((y < b.y)) ? y : b.y;
}
public function MulM(A:b2Mat22):void{
var tX:Number;
tX = x;
x = ((A.col1.x * tX) + (A.col2.x * y));
y = ((A.col1.y * tX) + (A.col2.y * y));
}
public function Normalize():Number{
var length:Number;
var invLength:Number;
length = Length();
if (length < Number.MIN_VALUE){
return (0);
};
invLength = (1 / length);
x = (x * invLength);
y = (y * invLength);
return (length);
}
public function Subtract(v:b2Vec2):void{
x = (x - v.x);
y = (y - v.y);
}
public function CrossFV(s:Number):void{
var tX:Number;
tX = x;
x = (-(s) * y);
y = (s * tX);
}
public static function Make(x_:Number, y_:Number):b2Vec2{
return (new b2Vec2(x_, y_));
}
}
}//package Engine.Common.Math
Section 39
//b2Settings (Engine.Common.b2Settings)
package Engine.Common {
import Engine.Common.Math.*;
public class b2Settings {
public static const b2_lengthUnitsPerMeter:Number = 1;
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_maxShapesPerBody:int = 32;
public static const b2_maxProxies:int = 0x0400;
public static const b2_velocityThreshold:Number = 1;
public static const b2_timeToSleep:Number = 0.5;
public static const b2_contactBaumgarte:Number = 0.2;
public static const b2_maxPairs:int = 8192;
public static const b2_maxManifoldPoints:int = 2;
public static const b2_maxAngularCorrection:Number = 0.139626340159546;
public static const b2_massUnitsPerKilogram:Number = 1;
public static const USHRT_MAX:int = 0xFFFF;
public static const b2_maxLinearCorrection:Number = 0.2;
public static const b2_maxPolyVertices:int = 8;
public static const b2_timeUnitsPerSecond:Number = 1;
public function b2Settings(){
super();
}
public static function b2Assert(a:Boolean):void{
var nullVec:b2Vec2;
if (!(a)){
nullVec.x++;
};
}
}
}//package Engine.Common
Section 40
//b2CircleContact (Engine.Dynamics.Contacts.b2CircleContact)
package Engine.Dynamics.Contacts {
import Engine.Collision.Shapes.*;
import Engine.Collision.*;
import Engine.Dynamics.*;
import Engine.Common.*;
import Engine.Common.Math.*;
public class b2CircleContact extends b2Contact {
public var m_manifold:Array;
public function b2CircleContact(shape1:b2Shape, shape2:b2Shape):void{
m_manifold = [new b2Manifold()];
super(shape1, shape2);
m_manifold[0].pointCount = 0;
m_manifold[0].points[0].normalImpulse = 0;
m_manifold[0].points[0].tangentImpulse = 0;
}
override public function GetManifolds():Array{
return (m_manifold);
}
override public function Evaluate():void{
b2Collision.b2CollideCircle(m_manifold[0], (m_shape1 as b2CircleShape), (m_shape2 as b2CircleShape));
if (m_manifold[0].pointCount > 0){
m_manifoldCount = 1;
} else {
m_manifoldCount = 0;
};
}
public static function Destroy(contact:b2Contact, allocator):void{
}
public static function Create(shape1:b2Shape, shape2:b2Shape, allocator):b2Contact{
return (new b2CircleContact(shape1, shape2));
}
}
}//package Engine.Dynamics.Contacts
Section 41
//b2Contact (Engine.Dynamics.Contacts.b2Contact)
package Engine.Dynamics.Contacts {
import Engine.Collision.*;
import Engine.Collision.Shapes.*;
import Engine.Common.*;
import Engine.Common.Math.*;
import Engine.Dynamics.*;
public class b2Contact {
public var m_shape1:b2Shape;
public var m_shape2:b2Shape;
public var m_prev:b2Contact;
public var m_next:b2Contact;
public var m_friction:Number;
public var m_manifoldCount:int;
public var m_node1:b2ContactNode;
public var m_node2:b2ContactNode;
public var m_restitution:Number;
public var m_flags:uint;
public static var s_registers:Array;
public static var s_initialized:Boolean = false;
public static var e_islandFlag:uint = 1;
public static var e_destroyFlag:uint = 2;
public function b2Contact(s1:b2Shape=null, s2:b2Shape=null):void{
m_node1 = new b2ContactNode();
m_node2 = new b2ContactNode();
super();
m_flags = 0;
if (((!(s1)) || (!(s2)))){
m_shape1 = null;
m_shape2 = null;
return;
};
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 GetShape1():b2Shape{
return (m_shape1);
}
public function GetNext():b2Contact{
return (m_next);
}
public function GetShape2():b2Shape{
return (m_shape2);
}
public function GetManifoldCount():int{
return (m_manifoldCount);
}
public function GetManifolds():Array{
return (null);
}
public function Evaluate():void{
}
public static function InitializeRegisters():void{
var shapeTypeCount:int;
var i:int;
var j:int;
shapeTypeCount = b2Shape.e_shapeTypeCount;
s_registers = new Array(shapeTypeCount);
i = 0;
while (i < shapeTypeCount) {
s_registers[i] = new Array(shapeTypeCount);
j = 0;
while (j < 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_polyShape, b2Shape.e_circleShape);
AddType(b2PolyContact.Create, b2PolyContact.Destroy, b2Shape.e_polyShape, b2Shape.e_polyShape);
}
public static function Destroy(contact:b2Contact, allocator):void{
var type1:int;
var type2:int;
var destroyFcn:*;
if (contact.GetManifoldCount() > 0){
contact.m_shape1.m_body.WakeUp();
contact.m_shape2.m_body.WakeUp();
};
type1 = contact.m_shape1.m_type;
type2 = contact.m_shape2.m_type;
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 type1:int;
var type2:int;
var createFcn:*;
var c:b2Contact;
var i:int;
var m:b2Manifold;
if (s_initialized === false){
InitializeRegisters();
s_initialized = true;
};
type1 = shape1.m_type;
type2 = shape2.m_type;
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 Engine.Dynamics.Contacts
Section 42
//b2ContactConstraint (Engine.Dynamics.Contacts.b2ContactConstraint)
package Engine.Dynamics.Contacts {
import Engine.Common.Math.*;
import Engine.Common.*;
import Engine.Dynamics.*;
import Engine.Collision.*;
public class b2ContactConstraint {
public var points:Array;
public var restitution:Number;
public var body1:b2Body;
public var manifold:b2Manifold;
public var normal:b2Vec2;
public var body2:b2Body;
public var friction:Number;
public var pointCount:int;
public function b2ContactConstraint(){
var i:int;
normal = new b2Vec2();
super();
points = new Array(b2Settings.b2_maxManifoldPoints);
i = 0;
while (i < b2Settings.b2_maxManifoldPoints) {
points[i] = new b2ContactConstraintPoint();
i++;
};
}
}
}//package Engine.Dynamics.Contacts
Section 43
//b2ContactConstraintPoint (Engine.Dynamics.Contacts.b2ContactConstraintPoint)
package Engine.Dynamics.Contacts {
import Engine.Common.Math.*;
public class b2ContactConstraintPoint {
public var separation:Number;
public var positionImpulse:Number;
public var normalImpulse:Number;
public var tangentImpulse:Number;
public var localAnchor1:b2Vec2;
public var localAnchor2:b2Vec2;
public var tangentMass:Number;
public var normalMass:Number;
public var velocityBias:Number;
public function b2ContactConstraintPoint(){
localAnchor1 = new b2Vec2();
localAnchor2 = new b2Vec2();
super();
}
}
}//package Engine.Dynamics.Contacts
Section 44
//b2ContactNode (Engine.Dynamics.Contacts.b2ContactNode)
package Engine.Dynamics.Contacts {
import Engine.Dynamics.*;
public class b2ContactNode {
public var next:b2ContactNode;
public var other:b2Body;
public var contact:b2Contact;
public var prev:b2ContactNode;
public function b2ContactNode(){
super();
}
}
}//package Engine.Dynamics.Contacts
Section 45
//b2ContactRegister (Engine.Dynamics.Contacts.b2ContactRegister)
package Engine.Dynamics.Contacts {
public class b2ContactRegister {
public var primary:Boolean;
public var createFcn;
public var destroyFcn;
public function b2ContactRegister(){
super();
}
}
}//package Engine.Dynamics.Contacts
Section 46
//b2ContactSolver (Engine.Dynamics.Contacts.b2ContactSolver)
package Engine.Dynamics.Contacts {
import Engine.Common.Math.*;
import Engine.Dynamics.*;
import Engine.Collision.*;
import Engine.Common.*;
public class b2ContactSolver {
public var m_constraintCount:int;
public var m_constraints:Array;
public var m_allocator;
public function b2ContactSolver(contacts:Array, contactCount:int, allocator):void{
var i:int;
var tVec:b2Vec2;
var tMat:b2Mat22;
var count:int;
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:int;
var cp:b2ContactPoint;
var ccp:b2ContactConstraintPoint;
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 tangentX:Number;
var tangentY:Number;
var rt1:Number;
var rt2:Number;
var kTangent:Number;
var tX:Number;
var tY:Number;
var vRel:Number;
m_constraints = new Array();
super();
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++;
};
count = 0;
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.normalImpulse = cp.normalImpulse;
ccp.tangentImpulse = cp.tangentImpulse;
ccp.separation = cp.separation;
r1X = (cp.position.x - b1.m_position.x);
r1Y = (cp.position.y - b1.m_position.y);
r2X = (cp.position.x - b2.m_position.x);
r2Y = (cp.position.y - b2.m_position.y);
tVec = ccp.localAnchor1;
tMat = b1.m_R;
tVec.x = ((r1X * tMat.col1.x) + (r1Y * tMat.col1.y));
tVec.y = ((r1X * tMat.col2.x) + (r1Y * tMat.col2.y));
tVec = ccp.localAnchor2;
tMat = b2.m_R;
tVec.x = ((r2X * tMat.col1.x) + (r2Y * tMat.col1.y));
tVec.y = ((r2X * tMat.col2.x) + (r2Y * tMat.col2.y));
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);
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);
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 = (-(c.restitution) * vRel);
} else {
ccp.velocityBias = 0;
};
k++;
};
count++;
j++;
};
i++;
};
}
public function SolvePositionConstraints(beta:Number):Boolean{
var minSeparation:Number;
var tMat:b2Mat22;
var tVec:b2Vec2;
var i:int;
var c:b2ContactConstraint;
var b1:b2Body;
var b2:b2Body;
var b1_position:b2Vec2;
var b1_rotation:Number;
var b2_position:b2Vec2;
var b2_rotation:Number;
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 tCount:int;
var j:int;
var ccp:b2ContactConstraintPoint;
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 dpX:Number;
var dpY:Number;
var separation:Number;
var C:Number;
var dImpulse:Number;
var impulse0:Number;
var impulseX:Number;
var impulseY:Number;
minSeparation = 0;
i = 0;
while (i < m_constraintCount) {
c = m_constraints[i];
b1 = c.body1;
b2 = c.body2;
b1_position = b1.m_position;
b1_rotation = b1.m_rotation;
b2_position = b2.m_position;
b2_rotation = b2.m_rotation;
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_R;
tVec = ccp.localAnchor1;
r1X = ((tMat.col1.x * tVec.x) + (tMat.col2.x * tVec.y));
r1Y = ((tMat.col1.y * tVec.x) + (tMat.col2.y * tVec.y));
tMat = b2.m_R;
tVec = ccp.localAnchor2;
r2X = ((tMat.col1.x * tVec.x) + (tMat.col2.x * tVec.y));
r2Y = ((tMat.col1.y * tVec.x) + (tMat.col2.y * tVec.y));
p1X = (b1_position.x + r1X);
p1Y = (b1_position.y + r1Y);
p2X = (b2_position.x + r2X);
p2Y = (b2_position.y + r2Y);
dpX = (p2X - p1X);
dpY = (p2Y - p1Y);
separation = (((dpX * normalX) + (dpY * normalY)) + ccp.separation);
minSeparation = b2Math.b2Min(minSeparation, separation);
C = (beta * b2Math.b2Clamp((separation + b2Settings.b2_linearSlop), -(b2Settings.b2_maxLinearCorrection), 0));
dImpulse = (-(ccp.normalMass) * C);
impulse0 = ccp.positionImpulse;
ccp.positionImpulse = b2Math.b2Max((impulse0 + dImpulse), 0);
dImpulse = (ccp.positionImpulse - impulse0);
impulseX = (dImpulse * normalX);
impulseY = (dImpulse * normalY);
b1_position.x = (b1_position.x - (invMass1 * impulseX));
b1_position.y = (b1_position.y - (invMass1 * impulseY));
b1_rotation = (b1_rotation - (invI1 * ((r1X * impulseY) - (r1Y * impulseX))));
b1.m_R.Set(b1_rotation);
b2_position.x = (b2_position.x + (invMass2 * impulseX));
b2_position.y = (b2_position.y + (invMass2 * impulseY));
b2_rotation = (b2_rotation + (invI2 * ((r2X * impulseY) - (r2Y * impulseX))));
b2.m_R.Set(b2_rotation);
j++;
};
b1.m_rotation = b1_rotation;
b2.m_rotation = b2_rotation;
i++;
};
return ((minSeparation >= -(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 i:int;
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 tCount:int;
var vn:Number;
var vt:Number;
var maxFriction:Number;
i = 0;
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_R;
tVec = ccp.localAnchor1;
r1X = ((tMat.col1.x * tVec.x) + (tMat.col2.x * tVec.y));
r1Y = ((tMat.col1.y * tVec.x) + (tMat.col2.y * tVec.y));
tMat = b2.m_R;
tVec = ccp.localAnchor2;
r2X = ((tMat.col1.x * tVec.x) + (tMat.col2.x * tVec.y));
r2Y = ((tMat.col1.y * tVec.x) + (tMat.col2.y * tVec.y));
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 = (-(ccp.normalMass) * (vn - ccp.velocityBias));
newImpulse = b2Math.b2Max((ccp.normalImpulse + lambda), 0);
lambda = (newImpulse - ccp.normalImpulse);
PX = (lambda * normalX);
PY = (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.normalImpulse = newImpulse;
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 = (ccp.tangentMass * -(vt));
maxFriction = (c.friction * ccp.normalImpulse);
newImpulse = b2Math.b2Clamp((ccp.tangentImpulse + lambda), -(maxFriction), maxFriction);
lambda = (newImpulse - ccp.tangentImpulse);
PX = (lambda * tangentX);
PY = (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.tangentImpulse = newImpulse;
j++;
};
b1.m_angularVelocity = b1_angularVelocity;
b2.m_angularVelocity = b2_angularVelocity;
i++;
};
}
public function PreSolve():void{
var tVec:b2Vec2;
var tVec2:b2Vec2;
var tMat:b2Mat22;
var i:int;
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 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;
i = 0;
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 = ((ccp.normalImpulse * normalX) + (ccp.tangentImpulse * tangentX));
PY = ((ccp.normalImpulse * normalY) + (ccp.tangentImpulse * tangentY));
tMat = b1.m_R;
tVec = ccp.localAnchor1;
r1X = ((tMat.col1.x * tVec.x) + (tMat.col2.x * tVec.y));
r1Y = ((tMat.col1.y * tVec.x) + (tMat.col2.y * tVec.y));
tMat = b2.m_R;
tVec = ccp.localAnchor2;
r2X = ((tMat.col1.x * tVec.x) + (tMat.col2.x * tVec.y));
r2Y = ((tMat.col1.y * tVec.x) + (tMat.col2.y * tVec.y));
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));
ccp.positionImpulse = 0;
j++;
};
} else {
tCount = c.pointCount;
j = 0;
while (j < tCount) {
ccp2 = c.points[j];
ccp2.normalImpulse = 0;
ccp2.tangentImpulse = 0;
ccp2.positionImpulse = 0;
j++;
};
};
i++;
};
}
public function PostSolve():void{
var i:int;
var c:b2ContactConstraint;
var m:b2Manifold;
var cPointCount:int;
var j:int;
var mPoint:b2ContactPoint;
var cPoint:b2ContactConstraintPoint;
i = 0;
while (i < m_constraintCount) {
c = m_constraints[i];
m = c.manifold;
cPointCount = c.pointCount;
j = 0;
while (j < cPointCount) {
mPoint = m.points[j];
cPoint = c.points[j];
mPoint.normalImpulse = cPoint.normalImpulse;
mPoint.tangentImpulse = cPoint.tangentImpulse;
j++;
};
i++;
};
}
}
}//package Engine.Dynamics.Contacts
Section 47
//b2NullContact (Engine.Dynamics.Contacts.b2NullContact)
package Engine.Dynamics.Contacts {
public class b2NullContact extends b2Contact {
public function b2NullContact():void{
super();
}
override public function GetManifolds():Array{
return (null);
}
override public function Evaluate():void{
}
}
}//package Engine.Dynamics.Contacts
Section 48
//b2PolyAndCircleContact (Engine.Dynamics.Contacts.b2PolyAndCircleContact)
package Engine.Dynamics.Contacts {
import Engine.Collision.Shapes.*;
import Engine.Collision.*;
import Engine.Common.*;
import Engine.Dynamics.*;
import Engine.Common.Math.*;
public class b2PolyAndCircleContact extends b2Contact {
public var m_manifold:Array;
public function b2PolyAndCircleContact(shape1:b2Shape, shape2:b2Shape):void{
m_manifold = [new b2Manifold()];
super(shape1, shape2);
b2Settings.b2Assert((m_shape1.m_type === b2Shape.e_polyShape));
b2Settings.b2Assert((m_shape2.m_type === b2Shape.e_circleShape));
m_manifold[0].pointCount = 0;
m_manifold[0].points[0].normalImpulse = 0;
m_manifold[0].points[0].tangentImpulse = 0;
}
override public function GetManifolds():Array{
return (m_manifold);
}
override public function Evaluate():void{
b2Collision.b2CollidePolyAndCircle(m_manifold[0], (m_shape1 as b2PolyShape), (m_shape2 as b2CircleShape));
if (m_manifold[0].pointCount > 0){
m_manifoldCount = 1;
} else {
m_manifoldCount = 0;
};
}
public static function Destroy(contact:b2Contact, allocator):void{
}
public static function Create(shape1:b2Shape, shape2:b2Shape, allocator):b2Contact{
return (new b2PolyAndCircleContact(shape1, shape2));
}
}
}//package Engine.Dynamics.Contacts
Section 49
//b2PolyContact (Engine.Dynamics.Contacts.b2PolyContact)
package Engine.Dynamics.Contacts {
import Engine.Collision.Shapes.*;
import Engine.Collision.*;
import Engine.Common.*;
import Engine.Common.Math.*;
import Engine.Dynamics.*;
public class b2PolyContact extends b2Contact {
public var m_manifold:Array;
private var m0:b2Manifold;
public function b2PolyContact(shape1:b2Shape, shape2:b2Shape):void{
m0 = new b2Manifold();
m_manifold = [new b2Manifold()];
super(shape1, shape2);
m_manifold[0].pointCount = 0;
}
override public function GetManifolds():Array{
return (m_manifold);
}
override public function Evaluate():void{
var tMani:b2Manifold;
var tPoints:Array;
var tManiPointCount:int;
var k:int;
var tPoint:b2ContactPoint;
var tPoint0:b2ContactPoint;
var match:Array;
var i:int;
var cp:b2ContactPoint;
var idKey:uint;
var j:int;
var cp0:b2ContactPoint;
var id0:b2ContactID;
tMani = m_manifold[0];
tPoints = m0.points;
tManiPointCount = tMani.pointCount;
k = 0;
while (k < tManiPointCount) {
tPoint = tPoints[k];
tPoint0 = tMani.points[k];
tPoint.normalImpulse = tPoint0.normalImpulse;
tPoint.tangentImpulse = tPoint0.tangentImpulse;
tPoint.id = tPoint0.id.Copy();
k++;
};
m0.pointCount = tMani.pointCount;
b2Collision.b2CollidePoly(tMani, (m_shape1 as b2PolyShape), (m_shape2 as b2PolyShape));
tManiPointCount = tMani.pointCount;
if (tManiPointCount > 0){
match = [false, false];
i = 0;
while (i < tManiPointCount) {
cp = tMani.points[i];
cp.normalImpulse = 0;
cp.tangentImpulse = 0;
idKey = cp.id.key;
j = 0;
while (j < m0.pointCount) {
if (match[j] == true){
} else {
cp0 = m0.points[j];
id0 = cp0.id;
if (id0.key === idKey){
match[j] = true;
cp.normalImpulse = cp0.normalImpulse;
cp.tangentImpulse = cp0.tangentImpulse;
break;
};
};
j++;
};
i++;
};
m_manifoldCount = 1;
} else {
m_manifoldCount = 0;
};
}
public static function Destroy(contact:b2Contact, allocator):void{
}
public static function Create(shape1:b2Shape, shape2:b2Shape, allocator):b2Contact{
return (new b2PolyContact(shape1, shape2));
}
}
}//package Engine.Dynamics.Contacts
Section 50
//b2DistanceJoint (Engine.Dynamics.Joints.b2DistanceJoint)
package Engine.Dynamics.Joints {
import Engine.Common.Math.*;
import Engine.Common.*;
import Engine.Dynamics.*;
public class b2DistanceJoint extends b2Joint {
public var m_localAnchor2:b2Vec2;
public var m_mass:Number;
public var m_localAnchor1:b2Vec2;
public var m_u:b2Vec2;
public var m_impulse:Number;
public var m_length:Number;
public function b2DistanceJoint(def:b2DistanceJointDef):void{
var tMat:b2Mat22;
var tX:Number;
var tY:Number;
m_localAnchor1 = new b2Vec2();
m_localAnchor2 = new b2Vec2();
m_u = new b2Vec2();
super(def);
tMat = m_body1.m_R;
tX = (def.anchorPoint1.x - m_body1.m_position.x);
tY = (def.anchorPoint1.y - m_body1.m_position.y);
m_localAnchor1.x = ((tX * tMat.col1.x) + (tY * tMat.col1.y));
m_localAnchor1.y = ((tX * tMat.col2.x) + (tY * tMat.col2.y));
tMat = m_body2.m_R;
tX = (def.anchorPoint2.x - m_body2.m_position.x);
tY = (def.anchorPoint2.y - m_body2.m_position.y);
m_localAnchor2.x = ((tX * tMat.col1.x) + (tY * tMat.col1.y));
m_localAnchor2.y = ((tX * tMat.col2.x) + (tY * tMat.col2.y));
tX = (def.anchorPoint2.x - def.anchorPoint1.x);
tY = (def.anchorPoint2.y - def.anchorPoint1.y);
m_length = Math.sqrt(((tX * tX) + (tY * tY)));
m_impulse = 0;
}
override public function SolveVelocityConstraints(step:b2StepInfo):void{
var tMat:b2Mat22;
var r1X:Number;
var r1Y:Number;
var r2X:Number;
var r2Y:Number;
var v1X:Number;
var v1Y:Number;
var v2X:Number;
var v2Y:Number;
var Cdot:Number;
var impulse:Number;
var PX:Number;
var PY:Number;
tMat = m_body1.m_R;
r1X = ((tMat.col1.x * m_localAnchor1.x) + (tMat.col2.x * m_localAnchor1.y));
r1Y = ((tMat.col1.y * m_localAnchor1.x) + (tMat.col2.y * m_localAnchor1.y));
tMat = m_body2.m_R;
r2X = ((tMat.col1.x * m_localAnchor2.x) + (tMat.col2.x * m_localAnchor2.y));
r2Y = ((tMat.col1.y * m_localAnchor2.x) + (tMat.col2.y * m_localAnchor2.y));
v1X = (m_body1.m_linearVelocity.x + (-(m_body1.m_angularVelocity) * r1Y));
v1Y = (m_body1.m_linearVelocity.y + (m_body1.m_angularVelocity * r1X));
v2X = (m_body2.m_linearVelocity.x + (-(m_body2.m_angularVelocity) * r2Y));
v2Y = (m_body2.m_linearVelocity.y + (m_body2.m_angularVelocity * r2X));
Cdot = ((m_u.x * (v2X - v1X)) + (m_u.y * (v2Y - v1Y)));
impulse = (-(m_mass) * Cdot);
m_impulse = (m_impulse + impulse);
PX = (impulse * m_u.x);
PY = (impulse * m_u.y);
m_body1.m_linearVelocity.x = (m_body1.m_linearVelocity.x - (m_body1.m_invMass * PX));
m_body1.m_linearVelocity.y = (m_body1.m_linearVelocity.y - (m_body1.m_invMass * PY));
m_body1.m_angularVelocity = (m_body1.m_angularVelocity - (m_body1.m_invI * ((r1X * PY) - (r1Y * PX))));
m_body2.m_linearVelocity.x = (m_body2.m_linearVelocity.x + (m_body2.m_invMass * PX));
m_body2.m_linearVelocity.y = (m_body2.m_linearVelocity.y + (m_body2.m_invMass * PY));
m_body2.m_angularVelocity = (m_body2.m_angularVelocity + (m_body2.m_invI * ((r2X * PY) - (r2Y * PX))));
}
override public function GetAnchor1():b2Vec2{
return (b2Math.AddVV(m_body1.m_position, b2Math.b2MulMV(m_body1.m_R, m_localAnchor1)));
}
override public function GetAnchor2():b2Vec2{
return (b2Math.AddVV(m_body2.m_position, b2Math.b2MulMV(m_body2.m_R, m_localAnchor2)));
}
override public function PrepareVelocitySolver():void{
var tMat:b2Mat22;
var r1X:Number;
var r1Y:Number;
var r2X:Number;
var r2Y:Number;
var length:Number;
var cr1u:Number;
var cr2u:Number;
var PX:Number;
var PY:Number;
tMat = m_body1.m_R;
r1X = ((tMat.col1.x * m_localAnchor1.x) + (tMat.col2.x * m_localAnchor1.y));
r1Y = ((tMat.col1.y * m_localAnchor1.x) + (tMat.col2.y * m_localAnchor1.y));
tMat = m_body2.m_R;
r2X = ((tMat.col1.x * m_localAnchor2.x) + (tMat.col2.x * m_localAnchor2.y));
r2Y = ((tMat.col1.y * m_localAnchor2.x) + (tMat.col2.y * m_localAnchor2.y));
m_u.x = (((m_body2.m_position.x + r2X) - m_body1.m_position.x) - r1X);
m_u.y = (((m_body2.m_position.y + r2Y) - m_body1.m_position.y) - r1Y);
length = 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();
};
cr1u = ((r1X * m_u.y) - (r1Y * m_u.x));
cr2u = ((r2X * m_u.y) - (r2Y * m_u.x));
m_mass = (((m_body1.m_invMass + ((m_body1.m_invI * cr1u) * cr1u)) + m_body2.m_invMass) + ((m_body2.m_invI * cr2u) * cr2u));
m_mass = (1 / m_mass);
if (b2World.s_enableWarmStarting){
PX = (m_impulse * m_u.x);
PY = (m_impulse * m_u.y);
m_body1.m_linearVelocity.x = (m_body1.m_linearVelocity.x - (m_body1.m_invMass * PX));
m_body1.m_linearVelocity.y = (m_body1.m_linearVelocity.y - (m_body1.m_invMass * PY));
m_body1.m_angularVelocity = (m_body1.m_angularVelocity - (m_body1.m_invI * ((r1X * PY) - (r1Y * PX))));
m_body2.m_linearVelocity.x = (m_body2.m_linearVelocity.x + (m_body2.m_invMass * PX));
m_body2.m_linearVelocity.y = (m_body2.m_linearVelocity.y + (m_body2.m_invMass * PY));
m_body2.m_angularVelocity = (m_body2.m_angularVelocity + (m_body2.m_invI * ((r2X * PY) - (r2Y * PX))));
} else {
m_impulse = 0;
};
}
override public function GetReactionTorque(invTimeStep:Number):Number{
return (0);
}
override public function GetReactionForce(invTimeStep:Number):b2Vec2{
var F:b2Vec2;
F = new b2Vec2();
F.SetV(m_u);
F.Multiply((m_impulse * invTimeStep));
return (F);
}
override public function SolvePositionConstraints():Boolean{
var tMat:b2Mat22;
var r1X:Number;
var r1Y:Number;
var r2X:Number;
var r2Y:Number;
var dX:Number;
var dY:Number;
var length:Number;
var C:Number;
var impulse:Number;
var PX:Number;
var PY:Number;
tMat = m_body1.m_R;
r1X = ((tMat.col1.x * m_localAnchor1.x) + (tMat.col2.x * m_localAnchor1.y));
r1Y = ((tMat.col1.y * m_localAnchor1.x) + (tMat.col2.y * m_localAnchor1.y));
tMat = m_body2.m_R;
r2X = ((tMat.col1.x * m_localAnchor2.x) + (tMat.col2.x * m_localAnchor2.y));
r2Y = ((tMat.col1.y * m_localAnchor2.x) + (tMat.col2.y * m_localAnchor2.y));
dX = (((m_body2.m_position.x + r2X) - m_body1.m_position.x) - r1X);
dY = (((m_body2.m_position.y + r2Y) - m_body1.m_position.y) - r1Y);
length = Math.sqrt(((dX * dX) + (dY * dY)));
dX = (dX / length);
dY = (dY / length);
C = (length - m_length);
C = b2Math.b2Clamp(C, -(b2Settings.b2_maxLinearCorrection), b2Settings.b2_maxLinearCorrection);
impulse = (-(m_mass) * C);
m_u.Set(dX, dY);
PX = (impulse * m_u.x);
PY = (impulse * m_u.y);
m_body1.m_position.x = (m_body1.m_position.x - (m_body1.m_invMass * PX));
m_body1.m_position.y = (m_body1.m_position.y - (m_body1.m_invMass * PY));
m_body1.m_rotation = (m_body1.m_rotation - (m_body1.m_invI * ((r1X * PY) - (r1Y * PX))));
m_body2.m_position.x = (m_body2.m_position.x + (m_body2.m_invMass * PX));
m_body2.m_position.y = (m_body2.m_position.y + (m_body2.m_invMass * PY));
m_body2.m_rotation = (m_body2.m_rotation + (m_body2.m_invI * ((r2X * PY) - (r2Y * PX))));
m_body1.m_R.Set(m_body1.m_rotation);
m_body2.m_R.Set(m_body2.m_rotation);
return ((b2Math.b2Abs(C) < b2Settings.b2_linearSlop));
}
}
}//package Engine.Dynamics.Joints
Section 51
//b2DistanceJointDef (Engine.Dynamics.Joints.b2DistanceJointDef)
package Engine.Dynamics.Joints {
import Engine.Common.Math.*;
public class b2DistanceJointDef extends b2JointDef {
public var anchorPoint2:b2Vec2;
public var anchorPoint1:b2Vec2;
public function b2DistanceJointDef(){
anchorPoint1 = new b2Vec2();
anchorPoint2 = new b2Vec2();
super();
type = b2Joint.e_distanceJoint;
}
}
}//package Engine.Dynamics.Joints
Section 52
//b2GearJoint (Engine.Dynamics.Joints.b2GearJoint)
package Engine.Dynamics.Joints {
import Engine.Common.Math.*;
import Engine.Dynamics.*;
import Engine.Common.*;
public class b2GearJoint extends b2Joint {
public var m_impulse:Number;
public var m_mass:Number;
public var m_prismatic1:b2PrismaticJoint;
public var m_prismatic2:b2PrismaticJoint;
public var m_ground1:b2Body;
public var m_ground2:b2Body;
public var m_constant:Number;
public var m_revolute1:b2RevoluteJoint;
public var m_revolute2:b2RevoluteJoint;
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_J:b2Jacobian;
public function b2GearJoint(def:b2GearJointDef):void{
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_impulse = 0;
}
override public function GetAnchor1():b2Vec2{
var tMat:b2Mat22;
tMat = m_body1.m_R;
return (new b2Vec2((m_body1.m_position.x + ((tMat.col1.x * m_localAnchor1.x) + (tMat.col2.x * m_localAnchor1.y))), (m_body1.m_position.y + ((tMat.col1.y * m_localAnchor1.x) + (tMat.col2.y * m_localAnchor1.y)))));
}
override public function GetAnchor2():b2Vec2{
var tMat:b2Mat22;
tMat = m_body2.m_R;
return (new b2Vec2((m_body2.m_position.x + ((tMat.col1.x * m_localAnchor2.x) + (tMat.col2.x * m_localAnchor2.y))), (m_body2.m_position.y + ((tMat.col1.y * m_localAnchor2.x) + (tMat.col2.y * m_localAnchor2.y)))));
}
override public function PrepareVelocitySolver():void{
var g1:b2Body;
var g2:b2Body;
var b1:b2Body;
var b2:b2Body;
var ugX:Number;
var ugY:Number;
var rX:Number;
var rY:Number;
var tMat:b2Mat22;
var tVec:b2Vec2;
var crug:Number;
var K:Number;
g1 = m_ground1;
g2 = m_ground2;
b1 = m_body1;
b2 = m_body2;
K = 0;
m_J.SetZero();
if (m_revolute1){
m_J.angular1 = -1;
K = (K + b1.m_invI);
} else {
tMat = g1.m_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_R;
rX = ((tMat.col1.x * m_localAnchor1.x) + (tMat.col2.x * m_localAnchor1.y));
rY = ((tMat.col1.y * m_localAnchor1.x) + (tMat.col2.y * m_localAnchor1.y));
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_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_R;
rX = ((tMat.col1.x * m_localAnchor2.x) + (tMat.col2.x * m_localAnchor2.y));
rY = ((tMat.col1.y * m_localAnchor2.x) + (tMat.col2.y * m_localAnchor2.y));
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);
b1.m_linearVelocity.x = (b1.m_linearVelocity.x + ((b1.m_invMass * m_impulse) * m_J.linear1.x));
b1.m_linearVelocity.y = (b1.m_linearVelocity.y + ((b1.m_invMass * m_impulse) * m_J.linear1.y));
b1.m_angularVelocity = (b1.m_angularVelocity + ((b1.m_invI * m_impulse) * m_J.angular1));
b2.m_linearVelocity.x = (b2.m_linearVelocity.x + ((b2.m_invMass * m_impulse) * m_J.linear2.x));
b2.m_linearVelocity.y = (b2.m_linearVelocity.y + ((b2.m_invMass * m_impulse) * m_J.linear2.y));
b2.m_angularVelocity = (b2.m_angularVelocity + ((b2.m_invI * m_impulse) * m_J.angular2));
}
override public function GetReactionForce(invTimeStep:Number):b2Vec2{
return (new b2Vec2());
}
override public function SolvePositionConstraints():Boolean{
var linearError:Number;
var b1:b2Body;
var b2:b2Body;
var coordinate1:Number;
var coordinate2:Number;
var C:Number;
var impulse:Number;
linearError = 0;
b1 = m_body1;
b2 = 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();
};
C = (m_constant - (coordinate1 + (m_ratio * coordinate2)));
impulse = (-(m_mass) * C);
b1.m_position.x = (b1.m_position.x + ((b1.m_invMass * impulse) * m_J.linear1.x));
b1.m_position.y = (b1.m_position.y + ((b1.m_invMass * impulse) * m_J.linear1.y));
b1.m_rotation = (b1.m_rotation + ((b1.m_invI * impulse) * m_J.angular1));
b2.m_position.x = (b2.m_position.x + ((b2.m_invMass * impulse) * m_J.linear2.x));
b2.m_position.y = (b2.m_position.y + ((b2.m_invMass * impulse) * m_J.linear2.y));
b2.m_rotation = (b2.m_rotation + ((b2.m_invI * impulse) * m_J.angular2));
b1.m_R.Set(b1.m_rotation);
b2.m_R.Set(b2.m_rotation);
return ((linearError < b2Settings.b2_linearSlop));
}
override public function GetReactionTorque(invTimeStep:Number):Number{
return (0);
}
public function GetRatio():Number{
return (m_ratio);
}
override public function SolveVelocityConstraints(step:b2StepInfo):void{
var b1:b2Body;
var b2:b2Body;
var Cdot:Number;
var impulse:Number;
b1 = m_body1;
b2 = m_body2;
Cdot = m_J.Compute(b1.m_linearVelocity, b1.m_angularVelocity, b2.m_linearVelocity, b2.m_angularVelocity);
impulse = (-(m_mass) * Cdot);
m_impulse = (m_impulse + impulse);
b1.m_linearVelocity.x = (b1.m_linearVelocity.x + ((b1.m_invMass * impulse) * m_J.linear1.x));
b1.m_linearVelocity.y = (b1.m_linearVelocity.y + ((b1.m_invMass * impulse) * m_J.linear1.y));
b1.m_angularVelocity = (b1.m_angularVelocity + ((b1.m_invI * impulse) * m_J.angular1));
b2.m_linearVelocity.x = (b2.m_linearVelocity.x + ((b2.m_invMass * impulse) * m_J.linear2.x));
b2.m_linearVelocity.y = (b2.m_linearVelocity.y + ((b2.m_invMass * impulse) * m_J.linear2.y));
b2.m_angularVelocity = (b2.m_angularVelocity + ((b2.m_invI * impulse) * m_J.angular2));
}
}
}//package Engine.Dynamics.Joints
Section 53
//b2GearJointDef (Engine.Dynamics.Joints.b2GearJointDef)
package Engine.Dynamics.Joints {
public class b2GearJointDef extends b2JointDef {
public var joint2:b2Joint;
public var joint1:b2Joint;
public var ratio:Number;
public function b2GearJointDef(){
super();
type = b2Joint.e_gearJoint;
joint1 = null;
joint2 = null;
ratio = 1;
}
}
}//package Engine.Dynamics.Joints
Section 54
//b2Jacobian (Engine.Dynamics.Joints.b2Jacobian)
package Engine.Dynamics.Joints {
import Engine.Common.Math.*;
public class b2Jacobian {
public var linear1:b2Vec2;
public var linear2:b2Vec2;
public var angular2:Number;
public var angular1: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 Engine.Dynamics.Joints
Section 55
//b2Joint (Engine.Dynamics.Joints.b2Joint)
package Engine.Dynamics.Joints {
import Engine.Common.Math.*;
import Engine.Dynamics.*;
public class b2Joint {
public var m_islandFlag:Boolean;
public var m_collideConnected:Boolean;
public var m_prev:b2Joint;
public var m_next:b2Joint;
public var m_type:int;
public var m_node1:b2JointNode;
public var m_node2:b2JointNode;
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):void{
m_node1 = new b2JointNode();
m_node2 = new b2JointNode();
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 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 GetBody2():b2Body{
return (m_body2);
}
public function PrepareVelocitySolver():void{
}
public function PreparePositionSolver():void{
}
public function GetReactionTorque(invTimeStep:Number):Number{
return (0);
}
public function GetUserData(){
return (m_userData);
}
public function GetReactionForce(invTimeStep:Number):b2Vec2{
return (null);
}
public function SolvePositionConstraints():Boolean{
return (false);
}
public function GetBody1():b2Body{
return (m_body1);
}
public function SolveVelocityConstraints(step:b2StepInfo):void{
}
public static function Destroy(joint:b2Joint, allocator):void{
}
public static function Create(def:b2JointDef, allocator):b2Joint{
var joint:b2Joint;
joint = null;
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 Engine.Dynamics.Joints
Section 56
//b2JointDef (Engine.Dynamics.Joints.b2JointDef)
package Engine.Dynamics.Joints {
import Engine.Dynamics.*;
public class b2JointDef {
public var collideConnected:Boolean;
public var body1:b2Body;
public var body2:b2Body;
public var userData;
public var type:int;
public function b2JointDef(){
super();
type = b2Joint.e_unknownJoint;
userData = null;
body1 = null;
body2 = null;
collideConnected = false;
}
}
}//package Engine.Dynamics.Joints
Section 57
//b2JointNode (Engine.Dynamics.Joints.b2JointNode)
package Engine.Dynamics.Joints {
import Engine.Dynamics.*;
public class b2JointNode {
public var joint:b2Joint;
public var other:b2Body;
public var next:b2JointNode;
public var prev:b2JointNode;
public function b2JointNode(){
super();
}
}
}//package Engine.Dynamics.Joints
Section 58
//b2MouseJoint (Engine.Dynamics.Joints.b2MouseJoint)
package Engine.Dynamics.Joints {
import Engine.Common.Math.*;
import Engine.Common.*;
import Engine.Dynamics.*;
public class b2MouseJoint extends b2Joint {
public var m_beta:Number;
public var m_target:b2Vec2;
public var m_impulse:b2Vec2;
public var m_ptpMass:b2Mat22;
public var m_localAnchor:b2Vec2;
private var K1:b2Mat22;
private var K2:b2Mat22;
private var K:b2Mat22;
public var m_gamma:Number;
public var m_C:b2Vec2;
public var m_maxForce:Number;
public function b2MouseJoint(def:b2MouseJointDef):void{
var tX:Number;
var tY:Number;
var mass:Number;
var omega:Number;
var d:Number;
var k:Number;
K = new b2Mat22();
K1 = new b2Mat22();
K2 = new b2Mat22();
m_localAnchor = new b2Vec2();
m_target = new b2Vec2();
m_impulse = new b2Vec2();
m_ptpMass = new b2Mat22();
m_C = new b2Vec2();
super(def);
m_target.SetV(def.target);
tX = (m_target.x - m_body2.m_position.x);
tY = (m_target.y - m_body2.m_position.y);
m_localAnchor.x = ((tX * m_body2.m_R.col1.x) + (tY * m_body2.m_R.col1.y));
m_localAnchor.y = ((tX * m_body2.m_R.col2.x) + (tY * m_body2.m_R.col2.y));
m_maxForce = def.maxForce;
m_impulse.SetZero();
mass = m_body2.m_mass;
omega = ((2 * b2Settings.b2_pi) * def.frequencyHz);
d = (((2 * mass) * def.dampingRatio) * omega);
k = ((mass * omega) * omega);
m_gamma = (1 / (d + (def.timeStep * k)));
m_beta = ((def.timeStep * k) / (d + (def.timeStep * k)));
}
override public function GetAnchor1():b2Vec2{
return (m_target);
}
override public function GetAnchor2():b2Vec2{
var tVec:b2Vec2;
tVec = b2Math.b2MulMV(m_body2.m_R, m_localAnchor);
tVec.Add(m_body2.m_position);
return (tVec);
}
override public function PrepareVelocitySolver():void{
var b:b2Body;
var tMat:b2Mat22;
var rX:Number;
var rY:Number;
var invMass:Number;
var invI:Number;
var PX:Number;
var PY:Number;
b = m_body2;
tMat = b.m_R;
rX = ((tMat.col1.x * m_localAnchor.x) + (tMat.col2.x * m_localAnchor.y));
rY = ((tMat.col1.y * m_localAnchor.x) + (tMat.col2.y * m_localAnchor.y));
invMass = b.m_invMass;
invI = 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_ptpMass);
m_C.x = ((b.m_position.x + rX) - m_target.x);
m_C.y = ((b.m_position.y + rY) - m_target.y);
b.m_angularVelocity = (b.m_angularVelocity * 0.98);
PX = m_impulse.x;
PY = m_impulse.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 GetReactionForce(invTimeStep:Number):b2Vec2{
var F:b2Vec2;
F = new b2Vec2();
F.SetV(m_impulse);
F.Multiply(invTimeStep);
return (F);
}
override public function SolvePositionConstraints():Boolean{
return (true);
}
override public function GetReactionTorque(invTimeStep:Number):Number{
return (0);
}
public function SetTarget(target:b2Vec2):void{
m_body2.WakeUp();
m_target = target;
}
override public function SolveVelocityConstraints(step:b2StepInfo):void{
var body:b2Body;
var tMat:b2Mat22;
var rX:Number;
var rY:Number;
var CdotX:Number;
var CdotY:Number;
var tX:Number;
var tY:Number;
var impulseX:Number;
var impulseY:Number;
var oldImpulseX:Number;
var oldImpulseY:Number;
var length:Number;
body = m_body2;
tMat = body.m_R;
rX = ((tMat.col1.x * m_localAnchor.x) + (tMat.col2.x * m_localAnchor.y));
rY = ((tMat.col1.y * m_localAnchor.x) + (tMat.col2.y * m_localAnchor.y));
CdotX = (body.m_linearVelocity.x + (-(body.m_angularVelocity) * rY));
CdotY = (body.m_linearVelocity.y + (body.m_angularVelocity * rX));
tMat = m_ptpMass;
tX = ((CdotX + ((m_beta * step.inv_dt) * m_C.x)) + (m_gamma * m_impulse.x));
tY = ((CdotY + ((m_beta * step.inv_dt) * m_C.y)) + (m_gamma * m_impulse.y));
impulseX = -(((tMat.col1.x * tX) + (tMat.col2.x * tY)));
impulseY = -(((tMat.col1.y * tX) + (tMat.col2.y * tY)));
oldImpulseX = m_impulse.x;
oldImpulseY = m_impulse.y;
m_impulse.x = (m_impulse.x + impulseX);
m_impulse.y = (m_impulse.y + impulseY);
length = m_impulse.Length();
if (length > (step.dt * m_maxForce)){
m_impulse.Multiply(((step.dt * m_maxForce) / length));
};
impulseX = (m_impulse.x - oldImpulseX);
impulseY = (m_impulse.y - oldImpulseY);
body.m_linearVelocity.x = (body.m_linearVelocity.x + (body.m_invMass * impulseX));
body.m_linearVelocity.y = (body.m_linearVelocity.y + (body.m_invMass * impulseY));
body.m_angularVelocity = (body.m_angularVelocity + (body.m_invI * ((rX * impulseY) - (rY * impulseX))));
}
}
}//package Engine.Dynamics.Joints
Section 59
//b2MouseJointDef (Engine.Dynamics.Joints.b2MouseJointDef)
package Engine.Dynamics.Joints {
import Engine.Common.Math.*;
public class b2MouseJointDef extends b2JointDef {
public var frequencyHz:Number;
public var dampingRatio:Number;
public var maxForce:Number;
public var target:b2Vec2;
public var timeStep:Number;
public function b2MouseJointDef(){
target = new b2Vec2();
super();
type = b2Joint.e_mouseJoint;
maxForce = 0;
frequencyHz = 5;
dampingRatio = 0.7;
timeStep = (1 / 60);
}
}
}//package Engine.Dynamics.Joints
Section 60
//b2PrismaticJoint (Engine.Dynamics.Joints.b2PrismaticJoint)
package Engine.Dynamics.Joints {
import Engine.Dynamics.*;
import Engine.Common.Math.*;
import Engine.Common.*;
public class b2PrismaticJoint extends b2Joint {
public var m_initialAngle:Number;
public var m_lowerTranslation:Number;
public var m_localXAxis1:b2Vec2;
public var m_enableLimit:Boolean;
public var m_maxMotorForce:Number;
public var m_angularMass:Number;
public var m_localYAxis1:b2Vec2;
public var m_linearImpulse:Number;
public var m_localAnchor1:b2Vec2;
public var m_localAnchor2:b2Vec2;
public var m_motorMass:Number;
public var m_limitState:int;
public var m_linearMass:Number;
public var m_upperTranslation:Number;
public var m_angularImpulse:Number;
public var m_motorImpulse:Number;
public var m_motorJacobian:b2Jacobian;
public var m_limitImpulse:Number;
public var m_motorSpeed:Number;
public var m_enableMotor:Boolean;
public var m_limitPositionImpulse:Number;
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);
tMat = m_body1.m_R;
tX = (def.anchorPoint.x - m_body1.m_position.x);
tY = (def.anchorPoint.y - m_body1.m_position.y);
m_localAnchor1.Set(((tX * tMat.col1.x) + (tY * tMat.col1.y)), ((tX * tMat.col2.x) + (tY * tMat.col2.y)));
tMat = m_body2.m_R;
tX = (def.anchorPoint.x - m_body2.m_position.x);
tY = (def.anchorPoint.y - m_body2.m_position.y);
m_localAnchor2.Set(((tX * tMat.col1.x) + (tY * tMat.col1.y)), ((tX * tMat.col2.x) + (tY * tMat.col2.y)));
tMat = m_body1.m_R;
tX = def.axis.x;
tY = def.axis.y;
m_localXAxis1.Set(((tX * tMat.col1.x) + (tY * tMat.col1.y)), ((tX * tMat.col2.x) + (tY * tMat.col2.y)));
m_localYAxis1.x = -(m_localXAxis1.y);
m_localYAxis1.y = m_localXAxis1.x;
m_initialAngle = (m_body2.m_rotation - m_body1.m_rotation);
m_linearJacobian.SetZero();
m_linearMass = 0;
m_linearImpulse = 0;
m_angularMass = 0;
m_angularImpulse = 0;
m_motorJacobian.SetZero();
m_motorMass = 0;
m_motorImpulse = 0;
m_limitImpulse = 0;
m_limitPositionImpulse = 0;
m_lowerTranslation = def.lowerTranslation;
m_upperTranslation = def.upperTranslation;
m_maxMotorForce = def.motorForce;
m_motorSpeed = def.motorSpeed;
m_enableLimit = def.enableLimit;
m_enableMotor = def.enableMotor;
}
override public function GetAnchor1():b2Vec2{
var b1:b2Body;
var tVec:b2Vec2;
b1 = m_body1;
tVec = new b2Vec2();
tVec.SetV(m_localAnchor1);
tVec.MulM(b1.m_R);
tVec.Add(b1.m_position);
return (tVec);
}
override public function GetAnchor2():b2Vec2{
var b2:b2Body;
var tVec:b2Vec2;
b2 = m_body2;
tVec = new b2Vec2();
tVec.SetV(m_localAnchor2);
tVec.MulM(b2.m_R);
tVec.Add(b2.m_position);
return (tVec);
}
override public function PrepareVelocitySolver():void{
var b1:b2Body;
var b2:b2Body;
var tMat:b2Mat22;
var r1X:Number;
var r1Y:Number;
var r2X:Number;
var r2Y:Number;
var invMass1:Number;
var invMass2:Number;
var invI1:Number;
var invI2:Number;
var ay1X:Number;
var ay1Y:Number;
var eX:Number;
var eY: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;
b1 = m_body1;
b2 = m_body2;
tMat = b1.m_R;
r1X = ((tMat.col1.x * m_localAnchor1.x) + (tMat.col2.x * m_localAnchor1.y));
r1Y = ((tMat.col1.y * m_localAnchor1.x) + (tMat.col2.y * m_localAnchor1.y));
tMat = b2.m_R;
r2X = ((tMat.col1.x * m_localAnchor2.x) + (tMat.col2.x * m_localAnchor2.y));
r2Y = ((tMat.col1.y * m_localAnchor2.x) + (tMat.col2.y * m_localAnchor2.y));
invMass1 = b1.m_invMass;
invMass2 = b2.m_invMass;
invI1 = b1.m_invI;
invI2 = b2.m_invI;
tMat = b1.m_R;
ay1X = ((tMat.col1.x * m_localYAxis1.x) + (tMat.col2.x * m_localYAxis1.y));
ay1Y = ((tMat.col1.y * m_localYAxis1.x) + (tMat.col2.y * m_localYAxis1.y));
eX = ((b2.m_position.x + r2X) - b1.m_position.x);
eY = ((b2.m_position.y + r2Y) - b1.m_position.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 = (1 / (invI1 + invI2));
if (((m_enableLimit) || (m_enableMotor))){
tMat = b1.m_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_limitImpulse = 0;
};
m_limitState = e_atLowerLimit;
} else {
if (jointTranslation >= m_upperTranslation){
if (m_limitState !== e_atUpperLimit){
m_limitImpulse = 0;
};
m_limitState = e_atUpperLimit;
} else {
m_limitState = e_inactiveLimit;
m_limitImpulse = 0;
};
};
};
};
};
if (m_enableMotor === false){
m_motorImpulse = 0;
};
if (m_enableLimit === false){
m_limitImpulse = 0;
};
if (b2World.s_enableWarmStarting){
P1X = ((m_linearImpulse * m_linearJacobian.linear1.x) + ((m_motorImpulse + m_limitImpulse) * m_motorJacobian.linear1.x));
P1Y = ((m_linearImpulse * m_linearJacobian.linear1.y) + ((m_motorImpulse + m_limitImpulse) * m_motorJacobian.linear1.y));
P2X = ((m_linearImpulse * m_linearJacobian.linear2.x) + ((m_motorImpulse + m_limitImpulse) * m_motorJacobian.linear2.x));
P2Y = ((m_linearImpulse * m_linearJacobian.linear2.y) + ((m_motorImpulse + m_limitImpulse) * m_motorJacobian.linear2.y));
L1 = (((m_linearImpulse * m_linearJacobian.angular1) - m_angularImpulse) + ((m_motorImpulse + m_limitImpulse) * m_motorJacobian.angular1));
L2 = (((m_linearImpulse * m_linearJacobian.angular2) + m_angularImpulse) + ((m_motorImpulse + m_limitImpulse) * 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_linearImpulse = 0;
m_angularImpulse = 0;
m_limitImpulse = 0;
m_motorImpulse = 0;
};
m_limitPositionImpulse = 0;
}
public function GetJointTranslation():Number{
var b1:b2Body;
var b2:b2Body;
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 dX:Number;
var dY:Number;
var ax1X:Number;
var ax1Y:Number;
var translation:Number;
b1 = m_body1;
b2 = m_body2;
tMat = b1.m_R;
r1X = ((tMat.col1.x * m_localAnchor1.x) + (tMat.col2.x * m_localAnchor1.y));
r1Y = ((tMat.col1.y * m_localAnchor1.x) + (tMat.col2.y * m_localAnchor1.y));
tMat = b2.m_R;
r2X = ((tMat.col1.x * m_localAnchor2.x) + (tMat.col2.x * m_localAnchor2.y));
r2Y = ((tMat.col1.y * m_localAnchor2.x) + (tMat.col2.y * m_localAnchor2.y));
p1X = (b1.m_position.x + r1X);
p1Y = (b1.m_position.y + r1Y);
p2X = (b2.m_position.x + r2X);
p2Y = (b2.m_position.y + r2Y);
dX = (p2X - p1X);
dY = (p2Y - p1Y);
tMat = b1.m_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));
return (translation);
}
override public function GetReactionForce(invTimeStep:Number):b2Vec2{
var tImp:Number;
var tMat:b2Mat22;
var ax1X:Number;
var ax1Y:Number;
var ay1X:Number;
var ay1Y:Number;
tImp = (invTimeStep * m_limitImpulse);
tMat = m_body1.m_R;
ax1X = (tImp * ((tMat.col1.x * m_localXAxis1.x) + (tMat.col2.x * m_localXAxis1.y)));
ax1Y = (tImp * ((tMat.col1.y * m_localXAxis1.x) + (tMat.col2.y * m_localXAxis1.y)));
ay1X = (tImp * ((tMat.col1.x * m_localYAxis1.x) + (tMat.col2.x * m_localYAxis1.y)));
ay1Y = (tImp * ((tMat.col1.y * m_localYAxis1.x) + (tMat.col2.y * m_localYAxis1.y)));
return (new b2Vec2((ax1X + ay1X), (ax1Y + ay1Y)));
}
override public function SolvePositionConstraints():Boolean{
var limitC:Number;
var oldLimitImpulse:Number;
var b1:b2Body;
var b2:b2Body;
var invMass1:Number;
var invMass2:Number;
var invI1:Number;
var invI2:Number;
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 dX:Number;
var dY:Number;
var ay1X:Number;
var ay1Y:Number;
var linearC:Number;
var linearImpulse:Number;
var positionError:Number;
var angularC:Number;
var angularImpulse:Number;
var angularError:Number;
var ax1X:Number;
var ax1Y:Number;
var translation:Number;
var limitImpulse:Number;
b1 = m_body1;
b2 = m_body2;
invMass1 = b1.m_invMass;
invMass2 = b2.m_invMass;
invI1 = b1.m_invI;
invI2 = b2.m_invI;
tMat = b1.m_R;
r1X = ((tMat.col1.x * m_localAnchor1.x) + (tMat.col2.x * m_localAnchor1.y));
r1Y = ((tMat.col1.y * m_localAnchor1.x) + (tMat.col2.y * m_localAnchor1.y));
tMat = b2.m_R;
r2X = ((tMat.col1.x * m_localAnchor2.x) + (tMat.col2.x * m_localAnchor2.y));
r2Y = ((tMat.col1.y * m_localAnchor2.x) + (tMat.col2.y * m_localAnchor2.y));
p1X = (b1.m_position.x + r1X);
p1Y = (b1.m_position.y + r1Y);
p2X = (b2.m_position.x + r2X);
p2Y = (b2.m_position.y + r2Y);
dX = (p2X - p1X);
dY = (p2Y - p1Y);
tMat = b1.m_R;
ay1X = ((tMat.col1.x * m_localYAxis1.x) + (tMat.col2.x * m_localYAxis1.y));
ay1Y = ((tMat.col1.y * m_localYAxis1.x) + (tMat.col2.y * m_localYAxis1.y));
linearC = ((ay1X * dX) + (ay1Y * dY));
linearC = b2Math.b2Clamp(linearC, -(b2Settings.b2_maxLinearCorrection), b2Settings.b2_maxLinearCorrection);
linearImpulse = (-(m_linearMass) * linearC);
b1.m_position.x = (b1.m_position.x + ((invMass1 * linearImpulse) * m_linearJacobian.linear1.x));
b1.m_position.y = (b1.m_position.y + ((invMass1 * linearImpulse) * m_linearJacobian.linear1.y));
b1.m_rotation = (b1.m_rotation + ((invI1 * linearImpulse) * m_linearJacobian.angular1));
b2.m_position.x = (b2.m_position.x + ((invMass2 * linearImpulse) * m_linearJacobian.linear2.x));
b2.m_position.y = (b2.m_position.y + ((invMass2 * linearImpulse) * m_linearJacobian.linear2.y));
b2.m_rotation = (b2.m_rotation + ((invI2 * linearImpulse) * m_linearJacobian.angular2));
positionError = b2Math.b2Abs(linearC);
angularC = ((b2.m_rotation - b1.m_rotation) - m_initialAngle);
angularC = b2Math.b2Clamp(angularC, -(b2Settings.b2_maxAngularCorrection), b2Settings.b2_maxAngularCorrection);
angularImpulse = (-(m_angularMass) * angularC);
b1.m_rotation = (b1.m_rotation - (b1.m_invI * angularImpulse));
b1.m_R.Set(b1.m_rotation);
b2.m_rotation = (b2.m_rotation + (b2.m_invI * angularImpulse));
b2.m_R.Set(b2.m_rotation);
angularError = b2Math.b2Abs(angularC);
if (((m_enableLimit) && (!((m_limitState === e_inactiveLimit))))){
tMat = b1.m_R;
r1X = ((tMat.col1.x * m_localAnchor1.x) + (tMat.col2.x * m_localAnchor1.y));
r1Y = ((tMat.col1.y * m_localAnchor1.x) + (tMat.col2.y * m_localAnchor1.y));
tMat = b2.m_R;
r2X = ((tMat.col1.x * m_localAnchor2.x) + (tMat.col2.x * m_localAnchor2.y));
r2Y = ((tMat.col1.y * m_localAnchor2.x) + (tMat.col2.y * m_localAnchor2.y));
p1X = (b1.m_position.x + r1X);
p1Y = (b1.m_position.y + r1Y);
p2X = (b2.m_position.x + r2X);
p2Y = (b2.m_position.y + r2Y);
dX = (p2X - p1X);
dY = (p2Y - p1Y);
tMat = b1.m_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_position.x = (b1.m_position.x + ((invMass1 * limitImpulse) * m_motorJacobian.linear1.x));
b1.m_position.y = (b1.m_position.y + ((invMass1 * limitImpulse) * m_motorJacobian.linear1.y));
b1.m_rotation = (b1.m_rotation + ((invI1 * limitImpulse) * m_motorJacobian.angular1));
b1.m_R.Set(b1.m_rotation);
b2.m_position.x = (b2.m_position.x + ((invMass2 * limitImpulse) * m_motorJacobian.linear2.x));
b2.m_position.y = (b2.m_position.y + ((invMass2 * limitImpulse) * m_motorJacobian.linear2.y));
b2.m_rotation = (b2.m_rotation + ((invI2 * limitImpulse) * m_motorJacobian.angular2));
b2.m_R.Set(b2.m_rotation);
};
return ((((positionError <= b2Settings.b2_linearSlop)) && ((angularError <= b2Settings.b2_angularSlop))));
}
public function GetJointSpeed():Number{
var b1:b2Body;
var b2:b2Body;
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 dX:Number;
var dY:Number;
var ax1X:Number;
var ax1Y:Number;
var v1:b2Vec2;
var v2:b2Vec2;
var w1:Number;
var w2:Number;
var speed:Number;
b1 = m_body1;
b2 = m_body2;
tMat = b1.m_R;
r1X = ((tMat.col1.x * m_localAnchor1.x) + (tMat.col2.x * m_localAnchor1.y));
r1Y = ((tMat.col1.y * m_localAnchor1.x) + (tMat.col2.y * m_localAnchor1.y));
tMat = b2.m_R;
r2X = ((tMat.col1.x * m_localAnchor2.x) + (tMat.col2.x * m_localAnchor2.y));
r2Y = ((tMat.col1.y * m_localAnchor2.x) + (tMat.col2.y * m_localAnchor2.y));
p1X = (b1.m_position.x + r1X);
p1Y = (b1.m_position.y + r1Y);
p2X = (b2.m_position.x + r2X);
p2Y = (b2.m_position.y + r2Y);
dX = (p2X - p1X);
dY = (p2Y - p1Y);
tMat = b1.m_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));
v1 = b1.m_linearVelocity;
v2 = b2.m_linearVelocity;
w1 = b1.m_angularVelocity;
w2 = b2.m_angularVelocity;
speed = (((dX * (-(w1) * ax1Y)) + (dY * (w1 * ax1X))) + ((ax1X * (((v2.x + (-(w2) * r2Y)) - v1.x) - (-(w1) * r1Y))) + (ax1Y * (((v2.y + (w2 * r2X)) - v1.y) - (w1 * r1X)))));
return (speed);
}
public function SetMotorSpeed(speed:Number):void{
m_motorSpeed = speed;
}
public function GetMotorForce(invTimeStep:Number):Number{
return ((invTimeStep * m_motorImpulse));
}
public function SetMotorForce(force:Number):void{
m_maxMotorForce = force;
}
override public function GetReactionTorque(invTimeStep:Number):Number{
return ((invTimeStep * m_angularImpulse));
}
override public function SolveVelocityConstraints(step:b2StepInfo):void{
var b1:b2Body;
var b2:b2Body;
var invMass1:Number;
var invMass2:Number;
var invI1:Number;
var invI2:Number;
var oldLimitImpulse:Number;
var linearCdot:Number;
var linearImpulse:Number;
var angularCdot:Number;
var angularImpulse:Number;
var motorCdot:Number;
var motorImpulse:Number;
var oldMotorImpulse:Number;
var limitCdot:Number;
var limitImpulse:Number;
b1 = m_body1;
b2 = m_body2;
invMass1 = b1.m_invMass;
invMass2 = b2.m_invMass;
invI1 = b1.m_invI;
invI2 = b2.m_invI;
linearCdot = m_linearJacobian.Compute(b1.m_linearVelocity, b1.m_angularVelocity, b2.m_linearVelocity, b2.m_angularVelocity);
linearImpulse = (-(m_linearMass) * linearCdot);
m_linearImpulse = (m_linearImpulse + linearImpulse);
b1.m_linearVelocity.x = (b1.m_linearVelocity.x + ((invMass1 * linearImpulse) * m_linearJacobian.linear1.x));
b1.m_linearVelocity.y = (b1.m_linearVelocity.y + ((invMass1 * linearImpulse) * m_linearJacobian.linear1.y));
b1.m_angularVelocity = (b1.m_angularVelocity + ((invI1 * linearImpulse) * m_linearJacobian.angular1));
b2.m_linearVelocity.x = (b2.m_linearVelocity.x + ((invMass2 * linearImpulse) * m_linearJacobian.linear2.x));
b2.m_linearVelocity.y = (b2.m_linearVelocity.y + ((invMass2 * linearImpulse) * m_linearJacobian.linear2.y));
b2.m_angularVelocity = (b2.m_angularVelocity + ((invI2 * linearImpulse) * m_linearJacobian.angular2));
angularCdot = (b2.m_angularVelocity - b1.m_angularVelocity);
angularImpulse = (-(m_angularMass) * angularCdot);
m_angularImpulse = (m_angularImpulse + angularImpulse);
b1.m_angularVelocity = (b1.m_angularVelocity - (invI1 * angularImpulse));
b2.m_angularVelocity = (b2.m_angularVelocity + (invI2 * angularImpulse));
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);
motorImpulse = (-(m_motorMass) * motorCdot);
oldMotorImpulse = m_motorImpulse;
m_motorImpulse = b2Math.b2Clamp((m_motorImpulse + motorImpulse), (-(step.dt) * m_maxMotorForce), (step.dt * m_maxMotorForce));
motorImpulse = (m_motorImpulse - oldMotorImpulse);
b1.m_linearVelocity.x = (b1.m_linearVelocity.x + ((invMass1 * motorImpulse) * m_motorJacobian.linear1.x));
b1.m_linearVelocity.y = (b1.m_linearVelocity.y + ((invMass1 * motorImpulse) * m_motorJacobian.linear1.y));
b1.m_angularVelocity = (b1.m_angularVelocity + ((invI1 * motorImpulse) * m_motorJacobian.angular1));
b2.m_linearVelocity.x = (b2.m_linearVelocity.x + ((invMass2 * motorImpulse) * m_motorJacobian.linear2.x));
b2.m_linearVelocity.y = (b2.m_linearVelocity.y + ((invMass2 * motorImpulse) * m_motorJacobian.linear2.y));
b2.m_angularVelocity = (b2.m_angularVelocity + ((invI2 * motorImpulse) * 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);
limitImpulse = (-(m_motorMass) * limitCdot);
if (m_limitState === e_equalLimits){
m_limitImpulse = (m_limitImpulse + limitImpulse);
} else {
if (m_limitState === e_atLowerLimit){
oldLimitImpulse = m_limitImpulse;
m_limitImpulse = b2Math.b2Max((m_limitImpulse + limitImpulse), 0);
limitImpulse = (m_limitImpulse - oldLimitImpulse);
} else {
if (m_limitState === e_atUpperLimit){
oldLimitImpulse = m_limitImpulse;
m_limitImpulse = b2Math.b2Min((m_limitImpulse + limitImpulse), 0);
limitImpulse = (m_limitImpulse - oldLimitImpulse);
};
};
};
b1.m_linearVelocity.x = (b1.m_linearVelocity.x + ((invMass1 * limitImpulse) * m_motorJacobian.linear1.x));
b1.m_linearVelocity.y = (b1.m_linearVelocity.y + ((invMass1 * limitImpulse) * m_motorJacobian.linear1.y));
b1.m_angularVelocity = (b1.m_angularVelocity + ((invI1 * limitImpulse) * m_motorJacobian.angular1));
b2.m_linearVelocity.x = (b2.m_linearVelocity.x + ((invMass2 * limitImpulse) * m_motorJacobian.linear2.x));
b2.m_linearVelocity.y = (b2.m_linearVelocity.y + ((invMass2 * limitImpulse) * m_motorJacobian.linear2.y));
b2.m_angularVelocity = (b2.m_angularVelocity + ((invI2 * limitImpulse) * m_motorJacobian.angular2));
};
}
}
}//package Engine.Dynamics.Joints
Section 61
//b2PrismaticJointDef (Engine.Dynamics.Joints.b2PrismaticJointDef)
package Engine.Dynamics.Joints {
import Engine.Common.Math.*;
public class b2PrismaticJointDef extends b2JointDef {
public var motorSpeed:Number;
public var anchorPoint:b2Vec2;
public var axis:b2Vec2;
public var upperTranslation:Number;
public var lowerTranslation:Number;
public var enableMotor:Boolean;
public var motorForce:Number;
public var enableLimit:Boolean;
public function b2PrismaticJointDef(){
super();
type = b2Joint.e_prismaticJoint;
anchorPoint = new b2Vec2(0, 0);
axis = new b2Vec2(0, 0);
lowerTranslation = 0;
upperTranslation = 0;
motorForce = 0;
motorSpeed = 0;
enableLimit = false;
enableMotor = false;
}
}
}//package Engine.Dynamics.Joints
Section 62
//b2PulleyJoint (Engine.Dynamics.Joints.b2PulleyJoint)
package Engine.Dynamics.Joints {
import Engine.Common.*;
import Engine.Common.Math.*;
import Engine.Dynamics.*;
public class b2PulleyJoint extends b2Joint {
public var m_ground:b2Body;
public var m_maxLength2:Number;
public var m_limitState1:int;
public var m_maxLength1:Number;
public var m_pulleyImpulse:Number;
public var m_limitPositionImpulse1:Number;
public var m_constant:Number;
public var m_ratio:Number;
public var m_groundAnchor1:b2Vec2;
public var m_groundAnchor2:b2Vec2;
public var m_limitPositionImpulse2:Number;
public var m_localAnchor1:b2Vec2;
public var m_localAnchor2:b2Vec2;
public var m_limitState2:int;
public var m_limitMass2:Number;
public var m_limitMass1:Number;
public var m_limitImpulse2:Number;
public var m_u1:b2Vec2;
public var m_u2:b2Vec2;
public var m_limitImpulse1:Number;
public var m_pulleyMass:Number;
public static var b2_minPulleyLength:Number = 1;
public function b2PulleyJoint(def:b2PulleyJointDef):void{
var tMat:b2Mat22;
var tX:Number;
var tY:Number;
var d1Len:Number;
var d2Len:Number;
var length1:Number;
var length2: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.groundPoint1.x - m_ground.m_position.x);
m_groundAnchor1.y = (def.groundPoint1.y - m_ground.m_position.y);
m_groundAnchor2.x = (def.groundPoint2.x - m_ground.m_position.x);
m_groundAnchor2.y = (def.groundPoint2.y - m_ground.m_position.y);
tMat = m_body1.m_R;
tX = (def.anchorPoint1.x - m_body1.m_position.x);
tY = (def.anchorPoint1.y - m_body1.m_position.y);
m_localAnchor1.x = ((tX * tMat.col1.x) + (tY * tMat.col1.y));
m_localAnchor1.y = ((tX * tMat.col2.x) + (tY * tMat.col2.y));
tMat = m_body2.m_R;
tX = (def.anchorPoint2.x - m_body2.m_position.x);
tY = (def.anchorPoint2.y - m_body2.m_position.y);
m_localAnchor2.x = ((tX * tMat.col1.x) + (tY * tMat.col1.y));
m_localAnchor2.y = ((tX * tMat.col2.x) + (tY * tMat.col2.y));
m_ratio = def.ratio;
tX = (def.groundPoint1.x - def.anchorPoint1.x);
tY = (def.groundPoint1.y - def.anchorPoint1.y);
d1Len = Math.sqrt(((tX * tX) + (tY * tY)));
tX = (def.groundPoint2.x - def.anchorPoint2.x);
tY = (def.groundPoint2.y - def.anchorPoint2.y);
d2Len = Math.sqrt(((tX * tX) + (tY * tY)));
length1 = b2Math.b2Max((0.5 * b2_minPulleyLength), d1Len);
length2 = b2Math.b2Max((0.5 * b2_minPulleyLength), d2Len);
m_constant = (length1 + (m_ratio * length2));
m_maxLength1 = b2Math.b2Clamp(def.maxLength1, length1, (m_constant - (m_ratio * b2_minPulleyLength)));
m_maxLength2 = b2Math.b2Clamp(def.maxLength2, length2, ((m_constant - b2_minPulleyLength) / m_ratio));
m_pulleyImpulse = 0;
m_limitImpulse1 = 0;
m_limitImpulse2 = 0;
}
public function GetLength1():Number{
var tMat:b2Mat22;
var pX:Number;
var pY:Number;
var dX:Number;
var dY:Number;
tMat = m_body1.m_R;
pX = (m_body1.m_position.x + ((tMat.col1.x * m_localAnchor1.x) + (tMat.col2.x * m_localAnchor1.y)));
pY = (m_body1.m_position.y + ((tMat.col1.y * m_localAnchor1.x) + (tMat.col2.y * m_localAnchor1.y)));
dX = (pX - (m_ground.m_position.x + m_groundAnchor1.x));
dY = (pY - (m_ground.m_position.y + m_groundAnchor1.y));
return (Math.sqrt(((dX * dX) + (dY * dY))));
}
override public function GetAnchor1():b2Vec2{
var tMat:b2Mat22;
tMat = m_body1.m_R;
return (new b2Vec2((m_body1.m_position.x + ((tMat.col1.x * m_localAnchor1.x) + (tMat.col2.x * m_localAnchor1.y))), (m_body1.m_position.y + ((tMat.col1.y * m_localAnchor1.x) + (tMat.col2.y * m_localAnchor1.y)))));
}
override public function GetAnchor2():b2Vec2{
var tMat:b2Mat22;
tMat = m_body2.m_R;
return (new b2Vec2((m_body2.m_position.x + ((tMat.col1.x * m_localAnchor2.x) + (tMat.col2.x * m_localAnchor2.y))), (m_body2.m_position.y + ((tMat.col1.y * m_localAnchor2.x) + (tMat.col2.y * m_localAnchor2.y)))));
}
override public function PrepareVelocitySolver():void{
var b1:b2Body;
var b2:b2Body;
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 s1X:Number;
var s1Y:Number;
var s2X:Number;
var s2Y:Number;
var length1:Number;
var length2:Number;
var cr1u1:Number;
var cr2u2:Number;
var P1X:Number;
var P1Y:Number;
var P2X:Number;
var P2Y:Number;
b1 = m_body1;
b2 = m_body2;
tMat = b1.m_R;
r1X = ((tMat.col1.x * m_localAnchor1.x) + (tMat.col2.x * m_localAnchor1.y));
r1Y = ((tMat.col1.y * m_localAnchor1.x) + (tMat.col2.y * m_localAnchor1.y));
tMat = b2.m_R;
r2X = ((tMat.col1.x * m_localAnchor2.x) + (tMat.col2.x * m_localAnchor2.y));
r2Y = ((tMat.col1.y * m_localAnchor2.x) + (tMat.col2.y * m_localAnchor2.y));
p1X = (b1.m_position.x + r1X);
p1Y = (b1.m_position.y + r1Y);
p2X = (b2.m_position.x + r2X);
p2Y = (b2.m_position.y + r2Y);
s1X = (m_ground.m_position.x + m_groundAnchor1.x);
s1Y = (m_ground.m_position.y + m_groundAnchor1.y);
s2X = (m_ground.m_position.x + m_groundAnchor2.x);
s2Y = (m_ground.m_position.y + m_groundAnchor2.y);
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();
};
if (length1 < m_maxLength1){
m_limitState1 = e_inactiveLimit;
m_limitImpulse1 = 0;
} else {
m_limitState1 = e_atUpperLimit;
m_limitPositionImpulse1 = 0;
};
if (length2 < m_maxLength2){
m_limitState2 = e_inactiveLimit;
m_limitImpulse2 = 0;
} else {
m_limitState2 = e_atUpperLimit;
m_limitPositionImpulse2 = 0;
};
cr1u1 = ((r1X * m_u1.y) - (r1Y * m_u1.x));
cr2u2 = ((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);
P1X = ((-(m_pulleyImpulse) - m_limitImpulse1) * m_u1.x);
P1Y = ((-(m_pulleyImpulse) - m_limitImpulse1) * m_u1.y);
P2X = (((-(m_ratio) * m_pulleyImpulse) - m_limitImpulse2) * m_u2.x);
P2Y = (((-(m_ratio) * m_pulleyImpulse) - m_limitImpulse2) * m_u2.y);
b1.m_linearVelocity.x = (b1.m_linearVelocity.x + (b1.m_invMass * P1X));
b1.m_linearVelocity.y = (b1.m_linearVelocity.y + (b1.m_invMass * P1Y));
b1.m_angularVelocity = (b1.m_angularVelocity + (b1.m_invI * ((r1X * P1Y) - (r1Y * P1X))));
b2.m_linearVelocity.x = (b2.m_linearVelocity.x + (b2.m_invMass * P2X));
b2.m_linearVelocity.y = (b2.m_linearVelocity.y + (b2.m_invMass * P2Y));
b2.m_angularVelocity = (b2.m_angularVelocity + (b2.m_invI * ((r2X * P2Y) - (r2Y * P2X))));
}
override public function GetReactionForce(invTimeStep:Number):b2Vec2{
return (new b2Vec2());
}
override public function SolvePositionConstraints():Boolean{
var b1:b2Body;
var b2:b2Body;
var tMat:b2Mat22;
var s1X:Number;
var s1Y:Number;
var s2X:Number;
var s2Y:Number;
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 oldLimitPositionImpulse:Number;
var linearError:Number;
b1 = m_body1;
b2 = m_body2;
s1X = (m_ground.m_position.x + m_groundAnchor1.x);
s1Y = (m_ground.m_position.y + m_groundAnchor1.y);
s2X = (m_ground.m_position.x + m_groundAnchor2.x);
s2Y = (m_ground.m_position.y + m_groundAnchor2.y);
linearError = 0;
tMat = b1.m_R;
r1X = ((tMat.col1.x * m_localAnchor1.x) + (tMat.col2.x * m_localAnchor1.y));
r1Y = ((tMat.col1.y * m_localAnchor1.x) + (tMat.col2.y * m_localAnchor1.y));
tMat = b2.m_R;
r2X = ((tMat.col1.x * m_localAnchor2.x) + (tMat.col2.x * m_localAnchor2.y));
r2Y = ((tMat.col1.y * m_localAnchor2.x) + (tMat.col2.y * m_localAnchor2.y));
p1X = (b1.m_position.x + r1X);
p1Y = (b1.m_position.y + r1Y);
p2X = (b2.m_position.x + r2X);
p2Y = (b2.m_position.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, Math.abs(C));
C = b2Math.b2Clamp(C, -(b2Settings.b2_maxLinearCorrection), b2Settings.b2_maxLinearCorrection);
impulse = (-(m_pulleyMass) * C);
p1X = (-(impulse) * m_u1.x);
p1Y = (-(impulse) * m_u1.y);
p2X = ((-(m_ratio) * impulse) * m_u2.x);
p2Y = ((-(m_ratio) * impulse) * m_u2.y);
b1.m_position.x = (b1.m_position.x + (b1.m_invMass * p1X));
b1.m_position.y = (b1.m_position.y + (b1.m_invMass * p1Y));
b1.m_rotation = (b1.m_rotation + (b1.m_invI * ((r1X * p1Y) - (r1Y * p1X))));
b2.m_position.x = (b2.m_position.x + (b2.m_invMass * p2X));
b2.m_position.y = (b2.m_position.y + (b2.m_invMass * p2Y));
b2.m_rotation = (b2.m_rotation + (b2.m_invI * ((r2X * p2Y) - (r2Y * p2X))));
b1.m_R.Set(b1.m_rotation);
b2.m_R.Set(b2.m_rotation);
if (m_limitState1 === e_atUpperLimit){
tMat = b1.m_R;
r1X = ((tMat.col1.x * m_localAnchor1.x) + (tMat.col2.x * m_localAnchor1.y));
r1Y = ((tMat.col1.y * m_localAnchor1.x) + (tMat.col2.y * m_localAnchor1.y));
p1X = (b1.m_position.x + r1X);
p1Y = (b1.m_position.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_position.x = (b1.m_position.x + (b1.m_invMass * p1X));
b1.m_position.y = (b1.m_position.y + (b1.m_invMass * p1Y));
b1.m_rotation = (b1.m_rotation + (b1.m_invI * ((r1X * p1Y) - (r1Y * p1X))));
b1.m_R.Set(b1.m_rotation);
};
if (m_limitState2 === e_atUpperLimit){
tMat = b2.m_R;
r2X = ((tMat.col1.x * m_localAnchor2.x) + (tMat.col2.x * m_localAnchor2.y));
r2Y = ((tMat.col1.y * m_localAnchor2.x) + (tMat.col2.y * m_localAnchor2.y));
p2X = (b2.m_position.x + r2X);
p2Y = (b2.m_position.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_position.x = (b2.m_position.x + (b2.m_invMass * p2X));
b2.m_position.y = (b2.m_position.y + (b2.m_invMass * p2Y));
b2.m_rotation = (b2.m_rotation + (b2.m_invI * ((r2X * p2Y) - (r2Y * p2X))));
b2.m_R.Set(b2.m_rotation);
};
return ((linearError < b2Settings.b2_linearSlop));
}
public function GetGroundPoint1():b2Vec2{
return (new b2Vec2((m_ground.m_position.x + m_groundAnchor1.x), (m_ground.m_position.y + m_groundAnchor1.y)));
}
public function GetGroundPoint2():b2Vec2{
return (new b2Vec2((m_ground.m_position.x + m_groundAnchor2.x), (m_ground.m_position.y + m_groundAnchor2.y)));
}
override public function GetReactionTorque(invTimeStep:Number):Number{
return (0);
}
public function GetRatio():Number{
return (m_ratio);
}
public function GetLength2():Number{
var tMat:b2Mat22;
var pX:Number;
var pY:Number;
var dX:Number;
var dY:Number;
tMat = m_body2.m_R;
pX = (m_body2.m_position.x + ((tMat.col1.x * m_localAnchor2.x) + (tMat.col2.x * m_localAnchor2.y)));
pY = (m_body2.m_position.y + ((tMat.col1.y * m_localAnchor2.x) + (tMat.col2.y * m_localAnchor2.y)));
dX = (pX - (m_ground.m_position.x + m_groundAnchor2.x));
dY = (pY - (m_ground.m_position.y + m_groundAnchor2.y));
return (Math.sqrt(((dX * dX) + (dY * dY))));
}
override public function SolveVelocityConstraints(step:b2StepInfo):void{
var b1:b2Body;
var b2:b2Body;
var tMat:b2Mat22;
var r1X:Number;
var r1Y:Number;
var r2X:Number;
var r2Y:Number;
var v1X:Number;
var v1Y:Number;
var v2X:Number;
var v2Y:Number;
var P1X:Number;
var P1Y:Number;
var P2X:Number;
var P2Y:Number;
var Cdot:Number;
var impulse:Number;
var oldLimitImpulse:Number;
b1 = m_body1;
b2 = m_body2;
tMat = b1.m_R;
r1X = ((tMat.col1.x * m_localAnchor1.x) + (tMat.col2.x * m_localAnchor1.y));
r1Y = ((tMat.col1.y * m_localAnchor1.x) + (tMat.col2.y * m_localAnchor1.y));
tMat = b2.m_R;
r2X = ((tMat.col1.x * m_localAnchor2.x) + (tMat.col2.x * m_localAnchor2.y));
r2Y = ((tMat.col1.y * m_localAnchor2.x) + (tMat.col2.y * m_localAnchor2.y));
v1X = (b1.m_linearVelocity.x + (-(b1.m_angularVelocity) * r1Y));
v1Y = (b1.m_linearVelocity.y + (b1.m_angularVelocity * r1X));
v2X = (b2.m_linearVelocity.x + (-(b2.m_angularVelocity) * r2Y));
v2Y = (b2.m_linearVelocity.y + (b2.m_angularVelocity * r2X));
Cdot = (-(((m_u1.x * v1X) + (m_u1.y * v1Y))) - (m_ratio * ((m_u2.x * v2X) + (m_u2.y * v2Y))));
impulse = (-(m_pulleyMass) * Cdot);
m_pulleyImpulse = (m_pulleyImpulse + impulse);
P1X = (-(impulse) * m_u1.x);
P1Y = (-(impulse) * m_u1.y);
P2X = ((-(m_ratio) * impulse) * m_u2.x);
P2Y = ((-(m_ratio) * impulse) * m_u2.y);
b1.m_linearVelocity.x = (b1.m_linearVelocity.x + (b1.m_invMass * P1X));
b1.m_linearVelocity.y = (b1.m_linearVelocity.y + (b1.m_invMass * P1Y));
b1.m_angularVelocity = (b1.m_angularVelocity + (b1.m_invI * ((r1X * P1Y) - (r1Y * P1X))));
b2.m_linearVelocity.x = (b2.m_linearVelocity.x + (b2.m_invMass * P2X));
b2.m_linearVelocity.y = (b2.m_linearVelocity.y + (b2.m_invMass * P2Y));
b2.m_angularVelocity = (b2.m_angularVelocity + (b2.m_invI * ((r2X * P2Y) - (r2Y * P2X))));
if (m_limitState1 === e_atUpperLimit){
v1X = (b1.m_linearVelocity.x + (-(b1.m_angularVelocity) * r1Y));
v1Y = (b1.m_linearVelocity.y + (b1.m_angularVelocity * r1X));
Cdot = -(((m_u1.x * v1X) + (m_u1.y * v1Y)));
impulse = (-(m_limitMass1) * Cdot);
oldLimitImpulse = m_limitImpulse1;
m_limitImpulse1 = b2Math.b2Max(0, (m_limitImpulse1 + impulse));
impulse = (m_limitImpulse1 - oldLimitImpulse);
P1X = (-(impulse) * m_u1.x);
P1Y = (-(impulse) * m_u1.y);
b1.m_linearVelocity.x = (b1.m_linearVelocity.x + (b1.m_invMass * P1X));
b1.m_linearVelocity.y = (b1.m_linearVelocity.y + (b1.m_invMass * P1Y));
b1.m_angularVelocity = (b1.m_angularVelocity + (b1.m_invI * ((r1X * P1Y) - (r1Y * P1X))));
};
if (m_limitState2 === e_atUpperLimit){
v2X = (b2.m_linearVelocity.x + (-(b2.m_angularVelocity) * r2Y));
v2Y = (b2.m_linearVelocity.y + (b2.m_angularVelocity * r2X));
Cdot = -(((m_u2.x * v2X) + (m_u2.y * v2Y)));
impulse = (-(m_limitMass2) * Cdot);
oldLimitImpulse = m_limitImpulse2;
m_limitImpulse2 = b2Math.b2Max(0, (m_limitImpulse2 + impulse));
impulse = (m_limitImpulse2 - oldLimitImpulse);
P2X = (-(impulse) * m_u2.x);
P2Y = (-(impulse) * m_u2.y);
b2.m_linearVelocity.x = (b2.m_linearVelocity.x + (b2.m_invMass * P2X));
b2.m_linearVelocity.y = (b2.m_linearVelocity.y + (b2.m_invMass * P2Y));
b2.m_angularVelocity = (b2.m_angularVelocity + (b2.m_invI * ((r2X * P2Y) - (r2Y * P2X))));
};
}
}
}//package Engine.Dynamics.Joints
Section 63
//b2PulleyJointDef (Engine.Dynamics.Joints.b2PulleyJointDef)
package Engine.Dynamics.Joints {
import Engine.Common.Math.*;
public class b2PulleyJointDef extends b2JointDef {
public var groundPoint1:b2Vec2;
public var groundPoint2:b2Vec2;
public var ratio:Number;
public var maxLength1:Number;
public var maxLength2:Number;
public var anchorPoint1:b2Vec2;
public var anchorPoint2:b2Vec2;
public function b2PulleyJointDef(){
groundPoint1 = new b2Vec2();
groundPoint2 = new b2Vec2();
anchorPoint1 = new b2Vec2();
anchorPoint2 = new b2Vec2();
super();
type = b2Joint.e_pulleyJoint;
groundPoint1.Set(-1, 1);
groundPoint2.Set(1, 1);
anchorPoint1.Set(-1, 0);
anchorPoint2.Set(1, 0);
maxLength1 = (0.5 * b2PulleyJoint.b2_minPulleyLength);
maxLength2 = (0.5 * b2PulleyJoint.b2_minPulleyLength);
ratio = 1;
collideConnected = true;
}
}
}//package Engine.Dynamics.Joints
Section 64
//b2RevoluteJoint (Engine.Dynamics.Joints.b2RevoluteJoint)
package Engine.Dynamics.Joints {
import Engine.Common.Math.*;
import Engine.Dynamics.*;
import Engine.Common.*;
public class b2RevoluteJoint extends b2Joint {
public var m_intialAngle:Number;
public var m_enableLimit:Boolean;
public var m_limitState:int;
public var m_ptpMass:b2Mat22;
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_limitImpulse:Number;
public var m_motorImpulse:Number;
public var m_enableMotor:Boolean;
public var m_lowerAngle:Number;
public var m_limitPositionImpulse:Number;
public var m_maxMotorTorque:Number;
public var m_upperAngle:Number;
public var m_motorSpeed:Number;
public var m_ptpImpulse:b2Vec2;
static var tImpulse:b2Vec2 = new b2Vec2();
public function b2RevoluteJoint(def:b2RevoluteJointDef):void{
var tMat:b2Mat22;
var tX:Number;
var tY:Number;
K = new b2Mat22();
K1 = new b2Mat22();
K2 = new b2Mat22();
K3 = new b2Mat22();
m_localAnchor1 = new b2Vec2();
m_localAnchor2 = new b2Vec2();
m_ptpImpulse = new b2Vec2();
m_ptpMass = new b2Mat22();
super(def);
tMat = m_body1.m_R;
tX = (def.anchorPoint.x - m_body1.m_position.x);
tY = (def.anchorPoint.y - m_body1.m_position.y);
m_localAnchor1.x = ((tX * tMat.col1.x) + (tY * tMat.col1.y));
m_localAnchor1.y = ((tX * tMat.col2.x) + (tY * tMat.col2.y));
tMat = m_body2.m_R;
tX = (def.anchorPoint.x - m_body2.m_position.x);
tY = (def.anchorPoint.y - m_body2.m_position.y);
m_localAnchor2.x = ((tX * tMat.col1.x) + (tY * tMat.col1.y));
m_localAnchor2.y = ((tX * tMat.col2.x) + (tY * tMat.col2.y));
m_intialAngle = (m_body2.m_rotation - m_body1.m_rotation);
m_ptpImpulse.Set(0, 0);
m_motorImpulse = 0;
m_limitImpulse = 0;
m_limitPositionImpulse = 0;
m_lowerAngle = def.lowerAngle;
m_upperAngle = def.upperAngle;
m_maxMotorTorque = def.motorTorque;
m_motorSpeed = def.motorSpeed;
m_enableLimit = def.enableLimit;
m_enableMotor = def.enableMotor;
}
override public function GetAnchor1():b2Vec2{
var tMat:b2Mat22;
tMat = m_body1.m_R;
return (new b2Vec2((m_body1.m_position.x + ((tMat.col1.x * m_localAnchor1.x) + (tMat.col2.x * m_localAnchor1.y))), (m_body1.m_position.y + ((tMat.col1.y * m_localAnchor1.x) + (tMat.col2.y * m_localAnchor1.y)))));
}
override public function GetAnchor2():b2Vec2{
var tMat:b2Mat22;
tMat = m_body2.m_R;
return (new b2Vec2((m_body2.m_position.x + ((tMat.col1.x * m_localAnchor2.x) + (tMat.col2.x * m_localAnchor2.y))), (m_body2.m_position.y + ((tMat.col1.y * m_localAnchor2.x) + (tMat.col2.y * m_localAnchor2.y)))));
}
override public function PrepareVelocitySolver():void{
var b1:b2Body;
var b2:b2Body;
var tMat:b2Mat22;
var r1X:Number;
var r1Y:Number;
var r2X:Number;
var r2Y:Number;
var invMass1:Number;
var invMass2:Number;
var invI1:Number;
var invI2:Number;
var jointAngle:Number;
b1 = m_body1;
b2 = m_body2;
tMat = b1.m_R;
r1X = ((tMat.col1.x * m_localAnchor1.x) + (tMat.col2.x * m_localAnchor1.y));
r1Y = ((tMat.col1.y * m_localAnchor1.x) + (tMat.col2.y * m_localAnchor1.y));
tMat = b2.m_R;
r2X = ((tMat.col1.x * m_localAnchor2.x) + (tMat.col2.x * m_localAnchor2.y));
r2Y = ((tMat.col1.y * m_localAnchor2.x) + (tMat.col2.y * m_localAnchor2.y));
invMass1 = b1.m_invMass;
invMass2 = b2.m_invMass;
invI1 = b1.m_invI;
invI2 = 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_ptpMass);
m_motorMass = (1 / (invI1 + invI2));
if (m_enableMotor === false){
m_motorImpulse = 0;
};
if (m_enableLimit){
jointAngle = ((b2.m_rotation - b1.m_rotation) - m_intialAngle);
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_limitImpulse = 0;
};
m_limitState = e_atLowerLimit;
} else {
if (jointAngle >= m_upperAngle){
if (m_limitState !== e_atUpperLimit){
m_limitImpulse = 0;
};
m_limitState = e_atUpperLimit;
} else {
m_limitState = e_inactiveLimit;
m_limitImpulse = 0;
};
};
};
} else {
m_limitImpulse = 0;
};
if (b2World.s_enableWarmStarting){
b1.m_linearVelocity.x = (b1.m_linearVelocity.x - (invMass1 * m_ptpImpulse.x));
b1.m_linearVelocity.y = (b1.m_linearVelocity.y - (invMass1 * m_ptpImpulse.y));
b1.m_angularVelocity = (b1.m_angularVelocity - (invI1 * ((((r1X * m_ptpImpulse.y) - (r1Y * m_ptpImpulse.x)) + m_motorImpulse) + m_limitImpulse)));
b2.m_linearVelocity.x = (b2.m_linearVelocity.x + (invMass2 * m_ptpImpulse.x));
b2.m_linearVelocity.y = (b2.m_linearVelocity.y + (invMass2 * m_ptpImpulse.y));
b2.m_angularVelocity = (b2.m_angularVelocity + (invI2 * ((((r2X * m_ptpImpulse.y) - (r2Y * m_ptpImpulse.x)) + m_motorImpulse) + m_limitImpulse)));
} else {
m_ptpImpulse.SetZero();
m_motorImpulse = 0;
m_limitImpulse = 0;
};
m_limitPositionImpulse = 0;
}
override public function GetReactionForce(invTimeStep:Number):b2Vec2{
var tVec:b2Vec2;
tVec = m_ptpImpulse.Copy();
tVec.Multiply(invTimeStep);
return (tVec);
}
override public function SolvePositionConstraints():Boolean{
var oldLimitImpulse:Number;
var limitC:Number;
var b1:b2Body;
var b2:b2Body;
var positionError:Number;
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 ptpCX:Number;
var ptpCY:Number;
var invMass1:Number;
var invMass2:Number;
var invI1:Number;
var invI2:Number;
var impulseX:Number;
var impulseY:Number;
var angularError:Number;
var angle:Number;
var limitImpulse:Number;
b1 = m_body1;
b2 = m_body2;
positionError = 0;
tMat = b1.m_R;
r1X = ((tMat.col1.x * m_localAnchor1.x) + (tMat.col2.x * m_localAnchor1.y));
r1Y = ((tMat.col1.y * m_localAnchor1.x) + (tMat.col2.y * m_localAnchor1.y));
tMat = b2.m_R;
r2X = ((tMat.col1.x * m_localAnchor2.x) + (tMat.col2.x * m_localAnchor2.y));
r2Y = ((tMat.col1.y * m_localAnchor2.x) + (tMat.col2.y * m_localAnchor2.y));
p1X = (b1.m_position.x + r1X);
p1Y = (b1.m_position.y + r1Y);
p2X = (b2.m_position.x + r2X);
p2Y = (b2.m_position.y + r2Y);
ptpCX = (p2X - p1X);
ptpCY = (p2Y - p1Y);
positionError = Math.sqrt(((ptpCX * ptpCX) + (ptpCY * ptpCY)));
invMass1 = b1.m_invMass;
invMass2 = b2.m_invMass;
invI1 = b1.m_invI;
invI2 = 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));
impulseX = tImpulse.x;
impulseY = tImpulse.y;
b1.m_position.x = (b1.m_position.x - (b1.m_invMass * impulseX));
b1.m_position.y = (b1.m_position.y - (b1.m_invMass * impulseY));
b1.m_rotation = (b1.m_rotation - (b1.m_invI * ((r1X * impulseY) - (r1Y * impulseX))));
b1.m_R.Set(b1.m_rotation);
b2.m_position.x = (b2.m_position.x + (b2.m_invMass * impulseX));
b2.m_position.y = (b2.m_position.y + (b2.m_invMass * impulseY));
b2.m_rotation = (b2.m_rotation + (b2.m_invI * ((r2X * impulseY) - (r2Y * impulseX))));
b2.m_R.Set(b2.m_rotation);
angularError = 0;
if (((m_enableLimit) && (!((m_limitState === e_inactiveLimit))))){
angle = ((b2.m_rotation - b1.m_rotation) - m_intialAngle);
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_rotation = (b1.m_rotation - (b1.m_invI * limitImpulse));
b1.m_R.Set(b1.m_rotation);
b2.m_rotation = (b2.m_rotation + (b2.m_invI * limitImpulse));
b2.m_R.Set(b2.m_rotation);
};
return ((((positionError <= b2Settings.b2_linearSlop)) && ((angularError <= b2Settings.b2_angularSlop))));
}
public function GetJointSpeed():Number{
return ((m_body2.m_angularVelocity - m_body1.m_angularVelocity));
}
public function SetMotorSpeed(speed:Number):void{
m_motorSpeed = speed;
}
public function SetMotorTorque(torque:Number):void{
m_maxMotorTorque = torque;
}
public function GetJointAngle():Number{
return ((m_body2.m_rotation - m_body1.m_rotation));
}
public function GetMotorTorque(invTimeStep:Number):Number{
return ((invTimeStep * m_motorImpulse));
}
override public function GetReactionTorque(invTimeStep:Number):Number{
return ((invTimeStep * m_limitImpulse));
}
override public function SolveVelocityConstraints(step:b2StepInfo):void{
var b1:b2Body;
var b2:b2Body;
var tMat:b2Mat22;
var r1X:Number;
var r1Y:Number;
var r2X:Number;
var r2Y:Number;
var oldLimitImpulse:Number;
var ptpCdotX:Number;
var ptpCdotY:Number;
var ptpImpulseX:Number;
var ptpImpulseY:Number;
var motorCdot:Number;
var motorImpulse:Number;
var oldMotorImpulse:Number;
var limitCdot:Number;
var limitImpulse:Number;
b1 = m_body1;
b2 = m_body2;
tMat = b1.m_R;
r1X = ((tMat.col1.x * m_localAnchor1.x) + (tMat.col2.x * m_localAnchor1.y));
r1Y = ((tMat.col1.y * m_localAnchor1.x) + (tMat.col2.y * m_localAnchor1.y));
tMat = b2.m_R;
r2X = ((tMat.col1.x * m_localAnchor2.x) + (tMat.col2.x * m_localAnchor2.y));
r2Y = ((tMat.col1.y * m_localAnchor2.x) + (tMat.col2.y * m_localAnchor2.y));
ptpCdotX = (((b2.m_linearVelocity.x + (-(b2.m_angularVelocity) * r2Y)) - b1.m_linearVelocity.x) - (-(b1.m_angularVelocity) * r1Y));
ptpCdotY = (((b2.m_linearVelocity.y + (b2.m_angularVelocity * r2X)) - b1.m_linearVelocity.y) - (b1.m_angularVelocity * r1X));
ptpImpulseX = -(((m_ptpMass.col1.x * ptpCdotX) + (m_ptpMass.col2.x * ptpCdotY)));
ptpImpulseY = -(((m_ptpMass.col1.y * ptpCdotX) + (m_ptpMass.col2.y * ptpCdotY)));
m_ptpImpulse.x = (m_ptpImpulse.x + ptpImpulseX);
m_ptpImpulse.y = (m_ptpImpulse.y + ptpImpulseY);
b1.m_linearVelocity.x = (b1.m_linearVelocity.x - (b1.m_invMass * ptpImpulseX));
b1.m_linearVelocity.y = (b1.m_linearVelocity.y - (b1.m_invMass * ptpImpulseY));
b1.m_angularVelocity = (b1.m_angularVelocity - (b1.m_invI * ((r1X * ptpImpulseY) - (r1Y * ptpImpulseX))));
b2.m_linearVelocity.x = (b2.m_linearVelocity.x + (b2.m_invMass * ptpImpulseX));
b2.m_linearVelocity.y = (b2.m_linearVelocity.y + (b2.m_invMass * ptpImpulseY));
b2.m_angularVelocity = (b2.m_angularVelocity + (b2.m_invI * ((r2X * ptpImpulseY) - (r2Y * ptpImpulseX))));
if (((m_enableMotor) && (!((m_limitState === e_equalLimits))))){
motorCdot = ((b2.m_angularVelocity - b1.m_angularVelocity) - m_motorSpeed);
motorImpulse = (-(m_motorMass) * motorCdot);
oldMotorImpulse = m_motorImpulse;
m_motorImpulse = b2Math.b2Clamp((m_motorImpulse + motorImpulse), (-(step.dt) * m_maxMotorTorque), (step.dt * m_maxMotorTorque));
motorImpulse = (m_motorImpulse - oldMotorImpulse);
b1.m_angularVelocity = (b1.m_angularVelocity - (b1.m_invI * motorImpulse));
b2.m_angularVelocity = (b2.m_angularVelocity + (b2.m_invI * motorImpulse));
};
if (((m_enableLimit) && (!((m_limitState === e_inactiveLimit))))){
limitCdot = (b2.m_angularVelocity - b1.m_angularVelocity);
limitImpulse = (-(m_motorMass) * limitCdot);
if (m_limitState === e_equalLimits){
m_limitImpulse = (m_limitImpulse + limitImpulse);
} else {
if (m_limitState === e_atLowerLimit){
oldLimitImpulse = m_limitImpulse;
m_limitImpulse = b2Math.b2Max((m_limitImpulse + limitImpulse), 0);
limitImpulse = (m_limitImpulse - oldLimitImpulse);
} else {
if (m_limitState === e_atUpperLimit){
oldLimitImpulse = m_limitImpulse;
m_limitImpulse = b2Math.b2Min((m_limitImpulse + limitImpulse), 0);
limitImpulse = (m_limitImpulse - oldLimitImpulse);
};
};
};
b1.m_angularVelocity = (b1.m_angularVelocity - (b1.m_invI * limitImpulse));
b2.m_angularVelocity = (b2.m_angularVelocity + (b2.m_invI * limitImpulse));
};
}
}
}//package Engine.Dynamics.Joints
Section 65
//b2RevoluteJointDef (Engine.Dynamics.Joints.b2RevoluteJointDef)
package Engine.Dynamics.Joints {
import Engine.Common.Math.*;
public class b2RevoluteJointDef extends b2JointDef {
public var upperAngle:Number;
public var lowerAngle:Number;
public var motorSpeed:Number;
public var anchorPoint:b2Vec2;
public var motorTorque:Number;
public var enableMotor:Boolean;
public var enableLimit:Boolean;
public function b2RevoluteJointDef(){
super();
type = b2Joint.e_revoluteJoint;
anchorPoint = new b2Vec2(0, 0);
lowerAngle = 0;
upperAngle = 0;
motorTorque = 0;
motorSpeed = 0;
enableLimit = false;
enableMotor = false;
}
}
}//package Engine.Dynamics.Joints
Section 66
//b2Body (Engine.Dynamics.b2Body)
package Engine.Dynamics {
import Engine.Collision.Shapes.*;
import Engine.Common.Math.*;
import Engine.Dynamics.Contacts.*;
import Engine.Dynamics.Joints.*;
import Engine.Common.*;
public class b2Body {
public var m_next:b2Body;
public var m_mass:Number;
public var m_contactList:b2ContactNode;
public var m_angularVelocity:Number;
public var m_rotation:Number;
public var m_shapeList:b2Shape;
public var m_R:b2Mat22;
public var m_force:b2Vec2;
public var m_torque:Number;
public var m_userData;
public var m_linearVelocity:b2Vec2;
public var m_invMass:Number;
public var m_position:b2Vec2;
public var m_flags:uint;
public var m_world:b2World;
public var m_invI:Number;
public var m_shapeCount:int;
public var m_linearDamping:Number;
public var m_prev:b2Body;
public var m_angularDamping:Number;
public var m_center:b2Vec2;
public var m_sleepTime:Number;
public var m_I:Number;
public var m_jointList:b2JointNode;
public static var e_frozenFlag:uint = 2;
public static var e_sleepFlag:uint = 8;
public static var e_islandFlag:uint = 4;
public static var e_destroyFlag:uint = 32;
public static var e_allowSleepFlag:uint = 16;
public static var e_staticFlag:uint = 1;
public function b2Body(bd:b2BodyDef, world:b2World){
var i:int;
var sd:b2ShapeDef;
var massData:b2MassData;
var maxShapes:int;
var massDatas:Array;
var r:b2Vec2;
var shape:b2Shape;
m_position = new b2Vec2();
m_R = new b2Mat22(0);
super();
maxShapes = b2Settings.b2_maxShapesPerBody;
m_flags = 0;
m_position.SetV(bd.position);
m_rotation = bd.rotation;
m_R.Set(m_rotation);
m_world = world;
m_linearDamping = b2Math.b2Clamp((1 - bd.linearDamping), 0, 1);
m_angularDamping = b2Math.b2Clamp((1 - bd.angularDamping), 0, 1);
m_force = new b2Vec2(0, 0);
m_torque = 0;
m_mass = 0;
massDatas = new Array(b2Settings.b2_maxShapesPerBody);
i = 0;
while (i < maxShapes) {
massDatas[i] = new b2MassData();
i++;
};
m_shapeCount = 0;
m_center = new b2Vec2(0, 0);
i = 0;
while (i < maxShapes) {
sd = bd.shapes[i];
if (sd == null){
break;
};
massData = massDatas[i];
sd.ComputeMass(massData);
m_mass = (m_mass + massData.mass);
m_center.Add(b2Math.MulFV(massData.mass, b2Math.AddVV(sd.localPosition, massData.center)));
m_shapeCount++;
i++;
};
if (m_mass > 0){
m_center.Multiply((1 / m_mass));
m_position.Add(b2Math.b2MulMV(m_R, m_center));
} else {
m_flags = (m_flags | e_staticFlag);
};
m_I = 0;
i = 0;
while (i < m_shapeCount) {
sd = bd.shapes[i];
massData = massDatas[i];
m_I = (m_I + massData.I);
r = b2Math.SubtractVV(b2Math.AddVV(sd.localPosition, massData.center), m_center);
m_I = (m_I + (massData.mass * b2Math.b2Dot(r, r)));
i++;
};
if (m_mass > 0){
m_invMass = (1 / m_mass);
} else {
m_invMass = 0;
};
if ((((m_I > 0)) && ((bd.preventRotation === false)))){
m_invI = (1 / m_I);
} else {
m_I = 0;
m_invI = 0;
};
m_linearVelocity = b2Math.AddVV(bd.linearVelocity, b2Math.b2CrossFV(bd.angularVelocity, m_center));
m_angularVelocity = bd.angularVelocity;
m_jointList = null;
m_contactList = null;
m_prev = null;
m_next = null;
m_shapeList = null;
i = 0;
while (i < m_shapeCount) {
sd = bd.shapes[i];
shape = b2Shape.Create(sd, this, m_center);
shape.m_next = m_shapeList;
m_shapeList = shape;
i++;
};
m_sleepTime = 0;
if (bd.allowSleep){
m_flags = (m_flags | e_allowSleepFlag);
};
if (bd.isSleeping){
m_flags = (m_flags | e_sleepFlag);
};
if ((((m_flags & e_sleepFlag)) || ((m_invMass === 0)))){
m_linearVelocity.Set(0, 0);
m_angularVelocity = 0;
};
m_userData = bd.userData;
}
public function SetCenterPosition(position:b2Vec2, rotation:Number):void{
var s:b2Shape;
if (IsFrozen()){
return;
};
m_rotation = rotation;
m_R.Set(m_rotation);
m_position.SetV(position);
s = m_shapeList;
while (s != null) {
s.Synchronize(m_position, m_R);
s = s.m_next;
};
m_world.m_broadPhase.Flush();
}
public function GetWorldPoint(localPoint:b2Vec2):b2Vec2{
return (b2Math.AddVV(m_position, b2Math.b2MulMV(m_R, localPoint)));
}
public function SetLinearVelocity(v:b2Vec2):void{
m_linearVelocity.SetV(v);
}
public function IsFrozen():Boolean{
return (((m_flags & e_frozenFlag) == e_frozenFlag));
}
public function IsSleeping():Boolean{
return (((m_flags & e_sleepFlag) == e_sleepFlag));
}
public function GetInertia():Number{
return (m_I);
}
public function GetLocalVector(worldVector:b2Vec2):b2Vec2{
return (b2Math.b2MulTMV(m_R, worldVector));
}
public function GetLinearVelocity():b2Vec2{
return (m_linearVelocity);
}
public function GetJointList():b2JointNode{
return (m_jointList);
}
public function GetRotationMatrix():b2Mat22{
return (m_R);
}
public function Freeze():void{
m_flags = (m_flags | e_frozenFlag);
m_linearVelocity.SetZero();
m_angularVelocity = 0;
}
public function SetAngularVelocity(w:Number):void{
m_angularVelocity = w;
}
public function SynchronizeShapes():void{
var s:b2Shape;
s = m_shapeList;
while (s != null) {
s.Synchronize(m_position, m_R);
s = s.m_next;
};
}
public function ApplyForce(force:b2Vec2, point:b2Vec2):void{
if (IsSleeping() === false){
m_force.Add(force);
m_torque = (m_torque + b2Math.b2CrossVV(b2Math.SubtractVV(point, m_position), force));
};
}
public function GetOriginPosition():b2Vec2{
return (b2Math.SubtractVV(m_position, b2Math.b2MulMV(m_R, m_center)));
}
public function ApplyImpulse(impulse:b2Vec2, point:b2Vec2):void{
if (IsSleeping() === false){
m_linearVelocity.Add(b2Math.MulFV(m_invMass, impulse));
m_angularVelocity = (m_angularVelocity + (m_invI * b2Math.b2CrossVV(b2Math.SubtractVV(point, m_position), impulse)));
};
}
public function GetContactList():b2ContactNode{
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 SetOriginPosition(position:b2Vec2, rotation:Number):void{
var s:b2Shape;
if (IsFrozen()){
return;
};
m_rotation = rotation;
m_R.Set(m_rotation);
m_position = b2Math.AddVV(position, b2Math.b2MulMV(m_R, m_center));
s = m_shapeList;
while (s != null) {
s.Synchronize(m_position, m_R);
s = s.m_next;
};
m_world.m_broadPhase.Flush();
}
public function GetLocalPoint(worldPoint:b2Vec2):b2Vec2{
return (b2Math.b2MulTMV(m_R, b2Math.SubtractVV(worldPoint, m_position)));
}
public function GetRotation():Number{
return (m_rotation);
}
public function IsStatic():Boolean{
return (((m_flags & e_staticFlag) == e_staticFlag));
}
public function Destroy():void{
var s:b2Shape;
var s0:b2Shape;
s = m_shapeList;
while (s) {
s0 = s;
s = s.m_next;
b2Shape.Destroy(s0);
};
}
public function GetWorldVector(localVector:b2Vec2):b2Vec2{
return (b2Math.b2MulMV(m_R, localVector));
}
public function GetNext():b2Body{
return (m_next);
}
public function IsConnected(other:b2Body):Boolean{
var jn:b2JointNode;
jn = m_jointList;
while (jn != null) {
if (jn.other === other){
return ((jn.joint.m_collideConnected === false));
};
jn = jn.next;
};
return (false);
}
public function GetUserData(){
return (m_userData);
}
public function GetCenterPosition():b2Vec2{
return (m_position);
}
public function ApplyTorque(torque:Number):void{
if (IsSleeping() === false){
m_torque = (m_torque + torque);
};
}
public function AllowSleeping(flag:Boolean):void{
if (flag){
m_flags = (m_flags | e_allowSleepFlag);
} else {
m_flags = (m_flags & ~(e_allowSleepFlag));
WakeUp();
};
}
public function WakeUp():void{
m_flags = (m_flags & ~(e_sleepFlag));
m_sleepTime = 0;
}
}
}//package Engine.Dynamics
Section 67
//b2BodyDef (Engine.Dynamics.b2BodyDef)
package Engine.Dynamics {
import Engine.Common.*;
import Engine.Common.Math.*;
import Engine.Collision.Shapes.*;
public class b2BodyDef {
public var angularDamping:Number;
public var rotation:Number;
public var allowSleep:Boolean;
public var userData;
public var linearDamping:Number;
public var angularVelocity:Number;
public var linearVelocity:b2Vec2;
public var position:b2Vec2;
public var shapes:Array;
public var isSleeping:Boolean;
public var preventRotation:Boolean;
public function b2BodyDef():void{
var maxShapes:int;
var i:int;
shapes = new Array();
super();
maxShapes = b2Settings.b2_maxShapesPerBody;
userData = null;
i = 0;
while (i < maxShapes) {
shapes[i] = null;
i++;
};
position = new b2Vec2(0, 0);
rotation = 0;
linearVelocity = new b2Vec2(0, 0);
angularVelocity = 0;
linearDamping = 0;
angularDamping = 0;
allowSleep = true;
isSleeping = false;
preventRotation = false;
}
public function AddShape(shape:b2ShapeDef):void{
var maxShapes:int;
var i:int;
maxShapes = b2Settings.b2_maxShapesPerBody;
i = 0;
while (i < maxShapes) {
if (shapes[i] == null){
shapes[i] = shape;
break;
};
i++;
};
}
}
}//package Engine.Dynamics
Section 68
//b2ContactManager (Engine.Dynamics.b2ContactManager)
package Engine.Dynamics {
import Engine.Dynamics.Contacts.*;
import Engine.Collision.Shapes.*;
import Engine.Collision.*;
public class b2ContactManager extends b2PairCallback {
public var m_world:b2World;
public var m_destroyImmediate:Boolean;
public var m_nullContact:b2NullContact;
public function b2ContactManager():void{
m_nullContact = new b2NullContact();
super();
m_world = null;
m_destroyImmediate = false;
}
public function Collide():void{
var body1:b2Body;
var body2:b2Body;
var node1:b2ContactNode;
var node2:b2ContactNode;
var c:b2Contact;
var oldCount:int;
var newCount:int;
c = m_world.m_contactList;
while (c != null) {
if (((c.m_shape1.m_body.IsSleeping()) && (c.m_shape2.m_body.IsSleeping()))){
} else {
oldCount = c.GetManifoldCount();
c.Evaluate();
newCount = c.GetManifoldCount();
if ((((oldCount === 0)) && ((newCount > 0)))){
body1 = c.m_shape1.m_body;
body2 = c.m_shape2.m_body;
node1 = c.m_node1;
node2 = c.m_node2;
node1.contact = c;
node1.other = body2;
node1.prev = null;
node1.next = body1.m_contactList;
if (node1.next != null){
node1.next.prev = c.m_node1;
};
body1.m_contactList = c.m_node1;
node2.contact = c;
node2.other = body1;
node2.prev = null;
node2.next = body2.m_contactList;
if (node2.next != null){
node2.next.prev = node2;
};
body2.m_contactList = node2;
} else {
if ((((oldCount > 0)) && ((newCount === 0)))){
body1 = c.m_shape1.m_body;
body2 = c.m_shape2.m_body;
node1 = c.m_node1;
node2 = c.m_node2;
if (node1.prev){
node1.prev.next = node1.next;
};
if (node1.next){
node1.next.prev = node1.prev;
};
if (node1 === body1.m_contactList){
body1.m_contactList = node1.next;
};
node1.prev = null;
node1.next = null;
if (node2.prev){
node2.prev.next = node2.next;
};
if (node2.next){
node2.next.prev = node2.prev;
};
if (node2 === body2.m_contactList){
body2.m_contactList = node2.next;
};
node2.prev = null;
node2.next = null;
};
};
};
c = c.m_next;
};
}
public function DestroyContact(c:b2Contact):void{
var body1:b2Body;
var body2:b2Body;
var node1:b2ContactNode;
var node2:b2ContactNode;
if (c.m_prev){
c.m_prev.m_next = c.m_next;
};
if (c.m_next){
c.m_next.m_prev = c.m_prev;
};
if (c === m_world.m_contactList){
m_world.m_contactList = c.m_next;
};
if (c.GetManifoldCount() > 0){
body1 = c.m_shape1.m_body;
body2 = c.m_shape2.m_body;
node1 = c.m_node1;
node2 = c.m_node2;
body1.WakeUp();
body2.WakeUp();
if (node1.prev){
node1.prev.next = node1.next;
};
if (node1.next){
node1.next.prev = node1.prev;
};
if (node1 === body1.m_contactList){
body1.m_contactList = node1.next;
};
node1.prev = null;
node1.next = null;
if (node2.prev){
node2.prev.next = node2.next;
};
if (node2.next){
node2.next.prev = node2.prev;
};
if (node2 === body2.m_contactList){
body2.m_contactList = node2.next;
};
node2.prev = null;
node2.next = null;
};
b2Contact.Destroy(c, m_world.m_blockAllocator);
m_world.m_contactCount--;
}
override public function PairAdded(proxyUserData1, proxyUserData2){
var shape1:b2Shape;
var shape2:b2Shape;
var body1:b2Body;
var body2:b2Body;
var contact:b2Contact;
var tempShape:b2Shape;
var tempBody:b2Body;
shape1 = (proxyUserData1 as b2Shape);
shape2 = (proxyUserData2 as b2Shape);
body1 = shape1.m_body;
body2 = shape2.m_body;
if (((body1.IsStatic()) && (body2.IsStatic()))){
return (m_nullContact);
};
if (shape1.m_body === shape2.m_body){
return (m_nullContact);
};
if (body2.m_invMass === 0){
tempShape = shape1;
shape1 = shape2;
shape2 = tempShape;
tempBody = body1;
body1 = body2;
body2 = tempBody;
};
if (body2.IsConnected(body1)){
return (m_nullContact);
};
contact = b2Contact.Create(shape1, shape2, m_world.m_blockAllocator);
if (contact == null){
return (m_nullContact);
};
contact.m_prev = null;
contact.m_next = m_world.m_contactList;
if (m_world.m_contactList != null){
m_world.m_contactList.m_prev = contact;
};
m_world.m_contactList = contact;
m_world.m_contactCount++;
return (contact);
}
public function CleanContactList():void{
var c:b2Contact;
var c0:b2Contact;
c = m_world.m_contactList;
while (c != null) {
c0 = c;
c = c.m_next;
if ((c0.m_flags & b2Contact.e_destroyFlag)){
DestroyContact(c0);
c0 = null;
};
};
}
override public function PairRemoved(proxyUserData1, proxyUserData2, pairUserData):void{
var c:b2Contact;
if (pairUserData == null){
return;
};
c = (pairUserData as b2Contact);
if (c !== m_nullContact){
if (m_destroyImmediate === true){
DestroyContact(c);
c = null;
} else {
c.m_flags = (c.m_flags | b2Contact.e_destroyFlag);
};
};
}
}
}//package Engine.Dynamics
Section 69
//b2Island (Engine.Dynamics.b2Island)
package Engine.Dynamics {
import Engine.Dynamics.Contacts.*;
import Engine.Common.Math.*;
import Engine.Common.*;
import Engine.Dynamics.Joints.*;
public class b2Island {
public var m_positionError:Number;
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;
public static var m_positionIterationCount:int;
public function b2Island(bodyCapacity:int, contactCapacity:int, jointCapacity:int, allocator):void{
var i:int;
super();
m_bodyCapacity = bodyCapacity;
m_contactCapacity = contactCapacity;
m_jointCapacity = jointCapacity;
m_bodyCount = 0;
m_contactCount = 0;
m_jointCount = 0;
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_allocator = allocator;
}
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 Solve(step:b2StepInfo, gravity:b2Vec2):void{
var i:int;
var b:b2Body;
var contactSolver:b2ContactSolver;
var j:int;
var contactsOkay:Boolean;
var jointsOkay:Boolean;
var jointOkay:Boolean;
i = 0;
while (i < m_bodyCount) {
b = m_bodies[i];
if (b.m_invMass === 0){
} else {
b.m_linearVelocity.Add(b2Math.MulFV(step.dt, b2Math.AddVV(gravity, b2Math.MulFV(b.m_invMass, b.m_force))));
b.m_angularVelocity = (b.m_angularVelocity + ((step.dt * b.m_invI) * b.m_torque));
b.m_linearVelocity.Multiply(b.m_linearDamping);
b.m_angularVelocity = (b.m_angularVelocity * b.m_angularDamping);
};
i++;
};
contactSolver = new b2ContactSolver(m_contacts, m_contactCount, m_allocator);
contactSolver.PreSolve();
i = 0;
while (i < m_jointCount) {
m_joints[i].PrepareVelocitySolver();
i++;
};
i = 0;
while (i < step.iterations) {
contactSolver.SolveVelocityConstraints();
j = 0;
while (j < m_jointCount) {
m_joints[j].SolveVelocityConstraints(step);
j++;
};
i++;
};
i = 0;
while (i < m_bodyCount) {
b = m_bodies[i];
if (b.m_invMass === 0){
} else {
b.m_position.x = (b.m_position.x + (step.dt * b.m_linearVelocity.x));
b.m_position.y = (b.m_position.y + (step.dt * b.m_linearVelocity.y));
b.m_rotation = (b.m_rotation + (step.dt * b.m_angularVelocity));
b.m_R.Set(b.m_rotation);
};
i++;
};
i = 0;
while (i < m_jointCount) {
m_joints[i].PreparePositionSolver();
i++;
};
if (b2World.s_enablePositionCorrection){
m_positionIterationCount = 0;
while (m_positionIterationCount < step.iterations) {
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++;
};
};
contactSolver.PostSolve();
i = 0;
while (i < m_bodyCount) {
b = m_bodies[i];
if (b.m_invMass === 0){
} else {
b.m_R.Set(b.m_rotation);
b.SynchronizeShapes();
b.m_force.Set(0, 0);
b.m_torque = 0;
};
i++;
};
}
public function AddContact(contact:b2Contact):void{
var _local2 = m_contactCount++;
m_contacts[_local2] = contact;
}
public function Clear():void{
m_bodyCount = 0;
m_contactCount = 0;
m_jointCount = 0;
}
public function UpdateSleep(dt:Number):void{
var i:int;
var b:b2Body;
var minSleepTime:Number;
var linTolSqr:Number;
var angTolSqr:Number;
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 + 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);
i++;
};
};
}
}
}//package Engine.Dynamics
Section 70
//b2StepInfo (Engine.Dynamics.b2StepInfo)
package Engine.Dynamics {
public class b2StepInfo {
public var dt:Number;
public var iterations:int;
public var inv_dt:Number;
public function b2StepInfo(){
super();
}
}
}//package Engine.Dynamics
Section 71
//b2World (Engine.Dynamics.b2World)
package Engine.Dynamics {
import Engine.Collision.*;
import Engine.Common.Math.*;
import Engine.Dynamics.Joints.*;
import Engine.Collision.Shapes.*;
import Engine.Dynamics.Contacts.*;
public class b2World {
public var m_bodyCount:int;
public var m_gravity:b2Vec2;
public var m_listener:b2WorldListener;
private var step:b2StepInfo;
public var m_positionIterationCount:int;
public var m_blockAllocator;
public var m_contactList:b2Contact;
public var m_groundBody:b2Body;
public var m_contactCount:int;
public var m_broadPhase:b2BroadPhase;
public var m_stackAllocator;
public var m_jointCount:int;
public var m_bodyList:b2Body;
public var m_doSleep:Boolean;
public var m_bodyDestroyList:b2Body;
public var m_jointList:b2Joint;
public var m_contactManager:b2ContactManager;
public static var s_enableWarmStarting:int = 1;
public static var s_enablePositionCorrection:int = 1;
public function b2World(worldAABB:b2AABB, gravity:b2Vec2, doSleep:Boolean):void{
var bd:b2BodyDef;
step = new b2StepInfo();
m_contactManager = new b2ContactManager();
super();
m_listener = null;
m_bodyList = null;
m_contactList = null;
m_jointList = null;
m_bodyCount = 0;
m_contactCount = 0;
m_jointCount = 0;
m_bodyDestroyList = null;
m_doSleep = doSleep;
m_gravity = gravity;
m_contactManager.m_world = this;
m_broadPhase = new b2BroadPhase(worldAABB, m_contactManager);
bd = new b2BodyDef();
m_groundBody = CreateBody(bd);
}
public function GetContactList():b2Contact{
return (m_contactList);
}
public function CreateJoint(def:b2JointDef):b2Joint{
var j:b2Joint;
var b:b2Body;
var s:b2Shape;
j = 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);
s = s.m_next;
};
};
return (j);
}
public function DestroyJoint(j:b2Joint):void{
var collideConnected:Boolean;
var body1:b2Body;
var body2:b2Body;
var b:b2Body;
var s:b2Shape;
collideConnected = 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;
};
body1 = j.m_body1;
body2 = 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);
s = s.m_next;
};
};
}
public function DestroyBody(b:b2Body):void{
if ((b.m_flags & b2Body.e_destroyFlag)){
return;
};
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;
};
b.m_flags = (b.m_flags | b2Body.e_destroyFlag);
m_bodyCount--;
b.m_prev = null;
b.m_next = m_bodyDestroyList;
m_bodyDestroyList = b;
}
public function SetListener(listener:b2WorldListener):void{
m_listener = listener;
}
public function CreateBody(def:b2BodyDef):b2Body{
var b:b2Body;
b = new b2Body(def, this);
b.m_prev = null;
b.m_next = m_bodyList;
if (m_bodyList){
m_bodyList.m_prev = b;
};
m_bodyList = b;
m_bodyCount++;
return (b);
}
public function GetGroundBody():b2Body{
return (m_groundBody);
}
public function Query(aabb:b2AABB, shapes:Array, maxCount:int):int{
var results:Array;
var count:int;
var i:int;
results = new Array();
count = m_broadPhase.QueryAABB(aabb, results, maxCount);
i = 0;
while (i < count) {
shapes[i] = (results[i] as b2Shape);
i++;
};
return (count);
}
public function CleanBodyList():void{
var b:b2Body;
var b0:b2Body;
var jn:b2JointNode;
var jn0:b2JointNode;
m_contactManager.m_destroyImmediate = true;
b = m_bodyDestroyList;
while (b) {
b0 = b;
b = b.m_next;
jn = b0.m_jointList;
while (jn) {
jn0 = jn;
jn = jn.next;
if (m_listener){
m_listener.NotifyJointDestroyed(jn0.joint);
};
DestroyJoint(jn0.joint);
};
b0.Destroy();
};
m_bodyDestroyList = null;
m_contactManager.m_destroyImmediate = false;
}
public function Step(dt:Number, iterations:int):void{
var b:b2Body;
var other:b2Body;
var island:b2Island;
var c:b2Contact;
var j:b2Joint;
var stackSize:int;
var stack:Array;
var k:int;
var seed:b2Body;
var stackCount:int;
var i:int;
var cn:b2ContactNode;
var jn:b2JointNode;
var response:uint;
step.dt = dt;
step.iterations = iterations;
if (dt > 0){
step.inv_dt = (1 / dt);
} else {
step.inv_dt = 0;
};
m_positionIterationCount = 0;
m_contactManager.CleanContactList();
CleanBodyList();
m_contactManager.Collide();
island = new b2Island(m_bodyCount, m_contactCount, m_jointCount, m_stackAllocator);
b = m_bodyList;
while (b != null) {
b.m_flags = (b.m_flags & ~(b2Body.e_islandFlag));
b = b.m_next;
};
c = m_contactList;
while (c != null) {
c.m_flags = (c.m_flags & ~(b2Contact.e_islandFlag));
c = c.m_next;
};
j = m_jointList;
while (j != null) {
j.m_islandFlag = false;
j = j.m_next;
};
stackSize = m_bodyCount;
stack = new Array(m_bodyCount);
k = 0;
while (k < m_bodyCount) {
stack[k] = null;
k++;
};
seed = m_bodyList;
while (seed != null) {
if ((seed.m_flags & (((b2Body.e_staticFlag | b2Body.e_islandFlag) | b2Body.e_sleepFlag) | b2Body.e_frozenFlag))){
} else {
island.Clear();
stackCount = 0;
var _temp1 = stackCount;
stackCount = (stackCount + 1);
var _local17 = _temp1;
stack[_local17] = 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.m_flags & b2Body.e_staticFlag)){
} else {
cn = b.m_contactList;
while (cn != null) {
if ((cn.contact.m_flags & b2Contact.e_islandFlag)){
} 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 _local18 = _temp2;
stack[_local18] = other;
other.m_flags = (other.m_flags | b2Body.e_islandFlag);
};
};
cn = cn.next;
};
jn = b.m_jointList;
while (jn != null) {
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);
_local18 = _temp3;
stack[_local18] = other;
other.m_flags = (other.m_flags | b2Body.e_islandFlag);
};
};
jn = jn.next;
};
};
};
island.Solve(step, m_gravity);
m_positionIterationCount = b2Math.b2Max(m_positionIterationCount, b2Island.m_positionIterationCount);
if (m_doSleep){
island.UpdateSleep(dt);
};
i = 0;
while (i < island.m_bodyCount) {
b = island.m_bodies[i];
if ((b.m_flags & b2Body.e_staticFlag)){
b.m_flags = (b.m_flags & ~(b2Body.e_islandFlag));
};
if (((b.IsFrozen()) && (m_listener))){
response = m_listener.NotifyBoundaryViolated(b);
if (response === b2WorldListener.b2_destroyBody){
DestroyBody(b);
b = null;
island.m_bodies[i] = null;
};
};
i++;
};
};
seed = seed.m_next;
};
m_broadPhase.Flush();
}
public function GetJointList():b2Joint{
return (m_jointList);
}
public function GetBodyList():b2Body{
return (m_bodyList);
}
}
}//package Engine.Dynamics
Section 72
//b2WorldListener (Engine.Dynamics.b2WorldListener)
package Engine.Dynamics {
import Engine.Dynamics.Joints.*;
public class b2WorldListener {
public static var b2_freezeBody:uint = 0;
public static var b2_destroyBody:uint = 1;
public function b2WorldListener(){
super();
}
public function NotifyBoundaryViolated(body:b2Body):uint{
return (b2_freezeBody);
}
public function NotifyJointDestroyed(joint:b2Joint):void{
}
}
}//package Engine.Dynamics
Section 73
//FpsCounter (General.FpsCounter)
package General {
import flash.text.*;
import flash.utils.*;
import flash.system.*;
import flash.display.*;
public class FpsCounter extends Sprite {
var oldT:uint;
var mfpsCount:int;// = 0
var avgCount:int;// = 30
var avgCount2:int;// = 30
var textBox:TextField;
var mfpsCount2:int;// = 0
var textBox3:TextField;
var textBox2:TextField;
public function FpsCounter(){
mfpsCount = 0;
mfpsCount2 = 0;
avgCount = 30;
avgCount2 = 30;
super();
textBox = new TextField();
textBox.text = "fps average";
textBox.textColor = 11145540;
textBox.selectable = false;
textBox2 = new TextField();
textBox2.text = "fps (physics)";
textBox2.textColor = 11145540;
textBox2.selectable = false;
textBox2.y = 15;
textBox3 = new TextField();
textBox3.text = "memory wasted";
textBox3.textColor = 11145540;
textBox3.selectable = false;
textBox3.y = 30;
oldT = getTimer();
addChild(textBox);
addChild(textBox2);
addChild(textBox3);
}
public function updateEnd(){
}
public function updatePhys(oldT2:uint){
var newT:uint;
var f1:uint;
newT = getTimer();
f1 = (newT - oldT2);
mfpsCount2 = (mfpsCount2 + f1);
if (avgCount2 < 1){
textBox2.text = String((Math.round((1000 / (mfpsCount2 / 30))) + " fps (physics)"));
avgCount2 = 30;
mfpsCount2 = 0;
};
avgCount2--;
}
public function update(){
var newT:uint;
var f1:uint;
newT = getTimer();
f1 = (newT - oldT);
mfpsCount = (mfpsCount + f1);
if (avgCount < 1){
textBox.text = String((Math.round((1000 / (mfpsCount / 30))) + " fps average"));
avgCount = 30;
mfpsCount = 0;
};
avgCount--;
oldT = getTimer();
textBox3.text = (Math.round((System.totalMemory / (0x0400 * 0x0400))) + " MB used");
}
}
}//package General
Section 74
//FRateLimiter (General.FRateLimiter)
package General {
import flash.utils.*;
public class FRateLimiter {
static var newT:uint = oldT;
static var oldT:uint = getTimer();
public function FRateLimiter(){
super();
}
public static function limitFrame(maxFPS:uint){
var fTime:uint;
fTime = (1000 / maxFPS);
while (Math.abs((newT - oldT)) < fTime) {
newT = getTimer();
};
oldT = getTimer();
}
}
}//package General
Section 75
//Input (General.Input)
package General {
import flash.display.*;
import flash.events.*;
public class Input {
private static var keyArr:Array;
public static var ascii:Array;
public static var mouseX:Number = 0;
public static var mouseY:Number = 0;
private static var bufferSize:int;
public static var mouse:Sprite = new Sprite();
public static var mouseDown:Boolean = false;
public static var mouseReleased:Boolean = false;
public static var lastKey:int = 0;
public static var m_stageMc:Sprite;
private static var keyState:Array;
public static var timeSinceLastKey = 0;
private static var keyBuffer:Array;
public function Input(stageMc:Sprite){
var i:int;
var j:int;
super();
m_stageMc = stageMc;
ascii = new Array(222);
fillAscii();
keyState = new Array(222);
keyArr = new Array();
i = 0;
while (i < 222) {
keyState[i] = new int(0);
if (ascii[i] != undefined){
keyArr.push(i);
};
i++;
};
bufferSize = 5;
keyBuffer = new Array(bufferSize);
j = 0;
while (j < bufferSize) {
keyBuffer[j] = new Array(0, 0);
j++;
};
stageMc.stage.addEventListener(KeyboardEvent.KEY_DOWN, keyPress, false, 0, true);
stageMc.stage.addEventListener(KeyboardEvent.KEY_UP, keyRelease, false, 0, true);
stageMc.stage.addEventListener(MouseEvent.MOUSE_DOWN, mousePress, false, 0, true);
stageMc.stage.addEventListener(MouseEvent.MOUSE_UP, mouseRelease, false, 0, true);
stageMc.stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMove, false, 0, true);
mouse.graphics.lineStyle(1, 0, 100);
mouse.graphics.moveTo(0, 0);
mouse.graphics.lineTo(0, 1);
}
public function mouseRelease(e:MouseEvent){
mouseDown = false;
mouseReleased = true;
}
public function keyPress(e:KeyboardEvent){
keyState[e.keyCode] = Math.max(keyState[e.keyCode], 1);
lastKey = e.keyCode;
}
private function fillAscii(){
ascii[65] = "A";
ascii[66] = "B";
ascii[67] = "C";
ascii[68] = "D";
ascii[69] = "E";
ascii[70] = "F";
ascii[71] = "G";
ascii[72] = "H";
ascii[73] = "I";
ascii[74] = "J";
ascii[75] = "K";
ascii[76] = "L";
ascii[77] = "M";
ascii[78] = "N";
ascii[79] = "O";
ascii[80] = "P";
ascii[81] = "Q";
ascii[82] = "R";
ascii[83] = "S";
ascii[84] = "T";
ascii[85] = "U";
ascii[86] = "V";
ascii[87] = "W";
ascii[88] = "X";
ascii[89] = "Y";
ascii[90] = "Z";
ascii[48] = "0";
ascii[49] = "1";
ascii[50] = "2";
ascii[51] = "3";
ascii[52] = "4";
ascii[53] = "5";
ascii[54] = "6";
ascii[55] = "7";
ascii[56] = "8";
ascii[57] = "9";
ascii[32] = "Spacebar";
ascii[17] = "Ctrl";
ascii[16] = "Shift";
ascii[192] = "~";
ascii[38] = "up";
ascii[40] = "down";
ascii[37] = "left";
ascii[39] = "right";
ascii[96] = "Numpad 0";
ascii[97] = "Numpad 1";
ascii[98] = "Numpad 2";
ascii[99] = "Numpad 3";
ascii[100] = "Numpad 4";
ascii[101] = "Numpad 5";
ascii[102] = "Numpad 6";
ascii[103] = "Numpad 7";
ascii[104] = "Numpad 8";
ascii[105] = "Numpad 9";
ascii[111] = "Numpad /";
ascii[106] = "Numpad *";
ascii[109] = "Numpad -";
ascii[107] = "Numpad +";
ascii[110] = "Numpad .";
ascii[45] = "Insert";
ascii[46] = "Delete";
ascii[33] = "Page Up";
ascii[34] = "Page Down";
ascii[35] = "End";
ascii[36] = "Home";
ascii[112] = "F1";
ascii[113] = "F2";
ascii[114] = "F3";
ascii[115] = "F4";
ascii[116] = "F5";
ascii[117] = "F6";
ascii[118] = "F7";
ascii[119] = "F8";
ascii[188] = ",";
ascii[190] = ".";
ascii[186] = ";";
ascii[222] = "'";
ascii[219] = "[";
ascii[221] = "]";
ascii[189] = "-";
ascii[187] = "+";
ascii[220] = "\\";
ascii[191] = "/";
ascii[9] = "TAB";
ascii[8] = "Backspace";
}
public function mouseMove(e:MouseEvent){
mouseX = (e.stageX - m_stageMc.x);
mouseY = (e.stageY - m_stageMc.y);
mouse.x = mouseX;
mouse.y = mouseY;
}
public function keyRelease(e:KeyboardEvent){
var i:int;
keyState[e.keyCode] = -1;
i = (bufferSize - 1);
while (i > 0) {
keyBuffer[i] = keyBuffer[(i - 1)];
i--;
};
keyBuffer[0] = [e.keyCode, 0];
}
public function mousePress(e:MouseEvent){
mouseDown = true;
}
public static function getKeyHold(k:int):int{
return (Math.max(0, keyState[k]));
}
public static function update(){
var i:int;
var j:int;
i = 0;
while (i < keyArr.length) {
if (keyState[keyArr[i]] != 0){
var _local3 = keyState;
var _local4 = keyArr[i];
var _local5 = (_local3[_local4] + 1);
_local3[_local4] = _local5;
};
i++;
};
j = 0;
while (j < bufferSize) {
_local3 = keyBuffer[j];
_local4 = 1;
_local5 = (_local3[_local4] + 1);
_local3[_local4] = _local5;
j++;
};
mouseReleased = false;
}
public static function isKeyPressed(k:int):Boolean{
timeSinceLastKey = 0;
return ((keyState[k] == 1));
}
public static function isKeyDown(k:int):Boolean{
return ((keyState[k] > 0));
}
public static function getKeyString(k:uint):String{
return (ascii[k]);
}
public static function isKeyReleased(k:int):Boolean{
return ((keyState[k] == -1));
}
public static function isKeyInBuffer(k:int, i:int, t:int){
return ((((keyBuffer[i][0] == k)) && ((keyBuffer[i][1] <= t))));
}
}
}//package General
Section 76
//Back (gs.easing.Back)
package gs.easing {
public class Back {
public function Back(){
super();
}
public static function easeOut(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 easeIn(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 easeInOut(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));
}
}
}//package gs.easing
Section 77
//Elastic (gs.easing.Elastic)
package gs.easing {
public class Elastic {
private static const _2PI:Number = 6.28318530717959;
public function Elastic(){
super();
}
public static function easeIn(t:Number, b:Number, c:Number, d:Number, a:Number=0, p:Number=0):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 / _2PI) * Math.asin((c / a)));
};
t = (t - 1);
return ((-(((a * Math.pow(2, (10 * t))) * Math.sin(((((t * d) - s) * _2PI) / p)))) + b));
}
public static function easeInOut(t:Number, b:Number, c:Number, d:Number, a:Number=0, p:Number=0):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 / _2PI) * Math.asin((c / a)));
};
if (t < 1){
t = (t - 1);
return (((-0.5 * ((a * Math.pow(2, (10 * t))) * Math.sin(((((t * d) - s) * _2PI) / p)))) + b));
};
t = (t - 1);
return ((((((a * Math.pow(2, (-10 * t))) * Math.sin(((((t * d) - s) * _2PI) / p))) * 0.5) + c) + b));
}
public static function easeOut(t:Number, b:Number, c:Number, d:Number, a:Number=0, p:Number=0):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 / _2PI) * Math.asin((c / a)));
};
return (((((a * Math.pow(2, (-10 * t))) * Math.sin(((((t * d) - s) * _2PI) / p))) + c) + b));
}
}
}//package gs.easing
Section 78
//TweenEvent (gs.events.TweenEvent)
package gs.events {
import flash.events.*;
public class TweenEvent extends Event {
public var info:Object;
public static const UPDATE:String = "update";
public static const START:String = "start";
public static const version:Number = 0.9;
public static const COMPLETE:String = "complete";
public function TweenEvent($type:String, $info:Object=null, $bubbles:Boolean=false, $cancelable:Boolean=false){
super($type, $bubbles, $cancelable);
this.info = $info;
}
override public function clone():Event{
return (new TweenEvent(this.type, this.info, this.bubbles, this.cancelable));
}
}
}//package gs.events
Section 79
//OverwriteManager (gs.OverwriteManager)
package gs {
import flash.errors.*;
import flash.utils.*;
public class OverwriteManager {
public static const ALL:int = 1;
public static const NONE:int = 0;
public static const AUTO:int = 2;
public static const CONCURRENT:int = 3;
public static const version:Number = 0.96;
public static var mode:int;
public static var enabled:Boolean;
public function OverwriteManager(){
super();
}
public static function killVars($killVars:Object, $vars:Object, $tweens:Array, $subTweens:Array, $filters:Array):void{
var i:int;
var p:String;
i = ($subTweens.length - 1);
while (i > -1) {
if ($killVars[$subTweens[i].name] != undefined){
$subTweens.splice(i, 1);
};
i--;
};
i = ($tweens.length - 1);
while (i > -1) {
if ($killVars[$tweens[i].name] != undefined){
$tweens.splice(i, 1);
};
i--;
};
i = ($filters.length - 1);
while (i > -1) {
if ($killVars[$filters[i].name] != undefined){
$filters.splice(i, 1);
};
i--;
};
for (p in $killVars) {
delete $vars[p];
};
}
public static function manageOverwrites($instance:TweenLite, $objTweens:Dictionary):void{
var vars:Object;
var m:int;
var tw:Object;
var startTime:Number;
var a:Array;
var i:int;
var v:Object;
var p:String;
vars = $instance.vars;
m = ((vars.overwrite)==undefined) ? mode : int(vars.overwrite);
if (m < 2){
return;
};
startTime = $instance.startTime;
a = [];
for each (tw in $objTweens) {
if (((!((tw == $instance))) && ((tw.startTime <= startTime)))){
a[a.length] = tw;
};
};
if (a.length == 0){
return;
};
if (m == AUTO){
if (vars.isTV == true){
vars = vars.exposedProps;
};
v = {};
for (p in vars) {
if ((((((((((((((((((((((((((((((((((((((p == "ease")) || ((p == "delay")))) || ((p == "overwrite")))) || ((p == "onComplete")))) || ((p == "onCompleteParams")))) || ((p == "runBackwards")))) || ((p == "persist")))) || ((p == "onUpdate")))) || ((p == "onUpdateParams")))) || ((p == "timeScale")))) || ((p == "onStart")))) || ((p == "onStartParams")))) || ((p == "renderOnStart")))) || ((p == "proxiedEase")))) || ((p == "easeParams")))) || ((p == "onCompleteAll")))) || ((p == "onCompleteAllParams")))) || ((p == "yoyo")))) || ((p == "loop")))){
} else {
v[p] = 1;
};
};
i = (a.length - 1);
while (i > -1) {
a[i].killVars(v);
i--;
};
} else {
i = (a.length - 1);
while (i > -1) {
$objTweens[a[i]] = null;
delete $objTweens[a[i]];
i--;
};
};
}
public static function init($mode:int=2):int{
if (TweenLite.version < 8.14){
trace("TweenLite warning: Your TweenLite class needs to be updated to work with OverwriteManager (or you may need to clear your ASO files). Please download and install the latest version from http://www.tweenlite.com.");
};
TweenLite.overwriteManager = OverwriteManager;
mode = $mode;
enabled = true;
return (mode);
}
}
}//package gs
Section 80
//TweenFilterLite (gs.TweenFilterLite)
package gs {
import flash.filters.*;
import flash.utils.*;
public class TweenFilterLite extends TweenLite {
protected var _endMatrix:Array;
protected var _hf:Boolean;// = false
protected var _clrsa:Array;
protected var _filters:Array;
protected var _matrix:Array;
protected var _cmf:ColorMatrixFilter;
protected var _timeScale:Number;
public static var removeTween:Function = TweenLite.removeTween;
private static var _idMatrix:Array = [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0];
private static var _lumB:Number = 0.072169;
public static var delayedCall:Function = TweenLite.delayedCall;
public static var killTweensOf:Function = TweenLite.killTweensOf;
public static var version:Number = 9.03;
private static var _lumG:Number = 0.71516;
public static var killDelayedCallsTo:Function = TweenLite.killTweensOf;
private static var _lumR:Number = 0.212671;
protected static var _globalTimeScale:Number = 1;
public function TweenFilterLite($target:Object, $duration:Number, $vars:Object){
_hf = false;
_filters = [];
super($target, $duration, $vars);
if (((!((this.combinedTimeScale == 1))) && ((this.target is TweenFilterLite)))){
_timeScale = 1;
this.combinedTimeScale = _globalTimeScale;
} else {
_timeScale = this.combinedTimeScale;
this.combinedTimeScale = (this.combinedTimeScale * _globalTimeScale);
};
if (((!((this.combinedTimeScale == 1))) && (!((this.delay == 0))))){
this.startTime = (this.initTime + (this.delay * (1000 / this.combinedTimeScale)));
};
if (TweenLite.version < 9.04){
trace("TweenFilterLite error! Please update your TweenLite class or try deleting your ASO files. TweenFilterLite requires a more recent version. Download updates at http://www.TweenLite.com.");
};
if ($vars.type != undefined){
trace((("TweenFilterLite error: " + $target) + " is using deprecated syntax. Please update to the new syntax. See http://www.TweenFilterLite.com for details."));
};
}
override public function set enabled($b:Boolean):void{
super.enabled = $b;
this.combinedTimeScale = (_timeScale * _globalTimeScale);
}
override public function render($t:uint):void{
var time:Number;
var factor:Number;
var tp:Object;
var i:int;
var f:Array;
var j:int;
time = ((($t - this.startTime) / 1000) * this.combinedTimeScale);
if (time >= this.duration){
time = this.duration;
factor = ((((this.ease == this.vars.ease)) || ((this.duration == 0.001)))) ? 1 : 0;
} else {
factor = this.ease(time, 0, 1, this.duration);
};
i = (this.tweens.length - 1);
while (i > -1) {
tp = this.tweens[i];
tp.o[tp.p] = (tp.s + (factor * tp.c));
i--;
};
if (_hf){
i = (_clrsa.length - 1);
while (i > -1) {
tp = _clrsa[i];
tp.f[tp.p] = ((((tp.sr + (factor * tp.cr)) << 16) | ((tp.sg + (factor * tp.cg)) << 8)) | (tp.sb + (factor * tp.cb)));
i--;
};
if (_cmf != null){
ColorMatrixFilter(_cmf).matrix = _matrix;
};
f = this.target.filters;
i = 0;
while (i < _filters.length) {
j = (f.length - 1);
while (j > -1) {
if ((f[j] is _filters[i].type)){
f.splice(j, 1, _filters[i].filter);
break;
};
j--;
};
i++;
};
this.target.filters = f;
};
if (_hst){
i = (_subTweens.length - 1);
while (i > -1) {
_subTweens[i].proxy(_subTweens[i]);
i--;
};
};
if (_hasUpdate){
this.vars.onUpdate.apply(null, this.vars.onUpdateParams);
};
if (time == this.duration){
complete(true);
};
}
public function set timeScale($n:Number):void{
if ($n < 1E-5){
$n = (_timeScale = 1E-5);
} else {
_timeScale = $n;
$n = ($n * _globalTimeScale);
};
this.initTime = ((currentTime - ((((currentTime - this.initTime) - (this.delay * (1000 / _timeScale))) * _timeScale) * (1 / $n))) - (this.delay * (1000 / $n)));
if (this.startTime != 999999999999999){
this.startTime = (this.initTime + (this.delay * (1000 / $n)));
};
this.combinedTimeScale = $n;
}
override public function killVars($vars:Object):void{
if (TweenLite.overwriteManager.enabled){
TweenLite.overwriteManager.killVars($vars, this.vars, this.tweens, _subTweens, _filters);
};
}
public function get timeScale():Number{
return (_timeScale);
}
override public function initTweenVals($hrp:Boolean=false, $reservedProps:String=""):void{
var i:int;
var fv:Object;
var cmf:Object;
var tp:Object;
if (((((!($hrp)) && (!((this.delay == 0))))) && (TweenLite.overwriteManager.enabled))){
TweenLite.overwriteManager.manageOverwrites(this, masterList[this.target]);
};
_clrsa = [];
_filters = [];
_matrix = _idMatrix.slice();
$reservedProps = ($reservedProps + " blurFilter glowFilter colorMatrixFilter dropShadowFilter bevelFilter ");
if (_isDisplayObject){
if (this.vars.blurFilter != null){
fv = this.vars.blurFilter;
addFilter("blurFilter", fv, BlurFilter, ["blurX", "blurY", "quality"], new BlurFilter(0, 0, ((fv.quality) || (2))));
};
if (this.vars.glowFilter != null){
fv = this.vars.glowFilter;
addFilter("glowFilter", fv, GlowFilter, ["alpha", "blurX", "blurY", "color", "quality", "strength", "inner", "knockout"], new GlowFilter(0xFFFFFF, 0, 0, 0, ((fv.strength) || (1)), ((fv.quality) || (2)), fv.inner, fv.knockout));
};
if (this.vars.colorMatrixFilter != null){
fv = this.vars.colorMatrixFilter;
cmf = addFilter("colorMatrixFilter", fv, ColorMatrixFilter, [], new ColorMatrixFilter(_matrix));
_cmf = cmf.filter;
_matrix = ColorMatrixFilter(_cmf).matrix;
if (((!((fv.matrix == null))) && ((fv.matrix is Array)))){
_endMatrix = fv.matrix;
} else {
if (fv.relative == true){
_endMatrix = _matrix.slice();
} else {
_endMatrix = _idMatrix.slice();
};
_endMatrix = setBrightness(_endMatrix, fv.brightness);
_endMatrix = setContrast(_endMatrix, fv.contrast);
_endMatrix = setHue(_endMatrix, fv.hue);
_endMatrix = setSaturation(_endMatrix, fv.saturation);
_endMatrix = setThreshold(_endMatrix, fv.threshold);
if (!(isNaN(fv.colorize))){
_endMatrix = colorize(_endMatrix, fv.colorize, fv.amount);
} else {
if (!(isNaN(fv.color))){
_endMatrix = colorize(_endMatrix, fv.color, fv.amount);
};
};
};
i = 0;
while (i < _endMatrix.length) {
if (((!((_matrix[i] == _endMatrix[i]))) && (!((_matrix[i] == undefined))))){
this.tweens[this.tweens.length] = {o:_matrix, p:i.toString(), s:_matrix[i], c:(_endMatrix[i] - _matrix[i]), name:"colorMatrixFilter"};
};
i++;
};
};
if (this.vars.dropShadowFilter != null){
fv = this.vars.dropShadowFilter;
addFilter("dropShadowFilter", fv, DropShadowFilter, ["alpha", "angle", "blurX", "blurY", "color", "distance", "quality", "strength", "inner", "knockout", "hideObject"], new DropShadowFilter(0, 45, 0, 0, 0, 0, 1, ((fv.quality) || (2)), fv.inner, fv.knockout, fv.hideObject));
};
if (this.vars.bevelFilter != null){
fv = this.vars.bevelFilter;
addFilter("bevelFilter", fv, BevelFilter, ["angle", "blurX", "blurY", "distance", "highlightAlpha", "highlightColor", "quality", "shadowAlpha", "shadowColor", "strength"], new BevelFilter(0, 0, 0xFFFFFF, 0.5, 0, 0.5, 2, 2, 0, ((fv.quality) || (2))));
};
if (this.vars.runBackwards == true){
i = (_clrsa.length - 1);
while (i > -1) {
tp = _clrsa[i];
tp.sr = (tp.sr + tp.cr);
tp.cr = (tp.cr * -1);
tp.sg = (tp.sg + tp.cg);
tp.cg = (tp.cg * -1);
tp.sb = (tp.sb + tp.cb);
tp.cb = (tp.cb * -1);
tp.f[tp.p] = (((tp.sr << 16) | (tp.sg << 8)) | tp.sb);
i--;
};
};
super.initTweenVals(true, $reservedProps);
} else {
super.initTweenVals($hrp, $reservedProps);
};
}
private function addFilter($name:String, $fv:Object, $filterType:Class, $props:Array, $defaultFilter:BitmapFilter):Object{
var f:Object;
var fltrs:Array;
var i:int;
var prop:String;
var valChange:Number;
var begin:Object;
var end:Object;
f = {type:$filterType, name:$name};
fltrs = this.target.filters;
i = 0;
while (i < fltrs.length) {
if ((fltrs[i] is $filterType)){
f.filter = fltrs[i];
break;
};
i++;
};
if (f.filter == undefined){
f.filter = $defaultFilter;
fltrs[fltrs.length] = f.filter;
this.target.filters = fltrs;
};
i = 0;
while (i < $props.length) {
prop = $props[i];
if ($fv[prop] != undefined){
if ((((((prop == "color")) || ((prop == "highlightColor")))) || ((prop == "shadowColor")))){
begin = HEXtoRGB(f.filter[prop]);
end = HEXtoRGB($fv[prop]);
_clrsa[_clrsa.length] = {f:f.filter, p:prop, sr:begin.rb, cr:(end.rb - begin.rb), sg:begin.gb, cg:(end.gb - begin.gb), sb:begin.bb, cb:(end.bb - begin.bb)};
} else {
if ((((((((prop == "quality")) || ((prop == "inner")))) || ((prop == "knockout")))) || ((prop == "hideObject")))){
f.filter[prop] = $fv[prop];
} else {
if (typeof($fv[prop]) == "number"){
valChange = ($fv[prop] - f.filter[prop]);
} else {
valChange = Number($fv[prop]);
};
this.tweens[this.tweens.length] = {o:f.filter, p:prop, s:f.filter[prop], c:valChange, name:$name};
};
};
};
i++;
};
_filters[_filters.length] = f;
_hf = true;
return (f);
}
public static function setHue($m:Array, $n:Number):Array{
var c:Number;
var s:Number;
var temp:Array;
if (isNaN($n)){
return ($m);
};
$n = ($n * (Math.PI / 180));
c = Math.cos($n);
s = Math.sin($n);
temp = [((_lumR + (c * (1 - _lumR))) + (s * -(_lumR))), ((_lumG + (c * -(_lumG))) + (s * -(_lumG))), ((_lumB + (c * -(_lumB))) + (s * (1 - _lumB))), 0, 0, ((_lumR + (c * -(_lumR))) + (s * 0.143)), ((_lumG + (c * (1 - _lumG))) + (s * 0.14)), ((_lumB + (c * -(_lumB))) + (s * -0.283)), 0, 0, ((_lumR + (c * -(_lumR))) + (s * -((1 - _lumR)))), ((_lumG + (c * -(_lumG))) + (s * _lumG)), ((_lumB + (c * (1 - _lumB))) + (s * _lumB)), 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1];
return (applyMatrix(temp, $m));
}
public static function setContrast($m:Array, $n:Number):Array{
var temp:Array;
if (isNaN($n)){
return ($m);
};
$n = ($n + 0.01);
temp = [$n, 0, 0, 0, (128 * (1 - $n)), 0, $n, 0, 0, (128 * (1 - $n)), 0, 0, $n, 0, (128 * (1 - $n)), 0, 0, 0, 1, 0];
return (applyMatrix(temp, $m));
}
public static function applyMatrix($m:Array, $m2:Array):Array{
var temp:Array;
var i:int;
var z:int;
var y:int;
var x:int;
if (((!(($m is Array))) || (!(($m2 is Array))))){
return ($m2);
};
temp = [];
i = 0;
z = 0;
y = 0;
while (y < 4) {
x = 0;
while (x < 5) {
if (x == 4){
z = $m[(i + 4)];
} else {
z = 0;
};
temp[(i + x)] = ((((($m[i] * $m2[x]) + ($m[(i + 1)] * $m2[(x + 5)])) + ($m[(i + 2)] * $m2[(x + 10)])) + ($m[(i + 3)] * $m2[(x + 15)])) + z);
x++;
};
i = (i + 5);
y++;
};
return (temp);
}
public static function colorize($m:Array, $color:Number, $amount:Number=1):Array{
var r:Number;
var g:Number;
var b:Number;
var inv:Number;
var temp:Array;
if (isNaN($color)){
return ($m);
};
if (isNaN($amount)){
$amount = 1;
};
r = ((($color >> 16) & 0xFF) / 0xFF);
g = ((($color >> 8) & 0xFF) / 0xFF);
b = (($color & 0xFF) / 0xFF);
inv = (1 - $amount);
temp = [(inv + (($amount * r) * _lumR)), (($amount * r) * _lumG), (($amount * r) * _lumB), 0, 0, (($amount * g) * _lumR), (inv + (($amount * g) * _lumG)), (($amount * g) * _lumB), 0, 0, (($amount * b) * _lumR), (($amount * b) * _lumG), (inv + (($amount * b) * _lumB)), 0, 0, 0, 0, 0, 1, 0];
return (applyMatrix(temp, $m));
}
public static function setBrightness($m:Array, $n:Number):Array{
if (isNaN($n)){
return ($m);
};
$n = (($n * 100) - 100);
return (applyMatrix([1, 0, 0, 0, $n, 0, 1, 0, 0, $n, 0, 0, 1, 0, $n, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1], $m));
}
public static function setSaturation($m:Array, $n:Number):Array{
var inv:Number;
var r:Number;
var g:Number;
var b:Number;
var temp:Array;
if (isNaN($n)){
return ($m);
};
inv = (1 - $n);
r = (inv * _lumR);
g = (inv * _lumG);
b = (inv * _lumB);
temp = [(r + $n), g, b, 0, 0, r, (g + $n), b, 0, 0, r, g, (b + $n), 0, 0, 0, 0, 0, 1, 0];
return (applyMatrix(temp, $m));
}
public static function setGlobalTimeScale($scale:Number):void{
var a:Dictionary;
var p:Object;
var tw:Object;
if ($scale < 1E-5){
$scale = 1E-5;
};
a = masterList;
_globalTimeScale = $scale;
for each (p in a) {
for (tw in p) {
if ((p[tw] is TweenFilterLite)){
p[tw].timeScale = (p[tw].timeScale * 1);
};
};
};
}
public static function get globalTimeScale():Number{
return (_globalTimeScale);
}
public static function from($target:Object, $duration:Number, $vars:Object):TweenFilterLite{
$vars.runBackwards = true;
return (new TweenFilterLite($target, $duration, $vars));
}
public static function set globalTimeScale($n:Number):void{
setGlobalTimeScale($n);
}
public static function HEXtoRGB($n:Number):Object{
return ({rb:($n >> 16), gb:(($n >> 8) & 0xFF), bb:($n & 0xFF)});
}
public static function setThreshold($m:Array, $n:Number):Array{
var temp:Array;
if (isNaN($n)){
return ($m);
};
temp = [(_lumR * 0x0100), (_lumG * 0x0100), (_lumB * 0x0100), 0, (-256 * $n), (_lumR * 0x0100), (_lumG * 0x0100), (_lumB * 0x0100), 0, (-256 * $n), (_lumR * 0x0100), (_lumG * 0x0100), (_lumB * 0x0100), 0, (-256 * $n), 0, 0, 0, 1, 0];
return (applyMatrix(temp, $m));
}
public static function to($target:Object, $duration:Number, $vars:Object):TweenFilterLite{
return (new TweenFilterLite($target, $duration, $vars));
}
}
}//package gs
Section 81
//TweenLite (gs.TweenLite)
package gs {
import flash.utils.*;
import flash.display.*;
import flash.events.*;
import flash.geom.*;
public class TweenLite {
public var delay:Number;
protected var _hasUpdate:Boolean;
protected var _subTweens:Array;
public var initted:Boolean;
public var startTime:Number;
public var forceActive:Boolean;
public var duration:Number;
public var target:Object;
protected var _hst:Boolean;
protected var _isDisplayObject:Boolean;
public var vars:Object;
public var ease:Function;
public var tweens:Array;
public var combinedTimeScale:Number;
public var initTime:Number;
private static var _timer:Timer = new Timer(2000);
private static var _classInitted:Boolean;
public static var defaultEase:Function = TweenLite.easeOut;
public static var version:Number = 9.04;
public static var masterList:Dictionary = new Dictionary(false);
private static var _sprite:Sprite = new Sprite();
public static var currentTime:uint;
public static var overwriteManager:Object;
public static var killDelayedCallsTo:Function = TweenLite.killTweensOf;
private static var _listening:Boolean;
public function TweenLite($target:Object, $duration:Number, $vars:Object){
var mode:int;
var v:*;
super();
if ($target == null){
return;
};
if (!(_classInitted)){
currentTime = getTimer();
_sprite.addEventListener(Event.ENTER_FRAME, executeAll);
if (overwriteManager == null){
overwriteManager = {mode:1, enabled:false};
};
_classInitted = true;
};
this.vars = $vars;
this.duration = (($duration) || (0.001));
this.delay = (($vars.delay) || (0));
this.combinedTimeScale = (($vars.timeScale) || (1));
this.forceActive = ((($duration == 0)) && ((this.delay == 0)));
this.target = $target;
_isDisplayObject = ($target is DisplayObject);
if (!((this.vars.ease is Function))){
this.vars.ease = defaultEase;
};
if (this.vars.easeParams != null){
this.vars.proxiedEase = this.vars.ease;
this.vars.ease = easeProxy;
};
this.ease = this.vars.ease;
if (!(isNaN(Number(this.vars.autoAlpha)))){
this.vars.alpha = Number(this.vars.autoAlpha);
this.vars.visible = (this.vars.alpha > 0);
};
this.tweens = [];
_subTweens = [];
_hst = (this.initted = false);
this.initTime = currentTime;
this.startTime = (this.initTime + (this.delay * 1000));
mode = (((($vars.overwrite == undefined)) || (((!(overwriteManager.enabled)) && (($vars.overwrite > 1)))))) ? overwriteManager.mode : int($vars.overwrite);
if ((((masterList[$target] == undefined)) || (((!(($target == null))) && ((mode == 1)))))){
delete masterList[$target];
masterList[$target] = new Dictionary(true);
} else {
if ((((mode > 1)) && ((this.delay == 0)))){
overwriteManager.manageOverwrites(this, masterList[$target]);
};
};
masterList[$target][this] = this;
if ((((((this.vars.runBackwards == true)) && (!((this.vars.renderOnStart == true))))) || (this.forceActive))){
initTweenVals();
if (this.forceActive){
render((this.startTime + 1));
} else {
render(this.startTime);
};
v = this.vars.visible;
if (this.vars.isTV == true){
v = this.vars.exposedProps.visible;
};
if (((((!((v == null))) && ((this.vars.runBackwards == true)))) && (_isDisplayObject))){
this.target.visible = Boolean(v);
};
};
if (((!(_listening)) && (!(this.forceActive)))){
_timer.addEventListener("timer", killGarbage);
_timer.start();
_listening = true;
};
}
public function set enabled($b:Boolean):void{
if ($b){
if (masterList[this.target] == undefined){
masterList[this.target] = new Dictionary(true);
};
masterList[this.target][this] = this;
if (!(_listening)){
_timer.addEventListener("timer", killGarbage);
_timer.start();
_listening = true;
};
} else {
if (masterList[this.target] != undefined){
masterList[this.target][this] = null;
delete masterList[this.target][this];
};
};
}
protected function addSubTween($name:String, $proxy:Function, $target:Object, $props:Object, $info:Object=null):void{
var sub:Object;
var p:String;
sub = {name:$name, proxy:$proxy, target:$target, info:$info};
_subTweens[_subTweens.length] = sub;
for (p in $props) {
if (typeof($props[p]) == "number"){
this.tweens[this.tweens.length] = {o:$target, p:p, s:$target[p], c:($props[p] - $target[p]), sub:sub, name:$name};
} else {
this.tweens[this.tweens.length] = {o:$target, p:p, s:$target[p], c:Number($props[p]), sub:sub, name:$name};
};
};
_hst = true;
}
public function clear():void{
this.tweens = [];
_subTweens = [];
this.vars = {};
_hst = (_hasUpdate = false);
}
public function get active():Boolean{
if (this.forceActive){
return (true);
};
if (currentTime >= this.startTime){
this.forceActive = true;
if (!(this.initted)){
initTweenVals();
} else {
if (((!((this.vars.visible == undefined))) && (_isDisplayObject))){
this.target.visible = true;
};
};
if (this.vars.onStart != null){
this.vars.onStart.apply(null, this.vars.onStartParams);
};
if (this.duration == 0.001){
this.startTime = (this.startTime - 1);
};
return (true);
//unresolved jump
};
return (false);
}
public function render($t:uint):void{
var time:Number;
var factor:Number;
var tp:Object;
var i:int;
time = (($t - this.startTime) / 1000);
if (time >= this.duration){
time = this.duration;
factor = ((((this.ease == this.vars.ease)) || ((this.duration == 0.001)))) ? 1 : 0;
} else {
factor = this.ease(time, 0, 1, this.duration);
};
i = (this.tweens.length - 1);
while (i > -1) {
tp = this.tweens[i];
tp.o[tp.p] = (tp.s + (factor * tp.c));
i--;
};
if (_hst){
i = (_subTweens.length - 1);
while (i > -1) {
_subTweens[i].proxy(_subTweens[i]);
i--;
};
};
if (_hasUpdate){
this.vars.onUpdate.apply(null, this.vars.onUpdateParams);
};
if (time == this.duration){
complete(true);
};
}
protected function easeProxy($t:Number, $b:Number, $c:Number, $d:Number):Number{
return (this.vars.proxiedEase.apply(null, arguments.concat(this.vars.easeParams)));
}
public function get enabled():Boolean{
return (((!((masterList[this.target] == undefined))) && (!((masterList[this.target][this] == null)))));
}
public function initTweenVals($hrp:Boolean=false, $reservedProps:String=""):void{
var p:String;
var i:int;
var v:Object;
var endArray:Array;
var clr:ColorTransform;
var endClr:ColorTransform;
var tp:Object;
v = this.vars;
if (v.isTV == true){
v = v.exposedProps;
};
if (((((!($hrp)) && (!((this.delay == 0))))) && (overwriteManager.enabled))){
overwriteManager.manageOverwrites(this, masterList[this.target]);
};
if ((this.target is Array)){
endArray = ((this.vars.endArray) || ([]));
i = 0;
while (i < endArray.length) {
if (((!((this.target[i] == endArray[i]))) && (!((this.target[i] == undefined))))){
this.tweens[this.tweens.length] = {o:this.target, p:i.toString(), s:this.target[i], c:(endArray[i] - this.target[i]), name:i.toString()};
};
i++;
};
} else {
if (((((!((typeof(v.tint) == "undefined"))) || ((this.vars.removeTint == true)))) && (_isDisplayObject))){
clr = this.target.transform.colorTransform;
endClr = new ColorTransform();
if (v.alpha != undefined){
endClr.alphaMultiplier = v.alpha;
delete v.alpha;
} else {
endClr.alphaMultiplier = this.target.alpha;
};
if (((!((this.vars.removeTint == true))) && (((((!((v.tint == null))) && (!((v.tint == ""))))) || ((v.tint == 0)))))){
endClr.color = v.tint;
};
addSubTween("tint", tintProxy, {progress:0}, {progress:1}, {target:this.target, color:clr, endColor:endClr});
};
if (((!((v.frame == null))) && (_isDisplayObject))){
addSubTween("frame", frameProxy, {frame:this.target.currentFrame}, {frame:v.frame}, {target:this.target});
};
if (((!(isNaN(this.vars.volume))) && (this.target.hasOwnProperty("soundTransform")))){
addSubTween("volume", volumeProxy, this.target.soundTransform, {volume:this.vars.volume}, {target:this.target});
};
for (p in v) {
if ((((((((((((((((((((((((((((((((((((((p == "ease")) || ((p == "delay")))) || ((p == "overwrite")))) || ((p == "onComplete")))) || ((p == "onCompleteParams")))) || ((p == "runBackwards")))) || ((p == "visible")))) || ((p == "autoOverwrite")))) || ((p == "persist")))) || ((p == "onUpdate")))) || ((p == "onUpdateParams")))) || ((p == "autoAlpha")))) || ((((p == "timeScale")) && (!((this.target is TweenLite))))))) || ((p == "onStart")))) || ((p == "onStartParams")))) || ((p == "renderOnStart")))) || ((p == "proxiedEase")))) || ((p == "easeParams")))) || ((($hrp) && (!(($reservedProps.indexOf(((" " + p) + " ")) == -1))))))){
} else {
if (((!(((_isDisplayObject) && ((((((p == "tint")) || ((p == "removeTint")))) || ((p == "frame"))))))) && (!((((p == "volume")) && (this.target.hasOwnProperty("soundTransform"))))))){
if (typeof(v[p]) == "number"){
this.tweens[this.tweens.length] = {o:this.target, p:p, s:this.target[p], c:(v[p] - this.target[p]), name:p};
} else {
this.tweens[this.tweens.length] = {o:this.target, p:p, s:this.target[p], c:Number(v[p]), name:p};
};
};
};
};
};
if (this.vars.runBackwards == true){
i = (this.tweens.length - 1);
while (i > -1) {
tp = this.tweens[i];
tp.s = (tp.s + tp.c);
tp.c = (tp.c * -1);
i--;
};
};
if ((((v.visible == true)) && (_isDisplayObject))){
this.target.visible = true;
};
if (this.vars.onUpdate != null){
_hasUpdate = true;
};
this.initted = true;
}
public function killVars($vars:Object):void{
if (overwriteManager.enabled){
overwriteManager.killVars($vars, this.vars, this.tweens, _subTweens, []);
};
}
public function complete($skipRender:Boolean=false):void{
if (!($skipRender)){
if (!(this.initted)){
initTweenVals();
};
this.startTime = (currentTime - ((this.duration * 1000) / this.combinedTimeScale));
render(currentTime);
return;
};
if (((!((this.vars.visible == undefined))) && (_isDisplayObject))){
if (((!(isNaN(this.vars.autoAlpha))) && ((this.target.alpha == 0)))){
this.target.visible = false;
} else {
if (this.vars.runBackwards != true){
this.target.visible = this.vars.visible;
};
};
};
if (this.vars.persist != true){
this.enabled = false;
};
if (this.vars.onComplete != null){
this.vars.onComplete.apply(null, this.vars.onCompleteParams);
};
}
public static function frameProxy($o:Object):void{
$o.info.target.gotoAndStop(Math.round($o.target.frame));
}
public static function removeTween($t:TweenLite, $clear:Boolean=true):void{
if (((!(($t == null))) && (!((masterList[$t.target] == undefined))))){
if ((($clear) && (!((masterList[$t.target][$t] == null))))){
masterList[$t.target][$t].clear();
};
$t.enabled = false;
};
}
public static function killTweensOf($tg:Object=null, $complete:Boolean=false):void{
var o:Object;
var tw:*;
if (((!(($tg == null))) && (!((masterList[$tg] == undefined))))){
o = masterList[$tg];
for (tw in o) {
if ($complete){
o[tw].complete(false);
};
o[tw].clear();
};
delete masterList[$tg];
};
}
public static function delayedCall($delay:Number, $onComplete:Function, $onCompleteParams:Array=null):TweenLite{
return (new TweenLite($onComplete, 0, {delay:$delay, onComplete:$onComplete, onCompleteParams:$onCompleteParams, overwrite:0}));
}
public static function from($target:Object, $duration:Number, $vars:Object):TweenLite{
$vars.runBackwards = true;
return (new TweenLite($target, $duration, $vars));
}
public static function executeAll($e:Event=null):void{
var t:uint;
var a:Dictionary;
var p:Object;
var tw:Object;
t = (currentTime = getTimer());
if (_listening){
a = masterList;
for each (p in a) {
for (tw in p) {
if (((!((p[tw] == undefined))) && (p[tw].active))){
p[tw].render(t);
};
};
};
};
}
public static function easeOut($t:Number, $b:Number, $c:Number, $d:Number):Number{
$t = ($t / $d);
return ((((-($c) * $t) * ($t - 2)) + $b));
}
public static function volumeProxy($o:Object):void{
$o.info.target.soundTransform = $o.target;
}
public static function killGarbage($e:TimerEvent):void{
var tg_cnt:uint;
var found:Boolean;
var p:Object;
var twp:Object;
var tw:Object;
tg_cnt = 0;
for (p in masterList) {
found = false;
for (twp in masterList[p]) {
found = true;
break;
};
if (!(found)){
delete masterList[p];
} else {
tg_cnt++;
};
};
if (tg_cnt == 0){
_timer.removeEventListener("timer", killGarbage);
_timer.stop();
_listening = false;
};
}
public static function tintProxy($o:Object):void{
var n:Number;
var r:Number;
var sc:Object;
var ec:Object;
n = $o.target.progress;
r = (1 - n);
sc = $o.info.color;
ec = $o.info.endColor;
$o.info.target.transform.colorTransform = new ColorTransform(((sc.redMultiplier * r) + (ec.redMultiplier * n)), ((sc.greenMultiplier * r) + (ec.greenMultiplier * n)), ((sc.blueMultiplier * r) + (ec.blueMultiplier * n)), ((sc.alphaMultiplier * r) + (ec.alphaMultiplier * n)), ((sc.redOffset * r) + (ec.redOffset * n)), ((sc.greenOffset * r) + (ec.greenOffset * n)), ((sc.blueOffset * r) + (ec.blueOffset * n)), ((sc.alphaOffset * r) + (ec.alphaOffset * n)));
}
public static function to($target:Object, $duration:Number, $vars:Object):TweenLite{
return (new TweenLite($target, $duration, $vars));
}
}
}//package gs
Section 82
//TweenMax (gs.TweenMax)
package gs {
import flash.utils.*;
import gs.events.*;
import flash.events.*;
public class TweenMax extends TweenFilterLite implements IEventDispatcher {
protected var _dispatcher:EventDispatcher;
protected var _callbacks:Object;
protected var _pauseTime:int;
protected static const _RAD2DEG:Number = 57.2957795130823;
public static var removeTween:Function = TweenLite.removeTween;
private static var _overwriteMode:int = (OverwriteManager.enabled) ? OverwriteManager.mode : OverwriteManager.init();
;
public static var setGlobalTimeScale:Function = TweenFilterLite.setGlobalTimeScale;
public static var killTweensOf:Function = TweenLite.killTweensOf;
public static var version:Number = 3.04;
public static var killDelayedCallsTo:Function = TweenLite.killTweensOf;
public function TweenMax($target:Object, $duration:Number, $vars:Object){
super($target, $duration, $vars);
_pauseTime = -1;
if (((((!((this.vars.onCompleteListener == null))) || (!((this.vars.onUpdateListener == null))))) || (!((this.vars.onStartListener == null))))){
initDispatcher();
if (((($duration == 0)) && ((this.delay == 0)))){
onUpdateDispatcher();
onCompleteDispatcher();
};
};
if ((((this.vars.yoyo == true)) || ((this.vars.loop == true)))){
this.vars.persist = true;
};
if (TweenFilterLite.version < 9.03){
trace("TweenMax error! Please update your TweenFilterLite class or try deleting your ASO files. TweenMax requires a more recent version. Download updates at http://www.TweenMax.com.");
};
}
public function set reversed($b:Boolean):void{
if (this.reversed != $b){
reverse();
};
}
protected function onCompleteDispatcher(... _args):void{
if (_callbacks.onComplete != null){
_callbacks.onComplete.apply(null, this.vars.onCompleteParams);
};
_dispatcher.dispatchEvent(new TweenEvent(TweenEvent.COMPLETE));
}
override public function get active():Boolean{
if (this.forceActive){
return (true);
};
if (_pauseTime != -1){
return (false);
};
if (currentTime >= this.startTime){
this.forceActive = true;
if (!(this.initted)){
initTweenVals();
} else {
if (((!((this.vars.visible == undefined))) && (_isDisplayObject))){
this.target.visible = true;
};
};
if (this.vars.onStart != null){
this.vars.onStart.apply(null, this.vars.onStartParams);
};
if (this.duration == 0.001){
this.startTime = (this.startTime - 1);
};
return (true);
//unresolved jump
};
return (false);
}
protected function adjustStartValues():void{
var p:Number;
var factor:Number;
var endValue:Number;
var tp:Object;
var i:int;
p = this.progress;
if (p != 0){
factor = (1 / (1 - this.ease((p * this.duration), 0, 1, this.duration)));
i = (this.tweens.length - 1);
while (i > -1) {
tp = this.tweens[i];
endValue = (tp.s + tp.c);
tp.c = ((endValue - tp.o[tp.p]) * factor);
tp.s = (endValue - tp.c);
i--;
};
};
}
public function resume():void{
var d:Number;
var started:Boolean;
if (_pauseTime != -1){
d = (this.delay * (1000 / this.combinedTimeScale));
started = (_pauseTime > (this.initTime + d));
this.initTime = (this.initTime + (currentTime - _pauseTime));
this.startTime = (this.initTime + d);
_pauseTime = -1;
if (((!(started)) && ((currentTime >= this.startTime)))){
started = this.active;
} else {
this.forceActive = started;
};
};
this.enabled = true;
}
public function get paused():Boolean{
return (!((_pauseTime == -1)));
}
public function restart($includeDelay:Boolean=false):void{
if ($includeDelay){
this.initTime = currentTime;
this.startTime = (currentTime + (this.delay * (1000 / this.combinedTimeScale)));
} else {
this.startTime = currentTime;
this.initTime = (currentTime - (this.delay * (1000 / this.combinedTimeScale)));
};
if (this.target != this.vars.onComplete){
render(this.startTime);
};
_pauseTime = -1;
this.enabled = true;
}
public function get progress():Number{
var t:Number;
var p:Number;
t = ((_pauseTime)!=-1) ? _pauseTime : currentTime;
p = (((((t - this.initTime) / 1000) - (this.delay / this.combinedTimeScale)) / this.duration) * this.combinedTimeScale);
if (p > 1){
return (1);
};
if (p < 0){
return (0);
};
return (p);
}
override public function complete($skipRender:Boolean=false):void{
if ((((this.vars.yoyo == true)) || ((this.vars.loop == true)))){
if (this.vars.yoyo == true){
this.ease = ((this.vars.ease)==this.ease) ? reverseEase : this.vars.ease;
};
this.startTime = currentTime;
this.initTime = (this.startTime - (this.delay * (1000 / this.combinedTimeScale)));
} else {
if (this.vars.persist == true){
pause();
};
};
super.complete($skipRender);
}
public function invalidate($adjustStartValues:Boolean=true):void{
var p:Number;
if (this.initted){
p = this.progress;
if (((!($adjustStartValues)) && (!((p == 0))))){
this.progress = 0;
};
this.tweens = [];
_subTweens = [];
initTweenVals();
_timeScale = ((this.vars.timeScale) || (1));
this.combinedTimeScale = (_timeScale * _globalTimeScale);
this.delay = ((this.vars.delay) || (0));
if (_pauseTime == -1){
this.startTime = (this.initTime + ((this.delay * 1000) / this.combinedTimeScale));
};
if (((((!((this.vars.onCompleteListener == null))) || (!((this.vars.onUpdateListener == null))))) || (!((this.vars.onStartListener == null))))){
if (_dispatcher != null){
this.vars.onStart = _callbacks.onStart;
this.vars.onUpdate = _callbacks.onUpdate;
this.vars.onComplete = _callbacks.onComplete;
_dispatcher = null;
};
initDispatcher();
};
if (p != 0){
if ($adjustStartValues){
adjustStartValues();
} else {
this.progress = p;
};
};
};
}
public function willTrigger($type:String):Boolean{
if (_dispatcher == null){
return (false);
};
return (_dispatcher.willTrigger($type));
}
public function get reversed():Boolean{
return ((this.ease == reverseEase));
}
public function reverseEase($t:Number, $b:Number, $c:Number, $d:Number):Number{
return (this.vars.ease(($d - $t), $b, $c, $d));
}
public function dispatchEvent($e:Event):Boolean{
if (_dispatcher == null){
return (false);
};
return (_dispatcher.dispatchEvent($e));
}
protected function onStartDispatcher(... _args):void{
if (_callbacks.onStart != null){
_callbacks.onStart.apply(null, this.vars.onStartParams);
};
_dispatcher.dispatchEvent(new TweenEvent(TweenEvent.START));
}
public function setDestination($property:String, $value, $adjustStartValues:Boolean=true):void{
var p:Number;
var v:Object;
var i:int;
var varsOld:Object;
var tweensOld:Array;
var subTweensOld:Array;
p = this.progress;
if (((!((this.vars[$property] == undefined))) && (this.initted))){
if (((!($adjustStartValues)) && (!((p == 0))))){
i = (this.tweens.length - 1);
while (i > -1) {
if (this.tweens[i].name == $property){
this.tweens[i].o[this.tweens[i].p] = this.tweens[i].s;
};
i--;
};
};
v = {};
v[$property] = 1;
killVars(v);
};
this.vars[$property] = $value;
if (this.initted){
varsOld = this.vars;
tweensOld = this.tweens;
subTweensOld = _subTweens;
this.vars = {};
this.tweens = [];
_subTweens = [];
this.vars[$property] = $value;
initTweenVals();
if (((!((this.ease == reverseEase))) && ((varsOld.ease is Function)))){
this.ease = varsOld.ease;
};
if ((($adjustStartValues) && (!((p == 0))))){
adjustStartValues();
};
this.vars = varsOld;
this.tweens = tweensOld.concat(this.tweens);
_subTweens = subTweensOld.concat(_subTweens);
};
}
override public function initTweenVals($hrp:Boolean=false, $reservedProps:String=""):void{
var p:String;
var i:int;
var curProp:Object;
var props:Object;
var b:Array;
var bProxy:Function;
$reservedProps = ($reservedProps + " hexColors bezier bezierThrough orientToBezier quaternions onCompleteAll onCompleteAllParams yoyo loop onCompleteListener onUpdateListener onStartListener ");
if (((((!($hrp)) && (!((this.delay == 0))))) && (TweenLite.overwriteManager.enabled))){
TweenLite.overwriteManager.manageOverwrites(this, masterList[this.target]);
};
bProxy = bezierProxy;
if (this.vars.orientToBezier == true){
this.vars.orientToBezier = [["x", "y", "rotation", 0]];
bProxy = bezierProxy2;
} else {
if ((this.vars.orientToBezier is Array)){
bProxy = bezierProxy2;
};
};
if (((!((this.vars.bezier == undefined))) && ((this.vars.bezier is Array)))){
props = {};
b = this.vars.bezier;
i = 0;
while (i < b.length) {
for (p in b[i]) {
if (props[p] == undefined){
props[p] = [this.target[p]];
};
if (typeof(b[i][p]) == "number"){
props[p].push(b[i][p]);
} else {
props[p].push((this.target[p] + Number(b[i][p])));
};
};
i++;
};
for (p in props) {
if (typeof(this.vars[p]) == "number"){
props[p].push(this.vars[p]);
} else {
props[p].push((this.target[p] + Number(this.vars[p])));
};
delete this.vars[p];
};
addSubTween("bezier", bProxy, {t:0}, {t:1}, {props:parseBeziers(props, false), target:this.target, orientToBezier:this.vars.orientToBezier});
};
if (((!((this.vars.bezierThrough == undefined))) && ((this.vars.bezierThrough is Array)))){
props = {};
b = this.vars.bezierThrough;
i = 0;
while (i < b.length) {
for (p in b[i]) {
if (props[p] == undefined){
props[p] = [this.target[p]];
};
if (typeof(b[i][p]) == "number"){
props[p].push(b[i][p]);
} else {
props[p].push((this.target[p] + Number(b[i][p])));
};
};
i++;
};
for (p in props) {
if (typeof(this.vars[p]) == "number"){
props[p].push(this.vars[p]);
} else {
props[p].push((this.target[p] + Number(this.vars[p])));
};
delete this.vars[p];
};
addSubTween("bezierThrough", bProxy, {t:0}, {t:1}, {props:parseBeziers(props, true), target:this.target, orientToBezier:this.vars.orientToBezier});
};
if (((!((this.vars.hexColors == undefined))) && ((typeof(this.vars.hexColors) == "object")))){
for (p in this.vars.hexColors) {
addSubTween("hexColors", hexColorsProxy, {r:(this.target[p] >> 16), g:((this.target[p] >> 8) & 0xFF), b:(this.target[p] & 0xFF)}, {r:(this.vars.hexColors[p] >> 16), g:((this.vars.hexColors[p] >> 8) & 0xFF), b:(this.vars.hexColors[p] & 0xFF)}, {prop:p, target:this.target});
};
};
super.initTweenVals(true, $reservedProps);
}
protected function initDispatcher():void{
var v:Object;
var p:String;
if (_dispatcher == null){
_dispatcher = new EventDispatcher(this);
_callbacks = {onStart:this.vars.onStart, onUpdate:this.vars.onUpdate, onComplete:this.vars.onComplete};
v = {};
for (p in this.vars) {
v[p] = this.vars[p];
};
this.vars = v;
this.vars.onStart = onStartDispatcher;
this.vars.onComplete = onCompleteDispatcher;
if ((this.vars.onStartListener is Function)){
_dispatcher.addEventListener(TweenEvent.START, this.vars.onStartListener, false, 0, true);
};
if ((this.vars.onUpdateListener is Function)){
_dispatcher.addEventListener(TweenEvent.UPDATE, this.vars.onUpdateListener, false, 0, true);
this.vars.onUpdate = onUpdateDispatcher;
_hasUpdate = true;
};
if ((this.vars.onCompleteListener is Function)){
_dispatcher.addEventListener(TweenEvent.COMPLETE, this.vars.onCompleteListener, false, 0, true);
};
};
}
public function removeEventListener($type:String, $listener:Function, $useCapture:Boolean=false):void{
if (_dispatcher != null){
_dispatcher.removeEventListener($type, $listener, $useCapture);
};
}
public function killProperties($names:Array):void{
var v:Object;
var i:int;
v = {};
i = ($names.length - 1);
while (i > -1) {
if (this.vars[$names[i]] != null){
v[$names[i]] = 1;
};
i--;
};
killVars(v);
}
public function set progress($n:Number):void{
var b:Boolean;
var v:*;
this.startTime = (currentTime - ((this.duration * $n) * 1000));
this.initTime = (this.startTime - (this.delay * (1000 / this.combinedTimeScale)));
b = this.active;
render(currentTime);
if (_pauseTime != -1){
_pauseTime = currentTime;
this.startTime = 999999999999999;
};
v = this.vars.visible;
if (this.vars.isTV == true){
v = this.vars.exposedProps.visible;
};
if (((((!((v == null))) && (_isDisplayObject))) && (($n < 1)))){
this.target.visible = Boolean(v);
};
}
public function reverse($adjustDuration:Boolean=true, $forcePlay:Boolean=true):void{
var p:Number;
this.ease = ((this.vars.ease)==this.ease) ? reverseEase : this.vars.ease;
p = this.progress;
if ((($adjustDuration) && ((p > 0)))){
this.startTime = (currentTime - ((((1 - p) * this.duration) * 1000) / this.combinedTimeScale));
this.initTime = (this.startTime - (this.delay * (1000 / this.combinedTimeScale)));
};
if ($forcePlay != false){
if (p < 1){
resume();
} else {
restart();
};
};
}
public function set paused($b:Boolean):void{
if ($b){
pause();
} else {
resume();
};
}
public function addEventListener($type:String, $listener:Function, $useCapture:Boolean=false, $priority:int=0, $useWeakReference:Boolean=false):void{
if (_dispatcher == null){
initDispatcher();
};
if (((($type == TweenEvent.UPDATE)) && (!((this.vars.onUpdate == onUpdateDispatcher))))){
this.vars.onUpdate = onUpdateDispatcher;
_hasUpdate = true;
};
_dispatcher.addEventListener($type, $listener, $useCapture, $priority, $useWeakReference);
}
protected function onUpdateDispatcher(... _args):void{
if (_callbacks.onUpdate != null){
_callbacks.onUpdate.apply(null, this.vars.onUpdateParams);
};
_dispatcher.dispatchEvent(new TweenEvent(TweenEvent.UPDATE));
}
public function hasEventListener($type:String):Boolean{
if (_dispatcher == null){
return (false);
};
return (_dispatcher.hasEventListener($type));
}
public function pause():void{
if (_pauseTime == -1){
_pauseTime = currentTime;
this.startTime = 999999999999999;
this.forceActive = false;
};
}
public static function sequence($target:Object, $tweens:Array):Array{
trace("WARNING: TweenMax.sequence() has been deprecated in favor of the much more powerful and flexible TweenGroup class. See http://blog.greensock.com/tweengroup/ for more details.");
return ([]);
}
public static function bezierProxy($o:Object):void{
var factor:Number;
var props:Object;
var tg:Object;
var i:int;
var p:String;
var b:Object;
var t:Number;
var segments:uint;
factor = $o.target.t;
props = $o.info.props;
tg = $o.info.target;
if (factor == 1){
for (p in props) {
i = (props[p].length - 1);
tg[p] = props[p][i].e;
};
} else {
for (p in props) {
segments = props[p].length;
if (factor < 0){
i = 0;
} else {
if (factor >= 1){
i = (segments - 1);
} else {
i = int((segments * factor));
};
};
t = ((factor - (i * (1 / segments))) * segments);
b = props[p][i];
tg[p] = (b.s + (t * (((2 * (1 - t)) * (b.cp - b.s)) + (t * (b.e - b.s)))));
};
};
}
public static function hexColorsProxy($o:Object):void{
$o.info.target[$o.info.prop] = uint(((($o.target.r << 16) | ($o.target.g << 8)) | $o.target.b));
}
public static function parseBeziers($props:Object, $through:Boolean=false):Object{
var i:int;
var a:Array;
var b:Object;
var p:String;
var all:Object;
all = {};
if ($through){
for (p in $props) {
a = $props[p];
b = [];
all[p] = b;
if (a.length > 2){
b[b.length] = {s:a[0], cp:(a[1] - ((a[2] - a[0]) / 4)), e:a[1]};
i = 1;
while (i < (a.length - 1)) {
b[b.length] = {s:a[i], cp:(a[i] + (a[i] - b[(i - 1)].cp)), e:a[(i + 1)]};
i++;
};
} else {
b[b.length] = {s:a[0], cp:((a[0] + a[1]) / 2), e:a[1]};
};
};
} else {
for (p in $props) {
a = $props[p];
b = [];
all[p] = b;
if (a.length > 3){
b[b.length] = {s:a[0], cp:a[1], e:((a[1] + a[2]) / 2)};
i = 2;
while (i < (a.length - 2)) {
b.push({s:b[(i - 2)].e, cp:a[i], e:((a[i] + a[(i + 1)]) / 2)});
i++;
};
b[b.length] = {s:b[(b.length - 1)].e, cp:a[(a.length - 2)], e:a[(a.length - 1)]};
} else {
if (a.length == 3){
b[b.length] = {s:a[0], cp:a[1], e:a[2]};
} else {
if (a.length == 2){
b[b.length] = {s:a[0], cp:((a[0] + a[1]) / 2), e:a[1]};
};
};
};
};
};
return (all);
}
public static function bezierProxy2($o:Object):void{
var future:Object;
var tg:Object;
var otb:Array;
var a:Number;
var dx:Number;
var dy:Number;
var cotb:Array;
var toAdd:Number;
var i:uint;
bezierProxy($o);
future = {};
tg = $o.info.target;
$o.info.target = future;
$o.target.t = ($o.target.t + 0.01);
bezierProxy($o);
otb = $o.info.orientToBezier;
i = 0;
while (i < otb.length) {
cotb = otb[i];
toAdd = ((cotb[3]) || (0));
dx = (future[cotb[0]] - tg[cotb[0]]);
dy = (future[cotb[1]] - tg[cotb[1]]);
tg[cotb[2]] = ((Math.atan2(dy, dx) * _RAD2DEG) + toAdd);
i++;
};
$o.info.target = tg;
$o.target.t = ($o.target.t - 0.01);
}
public static function pauseAll($tweens:Boolean=true, $delayedCalls:Boolean=false):void{
changePause(true, $tweens, $delayedCalls);
}
public static function set globalTimeScale($n:Number):void{
setGlobalTimeScale($n);
}
public static function get globalTimeScale():Number{
return (_globalTimeScale);
}
public static function getTweensOf($target:Object):Array{
var t:Dictionary;
var a:Array;
var p:Object;
t = masterList[$target];
a = [];
if (t != null){
for (p in t) {
if (t[p].tweens != undefined){
a[a.length] = t[p];
};
};
};
return (a);
}
public static function killAllDelayedCalls($complete:Boolean=false):void{
killAll($complete, false, true);
}
public static function multiSequence($tweens:Array):Array{
trace("WARNING: TweenMax.multiSequence() has been deprecated in favor of the much more powerful and flexible TweenGroup class. See http://blog.greensock.com/tweengroup/ for more details.");
return ([]);
}
public static function delayedCall($delay:Number, $onComplete:Function, $onCompleteParams:Array=null, $persist:Boolean=false):TweenMax{
return (new TweenMax($onComplete, 0, {delay:$delay, onComplete:$onComplete, onCompleteParams:$onCompleteParams, persist:$persist, overwrite:0}));
}
public static function isTweening($target:Object):Boolean{
var a:Array;
var i:int;
a = getTweensOf($target);
i = (a.length - 1);
while (i > -1) {
if (a[i].active){
return (true);
};
i--;
};
return (false);
}
public static function killAll($complete:Boolean=false, $tweens:Boolean=true, $delayedCalls:Boolean=true):void{
var a:Array;
var isDC:Boolean;
var i:int;
a = getAllTweens();
i = (a.length - 1);
while (i > -1) {
isDC = (a[i].target == a[i].vars.onComplete);
if ((((isDC == $delayedCalls)) || (!((isDC == $tweens))))){
if ($complete){
a[i].complete(false);
a[i].clear();
} else {
TweenLite.removeTween(a[i], true);
};
};
i--;
};
}
public static function changePause($pause:Boolean, $tweens:Boolean=true, $delayedCalls:Boolean=false):void{
var a:Array;
var isDC:Boolean;
var i:int;
a = getAllTweens();
i = (a.length - 1);
while (i > -1) {
isDC = (a[i].target == a[i].vars.onComplete);
if ((((a[i] is TweenMax)) && ((((isDC == $delayedCalls)) || (!((isDC == $tweens))))))){
a[i].paused = $pause;
};
i--;
};
}
public static function callbackProxy($functions:Array, $params:Array=null):void{
var i:uint;
i = 0;
while (i < $functions.length) {
if ($functions[i] != undefined){
$functions[i].apply(null, $params[i]);
};
i++;
};
}
public static function allFrom($targets:Array, $duration:Number, $vars:Object):Array{
$vars.runBackwards = true;
return (allTo($targets, $duration, $vars));
}
public static function from($target:Object, $duration:Number, $vars:Object):TweenMax{
$vars.runBackwards = true;
return (new TweenMax($target, $duration, $vars));
}
public static function killAllTweens($complete:Boolean=false):void{
killAll($complete, true, false);
}
public static function getAllTweens():Array{
var a:Dictionary;
var all:Array;
var p:Object;
var tw:Object;
a = masterList;
all = [];
for each (p in a) {
for (tw in p) {
if (p[tw] != undefined){
all[all.length] = p[tw];
};
};
};
return (all);
}
public static function resumeAll($tweens:Boolean=true, $delayedCalls:Boolean=false):void{
changePause(false, $tweens, $delayedCalls);
}
public static function to($target:Object, $duration:Number, $vars:Object):TweenMax{
return (new TweenMax($target, $duration, $vars));
}
public static function allTo($targets:Array, $duration:Number, $vars:Object):Array{
var i:int;
var v:Object;
var p:String;
var dl:Number;
var lastVars:Object;
var a:Array;
var dli:Number;
if ($targets.length == 0){
return ([]);
};
a = [];
dli = (($vars.delayIncrement) || (0));
delete $vars.delayIncrement;
if ($vars.onCompleteAll == undefined){
lastVars = $vars;
} else {
lastVars = {};
for (p in $vars) {
lastVars[p] = $vars[p];
};
lastVars.onCompleteParams = [[$vars.onComplete, $vars.onCompleteAll], [$vars.onCompleteParams, $vars.onCompleteAllParams]];
lastVars.onComplete = TweenMax.callbackProxy;
delete $vars.onCompleteAll;
};
delete $vars.onCompleteAllParams;
if (dli == 0){
i = 0;
while (i < ($targets.length - 1)) {
v = {};
for (p in $vars) {
v[p] = $vars[p];
};
a[a.length] = new TweenMax($targets[i], $duration, v);
i++;
};
} else {
dl = (($vars.delay) || (0));
i = 0;
while (i < ($targets.length - 1)) {
v = {};
for (p in $vars) {
v[p] = $vars[p];
};
v.delay = (dl + (i * dli));
a[a.length] = new TweenMax($targets[i], $duration, v);
i++;
};
lastVars.delay = (dl + (($targets.length - 1) * dli));
};
a[a.length] = new TweenMax($targets[($targets.length - 1)], $duration, lastVars);
if (($vars.onCompleteAllListener is Function)){
a[(a.length - 1)].addEventListener(TweenEvent.COMPLETE, $vars.onCompleteAllListener);
};
return (a);
}
}
}//package gs
Section 83
//boyThrowArm_53 (lib_fla.boyThrowArm_53)
package lib_fla {
import flash.display.*;
public dynamic class boyThrowArm_53 extends MovieClip {
public function boyThrowArm_53(){
super();
addFrameScript(0, frame1, 6, frame7);
}
function frame7(){
stop();
}
function frame1(){
stop();
}
}
}//package lib_fla
Section 84
//EndScreen1_39 (lib_fla.EndScreen1_39)
package lib_fla {
import flash.text.*;
import flash.display.*;
public dynamic class EndScreen1_39 extends MovieClip {
public var yourScore:TextField;
public function EndScreen1_39(){
super();
}
}
}//package lib_fla
Section 85
//gun_salve_01_67 (lib_fla.gun_salve_01_67)
package lib_fla {
import flash.display.*;
public dynamic class gun_salve_01_67 extends MovieClip {
public function gun_salve_01_67(){
super();
addFrameScript(14, frame15);
}
function frame15(){
stop();
}
}
}//package lib_fla
Section 86
//gun_salve_02_74 (lib_fla.gun_salve_02_74)
package lib_fla {
import flash.display.*;
public dynamic class gun_salve_02_74 extends MovieClip {
public function gun_salve_02_74(){
super();
addFrameScript(28, frame29);
}
function frame29(){
stop();
}
}
}//package lib_fla
Section 87
//gun_salve_04_80 (lib_fla.gun_salve_04_80)
package lib_fla {
import flash.display.*;
public dynamic class gun_salve_04_80 extends MovieClip {
public function gun_salve_04_80(){
super();
addFrameScript(19, frame20);
}
function frame20(){
stop();
}
}
}//package lib_fla
Section 88
//gunshotsSounds_01_73 (lib_fla.gunshotsSounds_01_73)
package lib_fla {
import flash.display.*;
public dynamic class gunshotsSounds_01_73 extends MovieClip {
public function gunshotsSounds_01_73(){
super();
addFrameScript(38, frame39);
}
function frame39(){
stop();
}
}
}//package lib_fla
Section 89
//gunshotsSounds_02_75 (lib_fla.gunshotsSounds_02_75)
package lib_fla {
import flash.display.*;
public dynamic class gunshotsSounds_02_75 extends MovieClip {
public function gunshotsSounds_02_75(){
super();
addFrameScript(38, frame39);
}
function frame39(){
stop();
}
}
}//package lib_fla
Section 90
//gunshotsSounds_03_79 (lib_fla.gunshotsSounds_03_79)
package lib_fla {
import flash.display.*;
public dynamic class gunshotsSounds_03_79 extends MovieClip {
public function gunshotsSounds_03_79(){
super();
addFrameScript(38, frame39);
}
function frame39(){
stop();
}
}
}//package lib_fla
Section 91
//HUD_64 (lib_fla.HUD_64)
package lib_fla {
import flash.display.*;
public dynamic class HUD_64 extends MovieClip {
public function HUD_64(){
super();
addFrameScript(59, frame60);
}
function frame60(){
stop();
}
}
}//package lib_fla
Section 92
//InputFix_1 (lib_fla.InputFix_1)
package lib_fla {
import flash.display.*;
public dynamic class InputFix_1 extends MovieClip {
public function InputFix_1(){
super();
addFrameScript(0, frame1);
}
function frame1(){
alpha = 0;
}
}
}//package lib_fla
Section 93
//obsticle_03_broken_69 (lib_fla.obsticle_03_broken_69)
package lib_fla {
import flash.display.*;
public dynamic class obsticle_03_broken_69 extends MovieClip {
public function obsticle_03_broken_69(){
super();
addFrameScript(74, frame75);
}
function frame75(){
stop();
}
}
}//package lib_fla
Section 94
//spaceship_65 (lib_fla.spaceship_65)
package lib_fla {
import flash.display.*;
public dynamic class spaceship_65 extends MovieClip {
public function spaceship_65(){
super();
addFrameScript(96, frame97);
}
function frame97(){
stop();
}
}
}//package lib_fla
Section 95
//xplosion_01_72 (lib_fla.xplosion_01_72)
package lib_fla {
import flash.display.*;
public dynamic class xplosion_01_72 extends MovieClip {
public function xplosion_01_72(){
super();
addFrameScript(21, frame22);
}
function frame22(){
stop();
}
}
}//package lib_fla
Section 96
//xplosion_02_78 (lib_fla.xplosion_02_78)
package lib_fla {
import flash.display.*;
public dynamic class xplosion_02_78 extends MovieClip {
public function xplosion_02_78(){
super();
addFrameScript(21, frame22);
}
function frame22(){
stop();
}
}
}//package lib_fla
Section 97
//xplosion_03_81 (lib_fla.xplosion_03_81)
package lib_fla {
import flash.display.*;
public dynamic class xplosion_03_81 extends MovieClip {
public function xplosion_03_81(){
super();
addFrameScript(21, frame22);
}
function frame22(){
stop();
}
}
}//package lib_fla
Section 98
//Scrollbar (ppstudio.Scrollbar)
package ppstudio {
import flash.display.*;
import flash.filters.*;
import flash.events.*;
import flash.geom.*;
public class Scrollbar extends MovieClip {
private var _ruler:MovieClip;
private var contentstarty:Number;
private var bf:BlurFilter;
private var minY:Number;
private var _dragged:MovieClip;
private var _hitarea:MovieClip;
private var maxY:Number;
private var _initY:Number;
private var _blurred:Boolean;
private var _YFactor:Number;
private var percentuale:uint;
private var _background:MovieClip;
private var _mask:MovieClip;
private var initialized:Boolean;// = false
public function Scrollbar(dragged:MovieClip, maskclip:MovieClip, ruler:MovieClip, background:MovieClip, hitarea:MovieClip, blurred:Boolean=false, yfactor:Number=4){
initialized = false;
super();
_dragged = dragged;
_mask = maskclip;
_ruler = ruler;
_background = background;
_hitarea = (hitarea as MovieClip);
trace(_hitarea);
_blurred = blurred;
_YFactor = yfactor;
}
public function set ruler(v:MovieClip):void{
_ruler = v;
}
public function init(e:Event=null):void{
if (checkPieces() == false){
trace("SCROLLBAR: CANNOT INITIALIZE");
} else {
if (initialized == true){
reset();
};
bf = new BlurFilter(0, 0, 1);
this._dragged.filters = new Array(bf);
this._dragged.mask = this._mask;
this._dragged.cacheAsBitmap = true;
this.minY = _background.y;
this._ruler.buttonMode = true;
this.contentstarty = _dragged.y;
_ruler.addEventListener(MouseEvent.MOUSE_DOWN, clickHandle);
Main.STAGE.addEventListener(MouseEvent.MOUSE_UP, releaseHandle);
Main.STAGE.addEventListener(MouseEvent.MOUSE_WHEEL, wheelHandle, true);
this.addEventListener(Event.ENTER_FRAME, enterFrameHandle);
initialized = true;
};
}
private function releaseHandle(e:MouseEvent):void{
_ruler.stopDrag();
}
public function set dragged(v:MovieClip):void{
_dragged = v;
}
public function positionContent():void{
var upY:Number;
var downY:Number;
var curY:Number;
var limit:Number;
var fx:Number;
var curry:Number;
var finalx:Number;
var diff:Number;
var bfactor:Number;
this._ruler.height = ((this._mask.height / this._dragged.height) * this._background.height);
this.maxY = (this._background.height - this._ruler.height);
limit = (this._background.height - this._ruler.height);
if (this._ruler.y > limit){
this._ruler.y = limit;
};
checkContentLength();
percentuale = ((100 / maxY) * _ruler.y);
upY = 0;
downY = (_dragged.height - (_mask.height / 2));
fx = (contentstarty - (((downY - (_mask.height / 2)) / 100) * percentuale));
curry = _dragged.y;
finalx = fx;
if (curry != finalx){
diff = (finalx - curry);
curry = (curry + (diff / _YFactor));
bfactor = (Math.abs(diff) / 8);
bf.blurY = (bfactor / 2);
if (_blurred == true){
_dragged.filters = new Array(bf);
};
};
_dragged.y = curry;
}
private function scrollData(q:int):void{
var d:Number;
var rulerY:Number;
var quantity:Number;
quantity = (this._ruler.height / 5);
d = (-(q) * Math.abs(quantity));
if (d > 0){
rulerY = Math.min(maxY, (_ruler.y + d));
};
if (d < 0){
rulerY = Math.max(minY, (_ruler.y + d));
};
_ruler.y = rulerY;
positionContent();
}
public function set background(v:MovieClip):void{
_background = v;
}
private function wheelHandle(e:MouseEvent):void{
if (this._hitarea.hitTestPoint(stage.mouseX, stage.mouseY, false)){
scrollData(e.delta);
};
}
public function set hitarea(v:MovieClip):void{
_hitarea = v;
}
public function reset():void{
_dragged.y = contentstarty;
_ruler.y = 0;
}
private function checkPieces():Boolean{
var ok:Boolean;
ok = true;
if (_dragged == null){
trace("SCROLLBAR: DRAGGED not set");
ok = false;
};
if (_mask == null){
trace("SCROLLBAR: MASK not set");
ok = false;
};
if (_ruler == null){
trace("SCROLLBAR: RULER not set");
ok = false;
};
if (_background == null){
trace("SCROLLBAR: BACKGROUND not set");
ok = false;
};
if (_hitarea == null){
trace("SCROLLBAR: HITAREA not set");
ok = false;
};
return (ok);
}
public function set maskclip(v:MovieClip):void{
_mask = v;
}
public function checkContentLength():void{
if (_dragged.height < _mask.height){
_ruler.visible = false;
reset();
} else {
_ruler.visible = true;
};
}
private function clickHandle(e:MouseEvent):void{
var rect:Rectangle;
rect = new Rectangle((_background.x - (_ruler.width / 2)), minY, 0, maxY);
_ruler.startDrag(false, rect);
}
private function enterFrameHandle(e:Event):void{
positionContent();
}
}
}//package ppstudio
Section 99
//SideScroll (ppstudio.SideScroll)
package ppstudio {
import flash.display.*;
public class SideScroll extends Sprite {
var background:Array;
var staticBg:Sprite;
var middleground:Array;
var forground:Array;
public function SideScroll(){
forground = new Array();
background = new Array();
middleground = new Array();
staticBg = new StaticBg();
super();
forground = [new Foreground(), new Foreground()];
background = [new Background(), new Background()];
middleground = [new Middleground(), new Middleground()];
addChild(staticBg);
addChild(background[0]);
addChild(background[1]);
addChild(middleground[0]);
addChild(middleground[1]);
addChild(forground[0]);
addChild(forground[1]);
forground[1].x = forground[0].width;
forground[0].y = 250;
forground[1].y = 250;
background[1].x = background[0].width;
background[0].y = 110;
background[1].y = 110;
middleground[1].x = middleground[0].width;
forground[0].cacheAsBitmap = true;
forground[1].cacheAsBitmap = true;
background[0].cacheAsBitmap = true;
background[1].cacheAsBitmap = true;
middleground[0].cacheAsBitmap = true;
middleground[1].cacheAsBitmap = true;
}
public function setScroll(offset:Number){
if (forground[0].x < -(forground[0].width)){
forground[0].x = (forground[1].width + forground[1].x);
};
if (forground[1].x < -(forground[0].width)){
forground[1].x = (forground[0].width + forground[0].x);
};
forground[0].x = (forground[0].x - (offset * 0.2));
forground[1].x = (forground[1].x - (offset * 0.2));
if (background[0].x < -(background[0].width)){
background[0].x = (background[1].width + background[1].x);
};
if (background[1].x < -(background[0].width)){
background[1].x = (background[0].width + background[0].x);
};
background[0].x = (background[0].x - (offset * 0.1));
background[1].x = (background[1].x - (offset * 0.1));
if (middleground[0].x < -(middleground[0].width)){
middleground[0].x = (middleground[1].width + middleground[1].x);
};
if (middleground[1].x < -(middleground[0].width)){
middleground[1].x = (middleground[0].width + middleground[0].x);
};
middleground[0].x = (middleground[0].x - (offset * 0.5));
middleground[1].x = (middleground[1].x - (offset * 0.5));
}
public function destroy(){
var i:Number;
i = numChildren;
while (i > 0) {
removeChildAt((i - 1));
i--;
};
}
}
}//package ppstudio
Section 100
//Snow (ppstudio.Snow)
package ppstudio {
import flash.display.*;
import flash.events.*;
public class Snow extends MovieClip {
public var wind:Number;
private var flakes:Array;
private var n:Number;
private var _height:Number;
private var _width:Number;
public function Snow(n:Number, __width:Number, __height:Number, _wind:Number=1){
var i:Number;
super();
_width = __width;
_height = __height;
wind = _wind;
flakes = new Array();
i = 0;
while (i < n) {
flakes[i] = new SnowFlake(_width, _height, this);
addChild(flakes[i]);
i++;
};
}
public function destroy():void{
var i:Number;
i = 0;
while (i < flakes.length) {
(flakes[i] as MovieClip).removeEventListener(Event.ENTER_FRAME, flakes[i].onEnterFrame);
removeChild(flakes[i]);
i++;
};
}
public function setWind(wind:Number):void{
this.wind = wind;
}
}
}//package ppstudio
Section 101
//SnowFlake (ppstudio.SnowFlake)
package ppstudio {
import flash.events.*;
import flash.display.*;
public class SnowFlake extends MovieClip {
private var wind:Number;
private var rad:Number;
private var i:Number;
private var k:Number;
private var w:Number;
private var h:Number;
private var _parent:Object;
public function SnowFlake(_width:Number, _height:Number, __parent:Object):void{
super();
_parent = __parent;
addChild(new SnowflakeMc());
w = _width;
h = _height;
x = 10;
y = 10;
scaleX = (1 + (4 * Math.random()));
scaleY = scaleX;
x = (-(w) + (Math.random() * (3 * w)));
y = (-10 + (Math.random() * h));
i = (1 + (Math.random() * 2));
k = (-(Math.PI) + (Math.random() * Math.PI));
rad = 0;
this.addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
public function onEnterFrame(evt:Event){
rad = (rad + ((k / 180) * Math.PI));
x = (x - (Math.cos(rad) + _parent.wind));
this.y = (this.y + i);
if (this.x > (w + 50)){
this.x = -45;
this.y = ((Math.random() * h) * 2);
};
if (this.x < -50){
this.x = (w + 45);
this.y = ((Math.random() * h) * 2);
};
if (this.y >= h){
this.y = -50;
this.x = (-(w) + (Math.random() * (3 * w)));
};
}
}
}//package ppstudio
Section 102
//UserData (ppstudio.UserData)
package ppstudio {
import flash.net.*;
public class UserData {
public static var highScoreSO:SharedObject;
public function UserData(){
super();
trace("userData");
highScoreSO = SharedObject.getLocal("highscore");
if (highScoreSO.data.highscore == undefined){
highScoreSO.data.highscore = 0;
};
}
public static function getScore():Number{
if (highScoreSO == null){
highScoreSO = SharedObject.getLocal("highscore");
if (highScoreSO.data.highscore == undefined){
highScoreSO.data.highscore = 0;
};
};
return (highScoreSO.data.highscore);
}
public static function setScore(_scr:Number):void{
if (_scr > highScoreSO.data.highscore){
highScoreSO.data.highscore = _scr;
highScoreSO.flush();
};
}
}
}//package ppstudio
Section 103
//Decapitation (TestBed.Decapitation)
package TestBed {
import gs.*;
import gs.easing.*;
import flash.utils.*;
import flash.events.*;
import flash.display.*;
public class Decapitation extends McDecapitation {
var timer:Timer;
var parentMovie:MovieClip;
public function Decapitation(_parentMovie:MovieClip, time:int=1000){
super();
trace(("Decapitation created. parent movie: " + _parentMovie));
TweenMax.to(this, 0, {x:300, y:-200});
TweenMax.to(this, 1, {x:300, y:150, ease:Elastic.easeOut});
timer = new Timer(time);
timer.start();
parentMovie = _parentMovie;
parentMovie.addChild(this);
timer.addEventListener(TimerEvent.TIMER, destroy);
}
private function destroy(e:TimerEvent):void{
timer.stop();
trace("removing decapitation");
TweenMax.to(this, 1, {x:300, y:350, ease:Back.easeIn});
}
}
}//package TestBed
Section 104
//highscoreEntry (TestBed.highscoreEntry)
package TestBed {
public class highscoreEntry {
public var score:int;
public var name:String;
public function highscoreEntry(_name:String, _score:int):void{
super();
name = _name;
score = _score;
}
}
}//package TestBed
Section 105
//HitMultiplier (TestBed.HitMultiplier)
package TestBed {
import flash.utils.*;
import flash.events.*;
import gs.*;
public class HitMultiplier extends McHitMultiplier {
private const fadeTime:int = 2000;
private var multiplierMax:int;// = 2147483647
private var timer:Timer;
private var multiplier:int;// = 1
public function HitMultiplier():void{
multiplierMax = int.MAX_VALUE;
multiplier = 1;
super();
timer = new Timer(fadeTime);
alpha = 0;
}
public function miss():void{
}
public function hit():void{
if (multiplier < multiplierMax){
multiplier++;
};
this.counter.text = multiplier.toString();
timer.reset();
timer.start();
timer.addEventListener(TimerEvent.TIMER, time);
TweenMax.to(this, 0, {scaleX:1.5, scaleY:1.5, alpha:1});
TweenMax.to(this, ((fadeTime / 1000) + 1), {scaleX:0.5, scaleY:0.5, alpha:0});
}
public function getMultiplier():int{
return (multiplier);
}
private function time(e:TimerEvent):void{
timer.stop();
multiplier = 1;
this.counter.text = multiplier.toString();
TweenMax.to(this, 0, {scaleX:1.5, scaleY:1.5, alpha:1});
TweenMax.to(this, ((fadeTime / 1000) + 2), {scaleX:0.5, scaleY:0.5, alpha:0});
}
}
}//package TestBed
Section 106
//Splash (TestBed.Splash)
package TestBed {
import flash.events.*;
import flash.display.*;
public class Splash extends MovieClip {
private var splash:MovieClip;
private var main:Main;
public function Splash(_splash:MovieClip, _main:Main):void{
super();
main = _main;
trace("splash created");
splash = _splash;
addChild(splash);
splash.gotoAndPlay(0);
this.addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
public function destroy():void{
trace(("this.parent : " + this.parent));
if (getChildAt(0) != null){
trace("removing splash");
removeChildAt(0);
main.init();
};
}
public function onEnterFrame(e:Event):void{
trace(("splash.totalFrames : " + splash.totalFrames));
trace(("splash.currentFrame : " + splash.currentFrame));
if ((splash.currentFrame + 1) == splash.totalFrames){
splash.stop();
destroy();
removeEventListener(Event.ENTER_FRAME, onEnterFrame);
};
}
}
}//package TestBed
Section 107
//Test (TestBed.Test)
package TestBed {
import Engine.Collision.*;
import Engine.Common.Math.*;
import Engine.Collision.Shapes.*;
import Engine.Dynamics.*;
import Engine.Dynamics.Joints.*;
import Engine.Dynamics.Contacts.*;
import Engine.Common.*;
import flash.display.*;
import flash.utils.*;
import General.*;
public class Test {
public var m_world:b2World;
public var m_physScale:Number;// = 32
public var m_iterations:int;// = 10
private var mousePVec:b2Vec2;
public var m_timeStep:Number;// = 0.0416666666666667
public var m_sprite:Sprite;
public var m_bomb:b2Body;
public var m_mouseJoint:b2MouseJoint;
public static var mouseYWorldPhys:Number;
public static var mouseXWorldPhys:Number;
public static var mouseYWorld:Number;
public static var mouseXWorld:Number;
public function Test(){
var worldAABB:b2AABB;
var gravity:b2Vec2;
var doSleep:Boolean;
var wallSd:b2BoxDef;
var wallBd:*;
m_iterations = 10;
m_timeStep = (1 / 24);
m_physScale = 32;
mousePVec = new b2Vec2();
super();
worldAABB = new b2AABB();
worldAABB.minVertex.Set(-200, -100);
worldAABB.maxVertex.Set(Number.MAX_VALUE, 100);
gravity = new b2Vec2(0, 10);
doSleep = true;
m_world = new b2World(worldAABB, gravity, doSleep);
m_sprite = Main.m_sprite;
wallSd = new b2BoxDef();
wallSd.groupIndex = 2;
wallBd = new b2BodyDef();
wallBd.AddShape(wallSd);
wallSd.extents.Set((100 / m_physScale), ((300 / m_physScale) / 2));
wallBd.position.Set((-95 / m_physScale), ((300 / m_physScale) / 2));
m_world.CreateBody(wallBd);
wallSd.extents.Set(((0xFFFFFF / m_physScale) / 2), (100 / m_physScale));
wallBd.position.Set(((470 / m_physScale) / 2), (-95 / m_physScale));
wallBd.position.Set(((470 / m_physScale) / 2), ((300 + 85) / m_physScale));
wallSd.friction = 1;
m_world.CreateBody(wallBd);
}
public function DrawJoint(joint:b2Joint){
var b1:b2Body;
var b2:b2Body;
var x1:b2Vec2;
var x2:b2Vec2;
var p1:b2Vec2;
var p2:b2Vec2;
var _local8:b2PulleyJoint;
var _local9:b2Vec2;
var _local10:b2Vec2;
b1 = joint.m_body1;
b2 = joint.m_body2;
x1 = b1.m_position;
x2 = b2.m_position;
p1 = joint.GetAnchor1();
p2 = joint.GetAnchor2();
m_sprite.graphics.lineStyle(1, 4500223, (1 / 1));
switch (joint.m_type){
case b2Joint.e_distanceJoint:
case b2Joint.e_mouseJoint:
m_sprite.graphics.moveTo((p1.x * m_physScale), (p1.y * m_physScale));
m_sprite.graphics.lineTo((p2.x * m_physScale), (p2.y * m_physScale));
break;
case b2Joint.e_pulleyJoint:
_local8 = (joint as b2PulleyJoint);
_local9 = _local8.GetGroundPoint1();
_local10 = _local8.GetGroundPoint2();
m_sprite.graphics.moveTo((_local9.x * m_physScale), (_local9.y * m_physScale));
m_sprite.graphics.lineTo((p1.x * m_physScale), (p1.y * m_physScale));
m_sprite.graphics.moveTo((_local10.x * m_physScale), (_local10.y * m_physScale));
m_sprite.graphics.lineTo((p2.x * m_physScale), (p2.y * m_physScale));
break;
default:
if (b1 == m_world.m_groundBody){
m_sprite.graphics.moveTo((p1.x * m_physScale), (p1.y * m_physScale));
m_sprite.graphics.lineTo((x2.x * m_physScale), (x2.y * m_physScale));
} else {
if (b2 == m_world.m_groundBody){
m_sprite.graphics.moveTo((p1.x * m_physScale), (p1.y * m_physScale));
m_sprite.graphics.lineTo((x1.x * m_physScale), (x1.y * m_physScale));
} else {
m_sprite.graphics.moveTo((x1.x * m_physScale), (x1.y * m_physScale));
m_sprite.graphics.lineTo((p1.x * m_physScale), (p1.y * m_physScale));
m_sprite.graphics.lineTo((x2.x * m_physScale), (x2.y * m_physScale));
m_sprite.graphics.lineTo((p2.x * m_physScale), (p2.y * m_physScale));
};
};
};
}
public function DrawPairs(){
var bp:b2BroadPhase;
var invQ:b2Vec2;
var i:int;
var pair:b2Pair;
var id1:uint;
var id2:uint;
var p1:b2Proxy;
var p2:b2Proxy;
var b1:b2AABB;
var b2:b2AABB;
var x1:b2Vec2;
var x2:b2Vec2;
bp = m_world.m_broadPhase;
invQ = new b2Vec2();
invQ.Set((1 / bp.m_quantizationFactor.x), (1 / bp.m_quantizationFactor.y));
i = 0;
while (i < bp.m_pairManager.m_pairCount) {
pair = bp.m_pairManager.m_pairs[i];
id1 = pair.proxyId1;
id2 = pair.proxyId2;
p1 = bp.m_proxyPool[id1];
p2 = bp.m_proxyPool[id2];
b1 = new b2AABB();
b2 = new b2AABB();
b1.minVertex.x = (bp.m_worldAABB.minVertex.x + (invQ.x * bp.m_bounds[0][p1.lowerBounds[0]].value));
b1.minVertex.y = (bp.m_worldAABB.minVertex.y + (invQ.y * bp.m_bounds[1][p1.lowerBounds[1]].value));
b1.maxVertex.x = (bp.m_worldAABB.minVertex.x + (invQ.x * bp.m_bounds[0][p1.upperBounds[0]].value));
b1.maxVertex.y = (bp.m_worldAABB.minVertex.y + (invQ.y * bp.m_bounds[1][p1.upperBounds[1]].value));
b2.minVertex.x = (bp.m_worldAABB.minVertex.x + (invQ.x * bp.m_bounds[0][p2.lowerBounds[0]].value));
b2.minVertex.y = (bp.m_worldAABB.minVertex.y + (invQ.y * bp.m_bounds[1][p2.lowerBounds[1]].value));
b2.maxVertex.x = (bp.m_worldAABB.minVertex.x + (invQ.x * bp.m_bounds[0][p2.upperBounds[0]].value));
b2.maxVertex.y = (bp.m_worldAABB.minVertex.y + (invQ.y * bp.m_bounds[1][p2.upperBounds[1]].value));
x1 = b2Math.MulFV(0.5, b2Math.AddVV(b1.minVertex, b1.maxVertex));
x2 = b2Math.MulFV(0.5, b2Math.AddVV(b2.minVertex, b2.maxVertex));
m_sprite.graphics.lineStyle(1, 16720418, 1);
m_sprite.graphics.moveTo((x1.x * m_physScale), (x1.y * m_physScale));
m_sprite.graphics.lineTo((x2.x * m_physScale), (x2.y * m_physScale));
i++;
};
}
public function MouseDrag(){
var body:b2Body;
var md:b2MouseJointDef;
var p2:b2Vec2;
if (((Input.mouseDown) && (!(m_mouseJoint)))){
body = GetBodyAtMouse();
if (body){
md = new b2MouseJointDef();
md.body1 = m_world.m_groundBody;
md.body2 = body;
md.target.Set(body.m_position.x, body.m_position.y);
md.maxForce = (500 * body.m_mass);
md.timeStep = m_timeStep;
m_mouseJoint = (m_world.CreateJoint(md) as b2MouseJoint);
body.WakeUp();
};
};
if (!(Input.mouseDown)){
if (m_mouseJoint){
m_world.DestroyJoint(m_mouseJoint);
m_mouseJoint = null;
};
};
if (m_mouseJoint){
p2 = new b2Vec2(mouseXWorldPhys, mouseYWorldPhys);
m_mouseJoint.SetTarget(p2);
};
}
public function GetBodyAtMouse(includeStatic:Boolean=false):b2Body{
var aabb:b2AABB;
var k_maxCount:int;
var shapes:Array;
var count:int;
var body:b2Body;
var i:int;
var inside:Boolean;
mousePVec.Set(mouseXWorldPhys, mouseYWorldPhys);
aabb = new b2AABB();
aabb.minVertex.Set((mouseXWorldPhys - 0.001), (mouseYWorldPhys - 0.001));
aabb.maxVertex.Set((mouseXWorldPhys + 0.001), (mouseYWorldPhys + 0.001));
k_maxCount = 10;
shapes = new Array();
count = m_world.Query(aabb, shapes, k_maxCount);
body = null;
i = 0;
while (i < count) {
if ((((shapes[i].m_body.IsStatic() == false)) || (includeStatic))){
inside = shapes[i].TestPoint(mousePVec);
if (inside){
body = shapes[i].m_body;
break;
};
};
i++;
};
return (body);
}
public function DrawContacts(){
var c:b2Contact;
var ms:Array;
var i:int;
var m:b2Manifold;
var j:int;
var v:b2Vec2;
c = m_world.m_contactList;
while (c) {
ms = c.GetManifolds();
i = 0;
while (i < c.GetManifoldCount()) {
m = ms[i];
j = 0;
while (j < m.pointCount) {
m_sprite.graphics.lineStyle(m.points[j].normalImpulse, 1166591, 0.7);
v = m.points[j].position;
m_sprite.graphics.moveTo((v.x * m_physScale), (v.y * m_physScale));
m_sprite.graphics.lineTo((v.x * m_physScale), (v.y * m_physScale));
j++;
};
i++;
};
c = c.m_next;
};
}
public function DrawShape(shape:b2Shape){
var circle:b2CircleShape;
var pos:b2Vec2;
var r:Number;
var k_segments:Number;
var k_increment:Number;
var theta:Number;
var i:int;
var ax:b2Vec2;
var pos2:b2Vec2;
var d:b2Vec2;
var v:b2Vec2;
var poly:b2PolyShape;
var tV:b2Vec2;
switch (shape.m_type){
case b2Shape.e_circleShape:
circle = (shape as b2CircleShape);
pos = circle.m_position;
r = circle.m_radius;
k_segments = 16;
k_increment = ((2 * Math.PI) / k_segments);
m_sprite.graphics.lineStyle(1, 0xFFFFFF, 1);
m_sprite.graphics.moveTo(((pos.x + r) * m_physScale), (pos.y * m_physScale));
theta = 0;
i = 0;
while (i < k_segments) {
d = new b2Vec2((r * Math.cos(theta)), (r * Math.sin(theta)));
v = b2Math.AddVV(pos, d);
m_sprite.graphics.lineTo((v.x * m_physScale), (v.y * m_physScale));
theta = (theta + k_increment);
i++;
};
m_sprite.graphics.lineTo(((pos.x + r) * m_physScale), (pos.y * m_physScale));
m_sprite.graphics.moveTo((pos.x * m_physScale), (pos.y * m_physScale));
ax = circle.m_R.col1;
pos2 = new b2Vec2((pos.x + (r * ax.x)), (pos.y + (r * ax.y)));
m_sprite.graphics.lineTo((pos2.x * m_physScale), (pos2.y * m_physScale));
break;
case b2Shape.e_polyShape:
poly = (shape as b2PolyShape);
tV = b2Math.AddVV(poly.m_position, b2Math.b2MulMV(poly.m_R, poly.m_vertices[i]));
m_sprite.graphics.lineStyle(1, 0xFFFFFF, 1);
m_sprite.graphics.moveTo((tV.x * m_physScale), (tV.y * m_physScale));
i = 0;
while (i < poly.m_vertexCount) {
v = b2Math.AddVV(poly.m_position, b2Math.b2MulMV(poly.m_R, poly.m_vertices[i]));
m_sprite.graphics.lineTo((v.x * m_physScale), (v.y * m_physScale));
i++;
};
m_sprite.graphics.lineTo((tV.x * m_physScale), (tV.y * m_physScale));
break;
};
}
public function Update(){
var physStart:uint;
var bb:b2Body;
var s:b2Shape;
physStart = getTimer();
m_world.Step(m_timeStep, m_iterations);
Main.m_fpsCounter.updatePhys(physStart);
bb = m_world.m_bodyList;
while (bb) {
s = bb.GetShapeList();
while (s != null) {
DrawShape(s);
s = s.GetNext();
};
bb = bb.m_next;
};
}
public function UpdateMouseWorld(){
mouseXWorldPhys = (Input.mouseX / m_physScale);
mouseYWorldPhys = (Input.mouseY / m_physScale);
mouseXWorld = Input.mouseX;
mouseYWorld = Input.mouseY;
}
}
}//package TestBed
Section 108
//TestPP (TestBed.TestPP)
package TestBed {
import ppstudio.*;
import flash.geom.*;
import flash.display.*;
import flash.ui.*;
import flash.events.*;
import com.kongregate.as3.client.*;
import Engine.Collision.*;
import Engine.Collision.Shapes.*;
import Engine.Common.*;
import Engine.Common.Math.*;
import Engine.Dynamics.*;
import Engine.Dynamics.Contacts.*;
import Engine.Dynamics.Joints.*;
import flash.utils.*;
import flash.filters.*;
import flash.media.*;
import flash.text.*;
public class TestPP extends Test {
var snowball:MovieClip;
var sideScroll:SideScroll;
private var scrollBar:Scrollbar;
var aimStart:Point;
var scoreBar:McScoreBar;
var endScreen:McEndScreen;
var soundIcon:McSoundIcon;
var xOffset:Number;// = 0
private var highscore:MovieClip;
var carBd:b2Body;// = null
var lastAnimOffset:Number;// = 0
var crossHair:CrossHair;
var wooshSound:Sound;
private var speed:Number;// = 0
var armTimer:Timer;
var soundOn:Boolean;// = true
var localHScore:Number;
private var intstructionText;
var boyIterator:Number;// = 0
var aimEnd:Point;
var impactSound:Sound;
var armFrame:int;// = 1
var ballsLeft:Number;// = 10
var snow:Snow;
var started:Boolean;// = false
var headJoint:b2Joint;
var chestUp:ChestUp;
var instruction:Instruction;
var outOfBalls:Boolean;// = false
var hatMc:MovieClip;
var score:Number;// = 0
var headMc:Sprite;
var aimStarted:Boolean;// = false
var oldScore:Number;// = 0
var hatJoint:b2Joint;
var aimTime:Number;
var gameScene:MovieClip;
private var hitMultiplier:HitMultiplier;
var allowHitSound:Boolean;// = true
var oldMouse:Point;
var soundChannel3:SoundChannel;
var soundChannel2:SoundChannel;
var boy:Boy;
var bgSound:Sound;
var boyTimer:Timer;
var localHighScore:TextField;
var snowmanArr:Array;
var ragdollStringJointArr:Array;
var boySkipFrames:Number;// = 1000
var soundChannel:SoundChannel;
private var highscoreList:Array;
var ballsInAir:Number;// = 0
var outOfBallsTimer:Timer;
public function TestPP(){
ragdollStringJointArr = new Array();
xOffset = 0;
sideScroll = new SideScroll();
snow = new Snow(50, 600, 300, 0);
oldMouse = new Point(500, 0);
aimStarted = false;
ballsLeft = 10;
ballsInAir = 0;
started = false;
soundOn = true;
allowHitSound = true;
boy = new Boy();
boySkipFrames = 1000;
boyIterator = 0;
lastAnimOffset = 0;
armFrame = 1;
carBd = null;
outOfBalls = false;
score = 0;
oldScore = 0;
scoreBar = new McScoreBar();
soundIcon = new McSoundIcon();
endScreen = new McEndScreen();
hitMultiplier = new HitMultiplier();
speed = 0;
intstructionText = new McIntroText();
highscore = new MovieClip();
super();
instruction = new Instruction();
crossHair = new CrossHair();
gameScene = new MovieClip();
snowmanArr = new Array();
Mouse.show();
m_sprite.addChild(gameScene);
localHScore = UserData.getScore();
boy.gotoAndStop(4);
boy.scaleX = (boy.scaleY = 0.6);
boy.x = 50;
boy.y = 250;
instruction.startBtn.buttonMode = true;
instruction.x = 80;
instruction.y = 10;
gameScene.addChild(sideScroll);
gameScene.addChild(instruction);
instruction.startBtn.visible = true;
instruction.startBtn.addEventListener(MouseEvent.CLICK, startClicked);
createMouseover(instruction.startBtn);
instruction.highscoreButton.tfButtonText.text = "Highscore";
instruction.highscoreButton.addEventListener(MouseEvent.CLICK, highscoreClick);
instruction.highscoreButton.buttonMode = true;
createMouseover(instruction.highscoreButton);
instruction.textPlaceHolder.addChild(intstructionText);
crossHair.visible = false;
crossHair.scaleX = (crossHair.scaleY = 0.4);
bgSound = new JingleBells();
wooshSound = new Woosh();
impactSound = new Impact();
soundOn = Main.soundOn;
if (!(Main.soundOn)){
soundIcon.gotoAndStop(2);
};
}
public function destroy(e:Event=null){
var i:Number;
trace("reset");
endScreen.tryAgainBtn.removeEventListener(MouseEvent.CLICK, destroy);
gameScene.removeChild(endScreen);
m_sprite.removeEventListener(MouseEvent.MOUSE_DOWN, onMouseUp);
m_sprite.removeChild(gameScene);
i = gameScene.numChildren;
while (i > 0) {
gameScene.removeChildAt((i - 1));
i--;
};
snow.destroy();
sideScroll.destroy();
armTimer.stop();
armTimer.removeEventListener(TimerEvent.TIMER, setArmFrame);
armTimer = null;
boyTimer.stop();
boyTimer.removeEventListener(TimerEvent.TIMER, setAnimationSpeed);
boyTimer = null;
this.outOfBallsTimer.stop();
outOfBallsTimer.removeEventListener(TimerEvent.TIMER, setOutOfBalls);
outOfBallsTimer = null;
Main.soundOn = this.soundOn;
Main.m_currTest = null;
}
public function soundMouseOver(e:Event){
soundIcon.over.alpha = 1;
}
public function makeSnowball(){
snowball = new Snowball();
snowball.y = 200;
snowball.x = 32;
snowball.scaleX = 0.6;
snowball.scaleY = snowball.scaleX;
}
public function makeSnowMan(offset:Number=0):void{
var bodyDefC:b2BodyDef;
var circDef:b2CircleDef;
var circle:*;
var bodyDef:b2BodyDef;
var boxDef:b2BoxDef;
var hat:SnowManHat;
var i:Number;
if (snowmanArr.length > 0){
trace("moveSnowMan");
i = 0;
while (i < snowmanArr.length) {
snowmanArr[i].m_position.x = ((520 + offset) / m_physScale);
snowmanArr[i].m_rotation = 0;
snowmanArr[i].WakeUp();
switch (i){
case 0:
snowmanArr[i].m_position.y = (265 / m_physScale);
break;
case 1:
snowmanArr[i].m_position.y = (211 / m_physScale);
break;
case 2:
snowmanArr[i].m_position.y = (171 / m_physScale);
break;
case 3:
snowmanArr[i].m_position.y = (115 / m_physScale);
break;
};
snowmanArr[i].m_linearVelocity.x = 0;
snowmanArr[i].m_linearVelocity.y = 0;
snowmanArr[i].m_angularVelocity = 0;
i++;
};
return;
};
trace("efter return");
bodyDefC = new b2BodyDef();
circDef = new b2CircleDef();
circDef.density = 2;
circDef.radius = (30 / m_physScale);
circDef.friction = 2;
bodyDefC.position.Set(((520 + offset) / m_physScale), (250 / m_physScale));
bodyDefC.rotation = 0;
bodyDefC.AddShape(circDef);
circle = new SnowManBall();
bodyDefC.userData = circle;
snowmanArr.push(m_world.CreateBody(bodyDefC));
gameScene.addChild(circle);
circle.x = (bodyDefC.position.x * m_physScale);
circle.y = (bodyDefC.position.y * m_physScale);
circle.width = ((circDef.radius * m_physScale) * 2);
circle.height = ((circDef.radius * m_physScale) * 2.2);
circle.rotation = (bodyDefC.rotation * (180 / Math.PI));
bodyDefC = new b2BodyDef();
circDef = new b2CircleDef();
circDef.density = 2;
circDef.radius = (24 / m_physScale);
circDef.friction = 2;
bodyDefC.position.Set(((520 + offset) / m_physScale), (210 / m_physScale));
bodyDefC.rotation = 0;
bodyDefC.AddShape(circDef);
circle = new SnowManBall();
bodyDefC.userData = circle;
snowmanArr.push(m_world.CreateBody(bodyDefC));
gameScene.addChild(circle);
circle.x = (bodyDefC.position.x * m_physScale);
circle.y = (bodyDefC.position.y * m_physScale);
circle.width = ((circDef.radius * m_physScale) * 2);
circle.height = ((circDef.radius * m_physScale) * 2.2);
circle.rotation = (bodyDefC.rotation * (180 / Math.PI));
bodyDefC = new b2BodyDef();
circDef = new b2CircleDef();
circDef.density = 1;
circDef.radius = (16 / m_physScale);
circDef.friction = 1;
bodyDefC.position.Set(((520 + offset) / m_physScale), (150 / m_physScale));
bodyDefC.rotation = 0;
bodyDefC.AddShape(circDef);
circle = new SnowManHead();
bodyDefC.userData = circle;
snowmanArr.push(m_world.CreateBody(bodyDefC));
gameScene.addChild(circle);
circle.x = (bodyDefC.position.x * m_physScale);
circle.y = (bodyDefC.position.y * m_physScale);
circle.width = ((circDef.radius * m_physScale) * 2);
circle.height = ((circDef.radius * m_physScale) * 2.2);
circle.rotation = (bodyDefC.rotation * (180 / Math.PI));
bodyDef = new b2BodyDef();
boxDef = new b2BoxDef();
boxDef.density = 1;
boxDef.friction = 0.1;
boxDef.restitution = 0;
boxDef.extents.Set((20 / m_physScale), (20 / m_physScale));
bodyDef.position.Set(((520 + offset) / m_physScale), (100 / m_physScale));
bodyDef.rotation = 0;
bodyDef.AddShape(boxDef);
hat = new SnowManHat();
gameScene.addChild(hat);
bodyDef.userData = hat;
snowmanArr.push(m_world.CreateBody(bodyDef));
hat.x = (bodyDef.position.x * m_physScale);
hat.y = (bodyDef.position.y * m_physScale);
hat.width = ((boxDef.extents.x * m_physScale) * 2);
hat.height = ((boxDef.extents.y * m_physScale) * 2.6);
hat.rotation = (bodyDef.rotation * (180 / Math.PI));
}
private function ballHit():void{
hitMultiplier.hit();
}
public function checkHighscore(e:Event=null){
if (isValidEmail(endScreen.highscore1.emailField.text) == false){
endScreen.highscore1.errorField.text = "Skriv en gyldig email";
} else {
endScreen.highscore1.errorField.text = "Godkendt email";
};
}
public function setAnimationSpeed(e:Event){
boySkipFrames = Math.floor(((200 - (xOffset - lastAnimOffset)) / 10));
if (boySkipFrames < 0){
boySkipFrames = 0;
};
lastAnimOffset = xOffset;
}
private function recieveHighscore(result:Object):void{
var highscoreMC:*;
var i:int;
var shownCountdown:int;
var tmpHiScore:McHighscoreText;
trace(("result.list : " + result.list));
highscoreMC = new MovieClip();
highscoreList = new Array();
if (result.success != "true"){
result.list = new Array();
};
i = 0;
while (i < result.list.length) {
highscoreList.push(new highscoreEntry(result.list[i].username, result.list[i].score));
i++;
};
highscoreList.sortOn("score", (Array.DESCENDING | Array.NUMERIC));
shownCountdown = 7;
i = 0;
while (i < highscoreList.length) {
shownCountdown--;
if (shownCountdown == 0){
break;
};
tmpHiScore = new McHighscoreText();
tmpHiScore.highscoreText.text = ((((int((i + 1)).toString() + ". ") + highscoreList[i].name) + " - ") + highscoreList[i].score);
tmpHiScore.y = (i * tmpHiScore.height);
highscoreMC.addChild(tmpHiScore);
i++;
};
instruction.textPlaceHolder.removeChildAt(0);
instruction.textPlaceHolder.addChild(highscoreMC);
instruction.highscoreButton.removeEventListener(MouseEvent.CLICK, highscoreClick);
instruction.highscoreButton.tfButtonText.text = "Instructions";
instruction.highscoreButton.addEventListener(MouseEvent.CLICK, instructionsClick);
}
public function extraBall(){
ballsLeft++;
scoreBar.ballsLeft.text = ("" + ballsLeft);
}
public function fireball(){
var bodyDef:b2BodyDef;
var boxDef:b2CircleDef;
var snowballMc:MovieClip;
var b:b2Body;
var force:b2Vec2;
var power:Number;
var point:b2Vec2;
crossHair.play();
ballsLeft--;
ballsInAir++;
scoreBar.ballsLeft.text = ballsLeft.toString();
aimStart = new Point(60, 200);
aimEnd = new Point(gameScene.mouseX, gameScene.mouseY);
if (aimEnd.x <= 60){
aimEnd.x = 61;
};
aimTime = 20;
if (armTimer != null){
armTimer.removeEventListener(TimerEvent.TIMER, setArmFrame);
armTimer.stop();
armTimer = null;
};
armTimer = new Timer(200, 1);
armFrame = 2;
armTimer.start();
boy.arm.gotoAndPlay(2);
if (soundOn){
soundChannel2 = wooshSound.play();
};
armTimer.addEventListener(TimerEvent.TIMER, setArmFrame);
if (ballsLeft == 0){
outOfBallsTimer.start();
};
bodyDef = new b2BodyDef();
boxDef = new b2CircleDef();
boxDef.density = 13;
boxDef.friction = 0.1;
boxDef.restitution = 0;
boxDef.radius = (26 / m_physScale);
bodyDef.position.Set(((aimStart.x + xOffset) / m_physScale), (aimStart.y / m_physScale));
bodyDef.rotation = (Math.PI * 0.5);
bodyDef.AddShape(boxDef);
snowballMc = new Snowball();
snowballMc.name = ("snowball" + ballsInAir);
bodyDef.userData = snowballMc;
boxDef.groupIndex = -8;
b = m_world.CreateBody(bodyDef);
gameScene.addChild(snowballMc);
snowballMc.x = (bodyDef.position.x * m_physScale);
snowballMc.y = (bodyDef.position.y * m_physScale);
snowballMc.width = ((boxDef.radius * m_physScale) * 1);
snowballMc.height = ((boxDef.radius * m_physScale) * 1);
snowballMc.rotation = (bodyDef.rotation * (180 / Math.PI));
force = new b2Vec2((aimEnd.x - aimStart.x), (aimEnd.y - aimStart.y));
power = (100 - aimTime);
if (power < 0){
power = 0;
};
force.Multiply((1 * power));
point = b.m_position;
b.WakeUp();
b.SetLinearVelocity(new b2Vec2((speed * 0.8), 0));
b.ApplyForce(force, point);
}
public function highscoreClick(e:Event=null):void{
var succes:Boolean;
trace(("KongregateAPI.getInstance().loaded : " + KongregateAPI.getInstance().loaded));
trace(("KongregateAPI.getInstance().connected : " + KongregateAPI.getInstance().connected));
succes = KongregateAPI.getInstance().scores.requestList(recieveHighscore);
trace(("succes : " + succes));
}
public function destroyRagdollStrings(){
var i:Number;
if (ragdollStringJointArr != null){
i = 0;
while (i < ragdollStringJointArr.length) {
m_world.DestroyJoint((ragdollStringJointArr[i] as b2Joint));
ragdollStringJointArr[i] = null;
i++;
};
ragdollStringJointArr = null;
};
}
public function makeLevel(){
var ground:b2Body;
var bd:b2BodyDef;
var circ:b2CircleDef;
var box:b2BoxDef;
var jd:b2RevoluteJointDef;
var startX:Number;
var startY:Number;
var head:b2Body;
var spr:Sprite;
var torso1:b2Body;
var torso2:b2Body;
var chestMid:*;
var torso3:b2Body;
var chestLow:*;
var upperArmL:b2Body;
var armLeftUpper:*;
var upperArmR:b2Body;
var armRightUpper:*;
var lowerArmL:b2Body;
var armLeftLower:*;
var lowerArmR:b2Body;
var armRightLower:*;
var upperLegL:b2Body;
var legLeftUpper:*;
var upperLegR:b2Body;
var legRightUpper:*;
var lowerLegL:b2Body;
var legLeftLower:*;
var lowerLegR:b2Body;
var legRightLower:*;
var md:b2DistanceJointDef;
var bodyDef:b2BodyDef;
var boxDef:b2BoxDef;
ground = m_world.m_groundBody;
circ = new b2CircleDef();
box = new b2BoxDef();
jd = new b2RevoluteJointDef();
box.categoryBits = 2;
startX = 400;
startY = 142;
circ.radius = (12.5 / m_physScale);
circ.density = 10;
circ.friction = 1;
circ.restitution = 0.65;
circ.radius = (12.5 / m_physScale);
circ.density = 10;
circ.friction = 1;
circ.restitution = 0.65;
bd = new b2BodyDef();
bd.linearDamping = 0.001;
bd.angularDamping = 0.04;
bd.AddShape(circ);
bd.position.Set((startX / m_physScale), (startY / m_physScale));
head = m_world.CreateBody(bd);
spr = new Head();
headMc = new Head();
headMc.name = "rd_head";
head.m_userData = headMc;
headMc.x = (bd.position.x * m_physScale);
headMc.y = (bd.position.y * m_physScale);
headMc.width = ((circ.radius * m_physScale) * 2.7);
headMc.height = ((circ.radius * m_physScale) * 2.7);
headMc.rotation = (bd.rotation * (180 / Math.PI));
box.extents.Set((15 / m_physScale), (10 / m_physScale));
box.density = 1;
box.friction = 0.4;
box.restitution = 0.2;
bd = new b2BodyDef();
bd.linearDamping = 0;
bd.AddShape(box);
bd.position.Set((startX / m_physScale), ((startY + 28) / m_physScale));
torso1 = m_world.CreateBody(bd);
chestUp = new ChestUp();
chestUp.name = "rd_chestUp";
torso1.m_userData = chestUp;
chestUp.x = (bd.position.x * m_physScale);
chestUp.y = (bd.position.y * m_physScale);
chestUp.width = ((box.extents.x * m_physScale) * 2.6);
chestUp.height = ((box.extents.y * m_physScale) * 4);
chestUp.rotation = (bd.rotation * (180 / Math.PI));
bd = new b2BodyDef();
bd.linearDamping = 0;
bd.AddShape(box);
bd.position.Set((startX / m_physScale), ((startY + 43) / m_physScale));
torso2 = m_world.CreateBody(bd);
chestMid = new ChestMid();
chestMid.name = "rd_chestMid";
torso2.m_userData = chestMid;
chestMid.x = (bd.position.x * m_physScale);
chestMid.y = (bd.position.y * m_physScale);
chestMid.width = ((box.extents.x * m_physScale) * 2.4);
chestMid.height = ((box.extents.y * m_physScale) * 3);
chestMid.rotation = (bd.rotation * (180 / Math.PI));
bd = new b2BodyDef();
bd.linearDamping = 0;
bd.AddShape(box);
bd.position.Set((startX / m_physScale), ((startY + 58) / m_physScale));
torso3 = m_world.CreateBody(bd);
chestLow = new ChestLow();
chestLow.name = "rd_chestLow";
torso3.m_userData = chestLow;
chestLow.x = (bd.position.x * m_physScale);
chestLow.y = (bd.position.y * m_physScale);
chestLow.width = ((box.extents.x * m_physScale) * 2.4);
chestLow.height = ((box.extents.y * m_physScale) * 2);
chestLow.rotation = (bd.rotation * (180 / Math.PI));
box.extents.Set((18 / m_physScale), (6.5 / m_physScale));
box.density = 1;
box.friction = 0.4;
box.restitution = 0.2;
bd = new b2BodyDef();
bd.linearDamping = 0;
bd.AddShape(box);
bd.position.Set(((startX - 30) / m_physScale), ((startY + 20) / m_physScale));
upperArmL = m_world.CreateBody(bd);
armLeftUpper = new ArmLeftUpper();
armLeftUpper.name = "rd_armLeftUpper";
upperArmL.m_userData = armLeftUpper;
armLeftUpper.x = (bd.position.x * m_physScale);
armLeftUpper.y = (bd.position.y * m_physScale);
armLeftUpper.width = ((box.extents.x * m_physScale) * 2);
armLeftUpper.height = ((box.extents.y * m_physScale) * 2);
armLeftUpper.rotation = (bd.rotation * (180 / Math.PI));
bd.position.Set(((startX + 30) / m_physScale), ((startY + 20) / m_physScale));
upperArmR = m_world.CreateBody(bd);
armRightUpper = new ArmRightUpper();
armRightUpper.name = "rd_armRightUpper";
upperArmR.m_userData = armRightUpper;
armRightUpper.x = (bd.position.x * m_physScale);
armRightUpper.y = (bd.position.y * m_physScale);
armRightUpper.width = ((box.extents.x * m_physScale) * 2);
armRightUpper.height = ((box.extents.y * m_physScale) * 2);
armRightUpper.rotation = (bd.rotation * (180 / Math.PI));
box.extents.Set((17 / m_physScale), (6 / m_physScale));
box.density = 1;
box.friction = 0.4;
box.restitution = 0.2;
bd = new b2BodyDef();
bd.AddShape(box);
bd.position.Set(((startX - 57) / m_physScale), ((startY + 20) / m_physScale));
lowerArmL = m_world.CreateBody(bd);
armLeftLower = new ArmLeftLower();
armLeftLower.name = "rd_armLeftLower";
lowerArmL.m_userData = armLeftLower;
armLeftLower.x = (bd.position.x * m_physScale);
armLeftLower.y = (bd.position.y * m_physScale);
armLeftLower.width = ((box.extents.x * m_physScale) * 2);
armLeftLower.height = ((box.extents.y * m_physScale) * 2);
armLeftLower.rotation = (bd.rotation * (180 / Math.PI));
bd.position.Set(((startX + 57) / m_physScale), ((startY + 20) / m_physScale));
lowerArmR = m_world.CreateBody(bd);
armRightLower = new ArmRightLower();
armRightLower.name = "rd_armRightLower";
lowerArmR.m_userData = armRightLower;
armRightLower.x = (bd.position.x * m_physScale);
armRightLower.y = (bd.position.y * m_physScale);
armRightLower.width = ((box.extents.x * m_physScale) * 2);
armRightLower.height = ((box.extents.y * m_physScale) * 2);
armRightLower.rotation = (bd.rotation * (180 / Math.PI));
box.extents.Set((7.5 / m_physScale), (22 / m_physScale));
box.density = 1;
box.friction = 0.4;
box.restitution = 0.2;
bd = new b2BodyDef();
bd.AddShape(box);
bd.position.Set(((startX - 8) / m_physScale), ((startY + 85) / m_physScale));
upperLegL = m_world.CreateBody(bd);
legLeftUpper = new LegLeftUpper();
legLeftUpper.name = "rd_legLeftUpper";
upperLegL.m_userData = legLeftUpper;
legLeftUpper.x = (bd.position.x * m_physScale);
legLeftUpper.y = (bd.position.y * m_physScale);
legLeftUpper.width = ((box.extents.x * m_physScale) * 2);
legLeftUpper.height = ((box.extents.y * m_physScale) * 2);
legLeftUpper.rotation = (bd.rotation * (180 / Math.PI));
bd.position.Set(((startX + 8) / m_physScale), ((startY + 85) / m_physScale));
upperLegR = m_world.CreateBody(bd);
legRightUpper = new LegRightUpper();
legRightUpper.name = "rd_legRightUpper";
upperLegR.m_userData = legRightUpper;
legRightUpper.x = (bd.position.x * m_physScale);
legRightUpper.y = (bd.position.y * m_physScale);
legRightUpper.width = ((box.extents.x * m_physScale) * 2);
legRightUpper.height = ((box.extents.y * m_physScale) * 2);
legRightUpper.rotation = (bd.rotation * (180 / Math.PI));
box.extents.Set((6 / m_physScale), (20 / m_physScale));
box.density = 1;
box.friction = 0.4;
box.restitution = 0.2;
bd = new b2BodyDef();
bd.AddShape(box);
bd.position.Set(((startX - 8) / m_physScale), ((startY + 119) / m_physScale));
lowerLegL = m_world.CreateBody(bd);
legLeftLower = new LegLeftLow();
legLeftLower.name = "rd_legLeftLower";
lowerLegL.m_userData = legLeftLower;
legLeftLower.x = (bd.position.x * m_physScale);
legLeftLower.y = (bd.position.y * m_physScale);
legLeftLower.width = ((box.extents.x * m_physScale) * 3);
legLeftLower.height = ((box.extents.y * m_physScale) * 2);
legLeftLower.rotation = (bd.rotation * (180 / Math.PI));
bd.position.Set(((startX + 8) / m_physScale), ((startY + 119) / m_physScale));
lowerLegR = m_world.CreateBody(bd);
legRightLower = new LegRightLow();
legRightLower.name = "rd_legRightLower";
lowerLegR.m_userData = legRightLower;
legRightLower.x = (bd.position.x * m_physScale);
legRightLower.y = (bd.position.y * m_physScale);
legRightLower.width = ((box.extents.x * m_physScale) * 3);
legRightLower.height = ((box.extents.y * m_physScale) * 2);
legRightLower.rotation = (bd.rotation * (180 / Math.PI));
jd.enableLimit = true;
jd.lowerAngle = (-40 / (180 / Math.PI));
jd.upperAngle = (40 / (180 / Math.PI));
jd.anchorPoint.Set((startX / m_physScale), ((startY + 15) / m_physScale));
jd.body1 = torso1;
jd.body2 = head;
hatJoint = m_world.CreateJoint(jd);
jd.lowerAngle = (-85 / (180 / Math.PI));
jd.upperAngle = (130 / (180 / Math.PI));
jd.anchorPoint.Set(((startX - 18) / m_physScale), ((startY + 20) / m_physScale));
jd.body1 = torso1;
jd.body2 = upperArmL;
m_world.CreateJoint(jd);
jd.lowerAngle = (-130 / (180 / Math.PI));
jd.upperAngle = (85 / (180 / Math.PI));
jd.anchorPoint.Set(((startX + 18) / m_physScale), ((startY + 20) / m_physScale));
jd.body1 = torso1;
jd.body2 = upperArmR;
m_world.CreateJoint(jd);
jd.lowerAngle = (-130 / (180 / Math.PI));
jd.upperAngle = (10 / (180 / Math.PI));
jd.anchorPoint.Set(((startX - 45) / m_physScale), ((startY + 20) / m_physScale));
jd.body1 = upperArmL;
jd.body2 = lowerArmL;
m_world.CreateJoint(jd);
jd.lowerAngle = (-10 / (180 / Math.PI));
jd.upperAngle = (130 / (180 / Math.PI));
jd.anchorPoint.Set(((startX + 45) / m_physScale), ((startY + 20) / m_physScale));
jd.body1 = upperArmR;
jd.body2 = lowerArmR;
m_world.CreateJoint(jd);
jd.lowerAngle = (-15 / (180 / Math.PI));
jd.upperAngle = (15 / (180 / Math.PI));
jd.anchorPoint.Set((startX / m_physScale), ((startY + 35) / m_physScale));
jd.body1 = torso1;
jd.body2 = torso2;
m_world.CreateJoint(jd);
jd.anchorPoint.Set((startX / m_physScale), ((startY + 50) / m_physScale));
jd.body1 = torso2;
jd.body2 = torso3;
m_world.CreateJoint(jd);
jd.lowerAngle = (-25 / (180 / Math.PI));
jd.upperAngle = (45 / (180 / Math.PI));
jd.anchorPoint.Set(((startX - 8) / m_physScale), ((startY + 72) / m_physScale));
jd.body1 = torso3;
jd.body2 = upperLegL;
m_world.CreateJoint(jd);
jd.lowerAngle = (-45 / (180 / Math.PI));
jd.upperAngle = (25 / (180 / Math.PI));
jd.anchorPoint.Set(((startX + 8) / m_physScale), ((startY + 72) / m_physScale));
jd.body1 = torso3;
jd.body2 = upperLegR;
m_world.CreateJoint(jd);
jd.lowerAngle = (-25 / (180 / Math.PI));
jd.upperAngle = (115 / (180 / Math.PI));
jd.anchorPoint.Set(((startX - 8) / m_physScale), ((startY + 107) / m_physScale));
jd.body1 = upperLegL;
jd.body2 = lowerLegL;
m_world.CreateJoint(jd);
jd.lowerAngle = (-115 / (180 / Math.PI));
jd.upperAngle = (25 / (180 / Math.PI));
jd.anchorPoint.Set(((startX + 8) / m_physScale), ((startY + 107) / m_physScale));
jd.body1 = upperLegR;
jd.body2 = lowerLegR;
m_world.CreateJoint(jd);
makeSnowMan();
makeCar();
gameScene.addChild(legLeftLower);
gameScene.addChild(legRightLower);
gameScene.addChild(legRightUpper);
gameScene.addChild(legLeftUpper);
gameScene.addChild(chestLow);
gameScene.addChild(chestMid);
gameScene.addChild(chestUp);
gameScene.addChild(armLeftLower);
gameScene.addChild(armLeftUpper);
gameScene.addChild(armRightLower);
gameScene.addChild(armRightUpper);
gameScene.addChild(headMc);
gameScene.addChild(boy);
gameScene.addChild(crossHair);
gameScene.addChild(snow);
xOffset = 0;
createTextFields();
md = new b2DistanceJointDef();
md.body1 = m_world.m_groundBody;
md.body2 = torso1;
md.anchorPoint1.Set((torso1.m_position.x + 100), (torso1.m_position.y - 10));
md.anchorPoint2.Set((torso1.m_position.x + 0.4), torso1.m_position.y);
ragdollStringJointArr.push((m_world.CreateJoint(md) as b2DistanceJoint));
md = new b2DistanceJointDef();
md.body1 = m_world.m_groundBody;
md.body2 = torso1;
md.anchorPoint1.Set((torso1.m_position.x - 100), (torso1.m_position.y - 10));
md.anchorPoint2.Set((torso1.m_position.x - 0.4), torso1.m_position.y);
ragdollStringJointArr.push((m_world.CreateJoint(md) as b2DistanceJoint));
md = new b2DistanceJointDef();
md.body1 = m_world.m_groundBody;
md.body2 = lowerLegR;
md.anchorPoint1.Set((lowerLegR.m_position.x + 10), (lowerLegR.m_position.y + 10));
md.anchorPoint2.Set(lowerLegR.m_position.x, (lowerLegR.m_position.y + 0.5));
ragdollStringJointArr.push((m_world.CreateJoint(md) as b2DistanceJoint));
md = new b2DistanceJointDef();
md.body1 = m_world.m_groundBody;
md.body2 = lowerLegL;
md.anchorPoint1.Set((lowerLegL.m_position.x - 10), (lowerLegL.m_position.y + 10));
md.anchorPoint2.Set(lowerLegL.m_position.x, (lowerLegL.m_position.y + 0.5));
ragdollStringJointArr.push((m_world.CreateJoint(md) as b2DistanceJoint));
bodyDef = new b2BodyDef();
boxDef = new b2BoxDef();
boxDef.density = 1;
boxDef.friction = 0.1;
boxDef.restitution = 0;
boxDef.extents.Set((30 / m_physScale), (75 / m_physScale));
bodyDef.position.Set((1200 / m_physScale), (525 / m_physScale));
bodyDef.AddShape(boxDef);
m_world.CreateBody(bodyDef);
makeSnowball();
}
public function makeCar(offset:Number=0){
var bd:b2BodyDef;
var car:Car;
var bd1:b2BoxDef;
var bd2:b2BoxDef;
if (carBd != null){
carBd.m_position.x = ((700 + offset) / m_physScale);
carBd.WakeUp();
carBd.m_userData.colorPart.transform.colorTransform = new ColorTransform(Math.random(), Math.random(), Math.random(), 1, 0, 0, 0, 0);
return;
};
bd = new b2BodyDef();
car = new Car();
bd1 = new b2BoxDef();
bd1.extents.Set((100 / m_physScale), (30 / m_physScale));
bd1.density = 200;
bd1.userData = car;
bd2 = new b2BoxDef();
bd2.extents.Set((45 / m_physScale), (30 / m_physScale));
bd2.localPosition.Set((10 / m_physScale), (-30 / m_physScale));
bd2.localRotation = 0;
bd2.density = 200;
bd2.userData = car;
bd = new b2BodyDef();
bd.AddShape(bd1);
bd.AddShape(bd2);
bd.position.Set((700 + (offset / m_physScale)), (300 / m_physScale));
bd.rotation = 0;
bd.userData = car;
bd1.maskBits = 2;
bd2.maskBits = 2;
bd1.groupIndex = 2;
bd2.groupIndex = 2;
carBd = m_world.CreateBody(bd);
car.x = (bd.position.x * m_physScale);
car.y = ((bd.position.y * m_physScale) - 80);
car.name = "car";
gameScene.addChild(car);
car.rotation = (bd.rotation * (180 / Math.PI));
car.width = ((bd2.extents.x * m_physScale) * 6);
car.height = ((bd2.extents.y * m_physScale) * 4);
}
public function saveHighscore(e:Event=null){
m_sprite.removeEventListener(MouseEvent.MOUSE_DOWN, onMouseUp);
endScreen.saveHighscoreBtn.removeEventListener(MouseEvent.CLICK, saveHighscore);
endScreen.removeChild(endScreen.endText);
endScreen.highscore1.visible = true;
endScreen.saveHighscoreBtn.addEventListener(MouseEvent.CLICK, checkHighscore);
endScreen.saveHighscoreBtn.buttonMode = true;
}
public function testThis(e:Event){
score = 100;
}
public function createTextFields(){
}
public function onMouseUp(e:Event){
if (ballsLeft > 0){
fireball();
};
}
public function handleBoyAnimation(){
boyIterator++;
if (boyIterator >= boySkipFrames){
boyIterator = 0;
boy.play();
return;
};
boy.stop();
}
public function onSnowballEnterFrame(e:Event){
if (e.currentTarget == null){
return;
};
if (e.currentTarget.currentFrame == e.currentTarget.totalFrames){
removeSnowball((e.currentTarget as MovieClip));
};
}
public function out(evt:MouseEvent):void{
evt.currentTarget.filters = [new GlowFilter(39423, 1, 16, 16, 1, 1, false, false)];
}
public function isValidEmail(email:String):Boolean{
var emailExpression:RegExp;
emailExpression = /^[a-z][\w.-]+@\w[\w.-]+\.[\w.-]*[a-z][a-z]$/i;
return (emailExpression.test(email));
}
public function createMouseover(target:DisplayObject):void{
target.addEventListener(MouseEvent.MOUSE_OVER, over);
target.addEventListener(MouseEvent.MOUSE_OUT, out);
}
public function removeHat(){
new Decapitation(gameScene);
addScore(100000);
m_world.DestroyJoint(hatJoint);
hatJoint = null;
chestUp.gotoAndPlay(2);
}
private function addScore(n:int):void{
var scrString:String;
var tempString:String;
score = (score + n);
trace(("score : " + score));
if (score < 1000){
scoreBar.score.text = Math.floor(score).toString();
} else {
if (score < 1000000){
scrString = ("" + Math.floor(score).toString());
scrString = ((scrString.substr(0, (scrString.length - 3)) + ".") + scrString.substr((scrString.length - 3)));
scoreBar.score.text = scrString;
} else {
scrString = ("" + Math.floor(score).toString());
tempString = scrString.substr(0, (scrString.length - 6));
tempString = ((tempString + ".") + scrString.substr((scrString.length - 7), (scrString.length - 4)));
tempString = ((tempString + ".") + scrString.substr((scrString.length - 3)));
scrString = tempString;
scoreBar.score.text = scrString;
};
};
}
public function startClicked(e:Event=null){
var scrString:String;
instruction.visible = false;
started = true;
Mouse.hide();
crossHair.visible = true;
makeLevel();
m_sprite.addEventListener(MouseEvent.MOUSE_DOWN, onMouseUp);
if (soundOn){
soundChannel = bgSound.play(0, 500);
} else {
soundChannel = bgSound.play(0, 500);
soundChannel.stop();
};
boy.stop();
boyTimer = new Timer(1000);
boyTimer.addEventListener(TimerEvent.TIMER, setAnimationSpeed);
boyTimer.start();
outOfBallsTimer = new Timer(6000, 1);
outOfBallsTimer.addEventListener(TimerEvent.TIMER, setOutOfBalls);
gameScene.addChild(scoreBar);
gameScene.addChild(hitMultiplier);
hitMultiplier.x = 500;
hitMultiplier.y = 70;
if (localHScore < 1000){
scoreBar.bestEver.text = localHScore.toString();
} else {
scrString = ("" + localHScore);
scrString = ((scrString.substr(0, (scrString.length - 3)) + ".") + scrString.substr((scrString.length - 3)));
scoreBar.bestEver.text = scrString;
};
gameScene.addChild(soundIcon);
soundIcon.x = 5;
soundIcon.y = 2;
soundIcon.addEventListener(MouseEvent.CLICK, soundOnOf);
soundIcon.addEventListener(MouseEvent.MOUSE_OVER, soundMouseOver);
soundIcon.addEventListener(MouseEvent.MOUSE_OUT, soundMouseOut);
}
public function playHitSound(){
if (soundOn){
soundChannel2 = impactSound.play();
};
}
override public function DrawShape(shape:b2Shape){
if (shape.GetBody().m_userData != null){
shape.GetBody().m_userData.x = ((shape.GetBody().m_position.x * m_physScale) - xOffset);
shape.GetBody().m_userData.y = (shape.GetBody().m_position.y * m_physScale);
shape.GetBody().m_userData.rotation = (shape.GetBody().m_rotation * (180 / Math.PI));
return;
};
}
public function soundMouseOut(e:Event){
soundIcon.over.alpha = 0;
}
public function setOutOfBalls(e:Event){
if (ballsLeft <= 0){
outOfBalls = true;
} else {
outOfBalls = false;
};
}
public function removeSnowball(mc:MovieClip){
mc.removeEventListener(Event.ENTER_FRAME, onSnowballEnterFrame);
gameScene.removeChild(mc);
mc = null;
snowball.visible = true;
}
public function allowSoundAgain(e:Event){
allowHitSound = true;
}
public function onMouseDown(e:Event){
}
public function over(evt:MouseEvent):void{
evt.currentTarget.filters = [new GlowFilter(26367, 1, 19, 19, 1, 1, false, false), new GlowFilter(26367, 1, 19, 19, 1, 1, true, false)];
}
public function soundOnOf(e:Event){
if (soundOn){
soundOn = false;
soundIcon.gotoAndStop(2);
soundChannel.stop();
soundChannel2.stop();
} else {
soundOn = true;
soundIcon.gotoAndStop(1);
soundChannel = bgSound.play(0, 500);
};
}
private function instructionsClick(e:MouseEvent=null):void{
instruction.textPlaceHolder.removeChildAt(0);
instruction.textPlaceHolder.addChild(intstructionText);
instruction.highscoreButton.removeEventListener(MouseEvent.CLICK, instructionsClick);
instruction.highscoreButton.tfButtonText.text = "Highscore";
instruction.highscoreButton.addEventListener(MouseEvent.CLICK, highscoreClick);
}
public function gameOver(){
started = false;
UserData.setScore(Math.floor(score));
Mouse.show();
soundChannel.stop();
gameScene.addChild(endScreen);
endScreen.tryAgainBtn.buttonMode = true;
endScreen.tryAgainBtn.addEventListener(MouseEvent.CLICK, destroy);
createMouseover(endScreen.tryAgainBtn);
endScreen.endText.yourScore.text = (("You Scored: " + scoreBar.score.text) + " point");
KongregateAPI.getInstance().scores.submit(score);
trace(("int(scoreBar.score.text) : " + score));
crossHair.visible = false;
}
override public function Update(){
var b:b2Body;
var xtraBall:Boolean;
var c:b2Contact;
var tmp:Number;
var body1:b2Body;
var body2:b2Body;
var mass1:Number;
var mass2:Number;
var tmpForce:Number;
if (!(started)){
return;
};
crossHair.x = gameScene.mouseX;
crossHair.y = gameScene.mouseY;
this.handleBoyAnimation();
boy.arm.gotoAndStop(armFrame);
super.Update();
b = m_world.GetBodyList();
while (b) {
if (b.m_userData != null){
if (b.m_userData == headMc){
tmp = ((b.m_position.x * m_physScale) - 400);
if (((((((b.IsSleeping()) || (((tmp - xOffset) < 2)))) && (outOfBalls))) || ((headMc.x < 0)))){
gameOver();
};
if ((((tmp > xOffset)) && ((tmp > 0)))){
sideScroll.setScroll((tmp - xOffset));
if ((tmp - xOffset) > 0){
snow.setWind(((tmp - xOffset) * 0.7));
} else {
snow.setWind(0);
};
if ((((Math.floor((xOffset / 8000)) < Math.floor((tmp / 8000)))) && ((xOffset > 1000)))){
makeSnowMan((tmp + 200));
};
if ((((Math.floor((xOffset / 5000)) < Math.floor((tmp / 5000)))) && ((xOffset > 1000)))){
makeCar((tmp + 200));
};
speed = (tmp - xOffset);
xOffset = tmp;
};
} else {
if (b.m_userData.name.substr(0, 8) == "snowball"){
if (((b.m_position.x * this.m_physScale) < xOffset)){
gameScene.removeChild(b.m_userData);
m_world.DestroyBody(b);
};
};
};
};
b = b.GetNext();
};
addScore((speed * hitMultiplier.getMultiplier()));
xtraBall = false;
c = m_world.GetContactList();
while (c) {
if (c.GetManifoldCount() > 0){
body1 = c.GetShape1().GetBody();
body2 = c.GetShape2().GetBody();
mass1 = body1.GetMass();
mass2 = body2.GetMass();
if (((!((body1.m_userData == null))) && (!((body2.m_userData == null))))){
if (((!((body1.m_userData.name == null))) && (!((body2.m_userData.name == null))))){
if ((((body1.m_userData.name.substr(0, 2) == "rd")) && ((body2.m_userData.name.substr(0, 8) == "snowball")))){
destroyRagdollStrings();
body2.m_userData.play();
playHitSound();
body2.m_userData.addEventListener(Event.ENTER_FRAME, onSnowballEnterFrame);
trace(("body2.m_linearVelocity.x=" + body2.m_linearVelocity.x));
tmpForce = body2.m_linearVelocity.x;
m_world.DestroyBody(body2);
body2 = null;
xtraBall = true;
if ((((((body1.m_userData.name == "rd_head")) && ((tmpForce > 110)))) && (!((hatJoint == null))))){
removeHat();
};
} else {
if ((((body2.m_userData.name.substr(0, 2) == "rd")) && ((body1.m_userData.name.substr(0, 8) == "snowball")))){
destroyRagdollStrings();
body1.m_userData.play();
playHitSound();
body1.m_userData.addEventListener(Event.ENTER_FRAME, onSnowballEnterFrame);
trace(("body1.m_linearVelocity.x=" + body1.m_linearVelocity.x));
tmpForce = body1.m_linearVelocity.x;
m_world.DestroyBody(body1);
body1 = null;
xtraBall = true;
hitMultiplier.hit();
if ((((((body2.m_userData.name == "rd_head")) && ((tmpForce > 110)))) && (!((hatJoint == null))))){
removeHat();
};
};
};
};
} else {
if (body2.m_userData != null){
if (body2.m_userData.name.substr(0, 8) == "snowball"){
body2.m_userData.play();
playHitSound();
body2.m_userData.addEventListener(Event.ENTER_FRAME, onSnowballEnterFrame);
m_world.DestroyBody(body2);
body2 = null;
};
} else {
if (body1.m_userData != null){
if (body1.m_userData.name.substr(0, 8) == "snowball"){
body1.m_userData.play();
playHitSound();
body1.m_userData.addEventListener(Event.ENTER_FRAME, onSnowballEnterFrame);
m_world.DestroyBody(body1);
body1 = null;
};
};
};
};
};
c = c.GetNext();
};
oldMouse = new Point(gameScene.mouseX, gameScene.mouseY);
if (xtraBall){
extraBall();
hitMultiplier.hit();
};
}
public function setArmFrame(e:Event){
armFrame = 1;
boy.arm.gotoAndStop(1);
}
}
}//package TestBed
Section 109
//AimingPanel (AimingPanel)
package {
import flash.display.*;
public dynamic class AimingPanel extends MovieClip {
public function AimingPanel(){
super();
}
}
}//package
Section 110
//ArmLeftLower (ArmLeftLower)
package {
import flash.display.*;
public dynamic class ArmLeftLower extends MovieClip {
public function ArmLeftLower(){
super();
}
}
}//package
Section 111
//ArmLeftUpper (ArmLeftUpper)
package {
import flash.display.*;
public dynamic class ArmLeftUpper extends MovieClip {
public function ArmLeftUpper(){
super();
}
}
}//package
Section 112
//ArmRightLower (ArmRightLower)
package {
import flash.display.*;
public dynamic class ArmRightLower extends MovieClip {
public function ArmRightLower(){
super();
}
}
}//package
Section 113
//ArmRightUpper (ArmRightUpper)
package {
import flash.display.*;
public dynamic class ArmRightUpper extends MovieClip {
public function ArmRightUpper(){
super();
}
}
}//package
Section 114
//Background (Background)
package {
import flash.display.*;
public dynamic class Background extends MovieClip {
public function Background(){
super();
}
}
}//package
Section 115
//Bg (Bg)
package {
import flash.display.*;
public dynamic class Bg extends MovieClip {
public function Bg(){
super();
}
}
}//package
Section 116
//Box (Box)
package {
import flash.display.*;
public dynamic class Box extends MovieClip {
public function Box(){
super();
addFrameScript(59, frame60);
}
function frame60(){
stop();
}
}
}//package
Section 117
//Boy (Boy)
package {
import flash.display.*;
public dynamic class Boy extends MovieClip {
public var arm:MovieClip;
public function Boy(){
super();
addFrameScript(0, frame1, 1, frame2, 2, frame3, 3, frame4, 4, frame5, 5, frame6, 6, frame7, 7, frame8, 8, frame9, 9, frame10);
}
function frame10(){
stop();
}
function frame3(){
stop();
}
function frame6(){
stop();
}
function frame7(){
stop();
}
function frame1(){
stop();
}
function frame4(){
stop();
}
function frame5(){
stop();
}
function frame9(){
stop();
}
function frame8(){
stop();
}
function frame2(){
stop();
}
}
}//package
Section 118
//Car (Car)
package {
import flash.display.*;
public dynamic class Car extends MovieClip {
public var colorPart:MovieClip;
public function Car(){
super();
}
}
}//package
Section 119
//ChestLow (ChestLow)
package {
import flash.display.*;
public dynamic class ChestLow extends MovieClip {
public function ChestLow(){
super();
}
}
}//package
Section 120
//ChestMid (ChestMid)
package {
import flash.display.*;
public dynamic class ChestMid extends MovieClip {
public function ChestMid(){
super();
}
}
}//package
Section 121
//ChestUp (ChestUp)
package {
import flash.display.*;
public dynamic class ChestUp extends MovieClip {
public function ChestUp(){
super();
addFrameScript(0, frame1, 16, frame17);
}
function frame1(){
stop();
}
function frame17(){
stop();
}
}
}//package
Section 122
//Circle (Circle)
package {
import flash.display.*;
public dynamic class Circle extends MovieClip {
public function Circle(){
super();
}
}
}//package
Section 123
//CrossHair (CrossHair)
package {
import flash.display.*;
public dynamic class CrossHair extends MovieClip {
public function CrossHair(){
super();
addFrameScript(0, frame1);
}
function frame1(){
stop();
}
}
}//package
Section 124
//FlexContentHolder (FlexContentHolder)
package {
import flash.display.*;
public dynamic class FlexContentHolder extends MovieClip {
public function FlexContentHolder(){
super();
}
}
}//package
Section 125
//Foreground (Foreground)
package {
import flash.display.*;
public dynamic class Foreground extends MovieClip {
public function Foreground(){
super();
}
}
}//package
Section 126
//Head (Head)
package {
import flash.display.*;
public dynamic class Head extends MovieClip {
public function Head(){
super();
}
}
}//package
Section 127
//Impact (Impact)
package {
import flash.media.*;
public dynamic class Impact extends Sound {
public function Impact(){
super();
}
}
}//package
Section 128
//Instruction (Instruction)
package {
import flash.display.*;
public dynamic class Instruction extends MovieClip {
public var textPlaceHolder:MovieClip;
public var highscoreButton:McLargeButton;
public var startBtn:MovieClip;
public function Instruction(){
super();
}
}
}//package
Section 129
//JingleBells (JingleBells)
package {
import flash.media.*;
public dynamic class JingleBells extends Sound {
public function JingleBells(){
super();
}
}
}//package
Section 130
//LegLeftLow (LegLeftLow)
package {
import flash.display.*;
public dynamic class LegLeftLow extends MovieClip {
public function LegLeftLow(){
super();
}
}
}//package
Section 131
//LegLeftUpper (LegLeftUpper)
package {
import flash.display.*;
public dynamic class LegLeftUpper extends MovieClip {
public function LegLeftUpper(){
super();
}
}
}//package
Section 132
//LegRightLow (LegRightLow)
package {
import flash.display.*;
public dynamic class LegRightLow extends MovieClip {
public function LegRightLow(){
super();
}
}
}//package
Section 133
//LegRightUpper (LegRightUpper)
package {
import flash.display.*;
public dynamic class LegRightUpper extends MovieClip {
public function LegRightUpper(){
super();
}
}
}//package
Section 134
//Main (Main)
package {
import com.kongregate.as3.client.*;
import General.*;
import flash.events.*;
import TestBed.*;
import flash.display.*;
import Engine.Collision.*;
import Engine.Collision.Shapes.*;
import Engine.Common.Math.*;
import Engine.Dynamics.*;
import Engine.Dynamics.Contacts.*;
import Engine.Dynamics.Joints.*;
import flash.text.*;
public class Main extends MovieClip {
public var tMc:MovieClip;
public var _mochiads_game_id:String;// = "5a42e5586b097f96"
private var intro:Splash;
public var m_input:Input;
public var m_currId:int;// = 0
public static var m_fpsCounter:FpsCounter = new FpsCounter();
public static var m_aboutText:TextField;
public static var soundOn = true;
public static var m_sprite:Sprite;
public static var kongregate:KongregateAPI = new KongregateAPI();
public static var m_currTest:Test;
public static var STAGE:Stage;
public function Main(){
_mochiads_game_id = "5a42e5586b097f96";
m_currId = 0;
super();
addFrameScript(0, frame1);
STAGE = this.stage;
addChild(kongregate);
this.addEventListener(Event.ADDED_TO_STAGE, initSplash);
}
public function init():void{
this.stage.frameRate = 24;
addEventListener(Event.ENTER_FRAME, update, false, 0, true);
m_fpsCounter.x = 170;
m_fpsCounter.y = 5;
m_sprite = (this as Sprite);
m_input = new Input(m_sprite);
}
function frame1(){
tMc = new MovieClip();
tMc.focus = true;
}
public function initSplash(e:Event):void{
intro = new Splash(new McIntro(), this);
intro.x = (stage.stageWidth / 2);
intro.y = (stage.stageHeight / 2);
addChild(intro);
}
public function update(e:Event){
if (!(m_currTest)){
m_currTest = new TestPP();
};
m_currTest.Update();
m_fpsCounter.update();
FRateLimiter.limitFrame(24);
}
public function checkForResetTest(){
if (m_currId == 0){
(m_currTest as TestPP).destroy();
};
}
}
}//package
Section 135
//McBench (McBench)
package {
import flash.display.*;
public dynamic class McBench extends MovieClip {
public function McBench(){
super();
}
}
}//package
Section 136
//McDecapitation (McDecapitation)
package {
import flash.display.*;
public dynamic class McDecapitation extends MovieClip {
public function McDecapitation(){
super();
}
}
}//package
Section 137
//McEndScreen (McEndScreen)
package {
import flash.display.*;
public dynamic class McEndScreen extends MovieClip {
public var endText:MovieClip;
public var tryAgainBtn:MovieClip;
public function McEndScreen(){
super();
}
}
}//package
Section 138
//McHat (McHat)
package {
import flash.display.*;
public dynamic class McHat extends MovieClip {
public function McHat(){
super();
}
}
}//package
Section 139
//McHighscoreText (McHighscoreText)
package {
import flash.text.*;
import flash.display.*;
public dynamic class McHighscoreText extends MovieClip {
public var highscoreText:TextField;
public function McHighscoreText(){
super();
}
}
}//package
Section 140
//McHitMultiplier (McHitMultiplier)
package {
import flash.text.*;
import flash.display.*;
public dynamic class McHitMultiplier extends MovieClip {
public var counter:TextField;
public function McHitMultiplier(){
super();
}
}
}//package
Section 141
//McIntro (McIntro)
package {
import flash.display.*;
public dynamic class McIntro extends MovieClip {
public function McIntro(){
super();
addFrameScript(131, frame132);
}
function frame132(){
stop();
}
}
}//package
Section 142
//McIntroText (McIntroText)
package {
import flash.text.*;
import flash.display.*;
public dynamic class McIntroText extends MovieClip {
public var instructionsText:TextField;
public function McIntroText(){
super();
}
}
}//package
Section 143
//McLargeButton (McLargeButton)
package {
import flash.text.*;
import flash.display.*;
public dynamic class McLargeButton extends MovieClip {
public var tfButtonText:TextField;
public function McLargeButton(){
super();
}
}
}//package
Section 144
//McPreloader (McPreloader)
package {
import flash.display.*;
public dynamic class McPreloader extends MovieClip {
public function McPreloader(){
super();
}
}
}//package
Section 145
//McScoreBar (McScoreBar)
package {
import flash.text.*;
import flash.display.*;
public dynamic class McScoreBar extends MovieClip {
public var bestEver:TextField;
public var ballsLeft:TextField;
public var score:TextField;
public function McScoreBar(){
super();
}
}
}//package
Section 146
//McSoundIcon (McSoundIcon)
package {
import flash.display.*;
public dynamic class McSoundIcon extends MovieClip {
public var over:MovieClip;
public function McSoundIcon(){
super();
addFrameScript(0, frame1, 1, frame2);
}
function frame1(){
stop();
}
function frame2(){
stop();
}
}
}//package
Section 147
//Middleground (Middleground)
package {
import flash.display.*;
public dynamic class Middleground extends MovieClip {
public function Middleground(){
super();
}
}
}//package
Section 148
//Snowball (Snowball)
package {
import flash.display.*;
public dynamic class Snowball extends MovieClip {
public function Snowball(){
super();
addFrameScript(0, frame1, 6, frame7);
}
function frame7(){
stop();
}
function frame1(){
stop();
}
}
}//package
Section 149
//SnowflakeMc (SnowflakeMc)
package {
import flash.display.*;
public dynamic class SnowflakeMc extends MovieClip {
public function SnowflakeMc(){
super();
}
}
}//package
Section 150
//SnowManBall (SnowManBall)
package {
import flash.display.*;
public dynamic class SnowManBall extends MovieClip {
public function SnowManBall(){
super();
}
}
}//package
Section 151
//SnowManHat (SnowManHat)
package {
import flash.display.*;
public dynamic class SnowManHat extends MovieClip {
public function SnowManHat(){
super();
}
}
}//package
Section 152
//SnowManHead (SnowManHead)
package {
import flash.display.*;
public dynamic class SnowManHead extends MovieClip {
public function SnowManHead(){
super();
}
}
}//package
Section 153
//StaticBg (StaticBg)
package {
import flash.display.*;
public dynamic class StaticBg extends MovieClip {
public function StaticBg(){
super();
}
}
}//package
Section 154
//Woosh (Woosh)
package {
import flash.media.*;
public dynamic class Woosh extends Sound {
public function Woosh(){
super();
}
}
}//package