Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 02-25-2008, 11:06 PM   #1
Xionraseri
Registered User
 
Join Date: Feb 2008
Posts: 17
Default Car won't move

Could Someone tell me why my car (instance name 'thing') wont move and i get the default in the switch (thing.dir)?
Code:
//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

Last edited by Xionraseri; 02-25-2008 at 11:47 PM.
Xionraseri is offline   Reply With Quote
Old 02-26-2008, 12:45 AM   #2
ASWC
Super Moderator
 
ASWC's Avatar
 
Join Date: Dec 2007
Location: Greenville, SC
Posts: 6,528
Default

that's not a pretty code to be honest. but mainly your problem come from the fact that a lot of your variables are initialized for car and not thing, so when you call thing.dx there's nothing because the variable does not exist.

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;

change all that for "thing" instead of "car" for a start. this code has a lot of problem to be honest.
__________________
aswebcreations
Super Duper!
ASWC is offline   Reply With Quote
Old 02-26-2008, 12:59 AM   #3
Xionraseri
Registered User
 
Join Date: Feb 2008
Posts: 17
Default

I know, i am a complete noob, started like 2 weeks ago. I following this tutorial book, and thing is i originally had instance name car. It didnt work, so i just changed it to thing to see if it would do anything. I had the same problem. Then i go and change it back to what i originally had, "car" and it works...i am confused, but thanks anyway.

Last edited by Xionraseri; 02-27-2008 at 11:38 PM.
Xionraseri is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
how to move movieclip and stop it flash art ActionScript 2.0 3 03-06-2008 12:43 AM
car accelerate, hit wall and stop k0oni3 Gaming and Game Development 1 02-09-2008 01:42 PM
Programmer Needed: Free Project: Car RPG Game cow1787 Projects and Positions 0 09-22-2007 10:49 PM
[AS1] Board game - problem with Move function gatsby23 Gaming and Game Development 1 11-03-2006 11:25 AM
move your body__ cisco Simple Stuff (Newbies) 4 02-26-2004 07:54 AM


All times are GMT. The time now is 12:34 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.