function Vector(x, y) { this.x = x; this.y = y; this.length = Math.sqrt(x * x + y * y); } // End of the function function constrain(p0, p1, l) { var correction = 0.025000; 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.500000 * r; var y = d.y * 0.500000 * r; p1._x = p1._x - (x - correction); p1._y = p1._y - y; p0._x = p0._x + (x + correction); p0._y = p0._y + y; } // End of the function function update() { var p; var i = 0; while (i < joints.length) { this[joints[i]].update(); i++; } // end while } // End of the function 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; } // end if i++; } // end while if (c) { if (!soundplaying) { var sbreak = new Sound(this); sbreak.onSoundComplete = function () { soundplaying = false; }; var rand = random(4); var pan = -100 + head._x * 200 / 445; sbreak.attachSound("break" + rand); sbreak.start(0, 0); sbreak.setVolume(75); sbreak.setPan(pan); soundplaying = true; } // end if drawblood(x, y); } // end if } // End of the function 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.500000); i++; } // end while } // End of the function 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++; } // end while } // End of the function 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++; } // end while } // End of the function 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 <= 6.283185) { head.lineTo(cx + Math.cos(a) * r, cy + Math.sin(a) * r); a = a + 0.069813; } // end while head.endFill(); } // End of the function 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 / 3.141593; } // End of the function function onEnterFrame() { update(); constraints(); collisions(); draw(ragdollcolor); } // End of the function MovieClip.prototype.useHandCursor = false; var dragging = null; var blooddepth = 0; var soundplaying = false; var ragdollcolor = 0; var joints = new Array("lhand", "lelbow", "rhand", "relbow", "neck", "waist", "lknee", "lfoot", "rknee", "rfoot", "head"); drawhead(ragdollcolor); setup(); stop();