Shooting works only when jumping not standing.
Hi All,
I'm having trouble getting my character to fire. it seems to fire when he jumps, but not while standing. I have attached my code to the zip file below:
http://www.mediafire.com/?jtkke490uzm4k5c
This is the code I used:
---------------------------------------------
onClipEvent (load) {
var gravity:Number = 0;
var speed:Number = 5;
var jumpHeight:Number = 13;
var scale:Number = _xscale;
this.gotoAndStop(2);
}
onClipEvent (enterFrame) {
gravity++;
_y += gravity;
while (_root.ground.hitTest(_x, _y, true)) {
_y--;
gravity = 0;
}
if (Key.isDown(Key.SPACE)) {
//
gotoAndPlay("fire");
}
if (Key.isDown(Key.RIGHT)) {
_x += speed;
_xscale = scale;
if (_root.ground.hitTest(_x, _y+3, true)) {
this.gotoAndStop(1);
} else {
this.gotoAndStop(2);
}
} else if (Key.isDown(Key.LEFT)) {
_x -= speed;
_xscale = -scale;
if (_root.ground.hitTest(_x, _y+3, true)) {
this.gotoAndStop(1);
} else {
this.gotoAndStop(2);
}
} else {
if (_root.ground.hitTest(_x, _y+3, true) && !Key.isDown(Key.LEFT) && !Key.isDown(Key.RIGHT)) {
this.gotoAndStop(3);
}
if (Key.isDown(Key.SPACE)) {
this.gotoAndPlay("fire");
}
}
if (Key.isDown(Key.UP) && _root.ground.hitTest(_x, _y+3, true)) {
gravity = -jumpHeight;
this.gotoAndStop(2);
}
}
----------------------------------------