Forum Topic: AS shooting help

(79 views • 3 replies)

This topic is 1 page long.

<< < > >>
Crying

This-Is-Freedom

Reply To Post Reply & Quote

Posted at: 1/12/09 06:10 PM

This-Is-Freedom FAB LEVEL 06

Sign-Up: 07/18/08

Posts: 141

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

Its Discusting When Fat People Realise There Fat Only Because There Too Fat To Even kill Themselves


None

crazysalt

Reply To Post Reply & Quote

Posted at: 1/12/09 09:00 PM

crazysalt EVIL LEVEL 04

Sign-Up: 12/24/08

Posts: 122

this is just my observation but i think when it calls in the movie clip to shoot its relocating the one that was just fired... so basically if you try to fire while the bullets in mid-air it reuses it... if that made sense so you just need to make it genrate movieclips for the occasion.


None

This-Is-Freedom

Reply To Post Reply & Quote

Posted at: 1/13/09 02:13 AM

This-Is-Freedom FAB LEVEL 06

Sign-Up: 07/18/08

Posts: 141

yeah that makes sence but i havent a clue how to do that

Its Discusting When Fat People Realise There Fat Only Because There Too Fat To Even kill Themselves


None

This-Is-Freedom

Reply To Post Reply & Quote

Posted at: 1/13/09 01:48 PM

This-Is-Freedom FAB LEVEL 06

Sign-Up: 07/18/08

Posts: 141

can anyone fix the script then?

it will help me loads

Its Discusting When Fat People Realise There Fat Only Because There Too Fat To Even kill Themselves


All times are Eastern Standard Time (GMT -5) | Current Time: 06:58 AM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!