Xionraseri
02-25-2008, 11:06 PM
Could Someone tell me why my car (instance name 'thing') wont move and i get the default in the switch (thing.dir)?
//carMove
//move the car random direction and speed
init();
function init(){
//direction constants
NORTH = 0;
NORTHEAST = 1;
EAST = 2;
SOUTHEAST = 3;
SOUTH = 4;
SOUTHWEST = 5;
WEST = 6;
NORTHWEST = 7;
//initialization
//randomly position car
car._x = Math.random() * Stage.width;
car._y = Math.random() * Stage.height;
car.dir = Math.random() *8;
car.dir = Math.floor(car.dir);
car.speed = Math.random() * 10;
turn(car);
/* debugging code
trace ("dir: " + car.dir);
trace ("rot: " + car._rotation);
trace ("dx: " + car.dx);
trace ("dy: " + car.dy);
*/
} //end init
function turn(thing){
thing._rotation = thing.dir * 45;
switch (thing.dir){
case NORTH:
thing.dx = 0;
thing.dy = -1;
break;
case NORTHEAST:
thing.dx = .7;
thing.dy = -.7;
break;
case EAST:
thing.dx = 1;
thing.dy = 0;
break;
case SOUTHEAST:
thing.dx = .7;
thing.dy = .7;
break;
case SOUTH:
thing.dx = 0;
thing.dy = 1;
break;
case SOUTHWEST:
thing.dx = -.7;
thing.dy = .7;
break;
case WEST:
thing.dx = -1;
thing.dy = 0;
break;
case NORTHWEST:
thing.dx = -.7;
thing.dy = -.7;
break;
default:
trace("There's a problem here...");
}//end switch
thing.dx *= thing.speed;
thing.dy *= thing.speed;
} //end turn
function move(thing){
//moves thing, wrapping around boundaries
//move
thing._x += thing.dx;
thing._y += thing.dy;
//check boundaries - wrap all directions
if (thing._x > Stage.width){
thing._x = 0;
}//end if
if (thing._x < 0){
thing._x = Stage.width;
}//end if
if (thing._y > Stage.height){
thing._y = 0;
} //end if
if (thing._y < 0){
thing._y = Stage.height;
}//end if
}//end move
thing.onEnterFrame = function(){
move(car);
}//end car enterframe
//carMove
//move the car random direction and speed
init();
function init(){
//direction constants
NORTH = 0;
NORTHEAST = 1;
EAST = 2;
SOUTHEAST = 3;
SOUTH = 4;
SOUTHWEST = 5;
WEST = 6;
NORTHWEST = 7;
//initialization
//randomly position car
car._x = Math.random() * Stage.width;
car._y = Math.random() * Stage.height;
car.dir = Math.random() *8;
car.dir = Math.floor(car.dir);
car.speed = Math.random() * 10;
turn(car);
/* debugging code
trace ("dir: " + car.dir);
trace ("rot: " + car._rotation);
trace ("dx: " + car.dx);
trace ("dy: " + car.dy);
*/
} //end init
function turn(thing){
thing._rotation = thing.dir * 45;
switch (thing.dir){
case NORTH:
thing.dx = 0;
thing.dy = -1;
break;
case NORTHEAST:
thing.dx = .7;
thing.dy = -.7;
break;
case EAST:
thing.dx = 1;
thing.dy = 0;
break;
case SOUTHEAST:
thing.dx = .7;
thing.dy = .7;
break;
case SOUTH:
thing.dx = 0;
thing.dy = 1;
break;
case SOUTHWEST:
thing.dx = -.7;
thing.dy = .7;
break;
case WEST:
thing.dx = -1;
thing.dy = 0;
break;
case NORTHWEST:
thing.dx = -.7;
thing.dy = -.7;
break;
default:
trace("There's a problem here...");
}//end switch
thing.dx *= thing.speed;
thing.dy *= thing.speed;
} //end turn
function move(thing){
//moves thing, wrapping around boundaries
//move
thing._x += thing.dx;
thing._y += thing.dy;
//check boundaries - wrap all directions
if (thing._x > Stage.width){
thing._x = 0;
}//end if
if (thing._x < 0){
thing._x = Stage.width;
}//end if
if (thing._y > Stage.height){
thing._y = 0;
} //end if
if (thing._y < 0){
thing._y = Stage.height;
}//end if
}//end move
thing.onEnterFrame = function(){
move(car);
}//end car enterframe