Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

firing bullets

Status
Not open for further replies.

orangelight

Technical User
Feb 17, 2005
20
GB
This is the first time I am having a go at a game. I need advice on firing bullets from a rotating cannon. I have got the cannon to rotate, but cant get the bullets to fire in the same directions and at the moment the bullets shows it self, but doesn't move.


please can anyone help on how i go about doing this i.e what maths to use etc
I am using flash mx

many thanks

i have two movieclipes called turrent and bullet
here is the ActionScript I have so far.

var bulletNum=0
//moving the turrent gun
turrent.onEnterFrame = function() {

if (Key.isDown(Key.LEFT)) {
this._rotation -= 6;
}
if (Key.isDown(Key.RIGHT)) {
this._rotation += 6;
}
}

spacebarListener=new Object();
spacebarListener.onKeyDown=fireBullet;
Key.addListener(spacebarListener);


//GETTING THE BULLETS and fireing the bullets
function fireBullet(){

if (Key.getAscii()==32)
{
bulletMC=attachMovie("bullet","bullet"+bulletNum,1000+bulletNum++);
bulletMc._x=turrent._x;
bulletMc._y=turrent._y;
shipAngle=2*Math.PI*(turrent._rotation-90)/360;
bulletMC.dx=Math.cos(shipAngle);
bulletMC.dy=Math.sin(shipAngle);
bulletMC.moveBullet=moveBulletFunction;
setInterval(buttetMC,"moveBullet",50,bulletMC)
}
}

//MOVING THE BLOODY THING
function moveBulletFunction(){
bulletSpeed=10.0;
this._x+=bulletSpeed*this.dx;
this._y+=bulletSpeed*this.dy
}



 
oops
Yhe BulletMc should be bulletMc - but I still can't get the bullet to move
thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top