Build 10 games and learn game development along the way in this fast paced game development course

Get the source code of 12 commercial games, loaded 50+ million times, and learn the secrets of game design

Learn how to make a successful Flash game from a real world example. Fully commented source code

Create realistic Flash physics games from scratch with advanced features, from Angry Birds to Crush the Castle

Create a flash artillery game – step 2

Welcome to the 2nd part of this tutorial. I recommend you to read the 1st part if you haven’t done it yet and we are ready to start.

Fixing bullets amount

In the last example, when you shot a bullet, it “lives” forever. I mean, once the bullet movieclip is on the stage, there isn’t any routine to check if the bullet should exist or not.

Try to imagine thousands of bullets that continue falling down at increasing speed. Obviously, if you fire a large amount of bullets, the movieclip starts lagging.

We need to remove bullets when they are off the stage.

Lines 42-44: Check if the bullet if out of visible left, right and bottom area (I did not include the top because a bullet is supposed to fall down…) and if true, removes the bullet movieclip.

In this case, the only movieclips active are those visible on stage plus the ones falling from the upper edge of the stage.

Maximum bullets at the same time

Now we need to put a limit to the maximum bullets fired at the same time. It would be too easy if we let the player fire a large amount of bullets. So we are going to put a limit.

Line 3: Variable designed to count the bullets currently on stage

Line 4: Maximum firepower allowed. Changing this value you will change the maximum bullets allowed to be shot at the same time. Changing this value will affect gameplay.

Line 34: When the player wants to fire, I check if the bullets on stage are minor than the maximum bullets allowrd

Line 35: if true, increases the fired variable

Line 48: decreases the fired variable when a bullet is removed. If you look at line 46, you will see the control is performed only on bullets leaving the stage to the bottom. This will always happen even for bullets thare are leaving to left or right, since when they fall, sooner or later they will leave to the bottom. This will make the game a little bit harder, because if you fire a bullet out to the right, you will have to wait for it to leave the stage to the bottom to have the bullet reloaded.

Now it’s time to introduce the other great star in an artillery game

The ground

I created a new movieclip linkaged as ground that represents… well… the ground.

Lines 6-7: Tank and ground are placed on the stage as if the tank were on the ground (of course…)

Line 47: the test to remove the bullet is extended to its collision with the ground. At the moment, I do not care about explosions or accurate hit test

The enemy

In an artillery game, you are supposed to shot to an enemy… so I linkaged another movieclip as enemy… it should be that red square (you know, red squares are evil).

Line 5: call to a place_enemy function that will… uh… something like placing an enemy…

Line 55: here starts the function place_enemy

Line 56: Placing an enemy in the bottom left of the stage

Line 57: Init enemy yspeed at zero. It’s obvious that I won’t move the enemy with a motion guide but with pure actionscript, just in case tomorrow I would like to change the terrain. I am using some of the basics explained in the tutorial called Create a flash draw game like Line Rider or others – part 5 so give it a look if you haven’t done it yet.

Line 58: Function to be executed every time the enemy enters in a frame.

Lines 59-69: As said, these are lines already explained in the the tutorial called Create a flash draw game like Line Rider or others – part 5

Lines 70-73: When the enemy reaches the right border, I remove it and call the function again, creating another enemy.

And we have our walking enemy… want to hurt it?

The killable enemy

In this tutorial I won’t cover energy, health and so on, but I will during next tuts. At the moment, when a bullet hits an enemy, he/it dies and repops in the starting point.

Lines 52-57: if a bullet hits THE enemy (I will explain that bold “the” later), I remove both the bullet (decreasing the fired variable) and the enemy and place another enemy.

It’s very simple, but I wrote that “the” because I know that A bullet on the stage can hit only THE only enemy on the stage.

When we’ll have lots of bullet that can hit lots of targets, it gets a bit more complicated.

That’s what I’ll cover during next step, coming soon.

Meanwhile, download the sources and give me feedback.

Rate this post: 1 Star2 Stars3 Stars4 Stars5 Stars (103 votes, average: 4.69 out of 5)
Learn how to make a successful commercial Flash game from a real world example: get the fully commented source code of Globez, a Flash game played millions of times which generated a four figure income. Limited copies available.

Get it now
Be my fan on Facebook and follow me on Twitter! Exclusive content for my Facebook fans and Twitter followers

This post has 55 comments

  1. Create a flash artillery game - step 1 at Emanuele Feronato

    on May 25, 2007 at 5:19 pm

    […] May 25th update: 2nd part released […]

  2. Callum

    on May 25, 2007 at 8:22 pm

    Wow, thats pretty good. Im making a Game where one of my teachers is throwing geography books at you and you have to shoot the geog books and at the end kill him xD

    Im using 2 of your tutorials and when Im finished ill show you the final thing xD

  3. And Mar

    on May 25, 2007 at 11:39 pm

    Hey I made a game using some of your tutes. Its not very good but its my first.

  4. Eblup

    on May 26, 2007 at 2:20 am

    veary good well don iam kinda con fused on how to wright action script in frames instead of movie clips.

  5. And Mar

    on May 27, 2007 at 4:45 am

    To write actionscript in frames, just click on the keyframe and open the actions panel.

  6. David

    on May 29, 2007 at 9:05 am

    love yout tuts i was wondering how could you instead of using mouse click to fire you press space bar? plz someone tell me how thx


  7. person

    on June 5, 2007 at 5:40 pm

    I can only shoot one bullet at a time and when I shoot the enemy suddenly disappears, does anyone know how to fix this? thanks

  8. Brandon

    on June 8, 2007 at 9:04 pm

    how do you add more enemys????

  9. sammo

    on June 20, 2007 at 5:46 am

    Hey great tutes it’s really hard to find good ones with good English and not too much detail. Look forward to more.

  10. bipin chander

    on June 22, 2007 at 11:01 am

    help me to learn to make flash game

  11. X-99

    on June 23, 2007 at 11:14 pm

    I’m making a game at the moment,
    so when your player touches the mighty and powerfull enemy
    you would go back to frame 1.
    Please help ME!!!!!!!!!!

  12. Tony

    on June 28, 2007 at 10:04 am

    [In the player movieclip]


  13. Marnix Pop

    on June 28, 2007 at 12:49 pm

    Nice tutorial you go there! Everything works, but it’s pretty hard to make the turret itself work correctly. Could you maybe make a defense game tutorial? Lots of people are asking for one, and I bet you can make one. ^^,

  14. Andy

    on August 14, 2007 at 9:42 pm

    i couldn’t get the rotation limiter to work with a script with similar to this.

    Please help!

  15. jummers

    on September 8, 2007 at 3:01 pm

    how could i do it so the cannon and the tank moved with the arrow keys?

  16. Ozzy

    on September 15, 2007 at 8:22 pm

    please help me,
    i’m making a game like this, and when the cannonball hits the enemy the enemy explodes.

    the actionscript:
    if (enemy.hitTest(this._x, this._y, true)) {
    _root.scoretext.text = deaths+ “Deaths!”;

    but the game still acts like the enemy is on stage, how do i remove him after the frames are played??

  17. zee

    on November 7, 2007 at 3:03 pm

    Great tut very helpfull i added a score variable wich worked fine
    then i drew a death sequence in enemy and i wrote this code in the hit test


    if (enemy.hitTest(this._x, this._y, true)) {
    score ++; this.removeMovieClip();

  18. Ruby

    on December 31, 2007 at 5:30 pm

    Heya, I’m making a shooter game that allows the player to shoot 10 times. If he shot 10 times I want the game to end. I tried it with your tut but it did not work. In your tut you can have 3 shots at the stage max. But when they are gone you can shoot another 3 times.

    So my question is:
    How can flash make my player shoot 10 times max., with only one bullet on screen at the time?

    Thank you so much,

  19. Aaron

    on April 3, 2008 at 5:57 am

    Hey, I know you probably get a lot of emails, and messages, but. I’ve looked all over and can’t figure out a way to do what I’m trying to do. I’m making a side scrolling shooter, where the character is in the center of the screen and as you move around you can traverse a map. I’m going to figure out all that later, but for now I need to find a way to have it so that my character’s arm and selected gun stay attached to the character but point toward the cursor location. I’ve tried dozens of methods and nothing works right. Thanks in advance.

  20. Maniac

    on May 10, 2008 at 6:57 pm

    =/ How do you combine the bouncing with getting rid of bullets that aren’t on the screen? No matter what I do to try and combine the two, I get an error.

  21. Arch Games Webmasters - Arcade Webmasters » Game Developer tutorial List

    on May 13, 2008 at 7:32 pm

    […] […]

  22. koala

    on June 2, 2008 at 6:36 pm

    @ Ruby
    make a damned counter.

  23. 90301

    on July 17, 2008 at 11:27 pm

    you did a.

    do this.
    _root.blank.hitTest(_x,_y,true) {

  24. fahad mohammad

    on October 25, 2008 at 7:04 pm

    hi, please help.
    i added a dynamic score box edited the ground everything added clouds and all.
    and it worked. but when i added the kongregate highscore api ,everything went wrong, now the score doesnt work it jus says _level0 or somtimes NaN please help.

  25. Sam

    on January 19, 2009 at 6:35 pm

    This works well! But I see that the hit test in the cannon ball relies on there being one definite enemy instance with a known name.

    How do you have it so there can be numerous enemies AND numerous cannonballs – where any enemy can collide with any cannonball?

    Would you need to create an array on which you place each instance – then loop through it?

  26. Cal

    on January 26, 2009 at 3:38 pm

    when will there be a second step?

  27. Eliott

    on February 24, 2009 at 8:00 pm

    Found the code on another website…

  28. vel

    on March 4, 2009 at 9:00 am

    thank you

  29. Como criar jogos online (em flash)?

    on April 11, 2009 at 10:20 pm

    […] 11. Jogo de artilharia […]

  30. Create a flash artillery game – step 2 | Tutorial Collection

    on July 1, 2009 at 3:24 am

    […] View Tutorial No Comment var addthis_pub="izwan00"; BOOKMARK This entry was posted on Wednesday, July 1st, 2009 at 6:54 am and is filed under Adobe Flash Tutorials. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site. […]

  31. Paanchow

    on July 2, 2009 at 5:01 pm

    por lo que entendi me gusto muchho el tutorial. lastima que no lo puedo completa por que no entiendo mucho inglés.

  32. Saberking13

    on July 3, 2009 at 7:07 pm

    when will the next one come out?

  33. Sam

    on July 5, 2009 at 9:09 pm

    i love your tutorials!
    i was wondering if you know a tutorial for a game like this?:

    keep it up!

  34. NewbieProgrammer

    on August 4, 2009 at 4:26 pm

    Hey I have a (newbie) Question. What Program Do you use because I have “Macromedia Flash MX 2004″
    And I Cannot find where to Add any Script. And I would be VERY interested in Game Programming But I do not no What Program to use, There is so Many of them. Thanks For your Help


  35. NewbieProgrammer

    on August 4, 2009 at 6:28 pm

    Never mine that post i figured out how to use it

  36. NewbieProgrammer

    on August 4, 2009 at 6:29 pm

    I need help tho when i test the cannon does not change angle and the cannon ball always goes left AND It goes for 50 Pixels the dissapears and i cannot shoot more than one the first one dissapears,

  37. chris

    on September 18, 2009 at 12:37 pm

    hey plz help me, i am making a similar kind of game and i really need help on making more enemies that come out of different directions at different speeds :S

    pls tell me asap when part 3 is ready or email the instuctions

    all help is greatly appreciated :D

  38. ofdhipfou

    on September 21, 2009 at 12:27 am

    man… you explain so hard. i hated this shit game , you such a bitch

  39. Poon Dawg

    on November 17, 2009 at 4:48 pm

    have u finished step 3 yet? and if so, where can i find it?

  40. Bc Nobel

    on February 12, 2010 at 1:00 am

    First off, I think you’re a great tutor, and these tutorials you write are real helpful for someone who doesn’t know sh*t about action scripting. I learned a great deal from a lot of your tutorials.

    Now to the point, I’m currently working on a turn based MMO artillery game. I made the server in Visual Basic 6.0, and the client, of course is made in flash..

    It’s all working great, except for one thing missing, and that thing is Voxtel-Mapping (FYI: voxtel mapping is the technology used to create the holes in the ground where the bomb exploded). I Know it’s possible, because I’ve seen it, but I can’t seem to get it to work, because I just don’t know enough about bitmapping in flash.

    Is there any way that you might look into that for me (I hope so)? Might be a fun project for yourself to work on too..

    If you decide to look into it, pliz send me an email at


  41. Tom da bomb

    on March 4, 2010 at 12:45 am

    I hate this tutorial because when I typed in the code it had many errors!

  42. Devon

    on March 15, 2010 at 4:47 am

    I would love to see the next one, please come out with it ASAP!

  43. ilikepie

    on May 23, 2010 at 1:29 am

    how do you get ocjects to move, objects & backrounds

  44. KING

    on May 27, 2010 at 1:39 pm

    If I join HP , you will teaching me?

  45. Some Guy

    on June 28, 2010 at 8:52 pm

    How do you test the flash game? I’ve been wondering if mine is working and I can’t seem to be able to test it out.

  46. Me

    on August 26, 2010 at 6:05 am

    I was wondering if it was possible to change lines 52-57 so that the object terminates when clicked.

  47. arik

    on December 7, 2010 at 6:19 pm

    hey man how do i make more enemies in different locations? so its sort of like an all out attack on the tank? thanks man great tut

  48. someone

    on December 29, 2010 at 12:41 am

    is there a 3rd part ? cool tut.

  49. eduardo lopez

    on May 30, 2011 at 1:24 am

    que programa tengo que tener para hacer uno de estos?

  50. KUSH

    on June 28, 2011 at 5:46 pm


  51. Joey

    on October 13, 2011 at 8:12 pm

    hello. i have followed this tut and i am haveing troble with killing the enemy.
    all of my symbols the same as yours(and there instince names) but the code doesnt work for me. i have
    if (enemy.hitTest(this._x, this._y, true)) {

    and i have been trying to figure it out for a hour. it seems to me like it is ignoring the hitTest. some one please help

  52. Flash Game Tutorial Roundup Part 2 | VapvaruN | Wp Experts

    on November 18, 2011 at 8:35 am

    […] Make a flash artillery game – step 2 […]

  53. Flash Game Tutorials.. « cneriportfolio

    on April 17, 2012 at 7:21 pm

    […] is an  artillery game it shows you how to fix the bullet amount what area it is and the Maximum bullets at the same time, […]

  54. guerra

    on August 18, 2012 at 5:26 pm

    es un juego matando cuadrito

  55. Nick

    on October 25, 2012 at 5:29 am

    Btw i really loved your efforts you put to write this useful tutorial, Can you also give some knowledge about strategy games development on flash As2.0 or AS3, AS3 will be better and i will be very thankful to you for that.

Thank you for the download!!

I hope you will find it useful and make something interesting out of it

To keep up to date with the blog, why don't you like my Facebook page and follow me on Twitter?

Want to learn more? Don't miss this:

Learn how to make a successful commercial Flash game from a real world example: get the fully commented source code of Globez, a Flash game played millions of times which generated a four figure income. Limited copies available.

Get it now