Untitled


SUBMITTED BY: Guest

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

FORMAT: Text only

SIZE: 1.9 kB

HITS: 1447

  1. var lx = _x;
  2. var ly = _y;
  3. var xs = 0;
  4. var ys = 0;
  5. var ms = 60;
  6. function update() {
  7. if (_root.dragging == this) {
  8. xs = _root._xmouse-_x;
  9. ys = _root._ymouse-_y;
  10. } else {
  11. xs = _x-lx;
  12. ys = _y-ly;
  13. }
  14. var s = Math.sqrt(xs*xs+ys*ys);
  15. if (s>ms) {
  16. xs *= (ms/s);
  17. ys *= (ms/s);
  18. }
  19. if (Math.abs(xs)<1) {
  20. xs = 0;
  21. }
  22. if (Math.abs(ys)<.25) {
  23. ys = 0;
  24. }
  25. lx = _x;
  26. ly = _y;
  27. _x += (xs*.94);
  28. _y += (ys+.5);
  29. }
  30. function force() {
  31. var s = Math.sqrt(xs*xs+ys*ys);
  32. return ((s>=12) and (_root.dragging != this));
  33. }
  34. function collisions() {
  35. var c = false;
  36. if (this._name != "headi") {
  37. if (_root.boden.hitTest(this._x,this._y+.1,true)) {
  38. _y -= ys+.5;
  39. c = true;
  40. } else if (_y<0) {
  41. _y = 0;
  42. c = true;
  43. }
  44. if (_root.boden.hitTest(this._x+.1,this._y,true)) {
  45. _x -= xs*.94;
  46. c = true;
  47. } else if (_root.boden.hitTest(this._x-.1,this._y,true)) {
  48. _x += xs*.94;
  49. c = true;
  50. }
  51. } else {
  52. var r = _width/2.5;
  53. if (_root.boden.hitTest(this._x,this._y+2.5,true)) {
  54. _y -= ys+2.5;
  55. c = true;
  56. } else if (_y<r) {
  57. _y = r;
  58. c = true;
  59. }
  60. if (_x>(640-r)) {
  61. _x = 640-r;
  62. c = true;
  63. } else if (_x<r) {
  64. _x = r;
  65. c = true;
  66. }
  67. }
  68. if (c) {
  69. return force();
  70. } else {
  71. return false;
  72. }
  73. }
  74. function onPress() {
  75. _root.dragging = this;
  76. }
  77. function onRelease() {
  78. _root.dragging = null;
  79. }
  80. var kl = {};
  81. Key.addListener(kl);
  82. kl.onKeyUp = function() {
  83. var k = Key.getCode();
  84. if (k == Key.SPACE) {
  85. var dx = _x-_root._xmouse;
  86. var dy = _y-_root._ymouse;
  87. var d = Math.sqrt(dx*dx+dy*dy);
  88. if (d<50) {
  89. _x += (dx/d)*(ms);
  90. _y += (dy/d)*(ms);
  91. }
  92. }
  93. };
  94. onReleaseOutside = onRelease;

comments powered by Disqus