Untitled


SUBMITTED BY: Guest

DATE: Aug. 4, 2013, 3:10 p.m.

FORMAT: Text only

SIZE: 4.5 kB

HITS: 1403

  1. function Vector(x, y)
  2. {
  3. this.x = x;
  4. this.y = y;
  5. this.length = Math.sqrt(x * x + y * y);
  6. } // End of the function
  7. function constrain(p0, p1, l)
  8. {
  9. var correction = 0.025000;
  10. var dx = p1._x - p0._x;
  11. var dy = p1._y - p0._y;
  12. var d = new Vector(dx, dy);
  13. var r = (d.length - l) / d.length;
  14. var x = d.x * 0.500000 * r;
  15. var y = d.y * 0.500000 * r;
  16. p1._x = p1._x - (x - correction);
  17. p1._y = p1._y - y;
  18. p0._x = p0._x + (x + correction);
  19. p0._y = p0._y + y;
  20. } // End of the function
  21. function update()
  22. {
  23. var p;
  24. var i = 0;
  25. while (i < joints.length)
  26. {
  27. this[joints[i]].update();
  28. i++;
  29. } // end while
  30. } // End of the function
  31. function collisions()
  32. {
  33. var p;
  34. var x;
  35. var y;
  36. var c = false;
  37. var i = 0;
  38. while (i < joints.length)
  39. {
  40. p = this[joints[i]];
  41. if (p.collisions())
  42. {
  43. c = true;
  44. x = p._x;
  45. y = p._y;
  46. } // end if
  47. i++;
  48. } // end while
  49. if (c)
  50. {
  51. if (!soundplaying)
  52. {
  53. var sbreak = new Sound(this);
  54. sbreak.onSoundComplete = function ()
  55. {
  56. soundplaying = false;
  57. };
  58. var rand = random(4);
  59. var pan = -100 + head._x * 200 / 445;
  60. sbreak.attachSound("break" + rand);
  61. sbreak.start(0, 0);
  62. sbreak.setVolume(75);
  63. sbreak.setPan(pan);
  64. soundplaying = true;
  65. } // end if
  66. drawblood(x, y);
  67. } // end if
  68. } // End of the function
  69. function constraints()
  70. {
  71. var i = 0;
  72. while (i < 2)
  73. {
  74. constrain(lhand, lelbow, 12);
  75. constrain(lelbow, neck, 12);
  76. constrain(rhand, relbow, 12);
  77. constrain(relbow, neck, 12);
  78. constrain(neck, waist, 20);
  79. constrain(lknee, waist, 20);
  80. constrain(lfoot, lknee, 20);
  81. constrain(rknee, waist, 20);
  82. constrain(rfoot, rknee, 20);
  83. constrain(head, neck, 3.500000);
  84. i++;
  85. } // end while
  86. } // End of the function
  87. function setup()
  88. {
  89. constraints();
  90. var p;
  91. var i = 0;
  92. while (i < joints.length)
  93. {
  94. p = this[joints[i]];
  95. p.lx = p._x;
  96. p.ly = p._y;
  97. i++;
  98. } // end while
  99. } // End of the function
  100. function drawblood(x, y)
  101. {
  102. var b;
  103. var i = 0;
  104. while (i <= random(3) + 3)
  105. {
  106. b = attachMovie("Blood", "Blood" + blooddepth, blooddepth++);
  107. b._x = x;
  108. b._y = y;
  109. i++;
  110. } // end while
  111. } // End of the function
  112. function drawhead(col)
  113. {
  114. var cx = 0;
  115. var cy = 0;
  116. var r = 7;
  117. head.beginFill(col == undefined ? (0) : (col), 100);
  118. head.moveTo(cx + r, cy);
  119. var a = 0;
  120. while (a <= 6.283185)
  121. {
  122. head.lineTo(cx + Math.cos(a) * r, cy + Math.sin(a) * r);
  123. a = a + 0.069813;
  124. } // end while
  125. head.endFill();
  126. } // End of the function
  127. function draw(col)
  128. {
  129. clear();
  130. lineStyle(5, col == undefined ? (0) : (col), 100);
  131. moveTo(lhand._x, lhand._y);
  132. lineTo(lelbow._x, lelbow._y);
  133. lineTo(neck._x, neck._y);
  134. lineTo(relbow._x, relbow._y);
  135. lineTo(rhand._x, rhand._y);
  136. moveTo(neck._x, neck._y);
  137. lineTo(waist._x, waist._y);
  138. lineTo(lknee._x, lknee._y);
  139. lineTo(lfoot._x, lfoot._y);
  140. moveTo(waist._x, waist._y);
  141. lineTo(rknee._x, rknee._y);
  142. lineTo(rfoot._x, rfoot._y);
  143. var dx = neck._x - head._x;
  144. var dy = neck._y - head._y;
  145. head._rotation = Math.atan2(dy, dx) * 180 / 3.141593;
  146. } // End of the function
  147. function onEnterFrame()
  148. {
  149. update();
  150. constraints();
  151. collisions();
  152. draw(ragdollcolor);
  153. } // End of the function
  154. MovieClip.prototype.useHandCursor = false;
  155. var dragging = null;
  156. var blooddepth = 0;
  157. var soundplaying = false;
  158. var ragdollcolor = 0;
  159. var joints = new Array("lhand", "lelbow", "rhand", "relbow", "neck", "waist", "lknee", "lfoot", "rknee", "rfoot", "head");
  160. drawhead(ragdollcolor);
  161. setup();
  162. stop();

comments powered by Disqus