thanks for the help, here is the code.
added comments to the code, it is now 150 lines:
bc = 1000;
base_range = 300;
clicked = false;
can_be_placed = false;
placed = false;
firing = false;
attachMovie("path", "path", _root.getNextHighestDepth());
attachMovie("cant_build_part1", "cant_build_part1", _root.getNextHighestDepth(), {_x:20, _y:0});
attachMovie("cant_build_part2", "cant_build_part2", _root.getNextHighestDepth(), {_x:20, _y:120});
attachMovie("cant_build_part3", "cant_build_part3", _root.getNextHighestDepth(), {_x:120, _y:80});
attachMovie("cant_build_part4", "cant_build_part4", _root.getNextHighestDepth(), {_x:120, _y:40});
attachMovie("cant_build_part5", "cant_build_part5", _root.getNextHighestDepth(), {_x:200, _y:40});
attachMovie("cant_build_part6", "cant_build_part6", _root.getNextHighestDepth(), {_x:60, _y:220});
attachMovie("cant_build_part7", "cant_build_part7", _root.getNextHighestDepth(), {_x:60, _y:260});
attachMovie("cant_build_part8", "cant_build_part8", _root.getNextHighestDepth(), {_x:100, _y:300});
attachMovie("cant_build_part9", "cant_build_part9", _root.getNextHighestDepth(), {_x:320, _y:80});
attachMovie("cant_build_part10", "cant_build_part10", _root.getNextHighestDepth(), {_x:360, _y:80});
attachMovie("cant_build_part11", "cant_build_part11", _root.getNextHighestDepth(), {_x:400, _y:0});
for (var j:Number = 1; j<12; j++) {
_root["cant_build_part"+j]._alpha = 0;
}
attachMovie("range", "range", _root.getNextHighestDepth(), {_width:base_range, _height:base_range});
attachMovie("base", "base", _root.getNextHighestDepth());
//array for checkpoint
waypoint_x = new Array(40, 140, 140, 220, 220, 80, 80, 340, 340, 420, 420);
waypoint_y = new Array(140, 140, 60, 60, 240, 240, 320, 320, 100, 100, -20);
delay = 25;
new_monster = 0;
monsters_placed = 0;
onEnterFrame = function () {
//placing "monsters"
if (monsters_placed<25) {
new_monster++;
}
if (new_monster == delay) {
monsters_placed++;
new_monster = 0;
min = attachMovie("minion", "minion"+monsters_placed, _root.getNextHighestDepth(), {_x:40, _y:-20});
min.alive = true;
min.point_to_reach = 0;
min.speed = 3;
min.health = 2;
min.onEnterFrame = function() {
//movement for monsters
dist_x = waypoint_x[this.point_to_reach]-this._x;
dist_y = waypoint_y[this.point_to_reach]-this._y;
if ((Math.abs(dist_x)+Math.abs(dist_y))<3) {
this._x = waypoint_x[this.point_to_reach];
this._y = waypoint_y[this.point_to_reach];
this.point_to_reach++;
}
angle = Math.atan2(dist_y, dist_x);
this._x = this._x+this.speed*Math.cos(angle);
this._y = this._y+this.speed*Math.sin(angle);
this._rotation = angle/Math.PI*180-90;
//hitests
//not working
for (var i:Number = 1; i<=20; i++) {
if (_root["bullet"+i].hitTest(this)) {
trace(1);
}
}
//not working
if (bullets.hitTest(this)) {
bullets.removeMovieClip();
min.health -= 1;
if (min.health<=0) {
this.removeMovieClip();
}
}
};
}
};
//firing
int1 = setInterval(function () {
if (placed) {
//get enemy in front of the pack
for (var i:Number = 1; i<=monsters_placed; i++) {
if (_root["minion"+i].alive == true) {
target = i;
//figure out the distance
distance_from_turret_x = gun1._x-_root["minion"+target]._x;
distance_from_turret_y = gun1._y-_root["minion"+target]._y;
//if enemy is in range
if (Math.sqrt(distance_from_turret_x*distance_from_turret_x+distance_from_turret_y*distance_from_turret_y)<base_range/2) {
i = monsters_placed+1;
//resetting bullet count if too large
if (bc>1019) {
bc = 1000;
}
//get angle for gun, which is then passed down to the bullet
dir = Math.atan2(distance_from_turret_y, distance_from_turret_x);
gun1._rotation = int((dir*360/(2*Math.PI))-90);
//gets a new bullet
bullets = duplicateMovieClip("bullet", "bullet"+bc, _root.getNextHighestDepth());
bc++;
//makes sure gun is on top of the bullets at all times
gun1.swapDepths(_root.getNextHighestDepth());
//to see if bullets touch edge of screen
if ((bullets._x<0) or (bullets._y<0) or (bullets._y>400) or (bullets._x>500)) {
bullets.removeMovieClip();
}
}
}
}
}
}, 250);
//to keep the base following the mouse when it is not placed yet
base.onEnterFrame = function() {
if (!placed) {
this._x = _root._xmouse;
this._y = _root._ymouse;
_root.range._alpha = 100;
can_be_placed = true;
if ((_root.cant_build_part1.hitTest(this)) || (_root.cant_build_part2.hitTest(this)) || (_root.cant_build_part3.hitTest(this)) || (_root.cant_build_part4.hitTest(this)) || (_root.cant_build_part5.hitTest(this)) || (_root.cant_build_part6.hitTest(this)) || (_root.cant_build_part7.hitTest(this)) || (_root.cant_build_part8.hitTest(this)) or (_root.cant_build_part9.hitTest(this)) || (_root.cant_build_part10.hitTest(this)) || (_root.cant_build_part11.hitTest(this))) {
_root.range._alpha = 0;
can_be_placed = false;
}
}
//to hide or display the range mc when clicked on
if (placed) {
base.onPress = function() {
if (!clicked) {
range._alpha = 100;
clicked = true;
} else if (clicked) {
range._alpha = 0;
clicked = false;
}
};
}
};
//to keep the range follwoing the mouse when it is not placed yet
range.onEnterFrame = function() {
if (!placed) {
this._x = _root._xmouse;
this._y = _root._ymouse;
}
};
//if you click and the base is not ontop of the path, it then is ready too shoot, and doesn't follow the mouse anymore
onMouseDown = function () {
if ((can_be_placed) && (!placed)) {
placed = true;
//applys the gun mc to the base
attachMovie("gun1", "gun1", _root.getNextHighestDepth());
gun1._x = _root.base._x;
gun1._y = _root.base._y;
range._alpha = 0;
}
};