|
-
Car Game!
Hello, I am creating a car game and this hitTest thing is really annoying me. It's not working for some reason... i have a road and grass on the outside. I want to make it so when the car hits the grass it doesn't move. In the car movie clip I have two other movie clips, both named car2... In my grass variable I basically tell _root.car.car2 to goto frame 2, which has no actions in it so the car can't move. here is the code for the grass...
onClipEvent (enterFrame) {
if (this.hitTest(_root.car)) {
tellTarget ("_level0.car.car2") {
gotoAndStop(2);
}
} else {
tellTarget ("_level0.car.car2") {
gotoAndStop(1);
}
}
}
here is the car code...
onClipEvent (load) {
maxspeed = 10;
maxnegspeed = -5;
function move(afstand) {
draaihoek = (_rotation/180)*Math.PI;
_x += afstand*Math.sin(draaihoek);
_y += -afstand*Math.cos(draaihoek);
return afstand;
}
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.UP)) {
if (speed<maxspeed) {
speed += 0.1;
}
} else {
if (Key.isDown(Key.DOWN) == false) {
speed *= 0.98;
if (speed<0.1 and speed>-0.1) {
speed = 0;
}
}
}
if (Key.isDown(Key.DOWN)) {
if (speed>maxnegspeed) {
speed -= 0.1;
}
}
if (Key.isDown(Key.SPACE)) {
if ((speed>=0)) {
speed -= 0.3;
if ((speed<=-0.1)) {
speed += 0.3;
if ((speed=0)) {
(speed=0);
}
}
}
}
if (Key.isDown(Key.LEFT)) {
_rotation -= speed/1.3;
}
if (Key.isDown(Key.RIGHT)) {
_rotation += speed/1.3;
}
move(speed);
_root.speed = Math.round(speed);
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|