In this case, your Player
might have a fire()
function that deals with this.
As an extremely simple example of that, you might have:
public function fire():void
{
var bullet:Bullet = new Bullet(x, y, rotation);
stage.addChild(bullet);
}
Where your Bullet
would accept the starting position and rotation:
class Bullet extends Sprite
{
public function Bullet(x:int, y:int, rotation:Number)
{
this.x = x;
this.y = y;
this.rotation = rotation;
}
}
This makes it easy to advance your fire()
function to deal with things like the Player having a different weapon, no ammunition, etc:
public function fire():void
{
if(currentWeapon.ammunition === 0) return;
if(currentWeapon is Handgun)
{
// Make a HandgunBullet.
}
if(currentWeapon is Shotgun)
{
// Make a ShotgunBullet.
}
}