earleybird
May 15th, 2004, 08:58 AM
Hi,
I've built a little experiment which lets the user control a car with the fwd and bckwrd arrow keys. the idea is to move the car fwd but if it goes above a certain speed you have to slow it down. I have it working but the way i've done it is to move the backround to make it look like the car is moving. However, the backround can only be a certain width so atfer a while is moves clear of the screen. I'm trying to have it so that when the road's _x coordinate hits a certain point then it will jump back to its original point and the road will look like its just continuously moving. Here is the main code.
onClipEvent (load){
//dir = 0;
speed = 0;
}
onClipEvent (enterFrame) {
xspeed = Math.cos(dir*Math.PI/180)*speed;
yspeed = Math.sin(dir*Math.PI/180)*speed;
_x += xspeed;
_y += yspeed;
//_rotation = dir;
if (Key.isDown(Key.RIGHT)) {
speed += -1;
}
if (speed<=0){
if (Key.isDown(Key.LEFT)) {
speed += 1;
}
}
if (speed<0) {
_root.caption.carspeed = -1*speed;
}
if (speed>=0){
_root.caption.carspeed = 1*speed;
}
if (speed<12){
_root.caption.health = "SAFE";
elseif (speed>=12)
_root.caption.health = "DANGER";
}
This is the bit where I tried to get the _x value to change:
if(_x==(-3104)){
_x =+ 3104;
}
}
I've attatched my .fla to help explain!
I think i'm totally wrong and would greatly appreciate some help!
:)
I've built a little experiment which lets the user control a car with the fwd and bckwrd arrow keys. the idea is to move the car fwd but if it goes above a certain speed you have to slow it down. I have it working but the way i've done it is to move the backround to make it look like the car is moving. However, the backround can only be a certain width so atfer a while is moves clear of the screen. I'm trying to have it so that when the road's _x coordinate hits a certain point then it will jump back to its original point and the road will look like its just continuously moving. Here is the main code.
onClipEvent (load){
//dir = 0;
speed = 0;
}
onClipEvent (enterFrame) {
xspeed = Math.cos(dir*Math.PI/180)*speed;
yspeed = Math.sin(dir*Math.PI/180)*speed;
_x += xspeed;
_y += yspeed;
//_rotation = dir;
if (Key.isDown(Key.RIGHT)) {
speed += -1;
}
if (speed<=0){
if (Key.isDown(Key.LEFT)) {
speed += 1;
}
}
if (speed<0) {
_root.caption.carspeed = -1*speed;
}
if (speed>=0){
_root.caption.carspeed = 1*speed;
}
if (speed<12){
_root.caption.health = "SAFE";
elseif (speed>=12)
_root.caption.health = "DANGER";
}
This is the bit where I tried to get the _x value to change:
if(_x==(-3104)){
_x =+ 3104;
}
}
I've attatched my .fla to help explain!
I think i'm totally wrong and would greatly appreciate some help!
:)