hirosum
08-16-2010, 05:24 PM
Hey guys I'm not very good at action script and I have a project comin up that I need to get done. Would someone be able to help? I have to create a flash movie in which a car starts in the centre and moves in random directions around the screen, up, down, left, right and diagonally, and then is repositioned to the centre when it gets to the edge of the stage. I have code which I found to make the car move but I need help making it rotate when it turns and reposition itself when it gets to the edge.This is the code I have to make the car move
function carMover(eTarget) {
dir = ["west", "northwest", "southwest", "east", "northeast", "southeast", "north", "south"];
randNum = random(8);
setDir = dir[randNum];
switch (setDir) {
case "west" :
xSpeed = -10;
ySpeed = 0;
break;
case "northwest" :
xSpeed = -10;
ySpeed = 10;
break;
case "southwest" :
xSpeed = -10;
ySpeed = -10;
break;
case "east" :
xSpeed = 10;
ySpeed = 0;
break;
case "northeast" :
xSpeed = 10;
ySpeed = 10;
break;
case "southeast" :
xSpeed = 10;
ySpeed = -10;
break;
case "north" :
xSpeed = 0;
ySpeed = -10;
break;
case "south" :
xSpeed = 0;
ySpeed = 10;
break;
}
this.onEnterFrame = function() {
eTarget._x += xSpeed;
eTarget._y += ySpeed;
eTarget._rotation = rot;
};
}
function callMover() {
_root.carMover(_root.theCar);
}
myInterval = setInterval(callMover, 1000);
function carMover(eTarget) {
dir = ["west", "northwest", "southwest", "east", "northeast", "southeast", "north", "south"];
randNum = random(8);
setDir = dir[randNum];
switch (setDir) {
case "west" :
xSpeed = -10;
ySpeed = 0;
break;
case "northwest" :
xSpeed = -10;
ySpeed = 10;
break;
case "southwest" :
xSpeed = -10;
ySpeed = -10;
break;
case "east" :
xSpeed = 10;
ySpeed = 0;
break;
case "northeast" :
xSpeed = 10;
ySpeed = 10;
break;
case "southeast" :
xSpeed = 10;
ySpeed = -10;
break;
case "north" :
xSpeed = 0;
ySpeed = -10;
break;
case "south" :
xSpeed = 0;
ySpeed = 10;
break;
}
this.onEnterFrame = function() {
eTarget._x += xSpeed;
eTarget._y += ySpeed;
eTarget._rotation = rot;
};
}
function callMover() {
_root.carMover(_root.theCar);
}
myInterval = setInterval(callMover, 1000);