4 Replies Latest reply on Dec 3, 2007 6:55 PM by newbieian

    **Need Help with Basic Shooter Game!**

    newbieian
      I am making a Sniping game with Flash MX 2004 and I am having two problems. The first is concerning reloading your rifle and the display of your ammo. I am trying to have it so that when you click and fire a bullet from the six on your screen, one will disappear and continue to the point when none are left and you must click shift to reload it. However sometimes the display of the bullets is wacky, sometimes the bullets don't disappear, sometimes you can still shoot when out of ammo, and more. It worked earlier but doesn't work anymore.

      The second problem is that I want to have multiple enemies on stage that you can kill. I had code that when you clicked on the enemies they would fall down and die while the others remained unaffected, yet it doesn't work now either. I also don't know where the code for the soldiers as well as the code for the ammo goes. Does it go on the button, frame, etc.?

      Here it is:

      This code is on the button for the first soldier which is inside a separate movie clip of that soldier.
      onRelease = function () {
      if (_currentframe == 1 && _root.ammo.checkAmmo()) {
      play();
      }
      };

      Here is the code for the ammo, it is on the first frame on the ammo layer.

      bullets = [];
      function up() {
      if (bullets.length<6) {
      n = "a"+random(10000);
      duplicateMovieClip(original, n, this.getNextHighestDepth());
      bullets.push(this[n]);
      created = this[n];
      created._x = bullets.length*20;
      created._y = 20;
      }
      }
      function down() {
      if (bullets.length>0) {
      bullets.pop().removeMovieClip();
      }
      }
      function checkAmmo() {
      return bullets.length>=0;
      }
      function reload() {
      for (i=0; i<6; i++) {
      up();
      }
      }
      reload();
      original._visible = false;

      obj = new Object();
      Key.addListener(obj);
      obj.onKeyDown = function(){
      if (Key.isDown(Key.SHIFT)){
      reload();
      }
      }


      At the moment one bullet is displayed instead of six, and it doesn't disappear upon shooting. The soldier doesn't respond at all upon shooting him either.

      P.S. Am I working with Actionscript 2.0? I think I am, but I wanted to be sure. Btw, if you couldn't tell already I am not very good with Actionscript.

      Thanks in advance,

      Newbieian
        • 1. Re: **Need Help with Basic Shooter Game!**
          chopTheWood Level 1
          I can't answer your specific questions but might be able to give you some direction. It sounds like you could use a good reference book on basic Actionscript which also includes gaming techniques. I just happen to have a good one to recommend. It's Understanding Macromedia Flash 8 , Actonscript 2 (Rapo/Michael). I know you have MX but it may be most useful anyway. Chapters 17-20 focus on game building.
          Sorry I can't offer more immediate help.
          • 2. Re: **Need Help with Basic Shooter Game!**
            scicluna252
            Hey, what I usually do to simulate ammo and reloading, is to use a variable that holds how many bullets there are, and ach time you shoot or click on a character, minus that variable by 1. The code i for a simple game that has 6 bullet move clips, each with an instance name of bullet1 through 6, a gun movie clip with a reloading animation in it, and when a button that when it is pressed your ammo decreases.
            So you can start by clicking on the main frame and having the following code on the frame:

            //Make this number the number of bullets you have
            _root.ammo = 6;

            On the button you'd put
            on(release){
            _root.ammo -= 1;
            }

            Then on bullet 6 of 1 you could have:

            onClipEvent(enterFrame){
            if(_root.ammo == 6){
            this._visible = true;
            _root.bullet5._visible = true;
            _root.bullet4._visible = true;
            _root.bullet3._visible = true;
            _root.bullet2._visible = true;
            _root.bullet1._visible = true;
            }
            }

            And om bullet 5

            onClipEvent(enterFrame){
            if(_root.ammo == 5){
            this._visible = true;
            //Notice how bullet six is now invisible, because a shot was fired.
            _root.bullet6._visible = false;
            _root.bullet4._visible = true;
            _root.bullet3._visible = true;
            _root.bullet2._visible = true;
            _root.bullet1._visible = true;
            }
            }

            And on bullet 4

            onClipEvent(enterFrame){
            if(_root.ammo == 4){
            this._visible = true;
            //Now notice how 5 and 6 are invisible, because we have now fired two rounds.
            _root.bullet6._visible = false;
            _root.bullet5._visible = false;
            _root.bullet3._visible = true;
            _root.bullet2._visible = true;
            _root.bullet1._visible = true;
            }
            }

            Well you get the basic idea, just follow the pattern and repeat until you get _root.ammo == 0; then all of them will be invisible.


            Ok, now onto the gun.
            Have this code:

            onClipEvent(enterFrame){
            //If you are out of ammo.....
            if(_root.ammo == 0){
            //Go to the reloading animation
            this.gotoAndPlay("reloading");
            //Put the ammo back to 6
            _root.ammo = 6;
            }
            }

            Hope this helps!
            -Joseph
            • 3. Re: **Need Help with Basic Shooter Game!**
              newbieian Level 1
              Thx the ammo works now, but my enemies don't respond when shot no matter what. I am not sure if the new ammo code somehow affects it. Can I email someone my flash and they look at it or could someone atleast give me the code necessary for the enemies?