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 1

May 25th update: 2nd part released
October 29th update: modification with a bounce effect developed by Massimo M.

Here we are with the beginning of a new tutorial. We are going to create a flash artillery game. Something like Worms. Or similar.
Well… the first thing we need in an artillery game is…

The crosshair

I created a movieclip linkaged as “crosshair”, then on the first frame of the main scene entered this actionscript:

Line 1: Hiding the mouse

Line 2: Attaching the movie “crosshair” instanced as “crosshair” at depth 1

Lines 3-5: Every time the crosshair is in the stage, its position is updated to _xmouse and _ymouse coordinates. This means you will move the crosshair with the mouse.

Looks simple… it will get (much) more complicated.

The second thing we need in an artillery game is…

The tank

The tank is the core of an artillery game. You will love your tank. Of course I love mine.

Of course, every tank has its cannon. A big cannon. Size matters.

I created a new movieclip linkaged as “tank” and inside this movieclip I created another one instanced as “cannon”. Look at the picture to understand how I placed the movieclips.

Tank

Then the actionscript is:

Line 3: places the cannon on the stage

Lines 9-10 determine the x and y distance between the crosshair and the tank

Lines 11-17 determine the angle with trigonometry. This concept is explained in the tutorial called Create a flash draw game like Line Rider or others – part 3.

Line 18 rotates the cannon according to the angle

Sometimes you may need to limit the cannon angle. It’s very simple do it this way:

Lines 18-23 limit the cannon angle between 20 and 160 degrees. Limiting the cannon angle may affect gameplay, use it wisely.

Now it’s time to determine the firepower. In this game, we are going to determine it by the distance from the crosshair to the cannon.

Lines 24-27 calculate the fire power using the pythagorean theorem (there is no need to publish this example as a .swf because visually it does not change anything).

Now it’s time to make our tank do what every tank sould do:

FIRE !!

The first thing to do when you fire a bullet is determine the exit point of the bullet. I mean: the cannon is on a rotating turret, so I have to place the bullet right next to the end of the cannon to give the player the feeling he really fired that bullet.

So I created a new movieclip and linkaged it as “cannonball”

Then I added a new function to the script

Line 30: Beginning of the actions to be executed when the player press the fire… pardon, the mouse button.

Lines 32-33: Determining the exit point of the cannonball using with trigonometry. This concept too is explained in the tutorial called Create a flash draw game like Line Rider or others – part 3. The “48″ value you can see it given by the cannon lenght (40) plus the ball radius (5) plus 3 “safety pixels” since sine and cosine functions returns non-integer values.

Line 34: Attaching the movieclip with the cannon ball. Notice the “3″: it’s the depth of the movieclip, and giving a fixed depth assure us to have only one cannon ball on the stage.

FIRE!!! (again)

Now that the cannonball has been released, it’s time to make it fly.

Line 34: This time I want more than one cannonball in the stage, so I call the attachMovie function giving the cannon ball the next highest depth available. I can do this using the getNextHighestDepth() function. The name of the movieclip is also affected by the next highest depth available.

Line 35: The dirx variable is the horizontal vector of the cannonball, according to its firing angle and the firepower.

Line 36: Same thing for diry, the vertical vector

Line 37: Every time the cannonball enters in a frame (every frame)…

Lines 38-39: … its _x and _y position changes according to dirx and diry. That “50″ is simply a divider to make the ball not to go too fast.

What happens to a cannonball once in the air? It starts falling due to…

Gravity

In an arcade game initially gravity is not calculated in a strict physics formula, so we are going to simulate the gravity in this way:

Line 2: A variable called gravity is set to 2

Line 39: The gravity value is added to the vertical vector at every frame.

Final result is quite reasonable.

At the moment the tut stops here, download all source codes, give me feedback, change a line or two and publish them as your own game on various game portals :)

Rate this post: 1 Star2 Stars3 Stars4 Stars5 Stars (113 votes, average: 4.84 out of 5)
Loading ... Loading ...
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 157 comments

  1. NIc

    on April 28, 2007 at 6:21 pm

    Great tutorial. Keep them coming.

  2. intoxicatedLama

    on April 28, 2007 at 8:18 pm

    I love it! I will creat now a game!

  3. hansa

    on April 28, 2007 at 8:19 pm

    just wonder one thing i havent read the full tutorial butt i wonder do you delete the cannon ball or not???

  4. Callum

    on April 28, 2007 at 8:31 pm

    Nice… I cant wait for part 2 it looks like a game on my iPod called parachute. :]

    And Have you got My eMail?

  5. zak

    on April 28, 2007 at 11:03 pm

    this stuff is fantastic

  6. questo

    on April 30, 2007 at 11:36 pm

    nice tutorial, but I want the crosshair to be moved by arrow keys (up arrow counter clockwise down arrow clockwise. I also want a movable charecter

  7. hasna

    on May 2, 2007 at 10:01 pm

    @questo: read http://www.emanueleferonato.com/2006/10/29/flash-game-creation-tutorial-part-1/ for your char

  8. Elmer

    on May 5, 2007 at 2:37 pm

    Loved your tutorial. One little thing I can’t get to work.

    I have made a movieclip instanced as “ballon” And I want the ballon to load next frame where it blow up, when the cannonball hit it.

    So I have this action in the ballon;

    onClipEvent(load) {
    if (this.hitTest( _root.cannonball) ){
    _root.gotoAndPlay(2);
    }

    Maybe there’s another script or maybe my script is wrong. I would appreciate your help. Thanks and bye ;)

  9. sirus

    on May 6, 2007 at 12:07 am

    Really cool

    how do you figure this stuff out in the first place?

  10. Will

    on May 8, 2007 at 6:14 pm

    I liked it. Nice cover of the basics of actionscript and i liked the gravity on the balls.

    I think that the first code you did of the crosshair would be better if you used the “start drag” function instead of making the x and y values the same. It just tends to speed stuff up a little when you have loads of functions going on.

  11. Laura

    on May 8, 2007 at 10:58 pm

    Cool. I can’t wait to get started on my game…nice tank!

  12. levick

    on May 9, 2007 at 11:34 am

    Freekin’ sweet tut man.

  13. Seth

    on May 11, 2007 at 3:17 am

    Great tutorial, waiting second part :)

  14. Joe

    on May 14, 2007 at 3:05 am

    Awesome tut. May I suggest one thing? It would be cool if the cannonballs reacted with each other. For example, if you shot a cannonball at 200 firepower, and on it’s way down you shot another cannonball at 150 firepower, the two would collide and react physically? Just a thought.

  15. hanny

    on May 14, 2007 at 10:08 pm

    i think what would be really help full is if you made stage 2 for this tut and have it so that the “tank” can move around, because i folowed the tut and when i had done all the stages i moderated some parts and made the tank move, however the bullets only went upwards and it didnt function properly..

  16. N00b

    on May 15, 2007 at 9:31 pm

    oH IT didn’t all copy….

  17. conor

    on May 19, 2007 at 9:13 pm

    alrity then ive made this and ive edited it using bits of code
    i have made it so the enemys move towards the tank but and this is a big but, i need the right hittest heres the code foe the enemys. (if the tank moved they would follow the tnk where ever)help anyone?

    code for following tank

    onClipEvent (enterFrame) { if (_root.tank._x > _x) { _x = 5; }}onClipEvent (enterFrame) { if (_root.tank._x_y) { _y = 5; }}onClipEvent (enterFrame) { if (_root.tank._y

  18. conor

    on May 19, 2007 at 9:18 pm

    also i made the balls bounce off the walls just for fun like

    iwas thinking about making that an upgrade for the future i had to take out the grasvity to do that cause i couldent lower it enough

  19. darnpunk

    on May 20, 2007 at 5:45 pm

    Hello guys, I need some help regarding some trigo maths here. Referring to line 32:

    start_ball_x = tank._x 48*Math.cos(angle*Math.PI/180);

    Is this declaring that tank._x 48 is the hypotenuse if I were to refer to trigo formula -

    cos (angle in degrees) = adjacent / hypotenuse OR better written as,

    adjacent = hypotenuse * cos(angle in degrees) which is same format as,

    start_ball_x = tank._x 48*Math.cos(angle*Math.PI/180);

    So can I say tank._x 48 is like the hypotenuse? If it is, why are we not using Pythagorean theorem?

    Another one –

    On line 31 we have:

    angle = tank.cannon._rotation-1;

    this angle is in degrees and why are we converting it back to radians in line 32? is it cos flash measures angle in radians and we are just reversing the process?

    start_ball_x = tank._x 48*Math.cos(angle*Math.PI/180);

    I hope someone can enlighten me on this! Sorry for my poor maths!

  20. dishcdiu

    on May 22, 2007 at 3:04 am

    this is for elmer i had that action script before heres the problem

    onClipEvent(enterframe) {
    if (this.hitTest( _root.cannonball) ){
    _root.gotoAndPlay(2);
    }

    add the enter frame function

  21. person

    on May 22, 2007 at 4:03 am

    for some reason no matter what I do, the cannonball doesn’t fire, does anyone know what I should do?

  22. eblup

    on May 22, 2007 at 6:50 am

    hey i need help it wont let me open the sourse codes

  23. eblup

    on May 22, 2007 at 7:01 am

    plz help it keeps saying un expected file format

  24. Gagan

    on May 22, 2007 at 9:49 am

    Hi! I am having the same problem “Unexpected file format”. I am trying to open the .FLA file with Flash Mx. Please help

  25. Im here

    on May 22, 2007 at 7:20 pm

    how would you rotate the turret using left and right keys?

  26. eblup

    on May 23, 2007 at 5:37 am

    plz help me, help me plz.

  27. eblup

    on May 23, 2007 at 6:44 am

    i got it and now i need help agin lolol

    CAN YOU RE-MAKE THIS IN A MOVIE CLIP INSTEAD OF A FRAME

  28. George W. Bush

    on May 23, 2007 at 7:27 pm

    i disagree i think u can all u gotta do is switch the first actionscript with the next and there u go alright well i hope that solves your problems

  29. eblup

    on May 24, 2007 at 9:13 am

    to get te cross hair to move with up and down you need to make it so when you press up it will use cannon angle in some trig let me explain…

    tank.cannon._rotation = rot;

    if key is down key up
    rot -= 6;

    crosshair_x = tank._x 75*Math.cos(rot*Math.PI/180)
    crosshair_y = tank._y 75*Math.sin(rot*Math.PI/180)

    their may be some errors but thats the best i can do while not working and just being lazy

  30. George W. Bush

    on May 24, 2007 at 7:04 pm

    Hey guys, i just wanted to ask why are you guys deleting “King Kong’s” notes?I believe that we should all post our own oppinions and not to worry if it is going to get deleted.Well i hope you all listen to what i am saying and for you to stop deleting posts. Thank you

  31. Emanuele Feronato

    on May 24, 2007 at 7:29 pm

    Because it’s you…

  32. David

    on May 25, 2007 at 3:27 pm

    hey i love your tuts they are so cool best tut site on whole world but i was wondering how could you create a enemy so when the cannon ball hits it it dies? (enemy made by script like blah blah blah i)

    well thx for your tut reely COOL!

    cya

  33. Create a flash artillery game - step 2 at Emanuele Feronato

    on May 25, 2007 at 5:17 pm

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

  34. Alec

    on May 25, 2007 at 9:09 pm

    What is a movie clip linkage.

  35. Leon

    on May 26, 2007 at 9:58 pm

    Great tutorial dude I’m making a similar game, but you move the turret, and it goes around 360 degrees. But anyway, i was trying to get the spawn point working (where it duplicates) and I tried everything, and I wasforgot to conv sure I haert it to radians, and you reminded me. But I had no clue about how to make it move, but I figured it out from your code,, but because it moves 360 degrees, I had to edit it slightly, so I just changed it to:

    angle = this.Turret.Turret_rotatable._rotation-90

    Instead of minus 1, so thanks, keep it up! I can’t wait for the next tutorial. BY the way, could you help me with something? I have attached an “enemy” Movie clip which moves towards the player slowly, but as both the enemy and the bullets were created dynamically, I can’t really figure out how to do it. I think that a for loop is probably the bast way, but I don’t know how to tackle it myself. If I figure it out before you respond, I will post up how I did it. ANyway, thanks again for the help from your tutorial! It’s really good work! I’ve been following the line rider one, please will you do how to do a bike or car. I don’t need the line drawing part, it’s just for a different game I’m working on.

  36. And Mar

    on May 27, 2007 at 4:56 am

    @Leon

    In my game I had the same problem. What I did is I added an onEnterFrame function for each bullet I shot. In each event, it looped through an array of all enemies on stage.

    attachMovie(“bullet”, “bullet” i, _root.getNextHighestDepth());
    i ;
    _root["bullet" i].onEnterFrame = function() {
    for(j=0 ; j

  37. And Mar

    on May 27, 2007 at 5:00 am

    thats weird. it chopped my post in half. anyway…

    @leon

    _root[”bullet” i].onEnterFrame = function() {
    for(j=0 ; j

  38. And Mar

    on May 27, 2007 at 5:03 am

    dang
    Manny you got a bug with you post system. I’m guessing with less than or greater than signs

    @Leon

    _root[”bullet” i].onEnterFrame = function() {
    for(j=0 ; j < enemies.length ; j ){
    //check for collision between this bullet and the current enemy
    //e.g. if(this.hitTest(enemies[j])
    //if true then remove both
    }
    }

    each time you dynamically create an enemy, you must push it onto the array, “enemies”.

  39. And Mar

    on May 27, 2007 at 5:05 am

    srry again

    for(j=0 ; j < enemies.length ; j ){

    is supposed to be

    for(j=0 ; j < enemies.length ; j ){

    my bad :D

  40. And Mar

    on May 27, 2007 at 5:10 am

    omg!!

    I hate this!!

    for(j=0 ; j < enemies.length ; j ){

    >>>>

    for(j=0 ; j < enemies.length ; j *two plus signs here* ){

  41. Leon

    on May 27, 2007 at 8:45 pm

    dont worry, i get it, thanks!

  42. togie

    on May 30, 2007 at 4:14 am

    hey … dunno if its just me but im having some troubles with the cannonball … i have made the cannonball and named it “cannonball” following the script … and it will not #1 connect to the cannon, #2 shoot the cannonball…. not shur … thx in advanced (mx flash)(obiusly :P)

  43. person

    on June 1, 2007 at 11:09 pm

    I have the same problem as togie, someone help

  44. person

    on June 1, 2007 at 11:09 pm

    I’m having the same problem togie

  45. wawa

    on June 4, 2007 at 2:13 pm

    you have to fix the linkage for the cannonball, right click it in the library and select “linkage”, there mark the “export for actionscript” or something box. After that type “cannonball” in the “identifier” box.

  46. person

    on June 4, 2007 at 6:52 pm

    now it works, thanks wawa

  47. Kaimie

    on June 5, 2007 at 9:23 pm

    can anyone tell me how do I make the enemies move toward the tank? also how do I make the cannon balls bounce off the walls???

  48. A guy that needs help

    on June 8, 2007 at 3:13 pm

    ok I have a problem, I type the code for the crosshair and nothing happens in preview. all that happens is my real mouse disappears.

    Plz help

  49. cody Anderson

    on June 13, 2007 at 8:00 pm

    i followed the instructions but it only shoots one cannonball at a time and if i click 2 times my first cannon ball dissipears

    help!!

  50. hayden

    on June 14, 2007 at 8:06 pm

    I have a question
    Games just like this have like upgrades which change things and add new units etc
    how would that be in script?

    and btw this sites tutorials are awesome,a big help ty!

  51. flaming

    on June 15, 2007 at 12:44 am

    whenever i type the script, it doesn’t work. but when i copy and paste,even when its the same, it somehow works.

    Am i doing something worng?

  52. Cj

    on June 15, 2007 at 7:31 pm

    Um Hey i’m just wondering how you get to those places where you type all that stuff down. I’ve never done this.

  53. anonymous

    on June 18, 2007 at 2:58 am

    How come my action script has errors, even though I copied yours

  54. Leon

    on June 19, 2007 at 1:07 am

    “I created a new movieclip linkaged as “tank” and inside this movieclip I created another one instanced as “cannon”. Look at the picture to understand how I placed the movieclips.”

    I am really new so forgive me being a total noob.

    I don’t fully understand what I am to do here. I created the two movieclips and placed them in the tank shape position. I even set two linkages. From what i understand we set a linkage so that they will be available without having to be on the stage?? The tank body moves to the stage with the attachMovie(“tank”,”tank”,2,{_x:230, _y:350}); but the cannon is missing. I guess what I am really after is what/how do i do “and inside this movieclip” from the above text?

  55. tyler

    on June 23, 2007 at 4:56 pm

    hello, I’ve been looking at this and yes It’s good, almost too good. Anyways, I was wondering on line 34 how It supose to duplicate the bullets or somthing. So it shot more then 1. Problem It keeps shooting 1 bullet and If I click again the bullet comes back and restarts. Also I’m using Macromedia Flash Mx 5. Should I get 8? Also If you want an Idea Creator of this tutorial you should get out there and design games that way you can work your way up there and make big money.

    If you ever need a partner I’m availibly for 2-D kinda 3-D designing I can make sprites, Backgrounds, Objects, and etc(depends). Email me at tjmoore_1993@hotmail.com

  56. On the horizon #1 at Emanuele Feronato

    on June 24, 2007 at 2:04 am

    [...] Next part of the artillery game tutorial [...]

  57. s0daplayer

    on June 28, 2007 at 8:12 am

    Tyler, You may want to create the bullets on different depths. Like:

    depthholder = 1
    attachMovie(“bullet”, “bullet” depthholder, depthholder”)
    depthholder

    you may want to do something like this instead.

  58. Saad

    on July 1, 2007 at 8:22 pm

    for:

    start_ball_x = tank._x 48*Math.cos(angle*Math.PI/180);
    start_ball_y = tank._y 48*Math.sin(angle*Math.PI/180);

    if we get the xpos, don’t we go

    adj = hypotheneuse*cos(angle)?

    why is the code using the x pos of the main object rather than hypotheneuse?

  59. alex

    on July 2, 2007 at 9:16 am

    hey i can’t get the second bit of code to work are u some how ment to make the tank and the cannon in the same movieclip but with different instances or wat?

    plz help some 1!?!

  60. bontif

    on July 3, 2007 at 6:57 am

    I came upon this site while googling “geometry of war”.I am a Maths teacher and I was looking for material I could use for a project based Maths grade 9/10 lesson to be done in groups of 3 or 4 over a couple of weeks. The Artillery game with all its trig fits the bill.

    Except that I know nothing about Flash programming although I cannot see this being a problem with my students- they pick up things very quickly and run with it. Since you guys are very good at what you do (that’s obvious from the games you have posted)and are probably closer in mindset to my students,I’d like your advice.

    If you were the teacher, what steps (1,2,3…)would you go through with the class before they got down to the project. You can safely assume that there are students who know something about Flash and can share their knowledge- one of the main ojectives of this exercise is collaoration anyway.The students have the necessary Trig background already.

    Thanks for any suggestions you might have.

  61. Bj

    on July 4, 2007 at 3:01 am

    The second part of the code does not work for me.I cant see why not,and i have the same setup.If anyone knows why it doesent work,pleasetell me.Also im using Flash 8 Pro,So if thats the problem please tell me

  62. Saad

    on July 4, 2007 at 9:30 pm

    Mr. bontif since your a math teacher maby you could help me with this problem I have:
    “start_ball_x = tank._x 48*Math.cos(angle*Math.PI/180);
    start_ball_y = tank._y 48*Math.sin(angle*Math.PI/180);

    if we get the xpos, don’t we go

    adj = hypotheneuse*cos(angle)?

    why is the code using the x pos of the main object rather than hypotheneuse?

  63. destructin

    on July 22, 2007 at 9:26 pm

    please help!!!

    **Error** Scene=Scene 1, layer=Layer 1, frame=2:Line 63: Statement must appear within on/onClipEvent handler
    Mouse.hide();

    **Error** Scene=Scene 1, layer=Layer 1, frame=2:Line 64: Statement must appear within on/onClipEvent handler
    attachMovie(“crosshair”, “crosshair”, 1);

    **Error** Scene=Scene 1, layer=Layer 1, frame=2:Line 65: Statement must appear within on/onClipEvent handler
    attachMovie(“tank”, “tank”, 2, {_x:230, _y:350});

    **Error** Scene=Scene 1, layer=Layer 1, frame=2:Line 66: Statement must appear within on/onClipEvent handler
    crosshair.onEnterFrame = function() {

    **Error** Scene=Scene 1, layer=Layer 1, frame=2:Line 70: Statement must appear within on/onClipEvent handler
    tank.onEnterFrame = function() {

    Total ActionScript Errors: 5 Reported Errors: 5

  64. Jake

    on July 24, 2007 at 12:54 am

    i know how to do that but if you have a tutorial for making an enemy in that sort of game can you e-mail me the url?

  65. Jake

    on August 1, 2007 at 8:43 pm

    hi im kinda new to reading these tutorials and i was wondering if you had a tutorial to make a game like Smashing http://www.miniclip.com/games/smashing/en/ i read how you made the angle calculator on the line rider tutorial but i really dont know where to start. if you have a tutorial like that can you email it to me or can you make one please?

  66. Andy

    on August 14, 2007 at 3:36 pm

    Great tute, i really learned loads from it.

  67. dudue

    on September 13, 2007 at 7:26 am

    everythings awesoem except the cannon ball which won’t appear or fire! lol y?

    Plz help
    wb

  68. endor

    on September 20, 2007 at 2:10 pm

    Your tutorials look great, but I have one problem, I try to use ActionScript 3.0
    Anyone here that uses Actionscript 3.0 that can help me to get started? They have removed the AttacheClip function, so I don’t know where to start.

  69. endor

    on September 20, 2007 at 3:09 pm

    I have now figured it out.
    To get the Crosshair to work in CS/AS 3.0 you can write this code:

    import flash.events.MouseEvent;

    Mouse.hide();
    var _crosshair:Crosshair= new Crosshair();
    stage.addEventListener(MouseEvent.MOUSE_MOVE, crosshairMove);
    function crosshairMove(ev:MouseEvent) {
    _crosshair.x = ev.stageX;
    _crosshair.y = ev.stageY;
    }

    addChild(_crosshair);

    You also need to rigth-click the MoveiClip in the Library and select Properties. Here you make sure the Export for ActionScript checkbox is checked, and give it a name.

    Hope this helpe you get started in AS/CS 3.0

  70. whatitdo

    on September 26, 2007 at 4:27 am

    awsome tutorial, thanks

  71. Paul

    on October 17, 2007 at 5:39 am

    This may sound real amateur-ish…But I’m using this code as an example, and I want to start a bullet from the beginning of the gun, which is a symbol inside of symbol…only thing is, where i set the start x and y locations to that of the gun, the bullets only come from the top of the screen where the gun seems to have started off, and it never appears on the gun location itself.
    I’m in a jam, can someone help me with this?

  72. Artillery with bounce: a modification of Artillery tutorial : Emanuele Feronato - italian geek and PROgrammer

    on October 29, 2007 at 5:10 pm

    [...] received an email from Massimo M. – an italian reader – that modified the code explained in Create a flash artillery game – step 1 [...]

  73. johanes

    on October 31, 2007 at 7:05 pm

    great tutorial… now i will began to create one…

  74. confused teenager

    on November 16, 2007 at 6:53 pm

    i have my crosshair on 2 scene.. one for the actual game and one for the menu.. i cant seem to get my crosshair to follow the mouse in my second scene.. what do i do?

  75. god

    on November 19, 2007 at 2:43 pm

    i managed to make a crosshair but i didn’t get the cannon n tank bits….i need help with step 2.

  76. Izzy

    on December 3, 2007 at 12:54 am

    seriously if you don’t know that yet you should skip ahead to things like this…the code to do that is extremely simple. You make yourself look like you just got flash and you already want to make games

  77. noob

    on December 4, 2007 at 4:54 am

    lol This is action script 2.0!!!?? I thought it was AS3.0 Nice tutorial!!! Doesn’t work well in AS3.0 compiler for those who are having same problem as me… i dnt think… 8P

  78. The RoosterRanger

    on December 5, 2007 at 11:21 pm

    Paul: to do what you wish to accomplish, you need to know a little about trigonometry. It has something to do with sine and cosine and you use them to achieve a coordinate. I haven’t done it in a long time, so I can’t tell u exactly. Try googling it.
    Noob: Stop being such a, well, N00B!…. N00b

  79. Ineedtoknowplz

    on December 6, 2007 at 6:20 am

    What flash version do you use??????? I need to know pleaseeeeeeee Its not working for meeee

  80. SirJackRex

    on December 7, 2007 at 7:14 am

    Well, it works for me, but I tested it after I got to the second part, but it will only rotate as if the pivot was on the left side, and not from the center.
    Like this: (* ) and not ( * )

  81. Zack

    on December 18, 2007 at 1:49 pm

    What you do, is make the base of the cannon, and call it tank as the instance name, then go into the edit mode for it (double click it) and draw another shape in there, and make that a movieclip (inside tank) called cannon.

  82. Zack

    on December 18, 2007 at 1:50 pm

    Sorry to double-post, but i forgot to ask: Does anyone know how to make like the projectile face the way it is going? I’m trying to make a missile.

  83. Connor

    on December 22, 2007 at 9:07 pm

    Hey I have issues with file format I would like to use the source and it just says “Unexpected file format!” Anyone know whats up??

  84. smelly

    on December 27, 2007 at 6:59 am

    im having trouble, the tanks cannon doesnt move at all and is doesnt fire! can anyone help?

  85. sd9sd

    on January 9, 2008 at 8:17 am

    Really good tutorial. Love the way it’s presented :)

  86. Ben

    on January 9, 2008 at 7:00 pm

    Hey when i try to make the cannon it put the cannon in a wierd place and the turret doesnt follow the mouse properly. it really anny cos i cant do the rest of the coding. its really annoying : p

  87. CHANDU

    on January 25, 2008 at 3:26 pm

    good

  88. hutman

    on February 16, 2008 at 7:55 am

    Maybe try onClipEvent(enterframe) instead of onClipEvent(load)

  89. Flash prototype of a game like Balloon Invasion : Emanuele Feronato - italian geek and PROgrammer

    on March 1, 2008 at 11:00 pm

    [...] of the game, that will be explained another day. It’s nothing so interesting, just a mix between Create a flash artillery game and Managing multiple collision detection with Flash [...]

  90. brendan

    on March 17, 2008 at 6:09 am

    i have gotten to the point where the cannon is supposed to aim at the crosshair but it doesn’t move- help please!

  91. Create a Flash game like Bloons tutorial : Emanuele Feronato - italian geek and PROgrammer

    on March 27, 2008 at 7:47 pm

    [...] prototype is heavily based on Create a flash artillery game – step 1, and I strongly recommend you to read [...]

  92. iaindada

    on April 10, 2008 at 9:20 am

    when the cannon ball hits something how can i get that to react, change scenes, explode, etc

  93. Ravinder

    on July 4, 2008 at 1:49 pm

    Hi there is no provision of attachMovieClip function in AS3. so u will have to use addChild() function and if u want to remove then use removeChild() function there is no any other way to do this type of job.

  94. Xlander

    on August 30, 2008 at 6:12 am

    Thanks for the tutorial!
    I am new to making Flash games and it has really helped me lot.

  95. Helpful Flash Tutorials | XlanderSoftware

    on August 30, 2008 at 6:33 am

    [...] Create a Flash artillery game [...]

  96. gameshed

    on September 22, 2008 at 10:02 pm

    Great tutorial. Keep them coming.

  97. wondering about flash

    on September 30, 2008 at 6:08 pm

    can you please post the 3rd tutorial i need to learn how to shoot multiple enemies.

  98. Luffy

    on October 24, 2008 at 12:24 am

    umm i tried this tutorial it works all the way up until i start shooting…. it shoots from the top left corner… :(

    can someone please help me?

    thanks

  99. Flash PAnda

    on November 9, 2008 at 11:02 pm

    I’m having trouble attaching the “tank” to the stage. It appears in the top left corner even though I specified the coordinates for it to go…
    Help would be appreciated…

  100. Flash PAnda

    on November 11, 2008 at 7:48 pm

    Can sum1 reply plz?!?

  101. Flash PAnda

    on November 13, 2008 at 8:23 pm

    Is this deserted or sumthing?

  102. Clay

    on November 18, 2008 at 5:53 am

    I want to make it so the tank can move how would i do that? thanks.

  103. MANINDER SINGH

    on December 6, 2008 at 11:39 am

    I like it. But this is very large tutorial.

  104. Ello

    on December 23, 2008 at 5:46 am

    So, where do I download the thing to make these games????!??!?!

  105. wowsa

    on January 8, 2009 at 2:43 am

    hey i was wondering why the code i used on setp two didnt work. id really like some help thanks.

  106. Joss

    on January 9, 2009 at 1:25 am

    **Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 1: Statement must appear within on/onClipEvent handler
    Mouse.hide();

    **Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 2: Statement must appear within on/onClipEvent handler
    attachMovie(“crosshair”, “crosshair”, 1);

    **Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 3: Statement must appear within on/onClipEvent handler
    attachMovie(“tank”, “tank”, 2, {_x:230, _y:350});

    **Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 4: Statement must appear within on/onClipEvent handler
    crosshair.onEnterFrame = function() {

    **Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 8: Statement must appear within on/onClipEvent handler
    tank.onEnterFrame = function() {

    Total ActionScript Errors: 5 Reported Errors: 5

    can some one help me? i tried to enter in the code and i didnt work these were the errors it said can someone plz help??

  107. alan

    on January 13, 2009 at 1:18 am

    problems with making something like this on my own… :(

    I’m spawning rocks the way you said here,

    _global.spawnRock = function() {

    rockSpawn = attachMovie(“rockMain”, “rock”+rockDepth, rockDepth, {_x:800, _y:300});

    but when I try to set the variable

    rockSpawn.xSpeed = 5

    i can’t get the onEnterFrame to use the variable.

    rockSpawn.onEnterFrame = function() {
    this._x += xSpeed

  108. pro

    on January 24, 2009 at 4:31 pm

    you suck realy hard you dont even tell where to add the script omg noob gay

  109. Aaron

    on March 24, 2009 at 6:20 am

    Hi I am just starting out with creating flash games, and if it not a problem, could you please
    show me the actionscript 2.0 command for rotating a object? It would be greatly appreciated.Im using Flash cs4 pro.

  110. Arxanas

    on March 31, 2009 at 4:24 am

    how do you make the ball rotate the way it’s going?

  111. pepe el grillo

    on May 1, 2009 at 8:15 pm

    codes for flash mx please

  112. Schizma

    on June 28, 2009 at 12:41 pm

    Yeah… but how to make a hitTest with that cannonballs?? :(

  113. Create a flash artillery game | Tutorial Collection

    on June 30, 2009 at 5:37 am

    [...] View Tutorial No Comment var addthis_pub="izwan00"; BOOKMARK This entry was posted on Tuesday, June 30th, 2009 at 9:07 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. [...]

  114. Saberking13

    on July 3, 2009 at 6:15 pm

    Ok, so, how do you make it so there are only one cannonball at a time?

  115. Flash Game Blog Friday: Emanuele Feronato | Freelance Flash Games News

    on July 17, 2009 at 6:02 pm

    [...] His collection of tutorials are my favorite, encompassing types such as his popular tower defense, artillery, and platform tutorials. If you find a popular game on the web, you can be almost certain Emanuele [...]

  116. lol

    on August 21, 2009 at 1:25 am

    it sucks and dosent work

  117. Creation of a Flash artillery game using Box2D : Emanuele Feronato

    on September 4, 2009 at 4:17 pm

    [...] saw readers liked a lot Create a flash artillery game – step 1 so I decided to create something similar with modern techniques (that post is dated 2007!!! Ages [...]

  118. ahmad riduan

    on September 5, 2009 at 9:22 pm

    u have a tutorial like math man ???

  119. Cano

    on October 22, 2009 at 2:07 am

    Wow man this is just what ive been looking for!!! great tutorial!!

  120. Dom

    on November 4, 2009 at 8:48 pm

    How do I perform a hittest between the cannonball_fired = attachMovie(“cannonball”, “cannonball_”+_root.getNextHighestDepth(), _root.getNextHighestDepth(), {_x:start_ball_x, _y:start_ball_y});

    and another attachmovie dynamic library instance.

  121. Balloon Games

    on November 22, 2009 at 7:23 pm

    if you like balloon invasion check out http://www.balloongame.org for more balloon games, perfect when your boss is not looking … ;-)

  122. Arwin

    on January 18, 2010 at 2:50 am

    Hi! i am using flash mx 2004. in your instruction: I created a new movieclip linkaged as “tank” and inside this movieclip I created another one instanced as “cannon”.
    I don’t know how to create a movie clip cannon inside the mc tank. Please help thanks!

  123. candy

    on February 28, 2010 at 10:27 am

    why won’t the cannonball shoot

  124. Tom da bomb

    on March 15, 2010 at 4:26 am

    go to http://www.tomdabomb.webs.com.

  125. murdoc

    on April 9, 2010 at 7:28 am

    This tut is really helpful. How can I convert this to AS3?

  126. sabin

    on May 15, 2010 at 3:52 am

    hey can u show how to do this in as 3.0

  127. Alessio

    on June 6, 2010 at 11:59 am

    Potresti modificare questo codice per As3.0?

    Da solo non ci riesco,
    non so far girare la torretta verso il puntatore…

    Saluti
    Alessio

  128. Worms-like destructible terrain in Flash - Emanuele Feronato

    on June 25, 2010 at 12:58 pm

    [...] game like Line Rider or others – part 1Make a Flash game like Flash Element Tower Defense – Part 1Create a flash artillery game – step 1 Flash game creation tutorial – part 4 [...]

  129. mae

    on July 7, 2010 at 3:28 am

    can you make it in AS3.0?… pls..

  130. 1221unger

    on August 12, 2010 at 1:07 am

    My cannon won’t follow the crosshair. The crosshair moves but the cannon doesn’t.
    Please help!!!

  131. Jaska

    on August 21, 2010 at 11:53 am

    Umm… what I did wrong, it says in actions that: the property being referenced does not ahve a static attribute. = Wtf??. So I made it into actionscript file (.as) excactly as that, but few chances but math is same. Still when I move mouse cannon shakes like hell and and points everywhere else but at my mouse… Little help is needed!

  132. Nick

    on September 15, 2010 at 9:34 pm

    Great tutorial. Will have to pass this one along for sure! Thanks.

  133. A.K.Meena

    on November 13, 2010 at 8:15 am

    very good tutorial! Thanks a lot!

  134. Rat

    on December 29, 2010 at 2:35 pm

    Cool. I can’t wait to get started on my game…nice tank!

  135. not you

    on January 11, 2011 at 9:24 pm

    WWOOWW…….i could never create this kind of stuff…i barely figure it all out dont mention the create part!!!!

  136. dang

    on March 17, 2011 at 7:41 am

    what is the -1 on line 31 for?

  137. Emin

    on June 16, 2011 at 3:36 pm

    Wich program u use?

  138. austin

    on June 29, 2011 at 12:35 am

    when it says “create another instance in the movie clip” what is it talking about

  139. austin

    on June 29, 2011 at 12:50 am

    re: when it says “create another instance in the movie clip” what is it talking about

  140. pablo

    on July 4, 2011 at 12:50 pm

    ola podrias acer un tutorial en you tube sobre esto porfavor esk soi principiante y no me aclaro….gracias mandame un email cuando subas el video…..gracias…..

  141. Fazlur

    on February 19, 2012 at 6:17 am

    Great ~~!!
    Thx ~~!!

  142. Jireh

    on March 20, 2012 at 4:12 pm

    What should be edited in the code so that only a single cannonball will fly in mouse click? So that when you clicked again, will loose the function of making another cannonball… Thank you! ^_^

  143. andre

    on May 29, 2012 at 12:42 am

    Great tutorial, it was really helpfull !!

  144. kevin

    on July 7, 2012 at 6:35 am

    My cannon is not moving.. :( What to do?
    I don’t want to just copy and paste the whole file. :(
    There are no errors on my code. It is all the same.. I already exported the tank and the crosshair. I’m still in part II. =/

  145. kevin

    on July 7, 2012 at 6:37 am

    this.cannon._rotation = angle*-1; –> this doesn’t work on me.. :(

  146. Juan

    on July 29, 2012 at 2:30 am

    I cant make even work the first step,
    I did everything right, i created the movieclip, then on the first frame (the only one), I rightclicked on it, selected actions, then I pasted the code in it, I clicked on the “check” button, no erros, but when I pressed Crtl+Ent, the only thing working was the mouse hide, whats wrong???

  147. Juan

    on July 29, 2012 at 3:29 am

    The only way to make it work is to registering the movie clips on the actionscript, an then erase the “, but still not shooting the damn ball, I know you meant to be clear with your explanation, but its a little confusing, anyway…NOT WORKING FOR ME…

  148. Membuat Artileri Game – Membuat Objek Peluru [part 3] | Gedebuk's Journal

    on October 16, 2012 at 5:16 am

    [...] Seperti biasa, tutorial ini merupakan translasi dari web ini. [...]

  149. Mauludin Indo

    on October 27, 2012 at 4:15 am

    this is great tutorial
    can I ask how to make power of firing, if we hold right click ??

  150. dmat

    on November 16, 2012 at 1:56 pm

    thx for the tut: made this into a facebook game:
    https://apps.facebook.com/fallofthegovernment/

  151. Membuat Artileri Game – Menggerakan Objek Peluru [part 4] | Gedebuk's Journal

    on November 30, 2012 at 10:39 am

    [...] biasa, tutorial ini merupakan translasi dari web ini. BioLatest Posts Sandy [...]

  152. Noobman

    on December 15, 2012 at 6:32 am

    Emanuel I need your help, I want that in a certain angle, it would face to another side. like beyond 90 degrees, it would face to left side and so forth. Im trying to make a platform/sidescroller/artillery shooting game and I already made the platform and the latter, but I can’t make a script of the artillery facing to the right. please help

  153. Membuat Artileri Game – Menggerakan cannon [part 2] | Gedebuk's Journal

    on January 16, 2013 at 11:49 am

    [...] ya, tutorial ini merupakan translasi dari web ini BioLatest Posts Sandy [...]

  154. Explosions-MovieClip nach Treffer des Gegners(Game) - Flashforum

    on April 22, 2013 at 8:13 pm

    [...] von 00noize00 Habe angefangen ein Spiel zu programmieren das nach diesem Tutorial vorgeht… Create a flash artillery game – step 1 – Emanuele Feronato Hier noch mal der Link, der ist in deinem Post nicht angezeigt worden, da du den Inhalt des tags [...]

  155. Bengemin

    on October 24, 2013 at 5:22 pm

    I obtained help in this page very much, but I would like to ask for help. You see I need to make a worms like game for a project at school, but I’m not that familiarized with programming yet, could you help me?

  156. 32 Best Action Script 3 Game Tutorials

    on April 18, 2014 at 10:56 am

    […] 28. Create a flash artillery game – step 1 […]

  157. Ryan

    on May 1, 2014 at 4:45 pm

    Hi, seems like a great tutorial but I cant even do the first step haha. Not to sure if its me or that the flash is 2014 edition or I’m posting the script in the wrong layer but would like some help. Here is the error im getting:
    Scene 1 1046: Type was not found or was not a compile-time constant: crosshair.
    Scene 1, Layer ‘Actions’, Frame 1, Line 2, Column 1 1180: Call to a possibly undefined method attachMovie.
    Scene 1, Layer ‘Actions’, Frame 1, Line 4, Column 15 1120: Access of undefined property _xmouse.
    Scene 1, Layer ‘Actions’, Frame 1, Line 5, Column 15 1120: Access of undefined property _ymouse.

    ??

    -Ryan

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

×