Well Im just learning trig and some flash and I was just wondering how well I did on this code... Is there any changes I should make?
This code is a simple gun turret that shoots bullets and when they hit the wall they expand and disapear.
var speed:Number = 10;
var depth:Number = 0;
var nose:Number = 50;
_root.onMouseMove = function() {
updateAfterEvent();
var xdiff:Number = _root._xmouse-spaceShip._x;
var ydiff:Number = _root._ymouse-spaceShip._y;
var angle:Number = Math.atan2(ydiff, xdiff);
angle = angle*180/Math.PI;
spaceShip._rotation = angle;
};
_root.onMouseDown = function() {
var angle:Number = spaceShip._rotation;
angle = angle*Math.PI/180;
++depth;
var name:String = "projectile"+depth;
var clip:MovieClip = _root.attachMovie("projectile", name, depth);
clip._x = spaceShip._x+nose*Math.cos(angle);
clip._y = spaceShip._y+nose*Math.sin(angle);
clip.xmov = speed*Math.cos(angle);
clip.ymov = speed*Math.sin(angle);
clip.ticker=0;
clip.explode=false;
clip.onEnterFrame = function() {
if (this.explode){
this.ticker+=4;
this._xscale=100+ (2*this.ticker);
this._yscale=100+(2*this.ticker);
this._alpha=200-(this.ticker);
if (this._alpha<1){
this.removeMovieClip();
}
}
if (this._x>700){
this.explode=true;
this.xmov = -this.xmov;
this._y += this.ymov;
}
if (this._x<0){
this.explode=true;
this.xmov = -this.xmov;
this._y += this.ymov;
}
if (this._y>400){
this.explode=true;
this._x+= this.xmov;
this.ymov =-this.ymov;
}
if (this._y<0){
this.explode=true;
this._x+= this.xmov;
this.ymov =-this.ymov;
}
this._x += this.xmov;
this._y += this.ymov;
};
};