orangelight
Technical User
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
}
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
}