Simple Shooter Game - Part 1

This set of tutorials with take you through the basics of how to create a simple shooter game. Note that this is the way I do it, not the only way, and feel free to change things as you read as every game maker has a different style. The first part of the tutorial will show you how to make the main player and how you can control it. This tutorial is done completely is Actionscript 3.0, so if you only know AS2, see this post and if you don’t know actionscript at all, go here.
The first step is to draw the main character. We’re going to be controlling him using the WASD or UP, LEFT, DOWN, RIGHT keys to move him, the mouse to aim and mouse click will fire bullets. This is what you’ll be able make after you do this part. After you’ve drawn the character, put it on the stage and give it an instance name of ’ship’.
Now add this code to the main timeline:
Skip the first few lines, I will talk about this later. The first variable I set is ‘rad’ short for radians. This helps me convert angles quickly between radians and degrees. If you don’t know what radians are, don’t worry - you just have to know that they’re another form of representing angles and AS3 uses them for calculations. So if a times an angle in degrees by ‘rad’, I will get radians, and if I divide ‘rad’ into radians, I will get degrees.
The other variables are xspeed, yspeed, speed (absolute value of both xspeed and yspeed), maxspeed, angle (of direction), acc (acceleration), friction, and mouse_angle.
The next stage is creating the key listeners so we can see what keys are down, and what keys aren’t. As you can see, I set left, up down and right_key to false to indicate no keys are being pressed. Then I add the KEY_DOWN and KEY_UP listeners. The ‘keyCode’ corresponds to the code of the key that is pressed. 37 and 65 are the keys for A and the left arrow key. In English, the code reads ‘if the keycode is 37 or 65 (if A or the left arrow key is pressed), set left_key to true’. The same goes for the next 6 keys. We duplicate this for the KEY_UP listener, except change the values to false to show the keys are no longer down. We are going to use these booleans (true/false) in controlling the ship later in the code.
Next we create the ENTER_FRAME function which I named ‘EF’. The next part of the code asks, ‘If the left key is down, make the xspeed go down by the acceleration, or if the right key is down, make xspeed go up by the acceleration. If neither key is down, friction will cause the xspeed to come to 0.’ The same goes for the yspeed.
The next part of the code aims to limit the speed so it never goes pass ‘maxspeed’. I use the following technique, which calculates the combined speed value of the x and y speed’s, checks if it’s too fast and then adjusts xspeed and yspeed accordingly. The reason I do this, instead of checking the xspeed and yspeed individually is because the overall speed will end up being faster at a 45°. For example, if the maxspeed was 10, and it was travelling right at full speed, the overall speed would be 10. If we were going straight up, the overall speed would be 10. However, if we were going diagonally left and up, the xspeed would be limited to 10, as well as yspeed, meaning an overall speed of about 14 (using Pythagoras’ thereom). My technique ensures the overall speed is always limited to the same number (maxspeed).
Firstly we calculate this speed by using Pythagoras’ Thereom:

Where speed = the square root of xspeed squared plus yspeed squared.
At this stage we also calculate the angle, as shown in the diagram. I add 90° worth of radians on just because this is right through trial and error. If the speed is greater than the maxspeed, then we calculate the xspeed and yspeed based on this angle. We say xspeed is the sine of the angle times the speed, and yspeed is the cosine of the angle times the speed (we use negative because the flash plane is the normal cartesian plane flipped upside down).
Next we relate the x and y speed’s to the actual ship, so we add xspeed to the ship’s x and yspeed to the ship’s y, just like you would add the speed of a car to it’s distance travelled every hour. We then calculate the angle between the mouse and the ship with the same technique as we calculated the other angle. Then, the ship’s rotation will be this angle in degrees, so we divide by ‘rad’.
The next part handles the trails that come out of the ship at it moves. First you’ll need to make the trail animation. I made a simple shape tween of a white dot fading away. On the last frame, when you want the trail to be removed, place this code:
First we stop the animation so it doesn’t continue playing. Then we remove the trail from it’s parent, which basically just removes the trail from view. Now go into the library, select your trails MC and right/control click on it and select properties, or press the tiny blue ‘i’ icon at the bottom of the library. Click ‘Advanced’ if you haven’t already and select ‘Export for Actionscript’. Where is says ‘Class’ type ‘Trail’. This creates a new class for AS and you can now grab the trail MC from the library using just code.
For a trail to to be put there each frame, speed must first be over 0.1, as there shouldn’t be any trails appearing when the speed is very small or 0. To bring an MC from the library to the code, we use the same format as other classes, like Number or MovieClip except we use the class name we gave the MC in it’s properties. At the start of the code, I created a new MC called ‘effects1_mc’. This was the MC where all the ‘under’ effects would go (effects that are shown below other things in the game). I then had to add the child, which makes the MC visible to the viewer. So that the ship MC appeared on top of the effects, I then added the ship child after the effects. After I made the trail MC I also had to add the child, this time to the effects1_mc who is the parent. This means the trails will appear below the ship. With the trail, I make the x and y positions equal to the ship’s position plus or minus a bit more.
Now you can export your movie and see what you came up with. Next time I’ll cover how to shoot bullets from the ship.
July 18th, 2008 at 7:12 pm
Johnnie Hair
Tamra Hatfield
Eva Keilbach
Penelope Mcintosh
Dona Pinney
Prudence Marriman
Shantelle Porter
Sherry Butler
Earline Echard
Brendan Brandenburg
Baptist Judge
Isidora Treeby
Orval Anderson
Bart Wheeler
Brittani Mcmichaels
Cara Rowe
Nevada G…
One notable blogging tool that does not support trackback yet is Blogger.) Some individuals or companies have abused the TrackBack…
July 23rd, 2008 at 4:41 am
St Louis Malpractice Lawyer…
hey nice site….
July 28th, 2008 at 3:34 am
The site http://www.kabomb.net is good resource, respect, owner. And look at this cover ipod nana star war
By.
July 29th, 2008 at 1:14 am
The http://www.kabomb.net is interesting resource, thanks, webmaster. look at this welchia worm remove
By.
July 30th, 2008 at 11:28 pm
Great Post!! I enjoyed every bit of it
July 31st, 2008 at 3:49 pm
ty vm really usefull
August 4th, 2008 at 1:36 am
[url=http://journals.aol.com/onlnpharmacy/buy-isotretinoin-generic-accutan/]alcohol use on accutane
[/url]
August 4th, 2008 at 9:33 pm
sofort angelina jolie filme downloaden…
Kennt jmd. ein website wo ich die Fernsehserie wie “Stargate” downloaden kann?…
August 5th, 2008 at 6:10 am
imitrex nasal
August 5th, 2008 at 8:13 am
Good post. good luck.
August 6th, 2008 at 6:14 am
irnc btgh nyoqx enkthy txoarlk hswxqbj aoxvjbe
August 12th, 2008 at 11:10 pm
sponsorship…
.A Trackback is one of three types of Linkbacks, methods for Web authors to request notification when somebody links to one of their…
August 16th, 2008 at 2:05 am
imitrex sumatriptan
August 16th, 2008 at 7:58 pm
hey…
agree…
August 17th, 2008 at 12:31 am
femjoy yasmin
August 20th, 2008 at 9:46 am
Pretty nice site, wants to see much more on it!
August 20th, 2008 at 7:09 pm
Pretty nice site, wants to see much more on it!
August 21st, 2008 at 11:14 pm
This is where you best savings accounts furnishings the economization your money. Most adroitly savings accounts in clarification that collapse duties picture from settling to combination and the weep for applies to paving overlook plenty buyers only.
August 22nd, 2008 at 1:46 am
Cool site….
Was not looking for your site, but great stuff….
August 22nd, 2008 at 1:51 pm
ing savings accountMi high interest saving account
August 22nd, 2008 at 6:09 pm
buy clomid
August 23rd, 2008 at 12:38 am
compare savings accountsMi children savings account
August 23rd, 2008 at 8:33 pm
Coll blog, thanks.
August 25th, 2008 at 4:50 pm
Cool blog
Thanks, webmaster.
August 25th, 2008 at 8:40 pm
Amazine site
Thanks, webmaster.
August 26th, 2008 at 6:40 am
Nice site
Thanks, webmaster.
August 26th, 2008 at 2:10 pm
Beautifull design
Thanks, webmaster.
August 26th, 2008 at 5:18 pm
Amazine site
Thanks, webmaster.
August 26th, 2008 at 6:43 pm
Excellent blog
Thanks, webmaster.
August 26th, 2008 at 11:51 pm
Nice site
Thanks, webmaster.
August 27th, 2008 at 2:37 am
Cool blog
Thanks, webmaster.
August 27th, 2008 at 5:32 am
Very amazing site
Thanks, webmaster.
August 27th, 2008 at 2:37 pm
Nice site
Thanks, webmaster.
August 27th, 2008 at 10:16 pm
aceon
August 31st, 2008 at 3:15 am
Cool blog
Thanks, webmaster.
August 31st, 2008 at 4:07 am
Nice site
Thanks, webmaster.
September 3rd, 2008 at 2:17 pm
Beautiful design.
Thanks, webmaster.
September 5th, 2008 at 1:47 pm
Amazine site
Thanks, webmaster.
September 5th, 2008 at 3:19 pm
Beautifull design
Thanks, webmaster.
September 6th, 2008 at 4:44 am
Very amazing site
Thanks, webmaster.
September 6th, 2008 at 6:24 am
Nice site
Thanks, webmaster.
September 7th, 2008 at 2:41 pm
Cool blog.
Thanks, admin.
September 7th, 2008 at 6:27 pm
Nice site.
Thanks, admin.
September 7th, 2008 at 11:25 pm
Amazing site.
Thanks, admin.
September 8th, 2008 at 12:10 pm
Amazing site.
Thanks, admin.
September 8th, 2008 at 9:07 pm
Beautiful design.
Thanks, webmaster.
September 9th, 2008 at 1:00 am
Amazing site.
Thanks, webmaster.
September 9th, 2008 at 1:50 am
Nice site.
Thanks, admin.
September 11th, 2008 at 3:44 pm
Amazing site.
Thanks, webmaster.
September 11th, 2008 at 7:43 pm
Cool blog.
Thanks, webmaster.
September 11th, 2008 at 8:57 pm
Amazing site.
Thanks, admin.
September 12th, 2008 at 2:09 am
Beautiful design.
Thanks, admin.
September 12th, 2008 at 3:02 am
Cool blog.
Thanks, webmaster.
September 12th, 2008 at 6:01 am
Amazing site.
Thanks, webmaster.
September 12th, 2008 at 6:52 am
Cool blog.
Thanks, webmaster.
September 12th, 2008 at 9:21 pm
Amazing site.
Thanks, webmaster.
September 13th, 2008 at 12:24 am
Amazing site.
Thanks, admin.
September 13th, 2008 at 1:44 am
Amazing site.
Thanks, webmaster.
September 13th, 2008 at 12:37 pm
Cool blog.
Thanks, admin.
September 13th, 2008 at 1:24 pm
Beautiful design.
Thanks, webmaster.
September 14th, 2008 at 11:31 am
Good site
Thanks.
September 14th, 2008 at 11:47 pm
Beautiful design.
Thanks, admin.
September 15th, 2008 at 1:48 am
Nice site.
Thanks, webmaster.
September 15th, 2008 at 2:32 am
Cool blog.
Thanks, admin.
September 15th, 2008 at 4:43 am
Beautiful design.
Thanks, webmaster.
September 15th, 2008 at 5:26 am
Nice site.
Thanks, admin.
September 15th, 2008 at 8:23 am
Beautiful design.
Thanks, webmaster.
September 15th, 2008 at 3:23 pm
Cool blog.
Thanks, webmaster.
September 15th, 2008 at 7:04 pm
Cool blog.
Thanks, admin.
September 16th, 2008 at 2:17 am
Cool blog.
ways to eat a girl out
Thanks, webmaster.
September 16th, 2008 at 3:05 am
Cool blog.
first class airline flights chedule
Thanks, admin.
September 17th, 2008 at 11:54 pm
Hey,
Good game. I like it.
Thanks.
September 22nd, 2008 at 9:08 am
ztijmgyn…
ztijmgyn…
September 23rd, 2008 at 6:57 pm
How i may contact the administrator of a site? I have a question.
September 24th, 2008 at 6:03 am
Discount Paradigm Speakers…
Discount Paradigm Speakers…
September 30th, 2008 at 1:55 pm
LOL
that doesn’t even make any sense!
October 2nd, 2008 at 3:16 am
nice blog, thanks
buy diflucan
October 2nd, 2008 at 11:04 am
How i may contact admin this site? I have a question.
iijiivei
October 3rd, 2008 at 6:50 am
I just want to take some money!
Press here
October 3rd, 2008 at 7:06 am
Searched for malpractice attorney in msn, but found this page. very helpful!
October 4th, 2008 at 6:14 pm
Hola Amigos, who know how can i buy diflucan with MC?
October 7th, 2008 at 2:07 am
travel…
travel…
October 7th, 2008 at 5:33 pm
Thanks for the interesting article, I love this site
October 8th, 2008 at 12:18 pm
blue mountain cards…
blue mountain cards…
October 8th, 2008 at 3:18 pm
vnzaoxbg erif pvrnhudz hypnxq wclt zhamo njvwmirp
October 10th, 2008 at 11:50 pm
Good job. Tnks, webmaster!
Boots travel insurance information:
boots travel insurance
October 11th, 2008 at 1:06 am
Excellent work! Respect, admin!
Boots travel insurance information:
boots travel insurance
October 11th, 2008 at 2:21 am
Good job, Tnks, owner.
Boots travel insurance information:
boots travel insurance
October 11th, 2008 at 3:37 am
Amazing job, Respect, admin!
Boots travel insurance information:
boots travel insurance
October 11th, 2008 at 9:57 am
Beautiful work, Tnks, owner.
Pirelli tires
Pirelli scorpion tires
October 12th, 2008 at 12:11 pm
Beautiful design. Tnks admin.
pallets of secondhand books types or tulips you can buy metal clothes chute doors where can i buy kerastase crystal glass beads in bulk ipod koi pound where can i buy butane for a stove 3xl motorcycle helmets lindt chocolate teddy bears bearded-collies shop where to buy wonton sheets i have rimadyl for sale where can i buy a silver and black shirt nortton definaiton “requesting virus scan” office word symantec norton antivivrus lindt chocolate in houston where to buy sd alcohol 40 b how big are the livestrong bracelets nuhvok
October 12th, 2008 at 1:18 pm
Good design. Tnks, webmaster!
Pirelli scorpion tires
Pirelli motorcycle tires
October 12th, 2008 at 2:45 pm
Excellent job, Thanks, webmaster!
Pirelli motorcycle tires
Pirelli tires
October 12th, 2008 at 3:18 pm
Beautiful work, Tnks, admin.
Pirelli tires
Pirelli tires
October 12th, 2008 at 5:18 pm
Amazing work. Thanks owner!
Pirelli scooter tires
Pirelli scooter tires
October 16th, 2008 at 12:37 pm
Beautiful site! Tnks webmaster!
October 16th, 2008 at 4:01 pm
Beautiful site! Respect, owner!
October 16th, 2008 at 7:05 pm
Nice site, Respect, admin.
October 16th, 2008 at 8:55 pm
Beautiful work, Tnks, admin.
October 16th, 2008 at 10:31 pm
Amazing site, Respect, admin.
October 19th, 2008 at 2:51 am
скачать порно видео ролики
October 19th, 2008 at 11:27 am
http://thinkpennystocks.info/stock-chat-room.html...
investment terms…
October 19th, 2008 at 2:02 pm
http://www.superpennystocks.info/free-analyst-stock-reports.html...
where can i check the stock market…
October 20th, 2008 at 1:21 am
click me
October 20th, 2008 at 1:12 pm
http://thinkpennystocks.info/russian-rouble.html...
nasdaq chart history…
October 23rd, 2008 at 2:10 am
http://www.stockpicktime.info/fun-facts-about-the-stock-market.html...
where can i find a list of stocks…
October 26th, 2008 at 5:51 am
buy zyban
November 2nd, 2008 at 10:35 pm
Excellent time. And nice site. Keep up a good work! :-))
November 3rd, 2008 at 1:36 am
Enjoyed your site very much! Thank you! Keep up a good work! :-))
November 8th, 2008 at 1:43 am
Howdy, I fell lucky that I located this post while browsing for shooter the movie. I am with you on the topic of Simple Shooter Game - Part 1. Ironically, I was just putting a lot of thought into this last Friday.
November 13th, 2008 at 7:15 am
I’ll bookmark your site! :-)) Keep up a good work! :-))
November 13th, 2008 at 7:29 am
! :-)) Keep up a good work!
November 13th, 2008 at 7:32 am
Perfect time. And nice site! :-)) Keep up a good work!
November 14th, 2008 at 1:41 am
Casino 491c7a1062…
Casino 491c7a1062…
November 15th, 2008 at 10:02 am
to: Admin - If You want to delete your site from my spam list, please sent url of your domain to my emai: stop.spam.today@gmail.com
And I will remove your site from my base within 24 hours
webmastegz
November 16th, 2008 at 9:54 pm
to: Admin - If You want to delete your site from my spam list, please sent url of your domain to my e-mail: stop.spam.today@gmail.com
And I will remove your site from my base within 24 hours
webmastegz
November 17th, 2008 at 12:13 am
Perfect project. Keep it up!
November 17th, 2008 at 7:18 pm
to: Admin - If You want to delete your site from my spam list, please sent url of your domain to my emai: stop.web.spam@gmail.com
And I will remove your site from my base within 24 hours
webmastegz
PS. As the previous address of an e-mail has been removed also all letters on it have been lost I is compelled to make this dispatch once again.
PS2. To send url your site on an e-mail stop.web.spam@gmail.com is a unique way to avoid a spam from me. To write abuses to the various “stop spam” sites - it is useless.
PS3. Your addresses of an e-mail are not necessary to me, you can create an e-mail through free service and send me yours url through this e-mail
PS4. sorry for my bad English
November 19th, 2008 at 12:41 am
Free Adult Friend Finder…
Interesting topic! I really enjoyed your discussion points and plan to share your blog with my friends! I didn’t quite agree with everything but I do like to see other peoples points of view. If you want to learn how to get 100% free access to Adul…
November 19th, 2008 at 4:08 am
The site very professional! Keep up the good work! Oh yes, one extra comment - maybe you could add more pictures too! So, good luck to your team!