3 Replies Latest reply on Jul 8, 2006 6:32 PM by DarkVortex

    Shooting

    DarkVortex Level 1
      im making a space invaders type game and i need help with the shooting.im using the mouse to move and im making the spacebar to shoot but what kkeps happening is if you press space it shoots. but if you press it again before the tween ends it shoots again. i was going to do variables but i dont know how. here is my code so far:

      onClipEvent (load) {
      _x = 0;
      speed = 5;
      }
      onClipEvent (enterFrame) {
      endX = _root._xmouse;
      _x += (endX-_x)/speed;
      }
      on (keyPress"<space>") {
      gotoAndPlay(2);
      }




      this is all in the ship mc
        • 1. Re: Shooting
          Level 7
          >>im making a space invaders type game

          >>i was going to do variables but i dont know how


          Sorry to say this, but you're not going to be able to make space invaders
          without knowing how to use variables. Right, the way you have your code it's
          just not going to work properly.

          Here's a little bullet sample for you. Mind you this isn't the only, or best
          way to do this, but it should give you a little understanding of how things
          can better be structured.

          Make a new Flash movie.
          Create a small circle on the stage. Select it and turn it into a MovieClip.
          Delete it from the stage. Right-click it in the Library and select
          Linkage... from the context menu
          Click Export for ActionScript and in the Identifier field enter: bullet
          Close the dialog.
          Select frame one and then paste in this code:

          var bulletNumber = 0;
          var keyListener:Object = new Object();
          keyListener.onKeyDown = function(){
          if(Key.getCode() == Key.SPACE){
          var ref = attachMovie("bullet","bullet" + bulletNumber,
          _root.getNextHighestDepth(), {_x:275, _y:400});
          bulletNumber++;
          ref.onEnterFrame = function(){
          this._y -= 5;
          if(this._y < -10){
          removeMovieClip(this);
          }
          }
          }
          }
          Key.addListener(keyListener);
          stop();


          What this does is attach a new instance of the bullet clip each time you
          press the space bar. The variable bulletNumber is used to give each instance
          a unique name - "bullet0", "bullet1"... etc. and it's incremented each time
          you press space by the bulletNumber++; line. As each bullet is attached it
          is given its own enterFrame function which does nothing more than decrement
          the _y property of the clip, until it's less than -10 - in other words off
          the top of the screen. When that happens the clip is removed... In this
          manner you can press space as many times as you like and more bullets will
          be created, and then destroyed automatically.

          HTH


          --
          Dave -
          Adobe Community Expert
          www.blurredistinction.com
          http://www.adobe.com/communities/experts/


          • 2. Shooting
            DarkVortex Level 1
            Ok cool, but how do i make the bullets faster and look like they are coming from the ship.
            • 3. Re: Shooting
              DarkVortex Level 1
              why will no one help me!? i need help, fast.