Frame 81
function Vector(x, y) {
this.x = x;
this.y = y;
this.length = Math.sqrt((x * x) + (y * y));
}
function constrain(p0, p1, l) {
var correction = 0.025;
var dx = (p1._x - p0._x);
var dy = (p1._y - p0._y);
var d = new Vector(dx, dy);
var r = ((d.length - l) / d.length);
var x = ((d.x * 0.5) * r);
var y = ((d.y * 0.5) * r);
p1._x = p1._x - (x - correction);
p1._y = p1._y - y;
p0._x = p0._x + (x + correction);
p0._y = p0._y + y;
}
function update() {
var p;
var i = 0;
while (i < joints.length) {
this[joints[i]].update();
i++;
}
}
function collisions() {
var p;
var x;
var y;
var c = false;
var i = 0;
while (i < joints.length) {
p = this[joints[i]];
if (p.collisions()) {
c = true;
x = p._x;
y = p._y;
}
i++;
}
if (c) {
if (!_root.soundplaying) {
delete sbreak;
sbreak = new Sound(_root);
var rand = random(3);
var pan = (-100 + ((head._x * 200) / 445));
sbreak.attachSound("break" + rand);
sbreak.start(0, 0);
sbreak.setVolume(75);
sbreak.setPan(50);
_root.soundplaying = true;
}
if (_root.soundplaying && (sbreak.position > 300)) {
_root.soundplaying = false;
}
drawblood(x, y);
}
}
function constraints() {
var i = 0;
while (i < 2) {
constrain(lhand, lelbow, 12);
constrain(lelbow, neck, 12);
constrain(rhand, relbow, 12);
constrain(relbow, neck, 12);
constrain(neck, waist, 20);
constrain(lknee, waist, 20);
constrain(lfoot, lknee, 20);
constrain(rknee, waist, 20);
constrain(rfoot, rknee, 20);
constrain(head, neck, 3.5);
i++;
}
}
function setup() {
constraints();
var p;
var i = 0;
while (i < joints.length) {
p = this[joints[i]];
p.lx = p._x;
p.ly = p._y;
i++;
}
}
function drawblood(x, y) {
var b;
var i = 0;
while (i <= (random(3) + 3)) {
b = attachMovie("Blood", "Blood" + blooddepth, blooddepth++);
b._x = x;
b._y = y;
i++;
}
}
function drawhead(col) {
var cx = 0;
var cy = 0;
var r = 7;
head.beginFill(((col == undefined) ? 0 : (col)), 100);
head.moveTo(cx + r, cy);
var a = 0;
while (a <= (Math.PI*2)) {
head.lineTo(cx + (Math.cos(a) * r), cy + (Math.sin(a) * r));
a = a + 0.0698131700797732;
}
head.endFill();
}
function draw(col) {
clear();
lineStyle(5, ((col == undefined) ? 0 : (col)), 100);
moveTo(lhand._x, lhand._y);
lineTo(lelbow._x, lelbow._y);
lineTo(neck._x, neck._y);
lineTo(relbow._x, relbow._y);
lineTo(rhand._x, rhand._y);
moveTo(neck._x, neck._y);
lineTo(waist._x, waist._y);
lineTo(lknee._x, lknee._y);
lineTo(lfoot._x, lfoot._y);
moveTo(waist._x, waist._y);
lineTo(rknee._x, rknee._y);
lineTo(rfoot._x, rfoot._y);
var dx = (neck._x - head._x);
var dy = (neck._y - head._y);
head._rotation = (Math.atan2(dy, dx) * 180) / Math.PI;
}
function onEnterFrame() {
update();
constraints();
collisions();
draw(ragdollcolor);
}
MovieClip.prototype.useHandCursor = false;
var dragging = null;
var blooddepth = 0;
_root.soundplaying = false;
var ragdollcolor = 0;
var joints = new Array("lhand", "lelbow", "rhand", "relbow", "neck", "waist", "lknee", "lfoot", "rknee", "rfoot", "head");
drawhead(ragdollcolor);
setup();
stop();
Symbol 4 MovieClip [Blood] Frame 1
function onEnterFrame() {
_x = (_x + ((xs = xs * decay)));
_y = (_y + ((ys = ys * decay)));
clear();
lineStyle(1, 10027008, 100);
lineTo(xs, ys);
var s = Math.sqrt((xs * xs) + (ys * ys));
if (s < 1) {
this.removeMovieClip();
}
}
var ms = ((Math.random() * 10) + 10);
var a = ((Math.random() * 2) * Math.PI);
var xs = (Math.cos(a) * ms);
var ys = (Math.sin(a) * ms);
var decay = (0.7 + (Math.random() * 0.25));
Symbol 6 MovieClip [Joint] Frame 1
function update() {
if (_root.dragging == this) {
xs = _root._xmouse - _x;
ys = _root._ymouse - _y;
} else {
xs = _x - lx;
ys = _y - ly;
}
var s = Math.sqrt((xs * xs) + (ys * ys));
if (s > ms) {
xs = xs * (ms / s);
ys = ys * (ms / s);
}
if (Math.abs(xs) < 1) {
xs = 0;
}
if (Math.abs(ys) < 0.25) {
ys = 0;
}
lx = _x;
ly = _y;
_x = (_x + (xs * 0.94));
_y = (_y + (ys + 0.5));
}
function force() {
var s = Math.sqrt((xs * xs) + (ys * ys));
return((s >= 12) and (_root.dragging != this));
}
function collisions() {
var c = false;
if (this._name != "head") {
if (_y > 245) {
_y = 245;
c = true;
} else if (_y < 0) {
_y = 0;
c = true;
}
if (_x > 445) {
_x = 445;
c = true;
} else if (_x < 0) {
_x = 0;
c = true;
}
} else {
var r = (_width / 2.5);
if (_y > (245 - r)) {
_y = (245 - r);
c = true;
} else if (_y < r) {
_y = r;
c = true;
}
if (_x > (445 - r)) {
_x = (445 - r);
c = true;
} else if (_x < r) {
_x = r;
c = true;
}
}
if (c) {
return(force());
}
return(false);
}
function onPress() {
_root.dragging = this;
}
function onRelease() {
_root.dragging = null;
}
var lx = _x;
var ly = _y;
var xs = 0;
var ys = 0;
var ms = 30;
var kl = {};
Key.addListener(kl);
kl.onKeyUp = function () {
var k = Key.getCode();
if (k == 32) {
var dx = (_x - _root._xmouse);
var dy = (_y - _root._ymouse);
var d = Math.sqrt((dx * dx) + (dy * dy));
if (d < 50) {
_x = (_x + ((dx / d) * ms));
_y = (_y + ((dy / d) * ms));
}
}
};
onReleaseOutside = onRelease;