Make a Flash game like Flash Element Tower Defense – Part 2
- November 6, 2007 by Emanuele Feronato
- Filed under Flash, Game design | 163 Comments
Welcome to the 2nd part of this tutorial. I recommend you to check part 1.
In this tutorial, we will place our first base, and it will start to fire.
Let’s have a look at the objects:

base: it’s the base
bullet: it’s the bullet the base will shoot
cant_build: it’s the area where you can’t build a base
minion: already explained in part 1.
path: already explained in part 1.
range: it’s the firing range of the base
Now, a little actionscript all in the first frame:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | base_range = 300;
can_be_placed = false;
placed = 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, 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 () {
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;
};
}
};
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;
}
}; |
Line 1: Defining the base range
Line 2: Defining if the base can be placed
Line 3: Defining if the base has been placed
Line 5: Attaching the cant_build movieclip
Line 6: Attaching the range movieclip and setting its width and height to match base_range
Line 7: Attaching the base movieclip
Line 36: Function to be executed for the base at every frame
Line 37: If the base is not already placed…
Lines 38-39: Move the base to the mouse pointer
Line 40: Set the transparency of the range to 100 (fully opaque)
Line 41: Updating can_be_placed to true
Line 42: If a corner of the base is over the cant_build area…
Line 43: Setting the transparency of the range to 0 (fully transparent)
Line 44: Setting can_be_placed to false
What I’ve done: I let the player move the base with the mouse. If the base can’t be placed, because it’s over the walking path, I hide the range to make the player know he is on an area where he can’t build.
Line 48: Function to be executed for the range at every frame
Lines 49-52: Same thing of lines 37-39… if the base has not been placed, then move the range with the mouse
Line 54: Function to be executed when the player clicks the mouse
Line 55: If the base can be placed…
Line 56: Then set placed to true. Now the base is placed
Look: you can now place your base, but only outside the walking path.
Now, we will make the base fire at the foes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | 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, 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 () {
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_turret_x+distance_from_turret_y*distance_from_turret_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;
}
}; |
Line 4: Setting the firing variable to false. Now the base is not firing
Line 34: Performing an hit test between the minion and the bullet. At this time in the script we haven’t already met the bullet, but anyway at this time I am performing this test
Line 35-37: If the test is positive, then remove the bullet and the minion that was hit (at this time minions do not have energy, so my turret is one shot one kill), then set firing to false.
Lines 40-41: Calculating x and y distance between the bullet and the minion
Line 42: If the distance between the bullet and the minion is less than half the range (in our case the range is the diameter of the circle, so half the range is the radius)
Line 43: Boom! The turret fires!
Line 44: Placing the bullet on stage, in the same position of the turret
Line 45: Setting bullet direction, accordind to its x and y distances from the minion
Line 46: Function to be executed for the bullet at every frame
Lines 47-48: Moving the bullet using trigonometry. If you don’t know what is trigonometry, then head to this tutorial
Line 49: Checking if the bullet is flying out of the stage
Lines 50-51: In this case, remove the bullet and set firing to false again to let the turret fire once more
And here it is our firing turret. You may need to reload the page to have the minion walking while you will place the turret and start killing them.
The fire rate sucks a lot, and the same thing does turret’s AI. But I got all those features in only 81 lines, I am sure I will create the complete game in less than 500 lines.
Not today, anyway. Today, download the source and if you have suggestion… just leave a comment.
They can be easily customized to meet the unique requirements of your project.
163 Responses
Leave a Reply
- Una guida completa al gioco del poker online e una selezione dei migliori casino online.
- casino online
- migliori casino online
- BlackJack online
- casinò online
- Giochi casino

(150 votes, average: 4.47 out of 5)



[...] 11th update: part 2 [...]
PLEASE HELP! i need to press buttons alternately to make the person move, but when
i try i can hold both and he’ll go really fast.
if you hold 1 it doesnt move. you want code
here:
onClipEvent (enterFrame) {
if (Key.isDown(Key.LEFT) && this._currentframe == 1) {
_root.BallOneMin._y -= 1;
_root.BallOneMax.play();
_root.BallOneMin.nextFrame();
} else {
if (Key.isDown(Key.RIGHT) && this._currentframe == 2) {
_root.BallOneMin._y -= 1;
_root.BallOneMax.play();
_root.BallOneMin.prevFrame();
}
}
}
for some reason when i try to place turret in above movies it only lets me place it in cant build area.
Great tutorial! Your coming out with new stuff almost every day. How do you manage to write so many a tutorials in such a short time?
I quit sleeping a year ago
hi,
gr8 tutorial Emanuele.
Anyways, i completed 5 levels of the game I am going to submit in MochiAds contest. I am planning to make 5 more levels. Shall I send u the complete game too? Whats ur email?
hi Emanuele,
Please make the next part of the claustrophobic SURVIVAL HORROR tut.
Emanuele, as always, nice tutorials. To you, it’s just some words, but to us, it’s something… something livechanging. – You help us so much, another time: thank YOU! :)
/Frederik J
i have said this many times already i’ve forgotten how to count
great tutorial
i can’t wait for the next tutorial on “Create a Flash Racing Game Tutorial”
David, thats not Emanuele who writes it, its GameSheep!
/Frederik J
nvrr mind i fixed it =)
errmmm love this tut but i got a problem…
how do ya post in user controbutions??
love the tutorial but i have a few quextions i need to ask…
1. how to post new topics in user contorbutions
2. can i post a game i made using a gamecore off my uncle and his program that i used to put it al together?
love a ansewr soon k?
p.s the game i made is a fps with AI and full functional action kinda like halo or doom but not as good
You can send your works to info@emanueleferonato.com
GR8! M8! did u quit sleeping? lol then we request u quiting lunch and nature’s call needs to write more tuts!! plzz! ;D
best regards
Nice tut. Reminded me for a few things I need to remember to do when making mine.
Huge thanks for the tutorial!
Been looking for something like this for along time. Can’t wait till it is finished!
“powered by coffee”, ay?
[...] Make a Flash Game Like Flash Element Tower Defense – Part 2 [...]
Mine never shoots! plz help
ok how do i run the fla filess?
I need help dude plleeeeaassee… Nothing works for me, the graphics don’t even show up!
I really need help as I ALWAYS wanted to build my own tower defence game!
What do you need in order to make td’s of your own??? and is it free??
What do you need in order to make td’s of your own??? and is it free??
The problem with placing the tower is that it checks if any of the corners are on the path and because the tower is wider than the path it can be placed over the path so long as all 4 corners aren’t on the path, might want to look into that for next tutorial or fix it in this one :)
juan,
You need to have a copy of Adobe Flash (Or Macromedia Flash) and some knowledge of Actionscript. Or, yo can follow tutorials such as those of Emanuele.
Can’t wait for the next parts Emanuele Feronato, great blog and tutorials.
What is actionscript and how do i get to it
to fix the hittest problem (the 4 corners issue), simply hittest the entire base, not just the corners. or maybe your allowed to place it over the path…
lol if u dont kno wut actionscript is i suggest u find a much simpler tut. (actionscript is the stuff u type in so that the funny pictures do stuff you want them to. its like a type of flash-language.)
also, emanuele, how do you make the rest of the whole game? or are you going to come out with a tut for that later? i didnt catch.
Man, real awesome tute, waiting for the final version..like in which you’ll cover the Fire rate and a much better AI
Thanks
Actionscript is what this tutorial is based on retard. you have to use it to code most of the online flash Tower Defences. there is racing and also action ones like Feudalism.
Wow, people are pretty rude on here sometimes and not very informative. For the people asking about this
1st: You need Adobe Flash to make these games
(go to adobe.com to get a 30day trial)
2nd: Actionscript is a programming language that Adobe Flash uses.
3rd: Hey Emanuele it’s been a long time since ive been here. Your 1st tut on a line rider game inspired me to continue learning flash when i was very doubtful in my skills. Now im thinking about making my own tutorials in flash. So keep up the good work! by the way ill send you my own tower defense game im making, not based on your tut though.
Hi can you tell me how to make so that i could upgrade,build more and turn off or destroy my towers?
Great Tutorial. Merry Christmas everyone
Hi, can anyone tell me how to start making a tower defense game?
i’d really appreciate it, thx
Joe:
First of all you need some basic/advanced Actionscript knowledge, if you don’t got it then look at some tutorials. You also need the program Macromedia flash 8 or MX2004 (I recommend 8), and then it is just to start developing the game. You can also follow Emanueles tutorial, that you’ve just read.
I already had flash, how do i open it and start making the game?
You just open it, make some movieclips and then start coding.. But it isn’t that simple. You need to know how you code actionscript..
will emanuelle launch a third part? cause i dont have the knowledge to develop the rest of the game myself
This is a great tutorial ! Thanks
i can’t open the sources =( It says unexpected file format….Anyone Help?
yeah,
i’ve got movie clips and code into actionscript window but how to make it now to work?
help us!
i built up to this point but when i try it on .swf the minions disappear. Any ideas?
Why, when the speed is adjusted, do the minions flicker and stop in the corners?
i have the same problem as you with the tower defence making. how do u fix it?
I’m 8 :-)
i put everything in place but when i try to play it it loads then sais “this script is causeing flash to run slowly. if this continues, your computer may become non responsive. do you want to abort?yes/no”
when i click no it just waits a little and sais the same thing again. how do i fix this?
hey, this is an awesome tut but im having a problem with the creeps turning, they get to a corner, then flick back and forewards until they are all doing it on top of eachother, when they start going again on top of eachother
here is the code as it is now (just the turning bit):
if (new_monster == delay) {
monsters_placed++;
new_monster = 0;
min = attachMovie(“minion”, “minion”+_root.getNextHighestDepth(), _root.getNextHighestDepth(), {_x:807.6, _y:252.3});
min.point_to_reach = 0;
min.speed = 1;
min.onEnterFrame = function() {
dist_x = waypoint_x[_root.min.point_to_reach]-this._x;
dist_y = waypoint_y[_root.min.point_to_reach]-this._y;
if ((Math.abs(dist_x)+Math.abs(dist_y))<min.speed) {
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;
Please help! thanks, Jamie
Please, release part 3 of this tutorial… It`s great tutorial!
i finished this doing what you said but, when i view it the minions never come. help!
i am very noob about making a game so where can i open this side where i can make a minion and pach
where is the end? part 3?
i dont know how to do the lines it just shows it on my com
click yes trust me
i am very excited about making my very own tower
defense.
Nice tutorial two questions can you speed up the speed of the bullets and is there a 3rd part to this tutorial yet
When are you going to finish?
I really want to make a td game!
why did i get modded?
btw i need help making it where you can buy bases.
when i buy one the background turns white and i can’t place it anywhere,and if i try to buy another one it goes up in the corner.
any help?
I got a question where do i get Macromedia Flash
and how much is it or is it free?
Great tut!!!
The thing is, I can’t play it… Kinda sad you know :(!!! Please help!!! If you know plese post to reply.
Thanks,
Rc
omg i dont got this…
Thanks for the great tutorials. I’m very bussy
making my own towerdefence, but offcourse i’m stuck now and then.
Hope you write a 3rd part, i would really appreciate it.
How do you call min outside of the min.onEnterFrame= function()
{
}
When I do a hitTest with _root.min inside the bullet’s onEnterFrame, it only works for the min that was most recently created. Is there a way I can program outside the min onEnterFrame and have the code work for all min’s created?
O.K. i need the program to make one of these please! Thank you!
[...] un gioco di difesa è facile: bastano alcune routine per generare i nemici (ma se ne può fare anche a meno agendo direttamente [...]
I’d really like to see part 3 on this one. I downloaded the source here to expand on and make an actual game, but there are so many things right now that are controlled in actionscript on the main frame, instead of via other controls and it’s a significant amount of work splitting those off without breaking the whole thing.
I’ve been pondering making a TD game for a while (mainly due to the fact that all the towers out there are the same, and I have a few new ideas to put to the test), but lack the knowhow to figure out how to get started. I really need some starter code and all I have to do is tweak.
when are you going to make the third part?? i havent got the brains to make the rest :D
how the hell do you even test it? :’(
Great tut. When are you going to get part 3 out?
Great tut. When are you going to get part 3 out? I need some help with the firing. How do i make the bullet never miss or disapear if it leave the range of the tower?
i love this website i just cant find astral tower defense cause i played it 1 time and then the next day i couldnt find it.
PLZ MAKE A THIRD PLZ!!!!
according to flash u have errors in lines 4 and 18 dude
That was for Jamie the last one
Dude, THIS IS AWESOME!!
3 Q’s
1 how do you increase the bullet speed?
2 could you make a part 3 about how to make a building menu where u can click on the base tower (small icon) so u can place it multiple times? (and with money from creeps offcourse)
3 could you tell me how to make waves? so 1st the triangles and after there are no triangles left, circles etc.
your joking about the non sleeping thing right???
hey mastermind you can make waves by using timers between 2 waves …
u can try to make a building menu by youreself just create some symbols whit small towers put them in a seperate space on youre frame use a release function so you can click them and copy the coding from the frame that makes you place a turret in the first place …
how do i ga the games maker wats it called and where do i download it???
Put this on the frame, and make the mc “ball”
/*
-Put this on the frame
-Make sure the mc is named “ball”
*/
speed=1;
//Specifies the mc’s movement speed in pixels
onEnterFrame = function () {
if (!Key.isDown (Key.LEFT)) {
l = “up”;
}
if (Key.isDown (Key.LEFT) && ball._currentframe == 1) {
if (l == “up”) {
ball._y -= speed;
ball.gotoAndStop (2);
}
r=”down”
}
if (!Key.isDown (Key.RIGHT)) {
r = “up”;
}
if (Key.isDown (Key.RIGHT) && ball._currentframe == 2) {
if (l == “up”) {
ball._y -= speed;
ball.gotoAndStop (1);
}
l=”down”;
}
};
I love you and this site… Not in a homo way =P
I haven’t been able to find tutorials like these anywhere else but here. I’m going to start work on a more in depth tower defense game after this by combining your code with codes I already know. I’ll post a link to it once its done if I can remember. ^_^
This site is epic and I demand that it stay open for eternity!
Ok Emanuelo this tutorial is awsome but you didn’t tell what programm did you use? please post more details because I want to enjoy making a TD game too…
I’m trying to load the builder but cannot. Can you help???
I would also like to know what program you used so I also can have fun making my own TD game.
Hi in response to your question, “What program is he using” he is using flash. You can download a free 30 day trial from:
http://www.adobe.com/products/flash/
Check out my site -
http://www.kongregate.com/accounts/cleverclogs
Cleverclogs =)
[...] Part2: http://www.emanueleferonato.com/2007/11/06/make-a-flash-game-like-flash-element-tower-defense-part-2... [...]
im so confused
how to make you lose lives if they get to middle!?
what program do you use
Please make a part 3 including:
-Waves, or levels, of enemies.
-How to create more towers by clicking and dragging from an icon of that tower.
-Incorperate money, enemy health, and lives.
-The ability to select a tower and see its stats.
Thanks! Awesome tutorial!!
ok im new to flash and i put the actions script in and made each symbol in a movie clip exaclty how the tutorial shows im just wondering if anything needs to be on the stage? all i have is the path and nothing is happening and when i drag the minions on nothing happens. any help would be greatly appreciated.
help plz not workin
i want the next part
whens the next one comming out?
Wow! Really amazing. Please make a third part if possible.
i have an idea for a flash elemet 3 but i really really think it should go to more then just the computer ….. mabey have a chance on systems like the ds or wii or something that would be awsome.
please make a third part if possible.
I wish i could make a game as cool as urs
yes who ever made this definitely should make a part 3 but add lots more towers and enemies so it blows us away
how do start making it
how do start making it in what place
hi, nice work dude. i really want to make a TD game. but i’m not sure how to do :S. u can e-mail me if u want. cya around :D
oh btw, i have made some changes on the suff u did. if your intrested mail me and ill send it to ya. that TD i made would rock if i got it nice and ready “/
markus teach me pls..
ok dude go take a week long nap and then make a part 3.also if any body is proficient in flash/actionsctirpt and wants to work together on a game contact me at electricbrock@gmail.com
hey go play new game of mine (way cool)
Does anyone know where i can get free online actionscript lessons cos me and my mates really want to make this HUGE flash game where you basicaly live out your life a bit like sims but bigger goryer and better graphics
I can’t open it because it is an unexpected file format
Can you get a grid for Macromedia Flash MX? And my syntax doesnt work very well… Tips? Comments?
Hey Emanuele,
I had to make a Tower Defence game for school lately and I based on your tutorial here to create it – though I had to write it AS3, so I actualy had to think a little myself :)
My game is embedded in Facebook, it uses pictures of your contacts there. You can see it here: http://apps.facebook.com/cliqster/index.php?vis=towerdefence (if you don’t see the game try looking for it on the lower right corner).
So thanks :) and enjoy.
did you really quit sleeping?
i don’t know how to anything.Do you know how?
I have NO idea.
Are you new to flash? You should use a flash program 6, 7, or, 8. you simply copy the programming and place it into “frame actions” which can be acessed by right clicking a frame and selecting “actions” from the list. you then past the code into the box and there you go. The programming also requires you to name the things in the library the same as in this tutorial otherwise it won’t work. You can also modify the actionscript so you can make up your own names. you also need the same path or again modify the
waypoint_x = new Array (modify the numbers) and do the same thing with “waypoint_y” You can find the coordinates through “mouse coordinates” by going to windows at the top, selecting panels and selecting info from that.
Hi im new here and im wondering where to put this stuff in? Also i don’t even kno wat the program is, wat is the program to make these and where do u paste it!
Cheers plz reply
My email to tell me: battleonkid1@hotmail.com
i need a free(not free so many-day trial)action script program for windows xp professional.
ok, but how do you do this with macromedia flash 8? i am a total begginer.
Hey I just stumbled across this. I found this ver insightful and my AI works and more. However the isse I am having is getting my characters to Steers around corners and not the zig-zag effect. Any pointers.
You ActionScript logic is very nice thanks.
that looks complicated!!!!!!!!!!!!!!!
How can I make it work with a lot of towers?
[...] Part 2 [...]
I’m making a similar game for a class of mine and I was wondering if you had any tips to make it simple but still work nicely…
Hey i am trying to make a TD game like this for a project but am confused please can you help me?
wat program to make one of these?
come on schools started again and you still havnt updated this tut lol its my fav so i would really like a better turret ai or a link to a site with a good script for it im kinda stuck right now
I’ve been using this instead of the ‘hitTest’ of the bullet
if (bullet._x this._x-10 && bullet._y > this._y-10 && bullet._y < this._y+10){
firing = false;
bullet.removeMovieClip();
this.removeMovieClip();
}
so it makes it somewhat easier for the tower to actually hit a monster :P
hey what program do u use you didnt say that…
how do i play it when i opened it with macromedia flash pro?
@Smurf
Your code doesn’t work
Hi,
I can’t find the software to use this code.
PLEASE HELP
ok……
what program do u use to make a td game like this???
You guys asking what program to use, you are all morons.
“Make a –>FLASHFLASH<– Element Tower Defence – Part 2″
The clue is there, in the NAME!
learn to read before posting retarded comments.
Jees.
Nice tut man, can’t wait for part three! ;)
Just to let people know I’ve been build a tutorial series like this off my blog – I will encompass all the items covered here and then some. Stop on by!
http://walterreid.com
The link to the flash is off my front page or can be searched with the keywords “How to build a tower defense flash game”
i don’t now how to make a game can you tach me how to make a game
When is part 3 comming out?
uughhh need part 3…
I modified the code to place multiple towers and to allow the towers to fire on a delay counter instead of waiting until the bullet is removed to fire another. I have used the same variables names with the suffix “Array”. Now, I am stuck on the direction. I can’t find a way to set the direction so that different bullets aren’t all updated to travel at the same angle. I tried using the direction as it’s own array, but can’t set the ID in the bullet.OnEnterFrame function.
Actually in most of my current projects, I have that problem. How do I have an onEnterFrame function recognize a value only intended for one instance of that function. Can anyone please help me out? I would really appreciate it. I am exhausted from all the Tutorials and forums in hunt of this.
(sorry for the long post, now lets hope everything paste correctly) here’s the code
for (i=0;i<towerArray.length;i++)
{
firingArray[i] -= 1;
if (placedArray[i])
{
distance_from_turret_x = towerArray[i]._x-this._x;
distance_from_turret_y = towerArray[i]._y-this._y;
if ((Math.sqrt(distance_from_turret_x*distance_from_turret_x+distance_from_turret_y*distance_from_turret_y)<base_range/2) and (firingArray[i] <= 0))
{
firingArray[i] = firingDelay;
bullet = attachMovie(“bullet”, “bullet”+_root.getNextHighestDepth(), _root.getNextHighestDepth(), {_x:towerArray[i]._x, _y:towerArray[i]._y});
bulletArray.push(bullet);
bullet.dir = Math.atan2(distance_from_turret_y, distance_from_turret_x);//here(?)
}
}
bullet.onEnterFrame = function()
{
this._x -= 1*Math.cos(bullet.dir);//here(?)
this._y -= 1*Math.sin(bullet.dir);//here(?)
if ((this._x<0) or (this._y400) or (this._x>500))
{
this.removeMovieClip();
}
};
I fixed the above code by changing bullet.dir to this.dir but it only works when the bullet.onEnterFrame is embedded in the main onEnterFrame function. Any help?
how do u do this i cant get to the part where u make a road or minions??????????????????
thx a lot man what do you need do download and where from
a new TD and i hope you like it
What language is used for this TD game?
PART 3!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Another person begging for a part three… Also, if you could clear up a couple things. The range and base both line up the top left corner instead of the middle, how do I fix this? And for the cant_build, do you draw that out in flash or use an imported image of the path? I tried importing the path I was using but it comes out as a rectangle. Is there a way to set it to ignore the transparent parts or do I just have to draw it out in Flash? (I’m using .png files for graphics.)
Last question for now… Know of any books or websites that could give me a good introduction to actionscript? I’m already reading everything I can get my hands on, but it’s difficult to find references for beginners, and a lot of the basics are geared towards presentations or web design rather than games.
[...] I was playing around with Emanuele Feronato’s Tower defence prototype, which I found at his great site here [...]
Hi guys,
I have been waiting for part 3 for a long time too, but anyways I decided to play around with the source file Emanuele’s given here and came up with an almost complete prototype.
You can check it out here
http://www.itsnags.com/archives/240
It features multiple towers
Multiple waves of monsters
Monsters getting tougher on each wave
I need some more time to complete it and then I’ll be posting a tutorial.
Thanks to Emanuele for his wonderful post!
I’ve tried to let the bullet (an arrow) rotate to the minion.
But I couldn’t figure out how.
please help
Please make a part 3 so people like me (really beginner at flash) can finish the game. Some good ideas would be money system, upgradable towers, selling towers, different types of towers.
Thanks for the Tutorial!
I though i’d let everyone know that i know a better tutorial for this. Just search for
Walter Reid Tower Defence tutorial.
This is amazing. I am a tower defence creator but I only do it on paper and on Microsoft PowerPoint. there is 1 question.
What progran do you use?
Thanks.
And come on my website!
Http//:www.freewebs.com/Clubarv/
Hey also I want a part 3!
Please
Ap
Apensea – Adobe Flash. Assuming that you aren’t a teacher or a student, it would cost about $750 to buy the program.
Hey im just wondering (im kinda new to this) would Adobe Flash Player 10 be a reliable program to build Tower Defense games? Thanks
suuup freakin sweet tuts but like wat program you use?? i kno it says Flash but can you email me a more specific thing? and maybe give me a link to where i can get it? plzzzzzz
my email is Coolmaster55@yahoo.com
i need help. i downloaded this thing and now i havent the slightest clue wat to do now. i dont even have a screen or anything just the thing is downloaded. this thing really doesnt explain that much at all, like wat to do RIGHT after it just assumes u know.
Just wanan say this is a great site, me and my friends are forming a programming team and Walter Reid, your site is very helpfu!
So I have this idea, in order to make the firing rate quicker, we need bullets fast, no? so how about a command that says “hey, you, bullet, yeah you, when you go outside the firing range, leav the clip so we can sand another one of our boys!” unfortunately I don’t know how to do this, but I have a theory:
if(_root.bullet. hitTest_range = false, remove clip)
sometihng like that….
Also, for bullet speed, stick this in somewhere
bullet.speed = 0;
tweak these a bit and you may come up with sometihng good, if you really needed this and it helped you, I’m happy to help!
Can you please finsh the tutorial and show us how to make weapons and make them fire.
This is wonderful i am loving it.
oigan yo tengo el flash 5 y puedo crear juegos pero me salen mal los de plataforma y tower defence
Wow, cool tutorial :D
Great tutorial but a simple game. I would like to see something more advanced :)
i want to make so bad thanks but this is my moms work computer so i cant download stuff thanks any way