PDA

View Full Version : Car game code?


illrainman
10-25-2003, 07:31 PM
I tried to make a car game and I posted it on another forum, but I cant move forward or backward. Some people said they could but I dont think Flash MX understands the speed coding I used. Can anyone give me some code for Flash MX I can try?

ferdymania
10-25-2003, 11:27 PM
speed = 10;
_root.onEnterFrame = function(){

if(Key.isDown(Key.UP)){
_root.car._y -= speed;
}
else if(Key.isDown(Key.DOWN)){
_root.car._y += speed;
}else {
// nothing so car stops..
}
}

you can also do some complex maths to get it to accelerate and
decelerate but i dunno...
steve

farafiro
10-26-2003, 02:46 AM
illrainman
welcome to the forums

http://www.freewebz.com/savco/tutorials/moving.htm

illrainman
10-26-2003, 07:58 PM
That bit of code you posted didn't work for me for some reason, but i found one that does so im using that. Thanks for the help anyway.

Colin Campbell
10-26-2003, 08:23 PM
Would you mind posting that code for people who come looking? :)

farafiro
10-27-2003, 03:07 AM
Originally posted by illrainman
That bit of code you posted didn't work for me for some reason, but i found one that does so im using that. Thanks for the help anyway. what do u mean?? ans why it doesn't work??
show us the code

Rachelliu
10-27-2003, 04:36 AM
That bit of code you posted didn't work for me too.:(

farafiro
10-27-2003, 04:57 AM
why?? show how did u posted it in flash and which version u have??

ferdymania
10-27-2003, 07:49 AM
here is some as2 code for controlling a spaceship by keys
same for a key or anything..


// check which key is pressed..
function checkKey():String{
if(Key.isDown(Key.RIGHT)){
dir = "right";
}
else if(Key.isDown(Key.LEFT)){
dir = "left";
}
else if(Key.isDown(Key.UP)){
dir = "up";
}
else if(Key.isDown(Key.DOWN)){
dir = "down";
}
else dir="stop";
//this works
//trace(dir + " - in game.checkey");

return dir;
}
// move ship function
function move(_dir:String){
dir = _dir;
if(dir=="left") _x -= 20;
if(dir=="right")_x += 20;
if(dir=="up") _y -= 20;
if(dir=="down") _y += 20;
if(dir=="stop"){
_x +=0;
_y +=0;
}
}



and to call these functions..
in your fla..like so:


// game loop
_root.onEnterFrame = function(){
checkKey();
moveShip(dir);
}


You get the drift ..
you should be able to work out how to do it yourselves if you are
given so much information..
steve

mandeep
03-26-2008, 11:03 AM
hi friends i m making car game almost i have dome but some problame with hitTest, i know hitTest funtion but can't make script.... when my car hit anmy cars... anyone help me ??

sd9sd
03-26-2008, 02:43 PM
You picked up a five year old thread for this?
Man! you really want an answer to this, don't you :)

Here you go:
http://www.newgrounds.com/bbs/topic/179441