var lx = _x;
var ly = _y;
var xs = 0;
var ys = 0;
var ms = 60;
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 *= (ms/s);
ys *= (ms/s);
}
if (Math.abs(xs)<1) {
xs = 0;
}
if (Math.abs(ys)<.25) {
ys = 0;
}
lx = _x;
ly = _y;
_x += (xs*.94);
_y += (ys+.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 != "headi") {
if (_root.boden.hitTest(this._x,this._y+.1,true)) {
_y -= ys+.5;
c = true;
} else if (_y<0) {
_y = 0;
c = true;
}
if (_root.boden.hitTest(this._x+.1,this._y,true)) {
_x -= xs*.94;
c = true;
} else if (_root.boden.hitTest(this._x-.1,this._y,true)) {
_x += xs*.94;
c = true;
}
} else {
var r = _width/2.5;
if (_root.boden.hitTest(this._x,this._y+2.5,true)) {
_y -= ys+2.5;
c = true;
} else if (_y<r) {
_y = r;
c = true;
}
if (_x>(640-r)) {
_x = 640-r;
c = true;
} else if (_x<r) {
_x = r;
c = true;
}
}
if (c) {
return force();
} else {
return false;
}
}
function onPress() {
_root.dragging = this;
}
function onRelease() {
_root.dragging = null;
}
var kl = {};
Key.addListener(kl);
kl.onKeyUp = function() {
var k = Key.getCode();
if (k == Key.SPACE) {
var dx = _x-_root._xmouse;
var dy = _y-_root._ymouse;
var d = Math.sqrt(dx*dx+dy*dy);
if (d<50) {
_x += (dx/d)*(ms);
_y += (dy/d)*(ms);
}
}
};
onReleaseOutside = onRelease;