Heres the code:
var depth:Number = 0;
var depth2:Number = 0;
var totalBalls:Number = 9
attachEnemy = setInterval(enemyFunc, 2000);
onMouseMove = function() {
gunMc._rotation = Math.atan2((_root._ymouse-gunMc._y), (_root._xmouse-gunMc._x))*180/Math.PI;
}
onMouseDown = function() {
shootBalls();
shootInter = setInterval(shootBalls, 200);
}
onMouseUp = function() {
clearInterval(shootInter);
}
onEnterFrame = function() {
if(depth2 > 50) {
clearInterval(attachEnemy);
}
for(var i2 = 0; i2 <= depth; i2++) {
bullets = _root["ball"+i2];
bulX = bullets._x;
bulY = bullets._y;
for(var i = 0; i < depth2; i++) {
ball = enemyHold["enemy"+i];
ballWidth = (ball._width/2);
distx = bulX-ball._x;
disty = bulY-ball._y;
distance = Math.sqrt(distx*distx+disty*disty);
if(distance < ((ball._width/2)-(bullets._width/2))) {
mag1 = Math.sqrt(bullets._xMov*bullets._xMov+bullets._yMov*bullets._yMov);
bullets._xMov = mag1*distx/distance;
bullets._yMov = mag1*disty/distance;
ball._xMov -= (mag1*distx/distance)/bullets._width;
ball._yMov -= (mag1*disty/distance)/bullets._width;
}
if(bullets._x > (Stage.width+(bullets._width/2)) || bullets._x < -(bullets._width/2) || bullets._y > (Stage.height+(bullets._height/2)) || bullets._y < -(bullets._height/2)) {
bullets.removeMovieClip();
}
if(ball._x > (Stage.width+(ball._width/2)) || ball._x < -(ball._width/2) || ball._y > (Stage.height+(ball._height/2)) || ball._y < -(ball._height/2)) {
ball.removeMovieClip();
}
}
}
}
function shootBalls() {
newBall = "ball"+depth;
angle = gunMc._rotation*Math.PI/180;
_root.attachMovie("ball", newBall, depth);
_root[newBall]._x = gunMc._x+30*Math.cos(angle);
_root[newBall]._y = gunMc._y+30*Math.sin(angle);
_root[newBall]._xMov = 10*Math.cos(angle);
_root[newBall]._yMov = 10*Math.sin(angle);
_root[newBall].onEnterFrame = function() {
this._x += this._xMov;
this._y += this._yMov;
}
depth++;
}
function enemyFunc() {
newEnemy = "enemy"+depth2;
enemyHold.attachMovie("enemy", newEnemy, depth2);
enemyHold[newEnemy]._x = random(Stage.width);
enemyHold[newEnemy]._y = random(Stage.height);
enemyHold[newEnemy]._rotation = Math.atan2((gunMc._y-enemyHold[newEnemy]._y), (gunMc._x-enemyHold[newEnemy]._x))*180/Math.PI;
angle2 = enemyHold[newEnemy]._rotation*Math.PI/180;
enemyHold[newEnemy]._speed = (random(4)+1);
enemyHold[newEnemy]._xMov = enemyHold[newEnemy]._speed*Math.cos(angle2);
enemyHold[newEnemy]._yMov = enemyHold[newEnemy]._speed*Math.sin(angle2);
enemyHold[newEnemy].onEnterFrame = function() {
this._x += this._xMov;
this._y += this._yMov;
}
depth2++;
}
Its for an upcoming game, please dont steal!
