Simple Shooter Game - Part 1

shooter ss2

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:
shooter ss1
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.

120 Responses to “Simple Shooter Game - Part 1”

  1. 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 Grant Says:

    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…

  2. stlouispersonalinjuryhelp.com Says:

    St Louis Malpractice Lawyer…

    hey nice site….

  3. ipodnana Says:

    The site http://www.kabomb.net is good resource, respect, owner. And look at this cover ipod nana star war
    By.

  4. blasterwormremove Says:

    The http://www.kabomb.net is interesting resource, thanks, webmaster. look at this welchia worm remove
    By.

  5. Information Says:

    Great Post!! I enjoyed every bit of it

  6. insert name here... Says:

    ty vm really usefull

  7. istoretinoineen Says:

    [url=http://journals.aol.com/onlnpharmacy/buy-isotretinoin-generic-accutan/]alcohol use on accutane
    [/url]

  8. Wo kann ich filme downloaden? Says:

    sofort angelina jolie filme downloaden…

    Kennt jmd. ein website wo ich die Fernsehserie wie “Stargate” downloaden kann?…

  9. sumatiptan Says:

    imitrex nasal

  10. Comprar Tadalafil Says:

    Good post. good luck.

  11. hkayvq qktdc Says:

    irnc btgh nyoqx enkthy txoarlk hswxqbj aoxvjbe

  12. sponsorship Says:

    sponsorship…

    .A Trackback is one of three types of Linkbacks, methods for Web authors to request notification when somebody links to one of their…

  13. sumatiptan Says:

    imitrex sumatriptan

  14. japan searches Says:

    hey…

    agree…

  15. yasmin Says:

    femjoy yasmin

  16. John Williams Says:

    Pretty nice site, wants to see much more on it! :)

  17. John Williams ok Says:

    Pretty nice site, wants to see much more on it! :)

  18. credit_unions_with_the_best_savings_accountsWeN Says:

    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.

  19. Debt Consolidation Says:

    Cool site….

    Was not looking for your site, but great stuff….

  20. bestsavingsaccountratesMi Says:

    ing savings accountMi high interest saving account

  21. buy clomid Says:

    buy clomid

  22. national savings accounts Says:

    compare savings accountsMi children savings account

  23. best internet savings accounts Says:

    Coll blog, thanks.

  24. best savings accounts Says:

    Cool blog
    Thanks, webmaster.

  25. find best on-line savings accounts Says:

    Amazine site
    Thanks, webmaster.

  26. Cheap Ipod Nana Says:

    Nice site
    Thanks, webmaster.

  27. digital cable hdtv Says:

    Beautifull design
    Thanks, webmaster.

  28. digital cable frequency Says:

    Amazine site
    Thanks, webmaster.

  29. digital cable descrambling Says:

    Excellent blog
    Thanks, webmaster.

  30. best savings accounts children Says:

    Nice site
    Thanks, webmaster.

  31. best savings accounts for children Says:

    Cool blog
    Thanks, webmaster.

  32. state water heaters Says:

    Very amazing site
    Thanks, webmaster.

  33. state water heater prices Says:

    Nice site
    Thanks, webmaster.

  34. aceon Says:

    aceon

  35. state select hot water heater Says:

    Cool blog
    Thanks, webmaster.

  36. state select gas water heaters Says:

    Nice site
    Thanks, webmaster.

  37. niherasebekei Says:

    Beautiful design.
    Thanks, webmaster.

  38. werewolf Says:

    Amazine site
    Thanks, webmaster.

  39. werewolf Says:

    Beautifull design
    Thanks, webmaster.

  40. Svetlana Says:

    Very amazing site
    Thanks, webmaster.

  41. Svetlana Says:

    Nice site
    Thanks, webmaster.

  42. pokemon Says:

    Cool blog.
    Thanks, admin.

  43. pokemon Says:

    Nice site.
    Thanks, admin.

  44. pokemon Says:

    Amazing site.
    Thanks, admin.

  45. helmet Says:

    Amazing site.
    Thanks, admin.

  46. helmet Says:

    Beautiful design.
    Thanks, webmaster.

  47. helmet Says:

    Amazing site.
    Thanks, webmaster.

  48. helmet Says:

    Nice site.
    Thanks, admin.

  49. were to buy Says:

    Amazing site.
    Thanks, webmaster.

  50. halloween Says:

    Cool blog.
    Thanks, webmaster.

  51. halloween Says:

    Amazing site.
    Thanks, admin.

  52. mario and luigi halloween costume Says:

    Beautiful design.
    Thanks, admin.

  53. mario and luigi halloween costume Says:

    Cool blog.
    Thanks, webmaster.

  54. homemade adult halloween costume Says:

    Amazing site.
    Thanks, webmaster.

  55. winnie the pooh halloween costume Says:

    Cool blog.
    Thanks, webmaster.

  56. Elena Says:

    Amazing site.
    Thanks, webmaster.

  57. Marina Says:

    Amazing site.
    Thanks, admin.

  58. Sveta Says:

    Amazing site.
    Thanks, webmaster.

  59. Marina Says:

    Cool blog.
    Thanks, admin.

  60. Pavel Says:

    Beautiful design.
    Thanks, webmaster.

  61. Boots travel insurance Says:

    Good site
    Thanks.

  62. Sveta Says:

    Beautiful design.
    Thanks, admin.

  63. Sveta Says:

    Nice site.
    Thanks, webmaster.

  64. Pavel Says:

    Cool blog.
    Thanks, admin.

  65. Sveta Says:

    Beautiful design.
    Thanks, webmaster.

  66. Elena Says:

    Nice site.
    Thanks, admin.

  67. Maria Says:

    Beautiful design.
    Thanks, webmaster.

  68. Sveta Says:

    Cool blog.
    Thanks, webmaster.

  69. Elena Says:

    Cool blog.
    Thanks, admin.

  70. idaho falls multiple listing service Says:

    Cool blog.
    ways to eat a girl out
    Thanks, webmaster.

  71. idaho falls multiple listing service Says:

    Cool blog.
    first class airline flights chedule
    Thanks, admin.

  72. flash game design Says:

    Hey,
    Good game. I like it.
    Thanks.

  73. ztijmgyn Says:

    ztijmgyn…

    ztijmgyn…

  74. pattspiniaHop Says:

    How i may contact the administrator of a site? I have a question.

  75. Discount Paradigm Speakers Says:

    Discount Paradigm Speakers…

    Discount Paradigm Speakers…

  76. Andrew Says:

    LOL
    that doesn’t even make any sense!

  77. Wipqjsim Says:

    nice blog, thanks
    buy diflucan

  78. Tretroofs Says:

    How i may contact admin this site? I have a question.
    iijiivei

  79. ovenehoumma Says:

    I just want to take some money! :)
    Press here

  80. Tatiana Says:

    Searched for malpractice attorney in msn, but found this page. very helpful!

  81. DorrinMallkov Says:

    Hola Amigos, who know how can i buy diflucan with MC?

  82. travel Says:

    travel…

    travel…

  83. bania Says:

    Thanks for the interesting article, I love this site

  84. blue mountain cards Says:

    blue mountain cards…

    blue mountain cards…

  85. owpv mhrxjdflg Says:

    vnzaoxbg erif pvrnhudz hypnxq wclt zhamo njvwmirp

  86. BootsTravelInsuranceves Says:

    Good job. Tnks, webmaster!
    Boots travel insurance information:
    boots travel insurance

  87. BootsTravelInsuranceves Says:

    Excellent work! Respect, admin!
    Boots travel insurance information:
    boots travel insurance

  88. BootsTravelInsuranceves Says:

    Good job, Tnks, owner.
    Boots travel insurance information:
    boots travel insurance

  89. BootsTravelInsuranceves Says:

    Amazing job, Respect, admin!
    Boots travel insurance information:
    boots travel insurance

  90. Pirelli-Tires-pa Says:

    Beautiful work, Tnks, owner.
    Pirelli tires
    Pirelli scorpion tires

  91. expado Says:

    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

  92. Pirelli-Tires-pa Says:

    Good design. Tnks, webmaster!
    Pirelli scorpion tires
    Pirelli motorcycle tires

  93. Pirelli-Tires-pa Says:

    Excellent job, Thanks, webmaster!
    Pirelli motorcycle tires
    Pirelli tires

  94. Pirelli-Tires-pa Says:

    Beautiful work, Tnks, admin.
    Pirelli tires
    Pirelli tires

  95. Pirelli-Tires-pa Says:

    Amazing work. Thanks owner!
    Pirelli scooter tires
    Pirelli scooter tires

  96. Coloflus Says:

    Beautiful site! Tnks webmaster!

  97. whingeli Says:

    Beautiful site! Respect, owner!

  98. whingeli Says:

    Nice site, Respect, admin.

  99. whingeli Says:

    Beautiful work, Tnks, admin.

  100. whingeli Says:

    Amazing site, Respect, admin.

  101. Gadyarida Says:

    скачать порно видео ролики

  102. http://thinkpennystocks.info/stock-chat-room.html Says:

    http://thinkpennystocks.info/stock-chat-room.html...

    investment terms…

  103. http://www.superpennystocks.info/free-analyst-stock-reports.html Says:

    http://www.superpennystocks.info/free-analyst-stock-reports.html...

    where can i check the stock market…

  104. arimaccurdy Says:

    click me

  105. http://thinkpennystocks.info/russian-rouble.html Says:

    http://thinkpennystocks.info/russian-rouble.html...

    nasdaq chart history…

  106. http://www.stockpicktime.info/fun-facts-about-the-stock-market.html Says:

    http://www.stockpicktime.info/fun-facts-about-the-stock-market.html...

    where can i find a list of stocks…

  107. teelmQuottced Says:

    buy zyban

  108. NikkyBlond Says:

    Excellent time. And nice site. Keep up a good work! :-))

  109. NikkyBlond Says:

    Enjoyed your site very much! Thank you! Keep up a good work! :-))

  110. Shooter The Movie Says:

    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.

  111. JessicaLynn Says:

    I’ll bookmark your site! :-)) Keep up a good work! :-))

  112. JessicaLynn Says:

    ! :-)) Keep up a good work!

  113. JessicaLynn Says:

    Perfect time. And nice site! :-)) Keep up a good work!

  114. Casino 491c7a1062 Says:

    Casino 491c7a1062…

    Casino 491c7a1062…

  115. votsstooseMoF Says:

    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

  116. votsstooseMoF Says:

    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

  117. LesMontgomeery Says:

    Perfect project. Keep it up!

  118. VatboalersVab Says:

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

  119. Free Adult Friend Finder Says:

    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…

  120. Vardenafil Says:

    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!

Leave a Reply