MikeRoch
03-12-2008, 02:27 PM
Right now im working on a flash maze tower defense game, and right now i have a working turret, enemies and bullets. This is the code so far
base_range = 300;
can_be_placed = false;
placed = false;
firing = false;
attachMovie("path", "path", _root.getNextHighestDepth());
attachMovie("cant_build", "cant_build", _root.getNextHighestDepth());
attachMovie("range", "range", _root.getNextHighestDepth(), {_width:base_range, _height:base_range});
attachMovie("base", "base", _root.getNextHighestDepth());
waypoint_x = new Array(40, 140, 140, 290, 290, 45, 45, 400, 400);
waypoint_y = new Array(220, 220, 120, 120, 320, 320, 430, 430, -30);
delay = 25;
new_monster = 0;
monsters_placed = 0;
onEnterFrame = function () {
if (monsters_placed<25) {
new_monster++;
}
if (new_monster == delay) {
monsters_placed++;
new_monster = 0;
min = attachMovie("minion", "minion"+_root.getNextHighestDepth(), _root.getNextHighestDepth(), {_x:40, _y:-20});
min.point_to_reach = 0;
min.speed = 1;
min.onEnterFrame = function() {
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))<1) {
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;
if (bullet.hitTest(this._x, this._y, true)) {
firing = false;
bullet.removeMovieClip();
this.removeMovieClip();
}
if (placed) {
distance_from_turret_x = base._x-this._x;
distance_from_turret_y = base._y-this._y;
if ((Math.sqrt(distance_from_turret_x*distance_from_t urret_x+distance_from_turret_y*distance_from_turre t_y)<base_range/2) and (!firing)) {
firing = true;
bullet = attachMovie("bullet", "bullet"+_root.getNextHighestDepth(), _root.getNextHighestDepth(), {_x:base._x, _y:base._y});
bullet.dir = Math.atan2(distance_from_turret_y, distance_from_turret_x);
bullet.onEnterFrame = function() {
this._x -= 3*Math.cos(bullet.dir);
this._y -= 3*Math.sin(bullet.dir);
if ((this._x<0) or (this._y<0) or (this._y>400) or (this._x>500)) {
firing = false;
this.removeMovieClip();
}
};
}
}
};
}
};
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.hitTest(this._x-this._width/2, this._y-this._height/2, true) or _root.cant_build.hitTest(this._x+this._width/2, this._y+this._height/2, true) or _root.cant_build.hitTest(this._x+this._width/2, this._y-this._height/2, true) or _root.cant_build.hitTest(this._x-this._width/2, this._y+this._height/2, true)) {
_root.range._alpha = 0;
can_be_placed = false;
}
}
};
range.onEnterFrame = function() {
if (!placed) {
this._x = _root._xmouse;
this._y = _root._ymouse;
}
};
onMouseDown = function () {
if (can_be_placed) {
placed = true;
}
};
My question is if anyone has any ideas on how to help make this do rounds with accumulating money per kill, along with buildable turrets. Also any tut's for this type of thing would help.
base_range = 300;
can_be_placed = false;
placed = false;
firing = false;
attachMovie("path", "path", _root.getNextHighestDepth());
attachMovie("cant_build", "cant_build", _root.getNextHighestDepth());
attachMovie("range", "range", _root.getNextHighestDepth(), {_width:base_range, _height:base_range});
attachMovie("base", "base", _root.getNextHighestDepth());
waypoint_x = new Array(40, 140, 140, 290, 290, 45, 45, 400, 400);
waypoint_y = new Array(220, 220, 120, 120, 320, 320, 430, 430, -30);
delay = 25;
new_monster = 0;
monsters_placed = 0;
onEnterFrame = function () {
if (monsters_placed<25) {
new_monster++;
}
if (new_monster == delay) {
monsters_placed++;
new_monster = 0;
min = attachMovie("minion", "minion"+_root.getNextHighestDepth(), _root.getNextHighestDepth(), {_x:40, _y:-20});
min.point_to_reach = 0;
min.speed = 1;
min.onEnterFrame = function() {
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))<1) {
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;
if (bullet.hitTest(this._x, this._y, true)) {
firing = false;
bullet.removeMovieClip();
this.removeMovieClip();
}
if (placed) {
distance_from_turret_x = base._x-this._x;
distance_from_turret_y = base._y-this._y;
if ((Math.sqrt(distance_from_turret_x*distance_from_t urret_x+distance_from_turret_y*distance_from_turre t_y)<base_range/2) and (!firing)) {
firing = true;
bullet = attachMovie("bullet", "bullet"+_root.getNextHighestDepth(), _root.getNextHighestDepth(), {_x:base._x, _y:base._y});
bullet.dir = Math.atan2(distance_from_turret_y, distance_from_turret_x);
bullet.onEnterFrame = function() {
this._x -= 3*Math.cos(bullet.dir);
this._y -= 3*Math.sin(bullet.dir);
if ((this._x<0) or (this._y<0) or (this._y>400) or (this._x>500)) {
firing = false;
this.removeMovieClip();
}
};
}
}
};
}
};
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.hitTest(this._x-this._width/2, this._y-this._height/2, true) or _root.cant_build.hitTest(this._x+this._width/2, this._y+this._height/2, true) or _root.cant_build.hitTest(this._x+this._width/2, this._y-this._height/2, true) or _root.cant_build.hitTest(this._x-this._width/2, this._y+this._height/2, true)) {
_root.range._alpha = 0;
can_be_placed = false;
}
}
};
range.onEnterFrame = function() {
if (!placed) {
this._x = _root._xmouse;
this._y = _root._ymouse;
}
};
onMouseDown = function () {
if (can_be_placed) {
placed = true;
}
};
My question is if anyone has any ideas on how to help make this do rounds with accumulating money per kill, along with buildable turrets. Also any tut's for this type of thing would help.