Hjælp til spil
hej eksperter... sidder og rodder med et spil, hvor man skal kunne få en ko til at gå rundt, ved tryk på mussetasten. Altså et platform spil:Koden til koen ser sådan ud:
Håber der er nogen der kan hjælpe?
onClipEvent (mouseDown) {
_root.move = "yes";
x = _root._xmouse - _x;
y =_root._ymouse - _y;
xorg = this._x;
yorg = thid._y;
}
onClipEvent (enterFrame) {
// SWAP:
this.swapDepths (this_x + this._y+55);
// SKRIDT!
if (_root.move == "yes") {
speed = 10;
z = Math.sqrt ( (x*x) + (y*y) );
steps = z / speed;
if (z < speed) {
_x = _root.pointx;
_y = _root.pointy;
dir=0;
_root.move = "no";
} else {
xstep = x / steps;
ystep = y / steps;
x -= xstep;
y -= ystep;
_x = _x + xstep;
_y = _y + ystep;
}
if (_root.hit= "yes") {
z = Math.sqrt ( (x*x) + (y*y) );
steps = z / speed;
_root.hit = "no";
}
}
}
onClipEvent (load) {
call ("dir");
call ("xm");
call ("ym");
call ("xc");
call ("yc");
}
// OPDAG MUSEN!! MUSSE SHAPER
onClipEvent (mouseDown) {
xm = _root._xmouse;
ym = _root._ymouse;
xc = this._x;
yc = this._y;
distx = int(getProperty("/mouse1", _x)-getProperty("", _x));
disty = int(getProperty("", _y)-getProperty("/mouse1", _y));
// Top Right
if (Number(disty)>0 and Number(distx)>0) {
if (Number(distx)<Number((disty/2))) {
dir = 1;
} else if (Number(disty)<Number((distx/2))) {
dir = 3;
} else {
dir = 2;
}
}
// Bottom Right
if (Number(disty)<0 and Number(distx)>0) {
disty = disty-(Number(disty)+Number(disty));
if (Number(distx)<Number((disty/2))) {
dir = 5;
} else if (Number(disty)<Number((distx/2))) {
dir = 3;
} else {
dir = 4;
}
}
// Bottom Left
if (Number(disty)<0 and Number(distx)<0) {
if (Number(distx)>Number((disty/2))) {
dir = 5;
} else if (Number(disty)>Number((distx/2))) {
dir = 7;
} else {
dir = 6;
}
}
if (Number(disty)>0 and Number(distx)<0) {
distx = distx-(Number(distx)+Number(distx));
if (Number(disty)<Number((distx/2))) {
dir = 7;
} else if (Number(distx)<Number((disty/2))) {
dir = 1;
} else {
dir = 8;
}
}
if (Number(distx) == 0 or Number(disty) == 0) {
dir = 5;
}
}
onClipEvent (enterFrame) {
yc = this._y;
xc = this._x;
spd = 1.8;
with (this) {
// left right
if (dir<5) {
_xscale = -50;
} else if (dir>5) {
_xscale = +50;
}
//dir 0
if (dir==0) {
gotoAndStop("StandDown");
trace ("StandDown");
}
//dir 1
if (dir==1) {
gotoAndStop("MoveUp");
trace ("MoveUp");
}
//dir 2
if (dir==2) {
gotoAndStop("MoveUpRight");
trace ("MoveUpRight");
}
//dir 3
if (dir==3) {
gotoAndStop("MoveRight");
trace ("MoveRight");
}
//dir 4
if (dir==4) {
gotoAndStop("MoveDownRight");
trace ("MoveDownRight");
}
//dir 5
if (dir==5) {
gotoAndStop("Movedown");
trace ("Movedown");
}
//dir 6
if (dir==6) {
gotoAndStop("MoveDownRight");
trace ("MoveDownRight");
}
//dir 7
if (dir==7) {
gotoAndStop("MoveRight");
trace ("MoveRight");
}
//dir 8
if (dir==8) {
gotoAndStop("MoveUpRight");
trace ("MoveUpRight");
}
}
}
//Anders
