Artillery with bounce: a modification of Artillery tutorial
I received an email from Massimo M. – an italian reader – that modified the code explained in Create a flash artillery game – step 1 tutorial.
Massimo wrote:
“Hi, my name is Massy and I browsed your tutorials about Flash games. I think they are very good.
I modified a bit your artillery 8 file adding two rows to the code and obtaining some kind of artillery 9. I am attaching it in case you are interested in publishing it.
I’ve just added elastic bounces to cannon balls when they hit the ground, using a low bounce factor to make it “realistic”.
This is the code to replace in the first frame:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | Mouse.hide();
gravity = 2;
attachMovie("crosshair", "crosshair", 1);
attachMovie("tank", "tank", 2, {_x:230, _y:350});
crosshair.onEnterFrame = function() {
this._x = _xmouse;
this._y = _ymouse;
};
tank.onEnterFrame = function() {
mousex = _xmouse-this._x;
mousey = (_ymouse-this._y)*-1;
angle = Math.atan(mousey/mousex)/(Math.PI/180);
if (mousex<0) {
angle += 180;
}
if (mousex>=0 && mousey<0) {
angle += 360;
}
if (angle>160) {
angle = 160;
}
if (angle<20) {
angle = 20;
}
firepower = Math.sqrt(mousex*mousex+mousey*mousey);
if (firepower>200) {
firepower = 200;
}
this.cannon._rotation = angle*-1;
};
function onMouseDown() {
angle = tank.cannon._rotation-1;
start_ball_x = tank._x+48*Math.cos(angle*Math.PI/180);
start_ball_y = tank._y+48*Math.sin(angle*Math.PI/180);
cannonball_fired = attachMovie("cannonball", "cannonball_"+_root.getNextHighestDepth(), _root.getNextHighestDepth(), {_x:start_ball_x, _y:start_ball_y});
cannonball_fired.dirx = Math.cos(angle*Math.PI/180)*firepower;
cannonball_fired.diry = Math.sin(angle*Math.PI/180)*firepower;
cannonball_fired.onEnterFrame = function() {
this.diry += gravity;
this._x += this.dirx/50;
this._y += this.diry/50;
if (this._y+this._height/2>350) {
this._y = 350-this._height/2;
this.diry = -this.diry*.3;
}
};
} |
and this is what you’ll get:
As you can see, now cannon balls bounce when they hit the ground.
Here it is the zip file with the source code.
Thank you Massimo!
They can be easily customized to meet the unique requirements of your project.
11 Responses to “Artillery with bounce: a modification of Artillery tutorial”
Leave a Reply
Trackbacks
-
Porting a game in ActionScript 2 to ActionScript 3 | zedia flash blog on
October 30th, 2007 5:14 am
[...] I blogged about a post on Emanuele Feronato’s blog. Today he put on is blog some code on an artillery game. It is nice code, but it is in ActionScript 2. I thought it would be fun to try to make the same [...]
-
A Gem of Flash Game Tutorials | Newbie Game Programmers on
December 17th, 2007 4:23 pm
[...] Create a flash artillery game – Part 1 :: Part 2 :: Modification [...]
-
Create a flash artillery game – step 1 : Emanuele Feronato on
September 4th, 2009 4:01 pm
[...] 25th update: 2nd part released October 29th update: modification with a bounce effect developed by Massimo [...]
- Citrus Engine released for free for learning
- My epic fail with ClickBank
- Get up to $100,000 for your next Flash game with Mochi GAME Developer Fund
- Create a dynamic content animated footer ad for your site in just 9 jQuery lines – 17 lines version
- Sell sitelocked version of your Flash games and even .fla sources to Free Online Games
- Protect your work from ActionScript code theft with SWF Protector
- Create a dynamic content animated footer ad for your site in just 9 jQuery lines
- Understanding Box2D’s one-way platforms, aka CLOUDS
- Triqui MochiAds Arcade plugin for WordPress upgraded to 1.2
- Box2D Flash game creation tutorial – part 2
- Create a Lightbox effect only with CSS - no javascript needed
- Flash game creation tutorial - part 1
- Create a Flash Racing Game Tutorial
- Flash game creation tutorial - part 2
- Make a Flash game like Flash Element Tower Defense - Part 2
- Flash game creation tutorial - part 3
- Triqui MochiAds Arcade plugin for WordPress official page
- Make a Flash game like Flash Element Tower Defense - Part 1
- Create a flash draw game like Line Rider or others - part 1
- Create a flash artillery game - step 1
- Flash game creation tutorial – part 5.2 (4.88/5)
- Create a flash artillery game – step 1 (4.79/5)
- Create a Flash Racing Game Tutorial (4.76/5)
- Create a survival horror game in Flash tutorial – part 1 (4.74/5)
- Create a flash artillery game – step 2 (4.74/5)
- Creation of a Flash arcade site using WordPress – step 2 (4.73/5)
- Flash game creation tutorial – part 1 (4.71/5)
- Flash game creation tutorial – part 2 (4.71/5)
- Create a flash draw game like Line Rider or others – part 1 (4.69/5)
- Creation of a platform game with Flash – step 2 (4.68/5)

(4 votes, average: 4.75 out of 5)



You can add some friction too that also to give some more realism. Velocity *= Friction (0.95 is pretty good)
Looks very cool, it add a nice look to the game.
But, some balls stay too much time in stage, you may want to slowly fade them out :)
Sorry for my bad english :s
Good idea for the next time ;)
it can be a good idea to fade out the ball after 2 or 3 bounces or at least after X seconds
Massimo :)
I you want to continue upgrading this game, you should consider ActionScript 3. I already converted it, you could go on from there.
Here is the source
http://www.zedia.net/2007/porting-a-game-in-actionscript-2-to-actionscript-3/
Pretty nice improvment.
I guess the bounce factor should be customable.
Nice. How i just love contributions. I’m on my way, to make another game, with help from this site. Good, Massimo!
/Frederik
tnx you Fred! ;)
(for monkios) to change the bounce factor simply change the “0.3″ value in line 44.
(for Zedia) tnx but for now i prefer to concentrate on version 2 cause i prefer better support for all to see my works ;) i will pass on flash 9 or more later!
its a good tutorial but how can we add wind