Make a Flash game like Flash Element Tower Defense - Part 2

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:

Tower Defense

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:

ACTIONSCRIPT:
  1. base_range = 300;
  2. can_be_placed = false;
  3. placed = false;
  4. attachMovie("path", "path", _root.getNextHighestDepth());
  5. attachMovie("cant_build", "cant_build", _root.getNextHighestDepth());
  6. attachMovie("range", "range", _root.getNextHighestDepth(), {_width:base_range, _height:base_range});
  7. attachMovie("base", "base", _root.getNextHighestDepth());
  8. waypoint_x = new Array(40, 140, 140, 220, 220, 80, 80, 340, 340, 420, 420);
  9. waypoint_y = new Array(140, 140, 60, 60, 240, 240, 320, 320, 100, 100, -20);
  10. delay = 25;
  11. new_monster = 0;
  12. monsters_placed = 0;
  13. onEnterFrame = function () {
  14.     if (monsters_placed<25) {
  15.         new_monster++;
  16.     }
  17.     if (new_monster == delay) {
  18.         monsters_placed++;
  19.         new_monster = 0;
  20.         min = attachMovie("minion", "minion"+_root.getNextHighestDepth(), _root.getNextHighestDepth(), {_x:40, _y:-20});
  21.         min.point_to_reach = 0;
  22.         min.speed = 1;
  23.         min.onEnterFrame = function() {
  24.             dist_x = waypoint_x[this.point_to_reach]-this._x;
  25.             dist_y = waypoint_y[this.point_to_reach]-this._y;
  26.             if ((Math.abs(dist_x)+Math.abs(dist_y))<1) {
  27.                 this.point_to_reach++;
  28.             }
  29.             angle = Math.atan2(dist_y, dist_x);
  30.             this._x = this._x+this.speed*Math.cos(angle);
  31.             this._y = this._y+this.speed*Math.sin(angle);
  32.             this._rotation = angle/Math.PI*180-90;
  33.         };
  34.     }
  35. };
  36. base.onEnterFrame = function() {
  37.     if (!placed) {
  38.         this._x = _root._xmouse;
  39.         this._y = _root._ymouse;
  40.         _root.range._alpha = 100;
  41.         can_be_placed = true;
  42.         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)) {
  43.             _root.range._alpha = 0;
  44.             can_be_placed = false;
  45.         }
  46.     }
  47. };
  48. range.onEnterFrame = function() {
  49.     if (!placed) {
  50.         this._x = _root._xmouse;
  51.         this._y = _root._ymouse;
  52.     }
  53. };
  54. onMouseDown = function () {
  55.     if (can_be_placed) {
  56.         placed = true;
  57.     }
  58. };

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

ACTIONSCRIPT:
  1. base_range = 300;
  2. can_be_placed = false;
  3. placed = false;
  4. firing = false;
  5. attachMovie("path", "path", _root.getNextHighestDepth());
  6. attachMovie("cant_build", "cant_build", _root.getNextHighestDepth());
  7. attachMovie("range", "range", _root.getNextHighestDepth(), {_width:base_range, _height:base_range});
  8. attachMovie("base", "base", _root.getNextHighestDepth());
  9. waypoint_x = new Array(40, 140, 140, 220, 220, 80, 80, 340, 340, 420, 420);
  10. waypoint_y = new Array(140, 140, 60, 60, 240, 240, 320, 320, 100, 100, -20);
  11. delay = 25;
  12. new_monster = 0;
  13. monsters_placed = 0;
  14. onEnterFrame = function () {
  15.     if (monsters_placed<25) {
  16.         new_monster++;
  17.     }
  18.     if (new_monster == delay) {
  19.         monsters_placed++;
  20.         new_monster = 0;
  21.         min = attachMovie("minion", "minion"+_root.getNextHighestDepth(), _root.getNextHighestDepth(), {_x:40, _y:-20});
  22.         min.point_to_reach = 0;
  23.         min.speed = 1;
  24.         min.onEnterFrame = function() {
  25.             dist_x = waypoint_x[this.point_to_reach]-this._x;
  26.             dist_y = waypoint_y[this.point_to_reach]-this._y;
  27.             if ((Math.abs(dist_x)+Math.abs(dist_y))<1) {
  28.                 this.point_to_reach++;
  29.             }
  30.             angle = Math.atan2(dist_y, dist_x);
  31.             this._x = this._x+this.speed*Math.cos(angle);
  32.             this._y = this._y+this.speed*Math.sin(angle);
  33.             this._rotation = angle/Math.PI*180-90;
  34.             if (bullet.hitTest(this._x, this._y, true)) {
  35.                 firing = false;
  36.                 bullet.removeMovieClip();
  37.                 this.removeMovieClip();
  38.             }
  39.             if (placed) {
  40.                 distance_from_turret_x = base._x-this._x;
  41.                 distance_from_turret_y = base._y-this._y;
  42.                 if ((Math.sqrt(distance_from_turret_x*distance_from_turret_x+distance_from_turret_y*distance_from_turret_y)<base_range/2) and (!firing)) {
  43.                     firing = true;
  44.                     bullet = attachMovie("bullet", "bullet"+_root.getNextHighestDepth(), _root.getNextHighestDepth(), {_x:base._x, _y:base._y});
  45.                     bullet.dir = Math.atan2(distance_from_turret_y, distance_from_turret_x);
  46.                     bullet.onEnterFrame = function() {
  47.                         this._x -= 3*Math.cos(bullet.dir);
  48.                         this._y -= 3*Math.sin(bullet.dir);
  49.                         if ((this._x<0) or (this._y<0) or (this._y>400) or (this._x>500)) {
  50.                             firing = false;
  51.                             this.removeMovieClip();
  52.                         }
  53.                     };
  54.                 }
  55.             }
  56.         };
  57.     }
  58. };
  59. base.onEnterFrame = function() {
  60.     if (!placed) {
  61.         this._x = _root._xmouse;
  62.         this._y = _root._ymouse;
  63.         _root.range._alpha = 100;
  64.         can_be_placed = true;
  65.         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)) {
  66.             _root.range._alpha = 0;
  67.             can_be_placed = false;
  68.         }
  69.     }
  70. };
  71. range.onEnterFrame = function() {
  72.     if (!placed) {
  73.         this._x = _root._xmouse;
  74.         this._y = _root._ymouse;
  75.     }
  76. };
  77. onMouseDown = function () {
  78.     if (can_be_placed) {
  79.         placed = true;
  80.     }
  81. };

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.

Improve the blog rating this post
Tell me what do you think about this post. I'll write better and better entries.
1 Star2 Stars3 Stars4 Stars5 Stars (26 votes, average: 4.58 out of 5)
Loading ... Loading ...

» Flash Templates provided by Template Monster are pre-made web design products developed using Flash technology.
They can be easily customized to meet the unique requirements of your project.

128 Responses to “Make a Flash game like Flash Element Tower Defense - Part 2”

  1. PLEASE HELP on November 6th, 2007 11:37 pm

    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();
    }
    }
    }

  2. Joshua threlfall on November 7th, 2007 12:07 am

    for some reason when i try to place turret in above movies it only lets me place it in cant build area.

  3. Matt on November 7th, 2007 4:09 am

    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?

  4. Emanuele Feronato on November 7th, 2007 11:28 am

    I quit sleeping a year ago

  5. shiv1411 on November 7th, 2007 2:15 pm

    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?

  6. shiv1411 on November 7th, 2007 2:21 pm

    hi Emanuele,
    Please make the next part of the claustrophobic SURVIVAL HORROR tut.

  7. Frederik J on November 7th, 2007 3:41 pm

    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

  8. David on November 7th, 2007 6:37 pm

    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”

  9. Frederik J on November 7th, 2007 7:56 pm

    David, thats not Emanuele who writes it, its GameSheep!
    /Frederik J

  10. PLEASE HELP on November 7th, 2007 10:21 pm

    nvrr mind i fixed it =)

  11. conor on November 8th, 2007 10:09 pm

    errmmm love this tut but i got a problem…

    how do ya post in user controbutions??

  12. conor on November 8th, 2007 10:28 pm

    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

  13. Emanuele Feronato on November 9th, 2007 3:45 pm

    You can send your works to info@emanueleferonato.com

  14. - on November 12th, 2007 1:26 pm

    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

  15. jabs on November 19th, 2007 3:15 am

    Nice tut. Reminded me for a few things I need to remember to do when making mine.

  16. Tosho on November 20th, 2007 11:02 pm

    Huge thanks for the tutorial!

    Been looking for something like this for along time. Can’t wait till it is finished!

  17. Thomas on November 25th, 2007 5:14 am

    “powered by coffee”, ay?

  18. Something on December 2nd, 2007 3:53 am

    Mine never shoots! plz help

  19. Bluy on December 2nd, 2007 11:34 pm

    ok how do i run the fla filess?

  20. Willem on December 5th, 2007 7:11 pm

    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!

  21. juan on December 8th, 2007 4:06 pm

    What do you need in order to make td’s of your own??? and is it free??

  22. juan on December 8th, 2007 4:06 pm

    What do you need in order to make td’s of your own??? and is it free??

  23. LordCrazyKing on December 8th, 2007 6:26 pm

    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 :)

  24. MJGB on December 11th, 2007 6:36 pm

    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.

  25. Jim on December 14th, 2007 4:55 am

    What is actionscript and how do i get to it

  26. Dakota on December 15th, 2007 8:36 am

    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…

  27. Padfoot02 on December 15th, 2007 5:25 pm

    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.)

  28. Padfoot02 on December 15th, 2007 5:28 pm

    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.

  29. 007 on December 15th, 2007 9:35 pm

    Man, real awesome tute, waiting for the final version..like in which you’ll cover the Fire rate and a much better AI

    Thanks

  30. luke on December 19th, 2007 5:32 pm

    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.

  31. Mark on December 21st, 2007 9:59 pm

    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.

  32. alderman on December 24th, 2007 9:27 pm

    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

  33. Joe on December 30th, 2007 4:42 pm

    Hi, can anyone tell me how to start making a tower defense game?
    i’d really appreciate it, thx

  34. Frederik J on December 30th, 2007 6:28 pm

    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.

  35. Joe on December 30th, 2007 10:08 pm

    I already had flash, how do i open it and start making the game?

  36. Frederik J on December 30th, 2007 10:10 pm

    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..

  37. erik on January 1st, 2008 4:24 am

    will emanuelle launch a third part? cause i dont have the knowledge to develop the rest of the game myself

  38. Kenneth on January 1st, 2008 10:49 am

    This is a great tutorial ! Thanks

  39. TheInfinity on January 2nd, 2008 8:43 pm

    i can’t open the sources =( It says unexpected file format….Anyone Help?

  40. kasiaijuz on January 5th, 2008 10:19 pm

    yeah,
    i’ve got movie clips and code into actionscript window but how to make it now to work?
    help us!

  41. TheInfinity on January 5th, 2008 10:29 pm

    i built up to this point but when i try it on .swf the minions disappear. Any ideas?

  42. Antony on January 6th, 2008 8:00 pm

    Why, when the speed is adjusted, do the minions flicker and stop in the corners?

  43. mikel on January 7th, 2008 7:12 am

    i have the same problem as you with the tower defence making. how do u fix it?

  44. Sach master on January 7th, 2008 5:33 pm

    I’m 8 :-)

  45. meee on January 10th, 2008 5:35 am

    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?

  46. Jamie on January 20th, 2008 4:35 pm

    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

  47. LUK on January 22nd, 2008 8:33 pm

    Please, release part 3 of this tutorial… It`s great tutorial!

  48. Danny Ocean on January 23rd, 2008 4:57 am

    i finished this doing what you said but, when i view it the minions never come. help!

  49. noob on January 23rd, 2008 7:40 pm

    i am very noob about making a game so where can i open this side where i can make a minion and pach

  50. Luiz Filipe on January 26th, 2008 10:29 am

    where is the end? part 3?

  51. david on January 27th, 2008 4:39 am

    i dont know how to do the lines it just shows it on my com

  52. david on January 27th, 2008 4:40 am

    click yes trust me

  53. lucas on January 30th, 2008 12:34 am

    i am very excited about making my very own tower
    defense.

  54. Jesse on January 30th, 2008 6:55 pm

    Nice tutorial two questions can you speed up the speed of the bullets and is there a 3rd part to this tutorial yet

  55. td on January 31st, 2008 5:08 am

    When are you going to finish?
    I really want to make a td game!

  56. td on January 31st, 2008 5:10 am

    why did i get modded?

  57. td on February 1st, 2008 10:49 am

    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?

  58. Ice_Hero on February 4th, 2008 9:19 pm

    I got a question where do i get Macromedia Flash
    and how much is it or is it free?

  59. Rc on February 5th, 2008 11:09 pm

    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

  60. W00T W00T on February 18th, 2008 4:47 pm

    omg i dont got this…

  61. Joar on February 20th, 2008 5:57 pm

    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.

  62. Andy on February 21st, 2008 12:38 am

    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?

  63. Cory on February 25th, 2008 1:35 am

    O.K. i need the program to make one of these please! Thank you!

  64. Draco18s on February 28th, 2008 9:33 am

    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.

  65. ... on March 1st, 2008 8:20 pm

    when are you going to make the third part?? i havent got the brains to make the rest :D

  66. stupid kid w/ dreams on March 5th, 2008 6:07 pm

    how the hell do you even test it? :’(

  67. Mike on March 5th, 2008 7:33 pm

    Great tut. When are you going to get part 3 out?

  68. Mike on March 5th, 2008 7:35 pm

    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?

  69. fgfgfdg on March 7th, 2008 10:48 pm

    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.

  70. ... on March 10th, 2008 9:11 pm

    PLZ MAKE A THIRD PLZ!!!!

  71. jared on March 12th, 2008 8:15 pm

    according to flash u have errors in lines 4 and 18 dude

  72. jared on March 12th, 2008 8:16 pm

    That was for Jamie the last one

  73. MasterMind on March 16th, 2008 2:17 pm

    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.

  74. Brandon on March 18th, 2008 1:38 am

    your joking about the non sleeping thing right???

  75. yoded on March 24th, 2008 12:49 pm

    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 …

  76. ryan on March 24th, 2008 6:59 pm

    how do i ga the games maker wats it called and where do i download it???

  77. Jaco208 on April 1st, 2008 5:51 am

    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”;
    }
    };

  78. Rather Cheesy on April 4th, 2008 8:54 pm

    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!

  79. Zync on April 8th, 2008 9:57 pm

    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…

  80. Chris on April 9th, 2008 12:50 am

    I’m trying to load the builder but cannot. Can you help???

  81. John on April 14th, 2008 3:19 am

    I would also like to know what program you used so I also can have fun making my own TD game.

  82. Cleverclogs on April 16th, 2008 9:54 am

    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 =)

  83. Scott on April 22nd, 2008 6:19 pm

    im so confused

  84. Zackorith on April 26th, 2008 9:48 pm

    how to make you lose lives if they get to middle!?

  85. help on April 29th, 2008 5:43 am

    what program do you use

  86. Eric on May 2nd, 2008 11:57 pm

    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!!

  87. armoured soul on May 7th, 2008 8:56 pm

    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.

  88. bud on May 13th, 2008 6:29 pm

    help plz not workin

  89. onlineflash on May 13th, 2008 7:37 pm

    i want the next part

  90. onlineflash on May 21st, 2008 10:02 pm

    whens the next one comming out?

  91. oliver_l1 on May 23rd, 2008 10:42 pm

    Wow! Really amazing. Please make a third part if possible.

  92. atrueguy4u on June 4th, 2008 5:52 pm

    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.

  93. infur on June 5th, 2008 4:25 pm

    please make a third part if possible.

  94. nathan & alex on June 7th, 2008 3:38 am

    I wish i could make a game as cool as urs

  95. atrueguy4u on June 9th, 2008 8:15 pm

    yes who ever made this definitely should make a part 3 but add lots more towers and enemies so it blows us away

  96. td on June 12th, 2008 1:30 am

    how do start making it

  97. td on June 12th, 2008 1:34 am

    how do start making it in what place

  98. markus on June 14th, 2008 10:24 pm

    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

  99. markus on June 14th, 2008 10:27 pm

    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 “/

  100. bl3h on June 17th, 2008 9:10 am

    markus teach me pls..

  101. random on June 18th, 2008 10:13 am

    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

  102. temp on June 21st, 2008 5:10 am

    hey go play new game of mine (way cool)

  103. dylmani555 on June 21st, 2008 3:55 pm

    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

  104. marre2795 on June 21st, 2008 11:05 pm

    I can’t open it because it is an unexpected file format

  105. Gamerz on June 24th, 2008 7:12 pm

    Can you get a grid for Macromedia Flash MX? And my syntax doesnt work very well… Tips? Comments?

  106. Atarsh on June 25th, 2008 9:43 pm

    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.

  107. kid programmer on June 27th, 2008 4:02 am

    did you really quit sleeping?

  108. seth on June 27th, 2008 9:01 pm

    i don’t know how to anything.Do you know how?

  109. seth on June 27th, 2008 9:03 pm

    I have NO idea.

  110. kid programmer on June 28th, 2008 9:52 pm

    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.

  111. Ben on June 29th, 2008 8:36 am

    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

  112. name on July 12th, 2008 4:35 am

    i need a free(not free so many-day trial)action script program for windows xp professional.

  113. ok on July 28th, 2008 3:52 pm

    ok, but how do you do this with macromedia flash 8? i am a total begginer.

  114. iK on August 8th, 2008 9:11 pm

    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.

  115. anonamus responder on August 11th, 2008 3:38 pm

    that looks complicated!!!!!!!!!!!!!!!

  116. Shedokan on August 20th, 2008 11:34 pm

    How can I make it work with a lot of towers?

  117. Alexius Lengele on September 1st, 2008 12:24 am

    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…

  118. Vishal on September 1st, 2008 6:26 pm

    Hey i am trying to make a TD game like this for a project but am confused please can you help me?

  119. cody on September 9th, 2008 12:52 am

    wat program to make one of these?

  120. Josh on September 9th, 2008 10:45 pm

    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

  121. Smurf on September 15th, 2008 7:10 pm

    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

  122. emil on October 8th, 2008 7:04 pm

    hey what program do u use you didnt say that…

  123. emil on October 9th, 2008 4:04 pm

    how do i play it when i opened it with macromedia flash pro?

Leave a Reply




Trackbacks

  1. Make a Flash game like Flash Element Tower Defense - Part 1 : Emanuele Feronato - italian geek and PROgrammer on November 6th, 2007 9:37 pm

    [...] 11th update: part 2 [...]

  2. Hoi! Koffie? » Tower “Addiction” Defense on November 25th, 2007 2:31 pm

    [...] Make a Flash Game Like Flash Element Tower Defense - Part 2 [...]

  3. L’ultima linea di difesa /4 - Faccio Cose Vedo Gente on February 27th, 2008 12:12 am

    [...] un gioco di difesa è facile: bastano alcune routine per generare i nemici (ma se ne può fare anche a meno agendo direttamente [...]

  4. digitalt skapande » Tower Defence on April 21st, 2008 2:49 pm
  5. Adobe Flash CS3- AS3 and AS2 game tutorials roundup | Lemlinh.com on August 28th, 2008 1:57 am

    [...] Part 2 [...]