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

  • NIc

    Great tutorial. Keep them coming.

  • I love it! I will creat now a game!

  • hansa

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

  • Callum

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

    And Have you got My eMail?

  • zak

    this stuff is fantastic

  • questo

    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

  • hasna
  • 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 ;)

  • sirus

    Really cool

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

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

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

  • Freekin’ sweet tut man.

  • Seth

    Great tutorial, waiting second part :)

  • Joe

    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.

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

  • N00b

    oH IT didn’t all copy….

  • conor

    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

  • conor

    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

  • darnpunk

    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!

  • dishcdiu

    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

  • person

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

  • eblup

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

  • eblup

    plz help it keeps saying un expected file format

  • Gagan

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

  • Im here

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

  • eblup

    plz help me, help me plz.

  • eblup

    i got it and now i need help agin lolol

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

  • George W. Bush

    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

  • eblup

    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

  • George W. Bush

    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

  • Emanuele Feronato

    Because it’s you…

  • David

    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

  • Pingback: Create a flash artillery game - step 2 at Emanuele Feronato()

  • Alec

    What is a movie clip linkage.

  • Leon

    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.

  • @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

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

    @leon

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

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

  • srry again

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

    is supposed to be

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

    my bad :D

  • omg!!

    I hate this!!

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

    >>>>

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

  • Leon

    dont worry, i get it, thanks!

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

  • person

    I have the same problem as togie, someone help

  • person

    I’m having the same problem togie

  • wawa

    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.

  • person

    now it works, thanks wawa

  • Kaimie

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

  • A guy that needs help

    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

  • cody Anderson

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

  • hayden

    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!

  • flaming

    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?

  • Cj

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

  • anonymous

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

  • Leon

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

  • 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

  • Pingback: On the horizon #1 at Emanuele Feronato()

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

  • Saad

    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?

  • alex

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

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

  • Bj

    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

  • Saad

    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?

  • destructin

    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

  • Jake

    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?

  • Jake

    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?

  • Andy

    Great tute, i really learned loads from it.

  • dudue

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

    Plz help
    wb

  • endor

    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.

  • endor

    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

  • whatitdo

    awsome tutorial, thanks

  • Paul

    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?

  • Pingback: Artillery with bounce: a modification of Artillery tutorial : Emanuele Feronato - italian geek and PROgrammer()

  • great tutorial… now i will began to create one…

  • confused teenager

    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?

  • god

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

  • Izzy

    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

  • 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

  • The RoosterRanger

    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

  • Ineedtoknowplz

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

  • SirJackRex

    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 ( * )

  • Zack

    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.

  • Zack

    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.

  • Connor

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

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

  • sd9sd

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

  • Ben

    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

  • CHANDU

    good

  • hutman

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

  • Pingback: Flash prototype of a game like Balloon Invasion : Emanuele Feronato - italian geek and PROgrammer()

  • brendan

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

  • Pingback: Create a Flash game like Bloons tutorial : Emanuele Feronato - italian geek and PROgrammer()

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

  • Ravinder

    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.

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

  • Pingback: Helpful Flash Tutorials | XlanderSoftware()

  • Great tutorial. Keep them coming.

  • wondering about flash

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

  • Luffy

    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

  • Flash PAnda

    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…

  • Flash PAnda

    Can sum1 reply plz?!?

  • Flash PAnda

    Is this deserted or sumthing?

  • Clay

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

  • I like it. But this is very large tutorial.

  • Ello

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

  • wowsa

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

  • Joss

    **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??

  • alan

    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

  • pro

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

  • Aaron

    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.

  • Arxanas

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

  • pepe el grillo

    codes for flash mx please

  • Schizma

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

  • Pingback: Create a flash artillery game | Tutorial Collection()

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

  • Pingback: Flash Game Blog Friday: Emanuele Feronato | Freelance Flash Games News()

  • lol

    it sucks and dosent work

  • Pingback: Creation of a Flash artillery game using Box2D : Emanuele Feronato()

  • ahmad riduan

    u have a tutorial like math man ???

  • Cano

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

  • Dom

    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.

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

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

  • candy

    why won’t the cannonball shoot

  • murdoc

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

  • sabin

    hey can u show how to do this in as 3.0

  • Alessio

    Potresti modificare questo codice per As3.0?

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

    Saluti
    Alessio

  • Pingback: Worms-like destructible terrain in Flash - Emanuele Feronato()

  • mae

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

  • 1221unger

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

  • Jaska

    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!

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

  • A.K.Meena

    very good tutorial! Thanks a lot!

  • Rat

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

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

  • dang

    what is the -1 on line 31 for?

  • Emin

    Wich program u use?

  • austin

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

  • austin

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

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

  • Fazlur

    Great ~~!!
    Thx ~~!!

  • Jireh

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

  • andre

    Great tutorial, it was really helpfull !!

  • kevin

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

  • kevin

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

  • Juan

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

  • Juan

    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…

  • Pingback: Membuat Artileri Game – Membuat Objek Peluru [part 3] | Gedebuk's Journal()

  • Mauludin Indo

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

  • dmat

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

  • Pingback: Membuat Artileri Game – Menggerakan Objek Peluru [part 4] | Gedebuk's Journal()

  • Noobman

    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

  • Pingback: Membuat Artileri Game – Menggerakan cannon [part 2] | Gedebuk's Journal()

  • Pingback: Explosions-MovieClip nach Treffer des Gegners(Game) - Flashforum()

  • Bengemin

    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?

  • Pingback: 32 Best Action Script 3 Game Tutorials()

  • Ryan

    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