(HELP!) 360-Degree Projectile Firing

Hi! This is my first week of learning Flash and ActionScript, and because I don’t have a good ActionScript book yet, I’ve been reading several basic Flash game programming tutorials online and doing my best to understand and learn the syntax and methods. After successfully creating “my” first Flash game (a space-shooter from the great tutorial on this website), I decided to set a high bar for myself and try to make a top-down shooter which I can expand on as I learn more.

My problem is that I simply cannot get Flash to recognize my “bullet” movie clip symbol in the library, place it by my character’s gun with correct rotation, and finally shoot it off into the distance. The gun is part of the same .png as the character is in, so it is part of the same symbol (“player”).

Below is the code I am working on for the shooting code:

Shooting Code: (Applied to my “Player” movie clip symbol’s “Actions”)

onClipEvent(load)
{
var bulletAngle:Number;
var bulletSpeed:Number = 2;
var i:Number = 0;
}

onClipEvent (enterFrame)
{
var radians = Math.atan2(_root._ymouse-this._y, _root._xmouse-this._x);
var degrees = (radians/Math.PI)*180;

this._rotation = degrees + 90;

if(Key.isDown(65))
{
    this._x -= 6;
}

if(Key.isDown(68))
{
    this._x += 6;
}

if(Key.isDown(87))
{
    this._y -= 6;
}

if(Key.isDown(83))
{
    this._y += 6;
}

onMouseDown = function ()
{
    _root.attachMovie("bullet2", "bullet2"+i, _root.getNextHighestDepth());
    bulletAngle = ((_root.player._rotation-90)*Math.PI/180);
    _root["bullet2" + i].xSpeed = Math.cos(bulletAngle)*bulletSpeed;
    _root["bullet2" + i].ySpeed = Math.sin(bulletAngle)*bulletSpeed;
    
    _root["bullet2"+i]._x = _root.player._x;
    _root["bullet2"+i]._y = _root.player._y;
    _root["bullet2"+i]._rotation = bulletAngle;
    i++;

    bulletSound = new Sound(this);
    bulletSound.attachSound("pistol_fire1");
    bulletSound.start(0, 1);
}
    
_root["bullet"+i].onEnterFrame = function()
{
    this._x += this.xSpeed;
    this._y += this.ySpeed;   
}

}

In my Flash scene, I have a “Crosshairs” movie clip symbol which I have successfully gotten to replace the hidden standard mouse cursor, a “player” movie clip who can move around the scene while always facing the crosshair, and a “bullet2” movie clip in my library. Both the player and bullet MC’s have identifiers of the same name applied to them.

I have posted this problem in the Actionscript.org forums, but I thought since this site has such great tutorials, I might get better help a little faster here. Thanks in advance to anyone who can gimme a hand fixing this, I really appreciate it. I really want to move on to other game elements such as the levels.

Thanks!

  • Michael