• Home
  • Free Tutorials
  • Free Video Tutorials

Adobe Photoshop
Autodesk 3ds Max
CSS
Flash
Help Center Live
iPhone
Joomla
Make Money Online!
Mambo
mIRC
Outlook Express
SEO / SEM
Simple Machine Forum
Target Explorer

Space Shooter - Shooting

Category : Flash Views : 88268
Version : 8 Rating : 
3.0/5 (140 votes)
  • Currently 2.99/5
  • 1
  • 2
  • 3
  • 4
  • 5
Type : Text Source File: space-shooter-shooting.zip
Result: See the result


<<< PreviousIndex SeriesNext >>>

Previous | 1 | 2 | Next

First we create a variable "i = 0", it is used to give different name to every bullet.

If the space bar is pressed we increase i by 1, attach the bullet Movie Clip and set the coordinates for our bullet.
i++; //Increase the variable i by 1. _root.attachMovie("Bullet", "Bullet" + i, _root.getNextHighestDepth());

This is a function to attach a Movie Clip from the library, its parameters are:
_root.attachMovie(identifier, new name, depth);
The "identifier" is "Bullet" that we set when creating our Movie Clip.
The "new name" is "Bullet" + i, so the name is "Bullet1" if i = 1, or "Bullet2" if i = 2.
The "depth" is in which "layer" the new Movie Clip instance is made, because of that we can't have two instances of "Bullet" with the same depth or one would overwrite the other. So we use _root.getNextHighestDepth() and flash automatically gets a free depth for us.

_root["Bullet" + i]._x = Ship._x + 3; _root["Bullet" + i]._y = Ship._y;
This code sets the new Bullet coordinates so it starts in front of our ship.

Before we finish this tutorial, let's put some limits to where our ship can go, we don't want it to get off the screen. Make these changes:
if (Key.isDown(Key.RIGHT)) { if (Ship.hitTest(550, Ship._y, true)) { Ship._x -= 5; } Ship._x += 5; } else if (Key.isDown(Key.LEFT)) { if (Ship.hitTest(0, Ship._y, true)) { Ship._x += 5; } Ship._x -= 5; } else if (Key.isDown(Key.UP)) { if (Ship.hitTest(Ship._x - 40, 0, true)) { Ship._y += 5; } Ship._y -= 5; } else if (Key.isDown(Key.DOWN)) { if (Ship.hitTest(Ship._x - 40, 300, true)) { Ship._y -= 5; } Ship._y += 5; } if (Ship.hitTest(550, Ship._y, true)) { Ship._x -= 5; }

This is a hitTest() function, it has these parameters:
hitTest(x, y, true)
If our ship hits our limit, we decrease its position by the same amount of the speed, so the Ship will never leave the screen.

Done! The ship should be shooting now, press Ctrl + Enter and test the game.

We continue our game in the next tutorial, where we will make an enemy ship and a simple AI.


del.icio.us digg it Reddit Stumble Upon Technorati

Previous | 1 | 2 | Next

<<< PreviousIndex SeriesNext >>>
How to Video Tutorials on software by Helpvids.com

Video tutorial: Forex trading



Sponsors



Advertisement









Studio | Advertisement | About Webzo | Contact Webzo | Terms of Use | Free Video Tutorials by Helpivds

Copyright © 2007 NR Concepts Ltd. All rights reserved.