Mark Aged
08-24-2006, 12:52 PM
Making a game where a guy can go and out of a car, it works, but the car can't drive. Here is the code:
onClipEvent (enterFrame) {
if (_root.ride == 1) {
if (Key.isDown(Key.ENTER)) {
_root.character._visible = true;
_root.character._x += 15;
_root.ride = 0;
}
_root.character._x = _x;
_root.character._y = _y;
if (Key.isDown(Key.RIGHT)) {
_rotation = _rotation+move;
}
if (Key.isDown(Key.LEFT)) {
_rotation = _rotation-move;
}
if (Key.isDown(Key.UP)) {
if (move<8) {
move++;
move++;
}
} else if (move>0) {
move--;
move--;
}
if (Key.isDown(Key.DOWN)) {
if (move>-10) {
move--;
move--;
}
} else if (move<0) {
move++;
move++;
}
if (_rotation>180) {
_y = _y+(move*Math.cos(Math.PI/180*_rotation));
_x = _x-(move*Math.sin(Math.PI/180*_rotation));
}
if (_rotation<180) {
_y = _y-(move*Math.cos(Math.PI/180*_rotation));
_x = _x+(move*Math.sin(Math.PI/180*_rotation));
}
}
}
onClipEvent (enterFrame) {
if (_root.ride == 1) {
if (Key.isDown(Key.SPACE)) {
_root.character._visible = true;
_root.character._x += 100;
_root.ride = 0;
_root.ride._visible = false;
_root.character1 = 1;
}
_root.character._x = _x;
_root.character._y = _y;
if (Key.isDown(Key.UP)) {
speed += .75;
d += 4;
moving = true;
}
if (Key.isDown(Key.DOWN)) {
speed -= .75;
}
if (Math.abs(speed)>7) {
speed *= .9;
moving = true;
}
if (Key.isDown(Key.LEFT)) {
_rotation -= 9;
moving = true;
}
if (Key.isDown(Key.RIGHT)) {
_rotation += 9;
moving = true;
}
speed *= .88;
x = Math.sin(_rotation*(Math.PI/180))*speed;
y = Math.cos(_rotation*(Math.PI/180))*speed*-1;
if (!_root.land.hitTest(_x+x, _y+y, true)) {
_x += x;
_y += y;
_root._x -= x;
_root._y -= y;
} else {
speed *= -.6;
}
}
}
onClipEvent (enterFrame) {
if (_root.ride == 0 && this.hitTest(_root.character) && Key.isDown(Key.ENTER)) {
_root.character._visible = false;
_root.ride = 1;
_root.character1 = 0;
}
}
onClipEvent (load) {
speed = 0;
_root.ride = 0;
}
And the car don't move normally. Help?
onClipEvent (enterFrame) {
if (_root.ride == 1) {
if (Key.isDown(Key.ENTER)) {
_root.character._visible = true;
_root.character._x += 15;
_root.ride = 0;
}
_root.character._x = _x;
_root.character._y = _y;
if (Key.isDown(Key.RIGHT)) {
_rotation = _rotation+move;
}
if (Key.isDown(Key.LEFT)) {
_rotation = _rotation-move;
}
if (Key.isDown(Key.UP)) {
if (move<8) {
move++;
move++;
}
} else if (move>0) {
move--;
move--;
}
if (Key.isDown(Key.DOWN)) {
if (move>-10) {
move--;
move--;
}
} else if (move<0) {
move++;
move++;
}
if (_rotation>180) {
_y = _y+(move*Math.cos(Math.PI/180*_rotation));
_x = _x-(move*Math.sin(Math.PI/180*_rotation));
}
if (_rotation<180) {
_y = _y-(move*Math.cos(Math.PI/180*_rotation));
_x = _x+(move*Math.sin(Math.PI/180*_rotation));
}
}
}
onClipEvent (enterFrame) {
if (_root.ride == 1) {
if (Key.isDown(Key.SPACE)) {
_root.character._visible = true;
_root.character._x += 100;
_root.ride = 0;
_root.ride._visible = false;
_root.character1 = 1;
}
_root.character._x = _x;
_root.character._y = _y;
if (Key.isDown(Key.UP)) {
speed += .75;
d += 4;
moving = true;
}
if (Key.isDown(Key.DOWN)) {
speed -= .75;
}
if (Math.abs(speed)>7) {
speed *= .9;
moving = true;
}
if (Key.isDown(Key.LEFT)) {
_rotation -= 9;
moving = true;
}
if (Key.isDown(Key.RIGHT)) {
_rotation += 9;
moving = true;
}
speed *= .88;
x = Math.sin(_rotation*(Math.PI/180))*speed;
y = Math.cos(_rotation*(Math.PI/180))*speed*-1;
if (!_root.land.hitTest(_x+x, _y+y, true)) {
_x += x;
_y += y;
_root._x -= x;
_root._y -= y;
} else {
speed *= -.6;
}
}
}
onClipEvent (enterFrame) {
if (_root.ride == 0 && this.hitTest(_root.character) && Key.isDown(Key.ENTER)) {
_root.character._visible = false;
_root.ride = 1;
_root.character1 = 0;
}
}
onClipEvent (load) {
speed = 0;
_root.ride = 0;
}
And the car don't move normally. Help?