# Shooting in a game-megaman style

**URL:** <https://forum.kirupa.com/t/shooting-in-a-game-megaman-style/2797>\
**Category:** Uncategorized\
**Created:** [April 5, 2002, 3:20am UTC](https://forum.kirupa.com/t/shooting-in-a-game-megaman-style/2797 "2002-04-05T03:20:32Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 5, 2002, 3:20am UTC](https://forum.kirupa.com/t/shooting-in-a-game-megaman-style/2797/1 "2002-04-05T03:20:32Z")

</div>

Ok I am creating a 2d game similar to the original mega mans and mario for nintendo. The character moves back and forth using the left and right arrow keys on the screen and has a walk animation and all. The next step is to get him to shoot his laser gun. I want this to be done using the space bar key. What I have right now is identical to Kirupa’s movement using X and Y values tutorial but it only moves one direction of course. How can I make it so that it will continue to move automatically after pressing space instead of having to hit the space bar each time I want it to move 10 units over etc.?\r\rThis is probably a simple question but I am new to flash. Most of my experience is in VB and C++ 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 5, 2002, 4:57am UTC](https://forum.kirupa.com/t/shooting-in-a-game-megaman-style/2797/2 "2002-04-05T04:57:48Z")

</div>

this is pretty simple to do, however, i’m a moron, and I can explain it. \r\r\rthe code on your button should look like this::\r\<font color=blue\>\ron (keyPress “\<Right\>”) {\r \_root.person.\_x = \_root.person.\_x+5;\r}\ron (keyPress “\<Left\>”) {\r \_root.person.\_x = \_root.person.\_x-5;\r}\ron (keyPress “\<Space\>”) {\r\_root.bullet.gotoAndPlay(2)\r}\</font\>\r\r_person is the person, and bullet is the thing you are going to be shooting_\r\rBullet is the name of the MC. Bullet has to have two frames, with a “stop()” action in each frame. however, the frist frame must be empty. and the second frame will hold what you actually want to move across the screen. (the object in the second frame **must** also be a movie clip)\r\ron the main stage, select the movieclip “bullet” which should just be a small white circle because it has nothing in the first frame. and put this code on it.\r\<font color=blue\>\ronClipEvent(enterFrame){\r\_x = \_root.person.\_x\r\_y = \_root.person.\_y\r}\</font\>\r\rthen on the MovieClip in the second frame of “bullet” put this code\r\<font color=blue\>\ronClipEvent (load){\rxVel = 6\r}\ronClipEvent (enterFrame){\r\_x += xVel\r}\</font\>\r\rthis is what it looks like::\r\r\<embed src=“[http://www.angelfire.com/dc/vidgame/game/Movie2.swf](http://www.angelfire.com/dc/vidgame/game/Movie2.swf)” height=200 width=200\>\</embed\>\r\rif you have any other questions post.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 5, 2002, 5:43am UTC](https://forum.kirupa.com/t/shooting-in-a-game-megaman-style/2797/3 "2002-04-05T05:43:02Z")

</div>

[jeremydecker.s5.com/shots\_fired.swf\r[url=“http://jeremydecker.s5.com/shots\_fired.fla”]jeremydecker.s5.com/shots\_fired.fla](http://jeremydecker.s5.com/shots_fired.swf)\r\rhere’s a sample file.\r:) \rjeremy

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 5, 2002, 11:34am UTC](https://forum.kirupa.com/t/shooting-in-a-game-megaman-style/2797/4 "2002-04-05T11:34:30Z")

</div>

Very nice Jubby. Great design. I really don’t understand how you could mke fun of my dragoon…\rBy the way, you should really learn to use the duplicate movie clip function.\r\rpom 0]

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 5, 2002, 12:42pm UTC](https://forum.kirupa.com/t/shooting-in-a-game-megaman-style/2797/5 "2002-04-05T12:42:12Z")

</div>

you like that design? i like it too. I was too dam lazy to draw anything else. yeah i keep forgetting to use duplicateMovieClip. I have a basic understand, but i should work on it a little more.\r\rVery nice Sinf, everything is much easier if you know all the actionscript. Whats this line?\r\rthis.attachMovie(“mcShot”,“mcShot”+nCount++,nCount);\r\rwhere do you define nCount? why do you have two + after the first nCount? and where is mcShot, i coudln’t find it on ?any stage. So how do you attach it?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 5, 2002, 3:53pm UTC](https://forum.kirupa.com/t/shooting-in-a-game-megaman-style/2797/6 "2002-04-05T15:53:34Z")

</div>

this.attachMovie(“mcShot”,“mcShot”+nCount++,nCount);\r\r’nCount++’ means to add 1 to the variable ‘nCount’. since it’s undeclared it has no value. adding 1 to it basically declares it as 1. from that point on it just increments.\rtry this:\rtrace(typeof(nCount++));\rtrace(typeof(nCount));\rit will return ‘undefined’ in the first line and ‘number’ in the second.\rnow, to use attach movie you just go into the library and right click on the movie clip and select ‘linkage’ in the menu that pops up select ‘export this symbol’ and give it a name. that name is just like to put an instance on the stage and gave it a name, except you don’t have to worry about an extra movie clip on the stage!\r:) \rjeremy

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 5, 2002, 4:15pm UTC](https://forum.kirupa.com/t/shooting-in-a-game-megaman-style/2797/7 "2002-04-05T16:15:16Z")

</div>

thanks for the explanation sinf

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 7, 2002, 4:47pm UTC](https://forum.kirupa.com/t/shooting-in-a-game-megaman-style/2797/8 "2002-04-07T16:47:34Z")

</div>

Thanks a ton for the help to both of you. He now moves and shoots lasers that come from the gun and move on their own. I tried using that duplicate movie clip but I can’t get it to work for the life of me. In something like VB or C++ I’d just create an array for the object that is the laser and make a new instance of the laser each time, but this doesn’t seem to be the case with flash. I went to linkage under the laser movie clip and named it “laser” but where would I put the attach movie clip line? My code is generally similar to Jubba’s in structure with several things added in. Thanks again you guys are great.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 7, 2002, 5:13pm UTC](https://forum.kirupa.com/t/shooting-in-a-game-megaman-style/2797/9 "2002-04-07T17:13:16Z")

</div>

you can create an array that stores references to all the ‘laser’ objects. but that’s another topic.\ranyways, you would put your attachmovie code wherever you have the code for your controls. just make sure that you attach the movie to the \_root and not a clip that moves on it’s own.\rso, instead of…\rthis.attachMovie(“mcShot”,“mcShot”+nCount++,nCount);\ryou would use…\r\_root.attachMovie(“mcShot”,“mcShot”+nCount++,nCount);\r\r:) \rjeremy

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 7, 2002, 9:26pm UTC](https://forum.kirupa.com/t/shooting-in-a-game-megaman-style/2797/10 "2002-04-07T21:26:19Z")

</div>

ok I got that all working. He moves, walks, shoots and now there is an enemy that comes at him. My next problem lies in the hit test function so the enemy can be shot. I read just about every hit test tutorial on the web and I am having trouble applying it to my game. I completely reworked my code today so it more resemble’s Sinf’s and can fire multiple shots. I put the hit test on the MC for the enemy and need to input the name of the instance of the laser to check to see if it hit it. My laser MC is called mcLaser right now. I have the line of code…\r\r\_root.attachMovie(“mcLaser”,“mcLaser”+nCount++,nCount);\r\rfrom Sinf. this looks like it refers to the movie clip, then creates a new instance of it with a number after the name, incrementing by one. My problem is when I do the hit test it looks like…\r\rif (\_root.badguy, hitTest(\_root.mcLaser+nCount++)) {\r z=\_root.bh+500;\r \_root.badguy.\_x=z;\r}\r\rThis code is in the enemy movie clip. bh is the x coord of badguy, which is the instance of the movie clip containing the enemy. So this should blow the enemy backward 500 units, but it doesn’t. Here is my .fla because its getting a little too complex to explain now.\r\r[members.cox.net/jaedan/flash/game.fla\r[url=“http://members.cox.net/jaedan/flash/game.swf”]members.cox.net/jaedan/flash/game.swf](http://members.cox.net/jaedan/flash/game.fla)\r\r\rP.S. Good idea to use counterstrike sounds 😛

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 7, 2002, 10:27pm UTC](https://forum.kirupa.com/t/shooting-in-a-game-megaman-style/2797/11 "2002-04-07T22:27:43Z")

</div>

here’s the problem with that code…\rwhere it says ‘nCount++’ that means that you are incrementing ‘nCount’ again and you only want to do that when you attach the movie.\rif there is only one bullet on the screen at a time, do this:\rif(\_root[“mcLaser”+nCount].hitTest(\_root.badguy)){\r// fun things happen here…\r}\r\rif you have many bullets there is a different way to handle that - but it looks like just the one so i won’t go into that can of worms just yet!\r:) \rjeremy

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 7, 2002, 11:17pm UTC](https://forum.kirupa.com/t/shooting-in-a-game-megaman-style/2797/12 "2002-04-07T23:17:53Z")

</div>

I see what you mean with the nCount++ thing, that was an oversight by me, but I did replace my hit test code with yours and played with it and it still doesn’t work ☹

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 9, 2002, 3:16am UTC](https://forum.kirupa.com/t/shooting-in-a-game-megaman-style/2797/13 "2002-04-09T03:16:22Z")

</div>

ok, here’s a sample game. something i started and didn’t finish, but it has all the components of what you are trying to do. the shots go up instead of left/right.\r[jeremydecker.s5.com/Cheese\_Game.swf\r[url=“http://jeremydecker.s5.com/Cheese\_Game.fla”]jeremydecker.s5.com/Cheese\_Game.fla](http://jeremydecker.s5.com/Cheese_Game.swf)\r\r:) \rjeremy
