PDA

View Full Version : firing from a rotating cannon



orangelightblub
February 16th, 2005, 12:31 PM
Hi
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.
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
Hesh

intrudah
February 16th, 2005, 12:32 PM
is this a 3d perspective in a 2d game?

orangelightblub
February 16th, 2005, 12:34 PM
its a 2d game, top down view

JoMan
February 16th, 2005, 02:09 PM
Ah yes, I have tried to do this exact thing before! Here is a link that might help you:

http://www.flashkit.com/tutorials/Games/Weapon_M-Flash_Ju-80/index.php


peace

lostinbeta
February 16th, 2005, 02:21 PM
You can also check out...

http://www.senocular.com/flash/source.php?id=0.125


Nevermind, I just saw the top-down part ^still a useful file for other cannon games...lol

orangelightblub
February 16th, 2005, 03:23 PM
ok, i have managed to get the bullet o the screen, but i can't seem to make it fire
please can anyone help
here is my code

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;
}