Combined Code
movieClip 2 {
}
movieClip 6 {
}
movieClip 7 {
frame 1 {
this.onEnterFrame = function () {
if (blink == undefined) {
blink = 0;
}
if (walking) {
walker._x -= 16;
if (walker._x <= -136) {
walker._x = -40;
}
} else {
++blink;
if (blink > 3) {
walker._x = -8;
}
if (blink > Math.random() * 40 + 40) {
walker._x = -24;
blink = 0;
}
}
_parent.ss.text = this._x + ' - ' + this._y + '\n' + _parent.moveTarget.x + ' - ' + _parent.moveTarget.y + (walking ? '\nwalking' : '');
};
}
}
movieClip 8 {
frame 1 {
function walk() {
var v2 = ['l', '', 'r', 'u', '', 'd'];
var v3 = {'d': -24, 'u': -48, 'l': -72, 'r': -96, 'ld': -120, 'rd': -144, 'lu': -168, 'ru': -192};
var v7 = (walky._x != moveTarget.x) ? (walky._x < moveTarget.x ? 1 : -1) : 0;
var v5 = (walky._y != moveTarget.y) ? (walky._y < moveTarget.y ? 1 : -1) : 0;
var v6 = Math.abs(moveTarget.x - walky._x);
var v4 = Math.abs(moveTarget.y - walky._y);
var v1 = decideStep(v7, v5, v6, v4);
if (v1 == null) {
dontWalk();
return undefined;
}
if (v1.x != walky._x | v1.y != walky._y) {
spriteDir = v2[v1.x - walky._x + 1] + v2[v1.y - walky._y + 4];
walky.walker._y = v3[spriteDir];
walky.walking = true;
walky._x = v1.x;
walky._y = v1.y;
} else {
trace('end of cycle');
dontWalk();
}
}
function dontWalk() {
clearInterval(mover);
walky.walking = false;
}
function decideStep(dirx, diry, disx, disy) {
var v4 = walky._x;
var v3 = walky._y;
var v1 = v4 + dirx;
var v2 = v3 + diry;
if (v4 == v1 | v3 == v2) {
var v7 = false;
} else {
var v7 = true;
}
if (v7) {
if (flor.hitTest(v1, v2, true)) {
return new Object({'x': v1, 'y': v2});
}
}
var v6 = flor.hitTest(v1, v3, true);
var v5 = flor.hitTest(v4, v2, true);
if (!v6 && !v5) {
return null;
}
if (v6 && v4 != v1 && !v5 | (v5 && v3 == v2)) {
return {'x': v1, 'y': v3};
}
if (v5 && v3 != v2 && !v6 | (v6 && v4 == v1)) {
return {'x': v4, 'y': v2};
}
}
var mouseListener = new Object();
mouseListener.onMouseDown = function () {
dontWalk();
moveTarget = {'x': Math.round(_xmouse), 'y': Math.round(_ymouse)};
walk();
mover = setInterval(walk, 45);
};
mouseListener.onMouseMove = function () {};
mouseListener.onMouseUp = function () {
dontWalk();
moveTarget = {'x': Math.round(_xmouse), 'y': Math.round(_ymouse)};
walk();
mover = setInterval(walk, 45);
};
Mouse.addListener(mouseListener);
}
}