Flash AS3 Left Right Shooter Game

Yes! You can definitely MAKE THIS YOURSELF! Step by step instructions included!

Fair Warning: This SWF plays SOUNDS! Adjust your volume before clicking!

(Want to save some time? Download the above ZIP file and you will get all 10 of the individual fla files from the succeeding web pages. Just for your convenience. Download this now, and you're done!).

This tutorial will show you how to make your own Flash AS3 Left-Right Shooter game! Oh, you gathered that from the title? Okay, so I get redundant sometimes (I looked up redundant in the dictionary, and what do you know? It didn't have any definition, but it was listed twice)!

Note: the files included here for download are in Flash CS4 format. They also include the Cooper Black font. If your system doesn't have Cooper Black, you will get a different font when you compile (test movie). That's just the way it is, but don't be alarmed if your version doesn't look exactly like mine. In fact, go ahead and embed a font from your computer. I won't mind. You do this using the embed button in the properties panel when a certain textfield is selected.

Note: Static textboxes are always embedded. But they must be embedded from a source, and that's important. They ultimately come from the computer of the person doing the compiling. So you will want to change out the static textboxes too, but you won't have to embed any fonts for those. Confusing? You betcha! But this tutorial won't be, I promise.

Grrr...

   I know from experience that there's usually a reason, but I'm just trying ot do the "make a quiz" tutorial from actionscript.org and... it simply doesn't work. I'm not getting the output I told the quizapp.as file to trace.  The first time, I got the warning message about assigning a class, tho' the files are in the very same folder... 

   I guess I should be grateful that it doesn't work from the git-go...  oh... now I see... I figgered I'd go to the end and get the files and see if htey worked and yea, second comment talks about getting a bunch of errors.   Hmmm... there's a link that doesn't work. 

  Okay, another dead end.   I know that with the web, you often get what you pay for it... but I was hoping to be a happy donater, since when I buy stuff I often *don't* get what I pay for it... even the zip file doesn't seem to want to download. I"m thinking there are version conflicts... dratfooey.

Geonz
http://www.resourceroom.net

Jody Hall's picture

Wrong tutorial, dude

geonz,

What does all that have to do with the left-right-shooter game? At least you could have placed your comment on the right tutorial!

Getting errors isn't the end of some kind of road, it's just an indicator that something is wrong and needs to be done differently. You have to have the patience to work through them. I would be glad to help you if you want to send the problem files along to me.

Okay, I"m going back and

Okay, I"m going back and forth here to try to see what I typed.  Thanks for replying! It would be nice to see the whole thread...

As I said in the opening of my comment, this is in response to the 'make a quiz' tutorial.

The tutorial is over at actionscript.org and that site doesn't let me comment (I suppose it will, all in good time, but even after registering, etc. things aren't showing up), and I figured posting to your website would be a more likely way to contact you.  I did a brief search for that same tutorial here, but all I found was what is apparently a follow-up one.  

I know it takes patience to find the little stuff (I'm a good touch typist, but SOmetimes my FIngers GO too FAst ;)) ... I've got a fair amount of that.  However, when that teensy weensy bit of code flunks the "are the two files talking?" test, it makes me reticent to proceed.  The reference to a dead end is that if, as that second comment after the original tutorial would indicate, it is common to get messes of error messages and... oh, the link to explain them doesn't even work... that since I want to learn how to do this, I should find another route, so that I don't look for errors that aren't mine.   Since cutting and pasting the code from the tutorial doesn't yield any better results (tho' other assorted tests along the way did work once I FOund the {assorted} little typos), I suspect the problem is some fundamental noob booboo in spelling QuizApp or getting the buttons into the library or something... (I *do* keep typing QuizQpp...) but the tutorial is from 2008 so there might be version issues, too. 

Again, thanks for your time.  There's an awful lot of positive feedback -- which is especially impressive at the beginner level.

Geonz
http://www.resourceroom.net

Brilliant tutorial

 Brilliant tutorial, Jody. Just what I was looking for.

And, as usual, you make it so easy to follow and understand. You have an excellent way of breaking complicated (to me, anyway) topics down into easily understood chunks.

Keep up the good work. Can't wait for your next one!

jamestagal's picture

Another fantastic tutorial

What a fantastic game Jody,

I will try to modify it to play on my mobile phone and get my son involved in creating the player and enemies. 

Thank you again for letting me know about your newest tutorial and for helping me with my confused modification via email!

I really appreciate the time you spend writing these tutorials and encourage you to continue your brilliant work.

Best wishes,

Ben.

Animating hit test object

Finally a great tutorial with having to use class files. Thanks very much but I have one question, if you were to add animation inside of your spider movie clip and wanted to play it each time the bullet hits the spider, where that code go? I believe it should go in the enemy hit test function but for me that didnt work, I beleive the code would be enemy.gotoAndPlay(2); and than it recycles. How would you do that. Also I am a new user on this website. Nice to meet you and I look foward to more flash tutorials.

Ness

Jody Hall's picture

Animating hit test object (reply)

Ness,

Sorry for the delay in answering this, but this involved getting back into the project, and I don't always have that kind of time.

Yeah, you can add whatever kind of (death) animation you want to the Spider movie clip, then use gotoAndPlay(2) to make it play when the spider is hit. This works, but the problem is that the recycleEnemy function kicks in right away, and moves the enemy to the top of the screen again. The animation no doubt plays, but the user can never see it happen.

So there needs to be a way to delay recycling the enemy until after its animation plays. I accomplished this by putting a line of code on the last frame of the Spider symbol:

dispatchEvent(new Event("done"));

Then I make the main timeline listen for this event as soon as a bullet hits an enemy. I added these lines in the enemiesHitTest function, somewhere around line 133:
spiderArray[i].gotoAndPlay(2);
spiderArray[i].addEventListener("done", spider_onDone);

Then I wrote a spider_onDone handler function, and moved the line that recycles the enemy to the inside of this function. Inside the function, by the way, I can no longer refer to the enemy spider as spiderArray[i] (because I'm not in the function containing that loop anymore), but fortunately I can get a reference to whatever enemy it was using event.currentTarget:

function spider_onDone(event:Event):void {
var spider:MovieClip = event.currentTarget as MovieClip;
recycleEnemy(spider);
}

I found that this all works well, but depending on how long your destruction animation runs, it can cause a couple of other problems. If the enemy is still sitting there, he can possibly be hit again by a second bullet. Also, the player might be in danger of being hit (unfairly) by the spider's destruction animation. I solved both of these situations by creating a dynamic property called wasHit. You can create dynamic properties on MovieClip instances by just using them as though they were already there. So when an enemy is hit, I set its wasHit property to true. Then I created a test for wasHit when the loop first begins. If the enemy was already hit, then bailing out of the loop will prevent it from being hit tested further. Then the wasHit variable is reset to false again in the event handler.

This way no matter how long your death animation or how large the graphical content of it is, it can't hurt the player and it will be impervious to all but the first bullet.

I can pass along this new version to you, if you write to me at mazoonist at gmail dot com (or just use my site's contact form).

Jody

Animated character

Hi,
This is really nice and well thought out coding thank you.
How would you approach adding the ability to animate the character with a few timeline frames
that have "walk Left" / "walk right" / "jump" /"duck" / "stop" animation sections?

The tricky part for me is that these looping sections must NOT receive continuous requests. So once the
player has pressed left arrow, the animation should go to the walk left block and not be spoken to again
until the user changes direction or state? If they receive all the time, the animation effectively "stands still" at
the go to frame request. Seems to get clumsy if you add more booleans but that does work.
eg if the key pressed is left and player is NOT moving left then make him go left and set going left to true!
Works and makes sense but wondering if you have a cleaner solution?

Thanks again for these excellent lessons. Paul

Paul Wright
www.spstudios.co.za

Jody Hall's picture

Try using sub-MovieClips that contain the animation

Paul,

You might create a series of separate MovieClips (one for each of those things you mentioned, like "move right," "move left", etc, and each one being an animation), then create one master MovieClip that has an instance of each of those on its frames. Label the frames. then just use something like gotoAndStop("walkRight") when you get a right arrow keypress. The master movie clip will goto and stop on that frame, but note--that frame contains a sub-MovieClip with an animation that will play continually. This approach seems better to me than managing a bunch of "looping sections" in the master clip.

I didn't have a walk animation on hand to experiment with (shame on me!), or I might have tried to put something together for you. I would love to see what you've done, if you'd care to send it to me at mazoonist at gmail dot com.

Jody