PDA

View Full Version : Game problem (simple) help please!



Zak
March 17th, 2004, 10:31 AM
ok well i just have a simple shooting game but the only problem is when you shoot and then move the "tank" left and right to shoot again the bullets move with you, any help would be apprecitated, thanks.

actions of "tank" (instance name bug)

on (keyPress "<Left>") {
currentX = this._x;
this._x = currentX - 5;
}
on (keyPress "<Right>") {
currentX = this._x;
this._x = currentX + 5;
}
on (keypress "<Space>") {
_root.fire = 1;
_root.i += 1;
duplicateMovieClip(_root.bullet, "bullet"+i, i);
}

And this is the actions of the bullet (instance name bullet)

onClipEvent (load) {
this._visible = 0;
if (_root.fire == 1) {
this._x = _root.bug._x;
this._y = _root.bug._y;
}
}
onClipEvent (enterFrame) {
if (this != _level0.bullet) {
if (_root.fire == 1) {
this._y -= 5;
this._visible = 1;
}
if (this._y<0) {
this.removeMovieClip();
}
}
}
onClipEvent (enterFrame) {
if (_root.bullet, hitTest(_root.block)) {
_root.total = _root.total + 10;
} else {
_root.total = _root.total - 0;
}
}

And it is supposed to hit a target (instance name block), it still does but when i move the bug / tank it moves everything, any help would be appreciated.

flashcat
March 17th, 2004, 10:53 AM
At a first look - there is a bug:


onClipEvent (enterFrame) {
// bug: if (_root.bullet, hitTest(_root.block)) {
if (_root.bullet.hitTest(_root.block)) {
_root.total += 10;
} else {
_root.total -= 0;
}
}

flashcat
March 17th, 2004, 10:58 AM
And here are the Key-Codes:


if(Key.isDown(Key.RIGHT)){
this._x += 5;
}
else if(Key.isDown(Key.LEFT)){
this._x -= 5;
}
else if(Key.isDown(Key.SPACE)){
_root.fire = 1;
_root.i += 1;
duplicateMovieClip(_root.bullet, "bullet"+i, i);

}