Section 1
//AbstractCollection (org.cove.ape.AbstractCollection)
package org.cove.ape {
import flash.display.*;
import flash.utils.*;
public class AbstractCollection {
private var _sprite:Sprite;
private var _isParented:Boolean;
private var _particles:Array;
private var _constraints:Array;
public function AbstractCollection(){
if (getQualifiedClassName(this) == "org.cove.ape::AbstractCollection"){
throw (new ArgumentError("AbstractCollection can't be instantiated directly"));
};
_isParented = false;
_particles = new Array();
_constraints = new Array();
}
public function getAll():Array{
return (particles.concat(constraints));
}
function checkCollisionsVsCollection(_arg1:AbstractCollection):void{
var _local2:int;
var _local3:int;
var _local4:int;
var _local5:AbstractParticle;
var _local6:int;
var _local7:int;
var _local8:int;
var _local9:AbstractParticle;
var _local10:SpringConstraint;
var _local11:SpringConstraint;
var _local12:int;
_local2 = _particles.length;
_local3 = 0;
while (_local3 < _local2) {
_local5 = _particles[_local3];
if (!_local5.collidable){
} else {
_local6 = _arg1.particles.length;
_local7 = 0;
while (_local7 < _local6) {
_local9 = _arg1.particles[_local7];
if (_local9.collidable){
CollisionDetector.test(_local5, _local9);
};
_local7++;
};
_local8 = _arg1.constraints.length;
_local7 = 0;
while (_local7 < _local8) {
_local10 = _arg1.constraints[_local7];
if (((_local10.collidable) && (!(_local10.isConnectedTo(_local5))))){
_local10.scp.updatePosition();
CollisionDetector.test(_local5, _local10.scp);
};
_local7++;
};
};
_local3++;
};
_local4 = _constraints.length;
_local3 = 0;
while (_local3 < _local4) {
_local11 = _constraints[_local3];
if (!_local11.collidable){
} else {
_local6 = _arg1.particles.length;
_local12 = 0;
while (_local12 < _local6) {
_local9 = _arg1.particles[_local12];
if (((_local9.collidable) && (!(_local11.isConnectedTo(_local9))))){
_local11.scp.updatePosition();
CollisionDetector.test(_local9, _local11.scp);
};
_local12++;
};
};
_local3++;
};
}
public function get sprite():Sprite{
if (_sprite != null){
return (_sprite);
};
if (APEngine.container == null){
throw (new Error("The container property of the APEngine class has not been set"));
};
_sprite = new Sprite();
APEngine.container.addChild(_sprite);
return (_sprite);
}
function checkInternalCollisions():void{
var _local1:int;
var _local2:int;
var _local3:AbstractParticle;
var _local4:int;
var _local5:int;
var _local6:int;
var _local7:AbstractParticle;
var _local8:SpringConstraint;
_local1 = _particles.length;
_local2 = 0;
while (_local2 < _local1) {
_local3 = _particles[_local2];
if (!_local3.collidable){
} else {
_local4 = (_local2 + 1);
while (_local4 < _local1) {
_local7 = _particles[_local4];
if (_local7.collidable){
CollisionDetector.test(_local3, _local7);
};
_local4++;
};
_local5 = _constraints.length;
_local6 = 0;
while (_local6 < _local5) {
_local8 = _constraints[_local6];
if (((_local8.collidable) && (!(_local8.isConnectedTo(_local3))))){
_local8.scp.updatePosition();
CollisionDetector.test(_local3, _local8.scp);
};
_local6++;
};
};
_local2++;
};
}
public function addParticle(_arg1:AbstractParticle):void{
particles.push(_arg1);
if (isParented){
_arg1.init();
};
}
public function removeConstraint(_arg1:AbstractConstraint):void{
var _local2:int;
_local2 = constraints.indexOf(_arg1);
if (_local2 == -1){
return;
};
constraints.splice(_local2, 1);
_arg1.cleanup();
}
function get isParented():Boolean{
return (_isParented);
}
public function init():void{
var _local1:int;
_local1 = 0;
while (_local1 < particles.length) {
particles[_local1].init();
_local1++;
};
_local1 = 0;
while (_local1 < constraints.length) {
constraints[_local1].init();
_local1++;
};
}
function satisfyConstraints():void{
var _local1:int;
var _local2:int;
var _local3:AbstractConstraint;
_local1 = _constraints.length;
_local2 = 0;
while (_local2 < _local1) {
_local3 = _constraints[_local2];
_local3.resolve();
_local2++;
};
}
public function paint():void{
var _local1:AbstractParticle;
var _local2:int;
var _local3:int;
var _local4:SpringConstraint;
_local2 = _particles.length;
_local3 = 0;
while (_local3 < _local2) {
_local1 = _particles[_local3];
if (((!(_local1.fixed)) || (_local1.alwaysRepaint))){
_local1.paint();
};
_local3++;
};
_local2 = _constraints.length;
_local3 = 0;
while (_local3 < _local2) {
_local4 = _constraints[_local3];
if (((!(_local4.fixed)) || (_local4.alwaysRepaint))){
_local4.paint();
};
_local3++;
};
}
public function addConstraint(_arg1:AbstractConstraint):void{
constraints.push(_arg1);
if (isParented){
_arg1.init();
};
}
function set isParented(_arg1:Boolean):void{
_isParented = _arg1;
}
public function removeParticle(_arg1:AbstractParticle):void{
var _local2:int;
_local2 = particles.indexOf(_arg1);
if (_local2 == -1){
return;
};
particles.splice(_local2, 1);
_arg1.cleanup();
}
public function cleanup():void{
var _local1:int;
_local1 = 0;
while (_local1 < particles.length) {
particles[_local1].cleanup();
_local1++;
};
_local1 = 0;
while (_local1 < constraints.length) {
constraints[_local1].cleanup();
_local1++;
};
}
public function get particles():Array{
return (_particles);
}
function integrate(_arg1:Number):void{
var _local2:int;
var _local3:int;
var _local4:AbstractParticle;
_local2 = _particles.length;
_local3 = 0;
while (_local3 < _local2) {
_local4 = _particles[_local3];
_local4.update(_arg1);
_local3++;
};
}
public function get constraints():Array{
return (_constraints);
}
}
}//package org.cove.ape
Section 2
//AbstractConstraint (org.cove.ape.AbstractConstraint)
package org.cove.ape {
import flash.utils.*;
public class AbstractConstraint extends AbstractItem {
private var _stiffness:Number;
public function AbstractConstraint(_arg1:Number){
if (getQualifiedClassName(this) == "org.cove.ape::AbstractConstraint"){
throw (new ArgumentError("AbstractConstraint can't be instantiated directly"));
};
this.stiffness = _arg1;
setStyle();
}
public function get stiffness():Number{
return (_stiffness);
}
public function set stiffness(_arg1:Number):void{
_stiffness = _arg1;
}
function resolve():void{
}
}
}//package org.cove.ape
Section 3
//AbstractItem (org.cove.ape.AbstractItem)
package org.cove.ape {
import flash.display.*;
public class AbstractItem {
var lineAlpha:Number;
var lineColor:uint;
var displayObjectOffset:Vector;
var lineThickness:Number;
var displayObject:DisplayObject;
var fillAlpha:Number;
private var _sprite:Sprite;
var fillColor:uint;
private var _visible:Boolean;
private var _alwaysRepaint:Boolean;
var displayObjectRotation:Number;
public function AbstractItem(){
_visible = true;
_alwaysRepaint = false;
}
public function setLine(_arg1:Number=0, _arg2:uint=0, _arg3:Number=1):void{
lineThickness = _arg1;
lineColor = _arg2;
lineAlpha = _arg3;
}
public function set visible(_arg1:Boolean):void{
_visible = _arg1;
sprite.visible = _arg1;
}
public function setFill(_arg1:uint=0xFFFFFF, _arg2:Number=1):void{
fillColor = _arg1;
fillAlpha = _arg2;
}
public function init():void{
}
public function get sprite():Sprite{
if (_sprite != null){
return (_sprite);
};
if (APEngine.container == null){
throw (new Error("The container property of the APEngine class has not been set"));
};
_sprite = new Sprite();
APEngine.container.addChild(_sprite);
return (_sprite);
}
public function paint():void{
}
public function cleanup():void{
var _local1:int;
sprite.graphics.clear();
_local1 = 0;
while (_local1 < sprite.numChildren) {
sprite.removeChildAt(_local1);
_local1++;
};
}
public function setStyle(_arg1:Number=0, _arg2:uint=0, _arg3:Number=1, _arg4:uint=0xFFFFFF, _arg5:Number=1):void{
setLine(_arg1, _arg2, _arg3);
setFill(_arg4, _arg5);
}
public function get visible():Boolean{
return (_visible);
}
final public function set alwaysRepaint(_arg1:Boolean):void{
_alwaysRepaint = _arg1;
}
final public function get alwaysRepaint():Boolean{
return (_alwaysRepaint);
}
}
}//package org.cove.ape
Section 4
//AbstractParticle (org.cove.ape.AbstractParticle)
package org.cove.ape {
import flash.display.*;
import flash.utils.*;
public class AbstractParticle extends AbstractItem {
private var _collidable:Boolean;
private var _multisample:int;
private var collision:Collision;
var prev:Vector;
private var _kfr:Number;
var curr:Vector;
private var _invMass:Number;
var interval:Interval;
private var _mass:Number;
private var temp:Vector;
private var _friction:Number;
private var forces:Vector;
var samp:Vector;
private var _center:Vector;
private var _fixed:Boolean;
public function AbstractParticle(_arg1:Number, _arg2:Number, _arg3:Boolean, _arg4:Number, _arg5:Number, _arg6:Number){
if (getQualifiedClassName(this) == "org.cove.ape::AbstractParticle"){
throw (new ArgumentError("AbstractParticle can't be instantiated directly"));
};
interval = new Interval(0, 0);
curr = new Vector(_arg1, _arg2);
prev = new Vector(_arg1, _arg2);
samp = new Vector();
temp = new Vector();
fixed = _arg3;
forces = new Vector();
collision = new Collision(new Vector(), new Vector());
collidable = true;
this.mass = _arg4;
this.elasticity = _arg5;
this.friction = _arg6;
setStyle();
_center = new Vector();
_multisample = 0;
}
public function set friction(_arg1:Number):void{
if ((((_arg1 < 0)) || ((_arg1 > 1)))){
throw (new ArgumentError("Legal friction must be >= 0 and <=1"));
};
_friction = _arg1;
}
public function get px():Number{
return (curr.x);
}
public function get py():Number{
return (curr.y);
}
public function set py(_arg1:Number):void{
curr.y = _arg1;
prev.y = _arg1;
}
function getComponents(_arg1:Vector):Collision{
var _local2:Vector;
var _local3:Number;
_local2 = velocity;
_local3 = _arg1.dot(_local2);
collision.vn = _arg1.mult(_local3);
collision.vt = _local2.minus(collision.vn);
return (collision);
}
public function set mass(_arg1:Number):void{
if (_arg1 <= 0){
throw (new ArgumentError("mass may not be set <= 0"));
};
_mass = _arg1;
_invMass = (1 / _mass);
}
public function get fixed():Boolean{
return (_fixed);
}
public function set px(_arg1:Number):void{
curr.x = _arg1;
prev.x = _arg1;
}
function initDisplay():void{
displayObject.x = displayObjectOffset.x;
displayObject.y = displayObjectOffset.y;
displayObject.rotation = displayObjectRotation;
sprite.addChild(displayObject);
}
function get invMass():Number{
return ((fixed) ? 0 : _invMass);
}
public function setDisplay(_arg1:DisplayObject, _arg2:Number=0, _arg3:Number=0, _arg4:Number=0):void{
displayObject = _arg1;
displayObjectRotation = _arg4;
displayObjectOffset = new Vector(_arg2, _arg3);
}
public function get position():Vector{
return (new Vector(curr.x, curr.y));
}
public function get multisample():int{
return (_multisample);
}
function resolveCollision(_arg1:Vector, _arg2:Vector, _arg3:Vector, _arg4:Number, _arg5:int, _arg6:AbstractParticle):void{
curr.plusEquals(_arg1);
velocity = _arg2;
}
public function set fixed(_arg1:Boolean):void{
_fixed = _arg1;
}
public function addMasslessForce(_arg1:Vector):void{
forces.plusEquals(_arg1);
}
public function set velocity(_arg1:Vector):void{
prev = curr.minus(_arg1);
}
public function set multisample(_arg1:int):void{
_multisample = _arg1;
}
public function get elasticity():Number{
return (_kfr);
}
public function set position(_arg1:Vector):void{
curr.copy(_arg1);
prev.copy(_arg1);
}
public function get center():Vector{
_center.setTo(px, py);
return (_center);
}
public function update(_arg1:Number):void{
var _local2:Vector;
if (fixed){
return;
};
addForce(APEngine.force);
addMasslessForce(APEngine.masslessForce);
temp.copy(curr);
_local2 = velocity.plus(forces.multEquals(_arg1));
curr.plusEquals(_local2.multEquals(APEngine.damping));
prev.copy(temp);
forces.setTo(0, 0);
}
public function set collidable(_arg1:Boolean):void{
_collidable = _arg1;
}
public function get velocity():Vector{
return (curr.minus(prev));
}
public function get collidable():Boolean{
return (_collidable);
}
public function addForce(_arg1:Vector):void{
forces.plusEquals(_arg1.mult(invMass));
}
public function set elasticity(_arg1:Number):void{
_kfr = _arg1;
}
public function get friction():Number{
return (_friction);
}
public function get mass():Number{
return (_mass);
}
}
}//package org.cove.ape
Section 5
//APEngine (org.cove.ape.APEngine)
package org.cove.ape {
import flash.display.*;
public final class APEngine {
private static var _container:DisplayObjectContainer;
private static var _damping:Number;
private static var _constraintCollisionCycles:int;
private static var groups:Array;
static var masslessForce:Vector;
private static var _constraintCycles:int;
static var force:Vector;
private static var timeStep:Number;
private static var numGroups:int;
public static function get container():DisplayObjectContainer{
return (_container);
}
public static function get constraintCollisionCycles():int{
return (_constraintCollisionCycles);
}
public static function set damping(_arg1:Number):void{
_damping = _arg1;
}
public static function step():void{
var _local1:int;
var _local2:int;
integrate();
_local1 = 0;
while (_local1 < _constraintCycles) {
satisfyConstraints();
_local1++;
};
_local2 = 0;
while (_local2 < _constraintCollisionCycles) {
satisfyConstraints();
checkCollisions();
_local2++;
};
}
public static function init(_arg1:Number=0.25):void{
timeStep = (_arg1 * _arg1);
numGroups = 0;
groups = new Array();
force = new Vector(0, 0);
masslessForce = new Vector(0, 0);
damping = 1;
_constraintCycles = 0;
_constraintCollisionCycles = 1;
}
public static function get constraintCycles():int{
return (_constraintCycles);
}
public static function set constraintCollisionCycles(_arg1:int):void{
_constraintCollisionCycles = _arg1;
}
public static function set constraintCycles(_arg1:int):void{
_constraintCycles = _arg1;
}
public static function addForce(_arg1:Vector):void{
force.plusEquals(_arg1);
}
public static function get damping():Number{
return (_damping);
}
public static function set container(_arg1:DisplayObjectContainer):void{
_container = _arg1;
}
public static function addGroup(_arg1:Group):void{
groups.push(_arg1);
_arg1.isParented = true;
numGroups++;
_arg1.init();
}
public static function removeGroup(_arg1:Group):void{
var _local2:int;
_local2 = groups.indexOf(_arg1);
if (_local2 == -1){
return;
};
groups.splice(_local2, 1);
_arg1.isParented = false;
numGroups--;
_arg1.cleanup();
}
public static function paint():void{
var _local1:int;
var _local2:Group;
_local1 = 0;
while (_local1 < numGroups) {
_local2 = groups[_local1];
_local2.paint();
_local1++;
};
}
private static function checkCollisions():void{
var _local1:int;
var _local2:Group;
_local1 = 0;
while (_local1 < numGroups) {
_local2 = groups[_local1];
_local2.checkCollisions();
_local1++;
};
}
private static function integrate():void{
var _local1:int;
var _local2:Group;
_local1 = 0;
while (_local1 < numGroups) {
_local2 = groups[_local1];
_local2.integrate(timeStep);
_local1++;
};
}
private static function satisfyConstraints():void{
var _local1:int;
var _local2:Group;
_local1 = 0;
while (_local1 < numGroups) {
_local2 = groups[_local1];
_local2.satisfyConstraints();
_local1++;
};
}
public static function addMasslessForce(_arg1:Vector):void{
masslessForce.plusEquals(_arg1);
}
}
}//package org.cove.ape
Section 6
//CircleParticle (org.cove.ape.CircleParticle)
package org.cove.ape {
public class CircleParticle extends AbstractParticle {
private var _radius:Number;
public function CircleParticle(_arg1:Number, _arg2:Number, _arg3:Number, _arg4:Boolean=false, _arg5:Number=1, _arg6:Number=0.3, _arg7:Number=0){
super(_arg1, _arg2, _arg4, _arg5, _arg6, _arg7);
_radius = _arg3;
}
function getIntervalX():Interval{
interval.min = (curr.x - _radius);
interval.max = (curr.x + _radius);
return (interval);
}
function getIntervalY():Interval{
interval.min = (curr.y - _radius);
interval.max = (curr.y + _radius);
return (interval);
}
override public function init():void{
cleanup();
if (displayObject != null){
initDisplay();
} else {
sprite.graphics.clear();
sprite.graphics.lineStyle(lineThickness, lineColor, lineAlpha);
sprite.graphics.beginFill(fillColor, fillAlpha);
sprite.graphics.drawCircle(0, 0, radius);
sprite.graphics.endFill();
};
paint();
}
public function set radius(_arg1:Number):void{
_radius = _arg1;
}
public function get radius():Number{
return (_radius);
}
function getProjection(_arg1:Vector):Interval{
var _local2:Number;
_local2 = samp.dot(_arg1);
interval.min = (_local2 - _radius);
interval.max = (_local2 + _radius);
return (interval);
}
override public function paint():void{
sprite.x = curr.x;
sprite.y = curr.y;
}
}
}//package org.cove.ape
Section 7
//Collision (org.cove.ape.Collision)
package org.cove.ape {
import org.cove.ape.*;
final class Collision {
var vn:Vector;
var vt:Vector;
function Collision(_arg1:Vector, _arg2:Vector){
this.vn = _arg1;
this.vt = _arg2;
}
}
}//package org.cove.ape
Section 8
//CollisionDetector (org.cove.ape.CollisionDetector)
package org.cove.ape {
import org.cove.ape.*;
final class CollisionDetector {
private static function testOBBvsCircle(_arg1:RectangleParticle, _arg2:CircleParticle):Boolean{
var _local3:Vector;
var _local4:Number;
var _local5:Array;
var _local6:int;
var _local7:Number;
var _local8:Vector;
var _local9:Number;
var _local10:Vector;
var _local11:Number;
_local4 = Number.POSITIVE_INFINITY;
_local5 = new Array(2);
_local6 = 0;
while (_local6 < 2) {
_local8 = _arg1.axes[_local6];
_local9 = testIntervals(_arg1.getProjection(_local8), _arg2.getProjection(_local8));
if (_local9 == 0){
return (false);
};
if (Math.abs(_local9) < Math.abs(_local4)){
_local3 = _local8;
_local4 = _local9;
};
_local5[_local6] = _local9;
_local6++;
};
_local7 = _arg2.radius;
if ((((Math.abs(_local5[0]) < _local7)) && ((Math.abs(_local5[1]) < _local7)))){
_local10 = closestVertexOnOBB(_arg2.samp, _arg1);
_local3 = _local10.minus(_arg2.samp);
_local11 = _local3.magnitude();
_local4 = (_local7 - _local11);
if (_local4 > 0){
_local3.divEquals(_local11);
} else {
return (false);
};
};
CollisionResolver.resolveParticleParticle(_arg1, _arg2, _local3, _local4);
return (true);
}
static function test(_arg1:AbstractParticle, _arg2:AbstractParticle):void{
if (((_arg1.fixed) && (_arg2.fixed))){
return;
};
if ((((_arg1.multisample == 0)) && ((_arg2.multisample == 0)))){
normVsNorm(_arg1, _arg2);
} else {
if ((((_arg1.multisample > 0)) && ((_arg2.multisample == 0)))){
sampVsNorm(_arg1, _arg2);
} else {
if ((((_arg2.multisample > 0)) && ((_arg1.multisample == 0)))){
sampVsNorm(_arg2, _arg1);
} else {
if (_arg1.multisample == _arg2.multisample){
sampVsSamp(_arg1, _arg2);
} else {
normVsNorm(_arg1, _arg2);
};
};
};
};
}
private static function testIntervals(_arg1:Interval, _arg2:Interval):Number{
var _local3:Number;
var _local4:Number;
if (_arg1.max < _arg2.min){
return (0);
};
if (_arg2.max < _arg1.min){
return (0);
};
_local3 = (_arg2.max - _arg1.min);
_local4 = (_arg2.min - _arg1.max);
return (((Math.abs(_local3))<Math.abs(_local4)) ? _local3 : _local4);
}
private static function normVsNorm(_arg1:AbstractParticle, _arg2:AbstractParticle):void{
_arg1.samp.copy(_arg1.curr);
_arg2.samp.copy(_arg2.curr);
testTypes(_arg1, _arg2);
}
private static function testCirclevsCircle(_arg1:CircleParticle, _arg2:CircleParticle):Boolean{
var _local3:Number;
var _local4:Number;
var _local5:Vector;
var _local6:Number;
var _local7:Number;
_local3 = testIntervals(_arg1.getIntervalX(), _arg2.getIntervalX());
if (_local3 == 0){
return (false);
};
_local4 = testIntervals(_arg1.getIntervalY(), _arg2.getIntervalY());
if (_local4 == 0){
return (false);
};
_local5 = _arg1.samp.minus(_arg2.samp);
_local6 = _local5.magnitude();
_local7 = ((_arg1.radius + _arg2.radius) - _local6);
if (_local7 > 0){
_local5.divEquals(_local6);
CollisionResolver.resolveParticleParticle(_arg1, _arg2, _local5, _local7);
return (true);
};
return (false);
}
private static function testTypes(_arg1:AbstractParticle, _arg2:AbstractParticle):Boolean{
if ((((_arg1 is RectangleParticle)) && ((_arg2 is RectangleParticle)))){
return (testOBBvsOBB((_arg1 as RectangleParticle), (_arg2 as RectangleParticle)));
};
if ((((_arg1 is CircleParticle)) && ((_arg2 is CircleParticle)))){
return (testCirclevsCircle((_arg1 as CircleParticle), (_arg2 as CircleParticle)));
};
if ((((_arg1 is RectangleParticle)) && ((_arg2 is CircleParticle)))){
return (testOBBvsCircle((_arg1 as RectangleParticle), (_arg2 as CircleParticle)));
};
if ((((_arg1 is CircleParticle)) && ((_arg2 is RectangleParticle)))){
return (testOBBvsCircle((_arg2 as RectangleParticle), (_arg1 as CircleParticle)));
};
return (false);
}
private static function sampVsNorm(_arg1:AbstractParticle, _arg2:AbstractParticle):void{
var _local3:Number;
var _local4:Number;
var _local5:int;
_local3 = (1 / (_arg1.multisample + 1));
_local4 = _local3;
_arg2.samp.copy(_arg2.curr);
_local5 = 0;
while (_local5 <= _arg1.multisample) {
_arg1.samp.setTo((_arg1.prev.x + (_local4 * (_arg1.curr.x - _arg1.prev.x))), (_arg1.prev.y + (_local4 * (_arg1.curr.y - _arg1.prev.y))));
if (testTypes(_arg1, _arg2)){
return;
};
_local4 = (_local4 + _local3);
_local5++;
};
}
private static function closestVertexOnOBB(_arg1:Vector, _arg2:RectangleParticle):Vector{
var _local3:Vector;
var _local4:Vector;
var _local5:int;
var _local6:Number;
_local3 = _arg1.minus(_arg2.samp);
_local4 = new Vector(_arg2.samp.x, _arg2.samp.y);
_local5 = 0;
while (_local5 < 2) {
_local6 = _local3.dot(_arg2.axes[_local5]);
if (_local6 >= 0){
_local6 = _arg2.extents[_local5];
} else {
if (_local6 < 0){
_local6 = -(_arg2.extents[_local5]);
};
};
_local4.plusEquals(_arg2.axes[_local5].mult(_local6));
_local5++;
};
return (_local4);
}
private static function testOBBvsOBB(_arg1:RectangleParticle, _arg2:RectangleParticle):Boolean{
var _local3:Vector;
var _local4:Number;
var _local5:int;
var _local6:Vector;
var _local7:Number;
var _local8:Vector;
var _local9:Number;
var _local10:Number;
var _local11:Number;
var _local12:Boolean;
_local4 = Number.POSITIVE_INFINITY;
_local5 = 0;
while (_local5 < 2) {
_local6 = _arg1.axes[_local5];
_local7 = testIntervals(_arg1.getProjection(_local6), _arg2.getProjection(_local6));
if (_local7 == 0){
return (false);
};
_local8 = _arg2.axes[_local5];
_local9 = testIntervals(_arg1.getProjection(_local8), _arg2.getProjection(_local8));
if (_local9 == 0){
return (false);
};
_local10 = Math.abs(_local7);
_local11 = Math.abs(_local9);
if ((((_local10 < Math.abs(_local4))) || ((_local11 < Math.abs(_local4))))){
_local12 = (_local10 < _local11);
_local3 = (_local12) ? _local6 : _local8;
_local4 = (_local12) ? _local7 : _local9;
};
_local5++;
};
CollisionResolver.resolveParticleParticle(_arg1, _arg2, _local3, _local4);
return (true);
}
private static function sampVsSamp(_arg1:AbstractParticle, _arg2:AbstractParticle):void{
var _local3:Number;
var _local4:Number;
var _local5:int;
_local3 = (1 / (_arg1.multisample + 1));
_local4 = _local3;
_local5 = 0;
while (_local5 <= _arg1.multisample) {
_arg1.samp.setTo((_arg1.prev.x + (_local4 * (_arg1.curr.x - _arg1.prev.x))), (_arg1.prev.y + (_local4 * (_arg1.curr.y - _arg1.prev.y))));
_arg2.samp.setTo((_arg2.prev.x + (_local4 * (_arg2.curr.x - _arg2.prev.x))), (_arg2.prev.y + (_local4 * (_arg2.curr.y - _arg2.prev.y))));
if (testTypes(_arg1, _arg2)){
return;
};
_local4 = (_local4 + _local3);
_local5++;
};
}
}
}//package org.cove.ape
Section 9
//CollisionResolver (org.cove.ape.CollisionResolver)
package org.cove.ape {
import org.cove.ape.*;
final class CollisionResolver {
static function resolveParticleParticle(_arg1:AbstractParticle, _arg2:AbstractParticle, _arg3:Vector, _arg4:Number):void{
var _local5:Vector;
var _local6:Number;
var _local7:Number;
var _local8:Number;
var _local9:Collision;
var _local10:Collision;
var _local11:Vector;
var _local12:Vector;
var _local13:Vector;
var _local14:Vector;
_arg1.curr.copy(_arg1.samp);
_arg2.curr.copy(_arg2.samp);
_local5 = _arg3.mult(_arg4);
_local6 = (_arg1.elasticity + _arg2.elasticity);
_local7 = (_arg1.invMass + _arg2.invMass);
_local8 = clamp((1 - (_arg1.friction + _arg2.friction)), 0, 1);
_local9 = _arg1.getComponents(_arg3);
_local10 = _arg2.getComponents(_arg3);
_local11 = _local10.vn.mult(((_local6 + 1) * _arg1.invMass)).plus(_local9.vn.mult((_arg2.invMass - (_local6 * _arg1.invMass)))).divEquals(_local7);
_local12 = _local9.vn.mult(((_local6 + 1) * _arg2.invMass)).plus(_local10.vn.mult((_arg1.invMass - (_local6 * _arg2.invMass)))).divEquals(_local7);
_local9.vt.multEquals(_local8);
_local10.vt.multEquals(_local8);
_local13 = _local5.mult((_arg1.invMass / _local7));
_local14 = _local5.mult((-(_arg2.invMass) / _local7));
_local11.plusEquals(_local9.vt);
_local12.plusEquals(_local10.vt);
if (!_arg1.fixed){
_arg1.resolveCollision(_local13, _local11, _arg3, _arg4, -1, _arg2);
};
if (!_arg2.fixed){
_arg2.resolveCollision(_local14, _local12, _arg3, _arg4, 1, _arg1);
};
}
static function clamp(_arg1:Number, _arg2:Number, _arg3:Number):Number{
if (_arg1 > _arg3){
return (_arg3);
};
if (_arg1 < _arg2){
return (_arg2);
};
return (_arg1);
}
}
}//package org.cove.ape
Section 10
//Composite (org.cove.ape.Composite)
package org.cove.ape {
public class Composite extends AbstractCollection {
private var delta:Vector;
public function Composite(){
delta = new Vector();
}
private function getRelativeAngle(_arg1:Vector, _arg2:Vector):Number{
delta.setTo((_arg2.x - _arg1.x), (_arg2.y - _arg1.y));
return (Math.atan2(delta.y, delta.x));
}
public function rotateByRadian(_arg1:Number, _arg2:Vector):void{
var _local3:AbstractParticle;
var _local4:Array;
var _local5:int;
var _local6:int;
var _local7:Number;
var _local8:Number;
_local4 = particles;
_local5 = _local4.length;
_local6 = 0;
while (_local6 < _local5) {
_local3 = _local4[_local6];
_local7 = _local3.center.distance(_arg2);
_local8 = (getRelativeAngle(_arg2, _local3.center) + _arg1);
_local3.px = ((Math.cos(_local8) * _local7) + _arg2.x);
_local3.py = ((Math.sin(_local8) * _local7) + _arg2.y);
_local6++;
};
}
public function rotateByAngle(_arg1:Number, _arg2:Vector):void{
var _local3:Number;
_local3 = (_arg1 * MathUtil.PI_OVER_ONE_EIGHTY);
rotateByRadian(_local3, _arg2);
}
public function set fixed(_arg1:Boolean):void{
var _local2:int;
_local2 = 0;
while (_local2 < particles.length) {
particles[_local2].fixed = _arg1;
_local2++;
};
}
public function get fixed():Boolean{
var _local1:int;
_local1 = 0;
while (_local1 < particles.length) {
if (!particles[_local1].fixed){
return (false);
};
_local1++;
};
return (true);
}
}
}//package org.cove.ape
Section 11
//Group (org.cove.ape.Group)
package org.cove.ape {
public class Group extends AbstractCollection {
private var _collideInternal:Boolean;
private var _composites:Array;
private var _collisionList:Array;
public function Group(_arg1:Boolean=false){
_composites = new Array();
_collisionList = new Array();
this.collideInternal = _arg1;
}
function checkCollisions():void{
var _local1:int;
var _local2:int;
var _local3:Group;
if (collideInternal){
checkCollisionGroupInternal();
};
_local1 = collisionList.length;
_local2 = 0;
while (_local2 < _local1) {
_local3 = collisionList[_local2];
checkCollisionVsGroup(_local3);
_local2++;
};
}
public function get composites():Array{
return (_composites);
}
override public function init():void{
var _local1:int;
super.init();
_local1 = 0;
while (_local1 < composites.length) {
composites[_local1].init();
_local1++;
};
}
public function removeCollidable(_arg1:Group):void{
var _local2:int;
_local2 = collisionList.indexOf(_arg1);
if (_local2 == -1){
return;
};
collisionList.splice(_local2, 1);
}
private function checkCollisionVsGroup(_arg1:Group):void{
var _local2:int;
var _local3:int;
var _local4:int;
var _local5:Composite;
var _local6:int;
var _local7:Composite;
checkCollisionsVsCollection(_arg1);
_local2 = _composites.length;
_local3 = _arg1.composites.length;
_local4 = 0;
while (_local4 < _local2) {
_local5 = _composites[_local4];
_local5.checkCollisionsVsCollection(_arg1);
_local6 = 0;
while (_local6 < _local3) {
_local7 = _arg1.composites[_local6];
_local5.checkCollisionsVsCollection(_local7);
_local6++;
};
_local4++;
};
_local6 = 0;
while (_local6 < _local3) {
_local7 = _arg1.composites[_local6];
checkCollisionsVsCollection(_local7);
_local6++;
};
}
override function satisfyConstraints():void{
var _local1:int;
var _local2:int;
var _local3:Composite;
super.satisfyConstraints();
_local1 = _composites.length;
_local2 = 0;
while (_local2 < _local1) {
_local3 = _composites[_local2];
_local3.satisfyConstraints();
_local2++;
};
}
public function get collideInternal():Boolean{
return (_collideInternal);
}
public function addCollidableList(_arg1:Array):void{
var _local2:int;
var _local3:Group;
_local2 = 0;
while (_local2 < _arg1.length) {
_local3 = _arg1[_local2];
collisionList.push(_local3);
_local2++;
};
}
public function removeComposite(_arg1:Composite):void{
var _local2:int;
_local2 = composites.indexOf(_arg1);
if (_local2 == -1){
return;
};
composites.splice(_local2, 1);
_arg1.isParented = false;
_arg1.cleanup();
}
override public function cleanup():void{
var _local1:int;
super.cleanup();
_local1 = 0;
while (_local1 < composites.length) {
composites[_local1].cleanup();
_local1++;
};
}
override public function paint():void{
var _local1:int;
var _local2:int;
var _local3:Composite;
super.paint();
_local1 = _composites.length;
_local2 = 0;
while (_local2 < _local1) {
_local3 = _composites[_local2];
_local3.paint();
_local2++;
};
}
public function addCollidable(_arg1:Group):void{
collisionList.push(_arg1);
}
override public function getAll():Array{
return (particles.concat(constraints).concat(composites));
}
public function get collisionList():Array{
return (_collisionList);
}
override function integrate(_arg1:Number):void{
var _local2:int;
var _local3:int;
var _local4:Composite;
super.integrate(_arg1);
_local2 = _composites.length;
_local3 = 0;
while (_local3 < _local2) {
_local4 = _composites[_local3];
_local4.integrate(_arg1);
_local3++;
};
}
public function addComposite(_arg1:Composite):void{
composites.push(_arg1);
_arg1.isParented = true;
if (isParented){
_arg1.init();
};
}
private function checkCollisionGroupInternal():void{
var _local1:int;
var _local2:int;
var _local3:Composite;
var _local4:int;
var _local5:Composite;
checkInternalCollisions();
_local1 = _composites.length;
_local2 = 0;
while (_local2 < _local1) {
_local3 = _composites[_local2];
_local3.checkCollisionsVsCollection(this);
_local4 = (_local2 + 1);
while (_local4 < _local1) {
_local5 = _composites[_local4];
_local3.checkCollisionsVsCollection(_local5);
_local4++;
};
_local2++;
};
}
public function set collideInternal(_arg1:Boolean):void{
_collideInternal = _arg1;
}
}
}//package org.cove.ape
Section 12
//Interval (org.cove.ape.Interval)
package org.cove.ape {
final class Interval {
var min:Number;
var max:Number;
function Interval(_arg1:Number, _arg2:Number){
this.min = _arg1;
this.max = _arg2;
}
function toString():String{
return (((min + " : ") + max));
}
}
}//package org.cove.ape
Section 13
//MathUtil (org.cove.ape.MathUtil)
package org.cove.ape {
final class MathUtil {
static var ONE_EIGHTY_OVER_PI:Number = 57.2957795130823;
static var PI_OVER_ONE_EIGHTY:Number = 0.0174532925199433;
static function clamp(_arg1:Number, _arg2:Number, _arg3:Number):Number{
if (_arg1 < _arg2){
return (_arg2);
};
if (_arg1 > _arg3){
return (_arg3);
};
return (_arg1);
}
static function sign(_arg1:Number):int{
if (_arg1 < 0){
return (-1);
};
return (1);
}
}
}//package org.cove.ape
Section 14
//RectangleParticle (org.cove.ape.RectangleParticle)
package org.cove.ape {
public class RectangleParticle extends AbstractParticle {
private var _axes:Array;
private var _radian:Number;
private var _extents:Array;
public function RectangleParticle(_arg1:Number, _arg2:Number, _arg3:Number, _arg4:Number, _arg5:Number=0, _arg6:Boolean=false, _arg7:Number=1, _arg8:Number=0.3, _arg9:Number=0){
super(_arg1, _arg2, _arg6, _arg7, _arg8, _arg9);
_extents = new Array((_arg3 / 2), (_arg4 / 2));
_axes = new Array(new Vector(0, 0), new Vector(0, 0));
radian = _arg5;
}
override public function init():void{
var _local1:Number;
var _local2:Number;
cleanup();
if (displayObject != null){
initDisplay();
} else {
_local1 = (extents[0] * 2);
_local2 = (extents[1] * 2);
sprite.graphics.clear();
sprite.graphics.lineStyle(lineThickness, lineColor, lineAlpha);
sprite.graphics.beginFill(fillColor, fillAlpha);
sprite.graphics.drawRect((-(_local1) / 2), (-(_local2) / 2), _local1, _local2);
sprite.graphics.endFill();
};
paint();
}
public function set width(_arg1:Number):void{
_extents[0] = (_arg1 / 2);
}
function get axes():Array{
return (_axes);
}
public function get height():Number{
return ((_extents[1] * 2));
}
function get extents():Array{
return (_extents);
}
public function set angle(_arg1:Number):void{
radian = (_arg1 * MathUtil.PI_OVER_ONE_EIGHTY);
}
private function setAxes(_arg1:Number):void{
var _local2:Number;
var _local3:Number;
_local2 = Math.sin(_arg1);
_local3 = Math.cos(_arg1);
axes[0].x = _local3;
axes[0].y = _local2;
axes[1].x = -(_local2);
axes[1].y = _local3;
}
public function get radian():Number{
return (_radian);
}
public function get width():Number{
return ((_extents[0] * 2));
}
public function set height(_arg1:Number):void{
_extents[1] = (_arg1 / 2);
}
public function get angle():Number{
return ((radian * MathUtil.ONE_EIGHTY_OVER_PI));
}
function getProjection(_arg1:Vector):Interval{
var _local2:Number;
var _local3:Number;
_local2 = ((extents[0] * Math.abs(_arg1.dot(axes[0]))) + (extents[1] * Math.abs(_arg1.dot(axes[1]))));
_local3 = samp.dot(_arg1);
interval.min = (_local3 - _local2);
interval.max = (_local3 + _local2);
return (interval);
}
public function set radian(_arg1:Number):void{
_radian = _arg1;
setAxes(_arg1);
}
override public function paint():void{
sprite.x = curr.x;
sprite.y = curr.y;
sprite.rotation = angle;
}
}
}//package org.cove.ape
Section 15
//RimParticle (org.cove.ape.RimParticle)
package org.cove.ape {
import org.cove.ape.*;
class RimParticle {
private var maxTorque:Number;
var curr:Vector;
var prev:Vector;
private var av:Number;
private var wr:Number;
private var sp:Number;
function RimParticle(_arg1:Number, _arg2:Number){
curr = new Vector(_arg1, 0);
prev = new Vector(0, 0);
sp = 0;
av = 0;
maxTorque = _arg2;
wr = _arg1;
}
function update(_arg1:Number):void{
var _local2:Number;
var _local3:Number;
var _local4:Number;
var _local5:Number;
var _local6:Number;
var _local7:Number;
var _local8:Number;
var _local9:Number;
var _local10:Number;
sp = Math.max(-(maxTorque), Math.min(maxTorque, (sp + av)));
_local2 = -(curr.y);
_local3 = curr.x;
_local4 = Math.sqrt(((_local2 * _local2) + (_local3 * _local3)));
_local2 = (_local2 / _local4);
_local3 = (_local3 / _local4);
curr.x = (curr.x + (sp * _local2));
curr.y = (curr.y + (sp * _local3));
_local5 = prev.x;
_local6 = prev.y;
_local7 = (prev.x = curr.x);
_local8 = (prev.y = curr.y);
curr.x = (curr.x + (APEngine.damping * (_local7 - _local5)));
curr.y = (curr.y + (APEngine.damping * (_local8 - _local6)));
_local9 = Math.sqrt(((curr.x * curr.x) + (curr.y * curr.y)));
_local10 = ((_local9 - wr) / _local9);
curr.x = (curr.x - (curr.x * _local10));
curr.y = (curr.y - (curr.y * _local10));
}
function set speed(_arg1:Number):void{
sp = _arg1;
}
function get angularVelocity():Number{
return (av);
}
function set angularVelocity(_arg1:Number):void{
av = _arg1;
}
function get speed():Number{
return (sp);
}
}
}//package org.cove.ape
Section 16
//SpringConstraint (org.cove.ape.SpringConstraint)
package org.cove.ape {
import flash.display.*;
public class SpringConstraint extends AbstractConstraint {
private var _collidable:Boolean;
private var _restLength:Number;
private var p1:AbstractParticle;
private var p2:AbstractParticle;
private var _scp:SpringConstraintParticle;
public function SpringConstraint(_arg1:AbstractParticle, _arg2:AbstractParticle, _arg3:Number=0.5, _arg4:Boolean=false, _arg5:Number=1, _arg6:Number=1, _arg7:Boolean=false){
super(_arg3);
this.p1 = _arg1;
this.p2 = _arg2;
checkParticlesLocation();
_restLength = currLength;
setCollidable(_arg4, _arg5, _arg6, _arg7);
}
public function set rectScale(_arg1:Number):void{
if (scp == null){
return;
};
scp.rectScale = _arg1;
}
override public function init():void{
cleanup();
if (collidable){
scp.init();
} else {
if (displayObject != null){
initDisplay();
};
};
paint();
}
function initDisplay():void{
if (collidable){
scp.initDisplay();
} else {
displayObject.x = displayObjectOffset.x;
displayObject.y = displayObjectOffset.y;
displayObject.rotation = displayObjectRotation;
sprite.addChild(displayObject);
};
}
private function checkParticlesLocation():void{
if ((((p1.curr.x == p2.curr.x)) && ((p1.curr.y == p2.curr.y)))){
p2.curr.x = (p2.curr.x + 0.0001);
};
}
public function get radian():Number{
var _local1:Vector;
_local1 = delta;
return (Math.atan2(_local1.y, _local1.x));
}
function get scp():SpringConstraintParticle{
return (_scp);
}
public function get rectHeight():Number{
return (scp.rectHeight);
}
public function setDisplay(_arg1:DisplayObject, _arg2:Number=0, _arg3:Number=0, _arg4:Number=0):void{
if (collidable){
scp.setDisplay(_arg1, _arg2, _arg3, _arg4);
} else {
displayObject = _arg1;
displayObjectRotation = _arg4;
displayObjectOffset = new Vector(_arg2, _arg3);
};
}
public function set restLength(_arg1:Number):void{
if (_arg1 <= 0){
throw (new ArgumentError("restLength must be greater than 0"));
};
_restLength = _arg1;
}
public function get currLength():Number{
return (p1.curr.distance(p2.curr));
}
public function get fixedEndLimit():Number{
return (scp.fixedEndLimit);
}
public function get rectScale():Number{
return (scp.rectScale);
}
function get delta():Vector{
return (p1.curr.minus(p2.curr));
}
public function get angle():Number{
return ((radian * MathUtil.ONE_EIGHTY_OVER_PI));
}
public function get center():Vector{
return (p1.curr.plus(p2.curr).divEquals(2));
}
public function set rectHeight(_arg1:Number):void{
if (scp == null){
return;
};
scp.rectHeight = _arg1;
}
public function get restLength():Number{
return (_restLength);
}
override public function paint():void{
var _local1:Vector;
if (collidable){
scp.paint();
} else {
if (displayObject != null){
_local1 = center;
sprite.x = _local1.x;
sprite.y = _local1.y;
sprite.rotation = angle;
} else {
sprite.graphics.clear();
sprite.graphics.lineStyle(lineThickness, lineColor, lineAlpha);
sprite.graphics.moveTo(p1.px, p1.py);
sprite.graphics.lineTo(p2.px, p2.py);
};
};
}
public function setCollidable(_arg1:Boolean, _arg2:Number, _arg3:Number, _arg4:Boolean=false):void{
_collidable = _arg1;
_scp = null;
if (_collidable){
_scp = new SpringConstraintParticle(p1, p2, this, _arg2, _arg3, _arg4);
};
}
public function get collidable():Boolean{
return (_collidable);
}
public function isConnectedTo(_arg1:AbstractParticle):Boolean{
return ((((_arg1 == p1)) || ((_arg1 == p2))));
}
override function resolve():void{
var _local1:Number;
var _local2:Number;
var _local3:Vector;
if (((p1.fixed) && (p2.fixed))){
return;
};
_local1 = currLength;
_local2 = ((_local1 - restLength) / (_local1 * (p1.invMass + p2.invMass)));
_local3 = delta.mult((_local2 * stiffness));
p1.curr.minusEquals(_local3.mult(p1.invMass));
p2.curr.plusEquals(_local3.mult(p2.invMass));
}
public function get fixed():Boolean{
return (((p1.fixed) && (p2.fixed)));
}
public function set fixedEndLimit(_arg1:Number):void{
if (scp == null){
return;
};
scp.fixedEndLimit = _arg1;
}
}
}//package org.cove.ape
Section 17
//SpringConstraintParticle (org.cove.ape.SpringConstraintParticle)
package org.cove.ape {
import org.cove.ape.*;
import flash.display.*;
class SpringConstraintParticle extends RectangleParticle {
private var _fixedEndLimit:Number;
private var _rectScale:Number;
private var rca:Vector;
private var rcb:Vector;
private var s:Number;
private var parent:SpringConstraint;
private var scaleToLength:Boolean;
private var p1:AbstractParticle;
private var p2:AbstractParticle;
private var lambda:Vector;
private var avgVelocity:Vector;
private var _rectHeight:Number;
function SpringConstraintParticle(_arg1:AbstractParticle, _arg2:AbstractParticle, _arg3:SpringConstraint, _arg4:Number, _arg5:Number, _arg6:Boolean){
super(0, 0, 0, 0, 0, false);
this.p1 = _arg1;
this.p2 = _arg2;
lambda = new Vector(0, 0);
avgVelocity = new Vector(0, 0);
parent = _arg3;
this.rectScale = _arg5;
this.rectHeight = _arg4;
this.scaleToLength = _arg6;
fixedEndLimit = 0;
rca = new Vector();
rcb = new Vector();
}
private function setCorners(_arg1:RectangleParticle, _arg2:int):void{
var _local3:Number;
var _local4:Number;
var _local5:Array;
var _local6:Array;
var _local7:Number;
var _local8:Number;
var _local9:Number;
var _local10:Number;
var _local11:Number;
var _local12:Number;
var _local13:Number;
var _local14:Number;
_local3 = _arg1.curr.x;
_local4 = _arg1.curr.y;
_local5 = _arg1.axes;
_local6 = _arg1.extents;
_local7 = (_local5[0].x * _local6[0]);
_local8 = (_local5[0].y * _local6[0]);
_local9 = (_local5[1].x * _local6[1]);
_local10 = (_local5[1].y * _local6[1]);
_local11 = (_local7 - _local9);
_local12 = (_local8 - _local10);
_local13 = (_local7 + _local9);
_local14 = (_local8 + _local10);
if (_arg2 == 0){
rca.x = (_local3 - _local13);
rca.y = (_local4 - _local14);
rcb.x = (_local3 + _local11);
rcb.y = (_local4 + _local12);
} else {
if (_arg2 == 1){
rca.x = (_local3 + _local11);
rca.y = (_local4 + _local12);
rcb.x = (_local3 + _local13);
rcb.y = (_local4 + _local14);
} else {
if (_arg2 == 2){
rca.x = (_local3 + _local13);
rca.y = (_local4 + _local14);
rcb.x = (_local3 - _local11);
rcb.y = (_local4 - _local12);
} else {
if (_arg2 == 3){
rca.x = (_local3 - _local11);
rca.y = (_local4 - _local12);
rcb.x = (_local3 - _local13);
rcb.y = (_local4 - _local14);
};
};
};
};
}
override public function init():void{
var _local1:Sprite;
var _local2:Number;
var _local3:Number;
if (displayObject != null){
initDisplay();
} else {
_local1 = new Sprite();
parent.sprite.addChild(_local1);
_local1.name = "inner";
_local2 = (parent.currLength * rectScale);
_local3 = rectHeight;
_local1.graphics.clear();
_local1.graphics.lineStyle(parent.lineThickness, parent.lineColor, parent.lineAlpha);
_local1.graphics.beginFill(parent.fillColor, parent.fillAlpha);
_local1.graphics.drawRect((-(_local2) / 2), (-(_local3) / 2), _local2, _local3);
_local1.graphics.endFill();
};
paint();
}
function updatePosition():void{
var _local1:Vector;
_local1 = parent.center;
curr.setTo(_local1.x, _local1.y);
width = (scaleToLength) ? (parent.currLength * rectScale) : (parent.restLength * rectScale);
height = rectHeight;
radian = parent.radian;
}
private function closestPtSegmentSegment():Number{
var _local1:Vector;
var _local2:Vector;
var _local3:Vector;
var _local4:Vector;
var _local5:Vector;
var _local6:Vector;
var _local7:Vector;
var _local8:Number;
var _local9:Number;
var _local10:Number;
var _local11:Number;
var _local12:Number;
var _local13:Number;
var _local14:Number;
var _local15:Vector;
var _local16:Vector;
var _local17:Vector;
_local1 = p1.curr;
_local2 = p2.curr;
_local3 = rca;
_local4 = rcb;
_local5 = _local2.minus(_local1);
_local6 = _local4.minus(_local3);
_local7 = _local1.minus(_local3);
_local9 = _local5.dot(_local5);
_local10 = _local6.dot(_local6);
_local11 = _local6.dot(_local7);
_local12 = _local5.dot(_local7);
_local13 = _local5.dot(_local6);
_local14 = ((_local9 * _local10) - (_local13 * _local13));
if (_local14 != 0){
s = MathUtil.clamp((((_local13 * _local11) - (_local12 * _local10)) / _local14), 0, 1);
} else {
s = 0.5;
};
_local8 = (((_local13 * s) + _local11) / _local10);
if (_local8 < 0){
_local8 = 0;
s = MathUtil.clamp((-(_local12) / _local9), 0, 1);
} else {
if (_local8 > 0){
_local8 = 1;
s = MathUtil.clamp(((_local13 - _local12) / _local9), 0, 1);
};
};
_local15 = _local1.plus(_local5.mult(s));
_local16 = _local3.plus(_local6.mult(_local8));
_local17 = _local15.minus(_local16);
return (_local15.minus(_local16).dot(_local17));
}
function get rectHeight():Number{
return (_rectHeight);
}
function get fixedEndLimit():Number{
return (_fixedEndLimit);
}
private function closestParamPoint(_arg1:Vector):Number{
var _local2:Vector;
var _local3:Number;
_local2 = p2.curr.minus(p1.curr);
_local3 = (_local2.dot(_arg1.minus(p1.curr)) / _local2.dot(_local2));
return (MathUtil.clamp(_local3, 0, 1));
}
function set rectHeight(_arg1:Number):void{
_rectHeight = _arg1;
}
override public function paint():void{
var _local1:Vector;
var _local2:Sprite;
_local1 = parent.center;
_local2 = parent.sprite;
if (scaleToLength){
_local2.getChildByName("inner").width = (parent.currLength * rectScale);
} else {
if (displayObject != null){
_local2.getChildByName("inner").width = (parent.restLength * rectScale);
};
};
_local2.x = _local1.x;
_local2.y = _local1.y;
_local2.rotation = parent.angle;
}
private function getContactPointParam(_arg1:AbstractParticle):Number{
var _local2:Number;
var _local3:Number;
var _local4:Array;
var _local5:Number;
var _local6:int;
var _local7:Number;
if ((_arg1 is CircleParticle)){
_local2 = closestParamPoint(_arg1.curr);
} else {
if ((_arg1 is RectangleParticle)){
_local4 = new Array(4);
_local5 = Number.POSITIVE_INFINITY;
_local6 = 0;
while (_local6 < 4) {
setCorners((_arg1 as RectangleParticle), _local6);
_local7 = closestPtSegmentSegment();
if (_local7 < _local5){
_local5 = _local7;
_local3 = _local6;
_local4[_local6] = s;
};
_local6++;
};
_local2 = _local4[_local3];
};
};
return (_local2);
}
function set fixedEndLimit(_arg1:Number):void{
_fixedEndLimit = _arg1;
}
override function get invMass():Number{
if (((p1.fixed) && (p2.fixed))){
return (0);
};
return ((1 / ((p1.mass + p2.mass) / 2)));
}
override function initDisplay():void{
var _local1:Sprite;
displayObject.x = displayObjectOffset.x;
displayObject.y = displayObjectOffset.y;
displayObject.rotation = displayObjectRotation;
_local1 = new Sprite();
_local1.name = "inner";
_local1.addChild(displayObject);
parent.sprite.addChild(_local1);
}
function set rectScale(_arg1:Number):void{
_rectScale = _arg1;
}
override function resolveCollision(_arg1:Vector, _arg2:Vector, _arg3:Vector, _arg4:Number, _arg5:int, _arg6:AbstractParticle):void{
var _local7:Number;
var _local8:Number;
var _local9:Number;
var _local10:Number;
var _local11:AbstractParticle;
_local7 = getContactPointParam(_arg6);
_local8 = (1 - _local7);
_local9 = _local7;
if (p1.fixed){
if (_local9 <= fixedEndLimit){
return;
};
lambda.setTo((_arg1.x / _local9), (_arg1.y / _local9));
p2.curr.plusEquals(lambda);
p2.velocity = _arg2;
} else {
if (p2.fixed){
if (_local8 <= fixedEndLimit){
return;
};
lambda.setTo((_arg1.x / _local8), (_arg1.y / _local8));
p1.curr.plusEquals(lambda);
p1.velocity = _arg2;
} else {
_local10 = ((_local8 * _local8) + (_local9 * _local9));
if (_local10 == 0){
return;
};
lambda.setTo((_arg1.x / _local10), (_arg1.y / _local10));
p1.curr.plusEquals(lambda.mult(_local8));
p2.curr.plusEquals(lambda.mult(_local9));
if (_local7 == 0.5){
p1.velocity = _arg2;
p2.velocity = _arg2;
} else {
_local11 = ((_local7)<0.5) ? p1 : p2;
_local11.velocity = _arg2;
};
};
};
}
override public function get elasticity():Number{
return (((p1.elasticity + p2.elasticity) / 2));
}
function get rectScale():Number{
return (_rectScale);
}
override public function get velocity():Vector{
var _local1:Vector;
var _local2:Vector;
_local1 = p1.velocity;
_local2 = p2.velocity;
avgVelocity.setTo(((_local1.x + _local2.x) / 2), ((_local1.y + _local2.y) / 2));
return (avgVelocity);
}
override public function get friction():Number{
return (((p1.friction + p2.friction) / 2));
}
override public function get mass():Number{
return (((p1.mass + p2.mass) / 2));
}
}
}//package org.cove.ape
Section 18
//Vector (org.cove.ape.Vector)
package org.cove.ape {
public class Vector {
public var x:Number;
public var y:Number;
public function Vector(_arg1:Number=0, _arg2:Number=0){
x = _arg1;
y = _arg2;
}
public function cross(_arg1:Vector):Number{
return (((x * _arg1.y) - (y * _arg1.x)));
}
public function magnitude():Number{
return (Math.sqrt(((x * x) + (y * y))));
}
public function divEquals(_arg1:Number):Vector{
if (_arg1 == 0){
_arg1 = 0.0001;
};
x = (x / _arg1);
y = (y / _arg1);
return (this);
}
public function times(_arg1:Vector):Vector{
return (new Vector((x * _arg1.x), (y * _arg1.y)));
}
public function plusEquals(_arg1:Vector):Vector{
x = (x + _arg1.x);
y = (y + _arg1.y);
return (this);
}
public function dot(_arg1:Vector):Number{
return (((x * _arg1.x) + (y * _arg1.y)));
}
public function toString():String{
return (((x + " : ") + y));
}
public function normalize():Vector{
var _local1:Number;
_local1 = magnitude();
if (_local1 == 0){
_local1 = 0.0001;
};
return (mult((1 / _local1)));
}
public function copy(_arg1:Vector):void{
x = _arg1.x;
y = _arg1.y;
}
public function minusEquals(_arg1:Vector):Vector{
x = (x - _arg1.x);
y = (y - _arg1.y);
return (this);
}
public function minus(_arg1:Vector):Vector{
return (new Vector((x - _arg1.x), (y - _arg1.y)));
}
public function plus(_arg1:Vector):Vector{
return (new Vector((x + _arg1.x), (y + _arg1.y)));
}
public function distance(_arg1:Vector):Number{
var _local2:Vector;
_local2 = this.minus(_arg1);
return (_local2.magnitude());
}
public function setTo(_arg1:Number, _arg2:Number):void{
x = _arg1;
y = _arg2;
}
public function multEquals(_arg1:Number):Vector{
x = (x * _arg1);
y = (y * _arg1);
return (this);
}
public function mult(_arg1:Number):Vector{
return (new Vector((x * _arg1), (y * _arg1)));
}
}
}//package org.cove.ape
Section 19
//WheelParticle (org.cove.ape.WheelParticle)
package org.cove.ape {
public class WheelParticle extends CircleParticle {
private var _traction:Number;
private var normSlip:Vector;
private var tan:Vector;
private var rp:RimParticle;
private var orientation:Vector;
public function WheelParticle(_arg1:Number, _arg2:Number, _arg3:Number, _arg4:Boolean=false, _arg5:Number=1, _arg6:Number=0.3, _arg7:Number=0, _arg8:Number=1){
super(_arg1, _arg2, _arg3, _arg4, _arg5, _arg6, _arg7);
tan = new Vector(0, 0);
normSlip = new Vector(0, 0);
rp = new RimParticle(_arg3, 2);
this.traction = _arg8;
orientation = new Vector();
}
override public function init():void{
cleanup();
if (displayObject != null){
initDisplay();
} else {
sprite.graphics.clear();
sprite.graphics.lineStyle(lineThickness, lineColor, lineAlpha);
sprite.graphics.beginFill(fillColor, fillAlpha);
sprite.graphics.drawCircle(0, 0, radius);
sprite.graphics.endFill();
sprite.graphics.moveTo(-(radius), 0);
sprite.graphics.lineTo(radius, 0);
sprite.graphics.moveTo(0, -(radius));
sprite.graphics.lineTo(0, radius);
};
paint();
}
public function set speed(_arg1:Number):void{
rp.speed = _arg1;
}
override function resolveCollision(_arg1:Vector, _arg2:Vector, _arg3:Vector, _arg4:Number, _arg5:int, _arg6:AbstractParticle):void{
super.resolveCollision(_arg1, _arg2, _arg3, _arg4, _arg5, _arg6);
resolve(_arg3.mult(MathUtil.sign((_arg4 * _arg5))));
}
public function get traction():Number{
return ((1 - _traction));
}
public function get radian():Number{
orientation.setTo(rp.curr.x, rp.curr.y);
return ((Math.atan2(orientation.y, orientation.x) + Math.PI));
}
public function set angularVelocity(_arg1:Number):void{
rp.angularVelocity = _arg1;
}
public function get speed():Number{
return (rp.speed);
}
override public function update(_arg1:Number):void{
super.update(_arg1);
rp.update(_arg1);
}
public function get angle():Number{
return ((radian * MathUtil.ONE_EIGHTY_OVER_PI));
}
override public function paint():void{
sprite.x = curr.x;
sprite.y = curr.y;
sprite.rotation = angle;
}
public function get angularVelocity():Number{
return (rp.angularVelocity);
}
private function resolve(_arg1:Vector):void{
var _local2:Vector;
var _local3:Vector;
var _local4:Number;
var _local5:Number;
tan.setTo(-(rp.curr.y), rp.curr.x);
tan = tan.normalize();
_local2 = tan.mult(rp.speed);
_local3 = velocity.plusEquals(_local2);
_local4 = _local3.cross(_arg1);
tan.multEquals(_local4);
rp.prev.copy(rp.curr.minus(tan));
_local5 = ((1 - _traction) * rp.speed);
normSlip.setTo((_local5 * _arg1.y), (_local5 * _arg1.x));
curr.plusEquals(normSlip);
rp.speed = (rp.speed * _traction);
}
public function set traction(_arg1:Number):void{
_traction = (1 - _arg1);
}
}
}//package org.cove.ape
Section 20
//Application (Application)
package {
import org.cove.ape.*;
import flash.display.*;
import flash.events.*;
import flash.text.*;
import flash.net.*;
import flash.system.*;
import flash.filters.*;
import flash.geom.*;
public class Application extends MovieClip {
var pegsHigh:Number;// = 7
private var spaceDiscBoard:Number;// = 2
var spaceBetweenPegs:Number;// = 25
var pegsWide:Number;// = 10
var discStartX:Number;// = 22
var discStartY:Number;// = 18
private var background:Shape;
private var discTextColor:String;// = "ffffff"
private var boardX:Number;// = 11
private var boardY:Number;// = 40
private var boardColor:String;// = "000000"
private var textColor:Number;// = 0
private var draggedDisc:Disc;
private var prevMouseX:Number;
private var prevMouseY:Number;
private var scoreTF:TextField;
var discRadius:Number;
var disc:Disc;
private var discFillColor:String;// = "ff3333"
var msOffsetX:Number;// = 0
var msOffsetY:Number;// = 0
private var discs:Array;
private var discLineColor:String;// = "960000"
private var board:Board;
private var backgroundColor:String;// = "FFFFFF"
private var discGroup:Group;
private var boardTextColor:String;// = "000000"
public function Application(){
spaceDiscBoard = 2;
textColor = 0;
boardX = 11;
boardY = 40;
pegsWide = 10;
pegsHigh = 7;
spaceBetweenPegs = 25;
discStartX = 22;
discStartY = 18;
msOffsetX = 0;
msOffsetY = 0;
backgroundColor = "FFFFFF";
discFillColor = "ff3333";
discLineColor = "960000";
discTextColor = "ffffff";
boardColor = "000000";
boardTextColor = "000000";
super();
addEventListener(Event.ENTER_FRAME, getStageDimensions);
}
public function init(){
var paramObj:Object;
var refreshButton:RefreshButton;
var discMass:Number;
var discElas:Number;
var numDiscs:Number;
var i:Number;
var scoreLabels:Sprite;
var link:Sprite;
var txt:TextField;
var request:URLRequest;
Security.allowDomain("bin.clearspring.com");
Security.allowDomain("widgets.clearspring.com");
discs = new Array();
paramObj = root.loaderInfo.parameters;
if (paramObj.up_backgroundColor != undefined){
backgroundColor = paramObj.up_backgroundColor;
};
if (paramObj.up_discFillColor != undefined){
discFillColor = paramObj.up_discFillColor;
};
if (paramObj.up_discLineColor != undefined){
discLineColor = paramObj.up_discLineColor;
};
if (paramObj.up_discTextColor != undefined){
discTextColor = paramObj.up_discTextColor;
};
if (paramObj.up_boardColor != undefined){
boardColor = paramObj.up_boardColor;
};
if (paramObj.up_boardTextColor != undefined){
boardTextColor = paramObj.up_boardTextColor;
};
background = new Shape();
addChild(background);
refreshButton = new RefreshButton(13, 22, parseInt(("0x" + backgroundColor)), parseInt(("0x" + boardColor)));
refreshButton.x = ((boardX + (spaceBetweenPegs * (pegsWide - 1))) - refreshButton.width);
refreshButton.y = 8;
refreshButton.addEventListener(MouseEvent.MOUSE_UP, reset);
addChild(refreshButton);
discRadius = ((spaceBetweenPegs / 2) * 0.8);
discMass = 1;
discElas = 0.3;
createScoreTF((boardX + ((spaceBetweenPegs * (pegsWide - 1)) * 0.3)), ((boardY + (spaceBetweenPegs * pegsHigh)) + 3), boardTextColor);
addEventListener(Event.ENTER_FRAME, run);
APEngine.init();
APEngine.container = this;
APEngine.addMasslessForce(new Vector(0, 3));
discGroup = new Group();
numDiscs = 5;
i = 0;
while (i < numDiscs) {
disc = new Disc(discFillColor, discLineColor, discTextColor, (i + 1), discStartX, discStartY, discRadius, true);
discs[i] = disc;
discGroup.addParticle(disc);
i = (i + 1);
};
board = new Board(boardColor, boardX, boardY, pegsWide, pegsHigh, spaceBetweenPegs);
discGroup.addCollidableList(new Array(board));
APEngine.addGroup(discGroup);
APEngine.addGroup(board);
scoreLabels = new Sprite();
board.drawScoreLabels(scoreLabels, boardTextColor);
addChild(scoreLabels);
i = 0;
while (i < numDiscs) {
discs[i].sprite.addEventListener(MouseEvent.MOUSE_DOWN, dragDisc);
i = (i + 1);
};
stage.addEventListener(MouseEvent.MOUSE_UP, dropDisc);
stage.addEventListener(Event.RESIZE, resize);
drawBackground();
link = new Sprite();
link.x = (boardX - 6);
link.y = ((boardY + board.sprite.height) - 4);
link.buttonMode = true;
link.mouseChildren = false;
link.addEventListener(MouseEvent.MOUSE_UP, function (){
navigateToURL(request, "_top");
});
addChild(link);
txt = new TextField();
txt.autoSize = TextFieldAutoSize.LEFT;
txt.embedFonts = true;
txt.htmlText = (("<FONT FACE='Icicle Country 2' COLOR='#" + boardTextColor) + "' SIZE='12'>aBowman<FONT>");
txt.selectable = false;
link.addChild(txt);
request = new URLRequest("http://abowman.com/google-modules/disc-drop/");
}
public function getStageDimensions(_arg1:Event){
if (stage.stageWidth > 0){
removeEventListener(Event.ENTER_FRAME, getStageDimensions);
init();
};
}
private function dropDisc(_arg1:Event){
var _local2:Number;
var _local3:Vector;
if (draggedDisc != null){
draggedDisc.fixed = false;
draggedDisc.collidable = true;
_local2 = mouseY;
_local3 = new Vector((mouseX - prevMouseX), (mouseY - prevMouseY));
draggedDisc.velocity = _local3;
};
trace("drop");
draggedDisc = null;
}
public function reset(_arg1:Event){
var _local2:Number;
_local2 = 0;
while (_local2 < discs.length) {
discs[_local2].init();
discs[_local2].px = discStartX;
discs[_local2].py = discStartY;
discs[_local2].fixed = true;
discs[_local2].alwaysRepaint = true;
_local2++;
};
}
private function drawBackground(){
trace("draw background");
background.graphics.clear();
background.graphics.beginFill(parseInt(("0x" + backgroundColor)));
background.graphics.drawRect((-(stage.stageWidth) / 2), (-(stage.stageHeight) / 2), (stage.stageWidth * 2), (stage.stageHeight * 2));
background.graphics.endFill();
}
private function resize(_arg1:Event=null){
drawBackground();
}
private function run(_arg1:Event):void{
var _local2:Number;
var _local3:Number;
var _local4:Number;
APEngine.step();
if (draggedDisc != null){
_local3 = mouseX;
_local4 = mouseY;
draggedDisc.px = (_local3 - msOffsetX);
draggedDisc.py = (Math.min((((boardY - discRadius) - spaceDiscBoard) + msOffsetY), _local4) - msOffsetY);
};
APEngine.paint();
prevMouseX = _local3;
prevMouseY = _local4;
_local2 = board.getScore(discs);
scoreTF.htmlText = (((("<FONT FACE='Icicle Country 2' COLOR='#" + boardTextColor) + "' SIZE='22'>") + _local2) + "<FONT>");
}
private function createScoreTF(_arg1:Number, _arg2:Number, _arg3:String){
var _local4:TextField;
_local4 = new TextField();
_local4.autoSize = TextFieldAutoSize.LEFT;
_local4.embedFonts = true;
_local4.x = _arg1;
_local4.y = _arg2;
_local4.htmlText = (("<FONT FACE='Icicle Country 2' COLOR='#" + _arg3) + "' SIZE='22'>Score:<FONT>");
_local4.antiAliasType = AntiAliasType.ADVANCED;
addChild(_local4);
scoreTF = new TextField();
scoreTF.autoSize = TextFieldAutoSize.LEFT;
scoreTF.embedFonts = true;
scoreTF.x = (_arg1 + _local4.width);
scoreTF.y = _arg2;
scoreTF.antiAliasType = AntiAliasType.ADVANCED;
addChild(scoreTF);
}
private function dragDisc(_arg1:Event){
var _local2:Number;
_local2 = 0;
while (_local2 < discs.length) {
if (discs[_local2].sprite == _arg1.currentTarget){
if (discs[_local2].py < boardY){
draggedDisc = discs[_local2];
draggedDisc.collidable = false;
draggedDisc.fixed = true;
draggedDisc.alwaysRepaint = true;
msOffsetX = (mouseX - discs[_local2].px);
msOffsetY = (mouseY - discs[_local2].py);
};
break;
};
_local2++;
};
}
}
}//package
Section 21
//Board (Board)
package {
import org.cove.ape.*;
import flash.display.*;
import flash.events.*;
import flash.text.*;
public class Board extends Group {
var boardWidth:Number;
var bottomThickness:Number;// = 3
private var textColor:String;// = "000000"
var pegCol:Number;// = 0
var pegsWide:Number;
var boardColor:Number;
var pegs:Array;
var bPegs:Array;
var bWalls:Array;
private var euph:Class;
private var scores:Array;
var boardX:Number;
var rPegs:Array;
var lPegs:Array;
var boardHeight:Number;
var pegsL:Array;
var pegsR:Array;
var boardSprite:Sprite;
var pocketDepth:Number;// = 23
var pegSpacing:Number;
var sideThickness:Number;// = 3
var pegsHigh:Number;
var boardY:Number;
var xBetween:Number;
var discs:Array;
public function Board(_arg1:String, _arg2:Number, _arg3:Number, _arg4:Number, _arg5:Number, _arg6:Number){
var _local7:*;
var _local8:*;
var _local9:Number;
var _local10:*;
var _local11:SpringConstraint;
var _local12:CircleParticle;
var _local13:SpringConstraint;
var _local14:*;
var _local15:CircleParticle;
pocketDepth = 23;
sideThickness = 3;
bottomThickness = 3;
pegCol = 0;
scores = new Array(5, 10, 25, 0, 50, 0, 25, 10, 5);
textColor = "000000";
super();
boardColor = (pegCol = parseInt(("0x" + _arg1)));
boardX = _arg2;
boardY = _arg3;
pocketDepth = (this.pegSpacing = _arg6);
pegsWide = _arg4;
pegsHigh = _arg5;
boardSprite = new Sprite();
sprite.addChild(boardSprite);
collideInternal = false;
_local7 = (this.xBetween = _arg6);
_local8 = _local7;
_local9 = 1.5;
this.pegsWide = _arg4;
this.pegsHigh = _arg5;
this.pegs = new Array();
this.rPegs = new Array();
this.lPegs = new Array();
this.bPegs = new Array();
this.boardWidth = ((this.pegsWide - 1) * _arg6);
this.boardHeight = (((this.pegsHigh - 1) * _arg6) + pocketDepth);
_local10 = 0;
while (_local10 < _arg5) {
_local14 = 0;
while (_local14 < _arg4) {
if (!(((_local10 % 2)) && ((_local14 == (_arg4 - 1))))){
_local15 = new CircleParticle((((((_local10 % 2) * _local7) / 2) + (_local7 * _local14)) + boardX), ((_local8 * _local10) + boardY), _local9, true);
pegs.push(_local15);
_local15.setStyle(1, pegCol, 0, pegCol);
if (_local14 == 0){
_local15.setStyle(0, pegCol, 0, pegCol);
rPegs.push(_local15);
_local15.visible = false;
_local15.collidable = false;
};
if ((((_local14 == (_arg4 - 1))) || ((((_local10 % 2)) && ((_local14 == (_arg4 - 2))))))){
_local15.setStyle(0, pegCol, 0, pegCol);
lPegs.push(_local15);
_local15.visible = false;
_local15.collidable = false;
};
if (_local10 == (_arg5 - 1)){
bPegs.push(_local15);
_local15.visible = false;
_local15.collidable = false;
};
addParticle(_local15);
};
_local14++;
};
_local10++;
};
_local14 = 0;
while (_local14 < _arg4) {
_local15 = new CircleParticle(((_local7 * _local14) + boardX), ((_local8 * _local10) + boardY), _local9, true);
_local15.setStyle(1, pegCol, 1, pegCol);
addParticle(_local15);
_local11 = new SpringConstraint(_local15, bPegs[_local14], 1, true);
_local11.setStyle(2, boardColor);
addConstraint(_local11);
if (_local14 == 0){
_local12 = _local15;
};
if (_local14 == (_arg4 - 1)){
_local13 = new SpringConstraint(_local12, _local15, 1, true);
_local13.setStyle(2, boardColor);
addConstraint(_local13);
};
_local14++;
};
_local10 = 1;
while (_local10 < _arg5) {
_local11 = new SpringConstraint(rPegs[(_local10 - 1)], rPegs[_local10], 1, true);
_local11.setStyle(2, boardColor);
addConstraint(_local11);
_local10++;
};
_local10 = 1;
while (_local10 < _arg5) {
_local11 = new SpringConstraint(lPegs[(_local10 - 1)], lPegs[_local10], 1, true);
_local11.setStyle(2, boardColor);
addConstraint(_local11);
_local10++;
};
_local15 = new CircleParticle((rPegs[0].px - sideThickness), boardY, _local9, true);
_local15.setStyle(0, pegCol, 0, pegCol);
_local15.visible = false;
_local15.collidable = false;
addParticle(_local15);
_local11 = new SpringConstraint(_local15, rPegs[0], 1, true);
_local11.setStyle(2, boardColor);
addConstraint(_local11);
_local15 = new CircleParticle((lPegs[0].px + sideThickness), boardY, _local9, true);
_local15.setStyle(0, pegCol, 0, pegCol);
_local15.visible = false;
_local15.collidable = false;
addParticle(_local15);
_local11 = new SpringConstraint(_local15, lPegs[0], 1, true);
_local11.setStyle(2, boardColor);
addConstraint(_local11);
drawBoard();
}
public function drawBoard(){
var _local1:Graphics;
var _local2:Number;
_local1 = boardSprite.graphics;
_local1.lineStyle(3, boardColor);
_local1.beginFill(boardColor);
_local1.moveTo(rPegs[0].px, rPegs[0].py);
_local2 = 1;
while (_local2 < pegsHigh) {
_local1.lineTo(rPegs[_local2].px, rPegs[_local2].py);
_local2++;
};
_local1.lineTo(rPegs[(pegsHigh - 1)].px, (rPegs[(pegsHigh - 1)].py + pocketDepth));
_local1.lineTo(lPegs[(pegsHigh - 1)].px, (lPegs[(pegsHigh - 1)].py + pocketDepth));
_local2 = (pegsHigh - 1);
while (_local2 >= 0) {
_local1.lineTo(lPegs[_local2].px, lPegs[_local2].py);
_local2--;
};
_local2 = 0;
while (_local2 < pegsHigh) {
_local1.lineTo((lPegs[_local2].px + sideThickness), lPegs[_local2].py);
_local2++;
};
_local1.lineTo((lPegs[(pegsHigh - 1)].px + sideThickness), ((lPegs[(pegsHigh - 1)].py + pocketDepth) + bottomThickness));
_local1.lineTo((rPegs[(pegsHigh - 1)].px - sideThickness), ((rPegs[(pegsHigh - 1)].py + pocketDepth) + bottomThickness));
_local2 = (pegsHigh - 1);
while (_local2 >= 0) {
_local1.lineTo((rPegs[_local2].px - sideThickness), rPegs[_local2].py);
_local2--;
};
_local1.lineTo(rPegs[0].px, rPegs[0].py);
_local1.endFill();
}
public function drawScoreLabels(_arg1:Sprite, _arg2:String){
var _local3:TextField;
var _local4:Number;
var _local5:*;
_local4 = pegsHigh;
_local5 = 0;
while (_local5 < pegsWide) {
if (_local5 != (pegsWide - 1)){
_local3 = new TextField();
_local3.autoSize = TextFieldAutoSize.LEFT;
_local3.embedFonts = true;
_local3.htmlText = (((("<FONT FACE='Icicle Country 2' COLOR='#" + _arg2) + "' SIZE='18'>") + scores[_local5]) + "<FONT>");
_local3.x = (((((xBetween * _local5) + (xBetween / 2)) - (_local3.width / 2)) - 1) + boardX);
_local3.y = ((((xBetween * _local4) - (xBetween / 2)) - (_local3.height / 2)) + boardY);
_local3.selectable = false;
_local3.antiAliasType = AntiAliasType.ADVANCED;
_arg1.addChild(_local3);
};
_local5++;
};
}
public function getScore(_arg1:Array):Number{
var _local2:Disc;
var _local3:Number;
var _local4:Number;
var _local5:Number;
_local3 = 0;
_local4 = 0;
while (_local4 < _arg1.length) {
_local2 = _arg1[_local4];
if ((((((_local2.py >= ((xBetween * (pegsHigh - 1)) + boardY))) && ((_local2.px > boardX)))) && ((_local2.px < ((xBetween * (pegsWide - 1)) + boardX))))){
_local5 = int(((_local2.px - boardX) / xBetween));
_local3 = (_local3 + scores[_local5]);
};
_local4++;
};
return (_local3);
}
}
}//package
Section 22
//Disc (Disc)
package {
import org.cove.ape.*;
import flash.display.*;
import flash.text.*;
public class Disc extends WheelParticle {
private var fillColor:String;// = "ff3333"
private var euph:Class;
public var discSprite:Sprite;
private var discNumber:Number;
private var lineColor:String;// = "960000"
private var textColor:String;// = "FFFFFF"
public function Disc(_arg1:String, _arg2:String, _arg3:String, _arg4:Number, _arg5:Number, _arg6:Number, _arg7:Number, _arg8:Boolean=false, _arg9:Number=1, _arg10:Number=0.3, _arg11:Number=0, _arg12:Number=1){
fillColor = "ff3333";
lineColor = "960000";
textColor = "FFFFFF";
lineColor = _arg2;
fillColor = _arg1;
textColor = _arg3;
super(_arg5, _arg6, _arg7, _arg8, _arg9, _arg10, _arg11, _arg12);
this.discNumber = _arg4;
discSprite = new Sprite();
}
override public function init():void{
var _local1:TextField;
super.init();
sprite.addChild(discSprite);
sprite.graphics.clear();
sprite.graphics.lineStyle(2, parseInt(("0x" + lineColor)));
sprite.graphics.beginFill(parseInt(("0x" + fillColor)));
sprite.graphics.drawCircle(0, 0, radius);
sprite.graphics.endFill();
_local1 = new TextField();
_local1.autoSize = TextFieldAutoSize.LEFT;
_local1.embedFonts = true;
_local1.htmlText = (((("<FONT FACE='Icicle Country 2' COLOR='#" + textColor) + "' SIZE='18'>") + discNumber) + "<FONT>");
_local1.x = (-(_local1.width) / 2);
_local1.y = ((-(_local1.height) / 2) + 1);
_local1.selectable = false;
discSprite.addChild(_local1);
discSprite.rotation = 180;
sprite.buttonMode = true;
sprite.mouseChildren = false;
}
public function draw(){
discSprite.graphics.lineStyle(3, 1);
discSprite.graphics.drawCircle(0, 0, (radius / 2));
}
}
}//package
Section 23
//icicleco (icicleco)
package {
import flash.text.*;
public dynamic class icicleco extends Font {
}
}//package
Section 24
//RefreshButton (RefreshButton)
package {
import flash.display.*;
public class RefreshButton extends Sprite {
private var foreColor:Number;
var h:Number;// = 18
var w:Number;// = 10
private var backColor:Number;
public function RefreshButton(_arg1:Number=10, _arg2:Number=18, _arg3:Number=0xFFFFFF, _arg4:Number=0){
w = 10;
h = 18;
super();
this.w = _arg1;
this.h = _arg2;
this.backColor = _arg3;
this.foreColor = _arg4;
buttonMode = true;
mouseChildren = false;
render();
}
private function render(){
var _local1:Graphics;
var _local2:Number;
var _local3:Number;
_local1 = graphics;
_local2 = 3;
_local3 = 1;
_local1.beginFill(backColor);
_local1.drawRect(0, 0, w, h);
_local1.endFill();
_local1.lineStyle(_local3, foreColor);
_local1.beginFill(foreColor);
_local1.moveTo(w, 0);
_local1.lineTo((w / 3), ((h * 2) / 5));
_local1.lineTo(w, ((h * 2) / 5));
_local1.lineTo(w, 0);
_local1.moveTo(0, ((h * 3) / 5));
_local1.lineTo(((w * 2) / 3), ((h * 3) / 5));
_local1.lineTo(0, h);
_local1.lineTo(0, ((h * 3) / 5));
_local1.endFill();
_local1.lineStyle(3, foreColor);
_local1.moveTo(((w * 2) / 3), (h / 5));
_local1.curveTo(0, (-(h) / 5), 0, ((h * 2) / 5));
_local1.moveTo((w / 3), ((h * 4) / 5));
_local1.curveTo(w, (h * 1.2), w, ((h * 3) / 5));
}
}
}//package