ok ive done most of the code for shooting but it seems that if i double tap the fire button the bullet fires but when i tap the fire again the last bullet i fired disappears while it is still traveling
code on ship:
onClipEvent (load) {
// only done once, therefore we'll put variables here so it won't update
thrust = 1;
decay = .97;
maxSpeed = 15;
spaceDown = true;
xSpeed = 0;
ySpeed = 0;
i = 0;
}
onClipEvent (enterFrame) {
// rotate right or left
if (Key.isDown(Key.RIGHT)) {
_rotation += 10;
}
if (Key.isDown(Key.LEFT)) {
_rotation -= 10;
}
// Shoot
if (Key.isDown(Key.SPACE) && spaceDown == false) {
b = _root.bulletz.duplicateMovieClip(["bulle tz"+i], _root.getNextHighestDepth());
b._x = _x;
b._y = _y;
b.xSpeed = 20*Math.sin(_rotation*(Math.PI/180));
b.ySpeed = 20*Math.cos(_rotation*(Math.PI/180));
b._rotation = _rotation;
i++;
spaceDown = true;
}
if (!Key.isDown(Key.SPACE)) {
spaceDown = false;
}
//
//
if (Key.isDown(Key.UP)) {
// calculate speed and way to move based on rotation
xSpeed += thrust*Math.sin(_rotation*(Math.PI/180))
;
ySpeed += thrust*Math.cos(_rotation*(Math.PI/180))
;
} else {
// indicates when the UP key is released
xSpeed *= decay;
ySpeed *= decay;
}
// maintain speed limit
speed = Math.sqrt((xSpeed*xSpeed)+(ySpeed*ySpeed ))
;
if (speed>maxSpeed) {
xSpeed *= maxSpeed/speed;
ySpeed *= maxSpeed/speed;
}
// move ship based on calculations above
_y -= ySpeed;
_x += xSpeed;
// moves the ship to other side when off-field
if (_y<0) {
_y = 399;
}
if (_y>399) {
_y = 0;
}
if (_x<0) {
_x = 549;
}
if (_x>549) {
_x = 0;
}
}
code on bullet:
onClipEvent(load){
spd=25; //bullet speed
_x=_root.gun._x; //Move to gun _x
_y=_root.gun._y; //Move to gun _y
_rotation= _root.gun._rotation; //Point in same direction as gun
}
onClipEvent(enterFrame){
if(_name == "bullet"){
_x = -1000; //Move the original bullet MC offstage
}else{
//Run this movement code on all dupes
if (_rotation>180) {
_y += (spd*Math.cos( Math.PI/180*_rotation));
_x -= (spd*Math.sin( Math.PI/180*_rotation));
} else {
_y -= (spd*Math.cos (Math.PI/180*_rotation));
_x += (spd*Math.sin( Math.PI/180*_rotation));
}
//if(hitTest(_root.enemy)){ blahh; } Not going to address this here, check AS: Main for hitTest threads.
}
if(_x>Stage.width || _x<0 || _y<0 || _y>Stage.height){
//If off-stage, delete the dupe to save CPU
this.removeMovieClip();
}
}
example :
http://spamtheweb.com/ul/upload/120109/7 1360_Untitled-1.php