6 Replies Latest reply on Nov 19, 2010 5:19 AM by Ned Murphy

    Adding score to shooting game

    flashhelpplease

      I am looking to have a 'score' funtion added to my shooting game.  I have started to implement the code but am having problems getting it to work.  The score will show at the beginning of the game but then it dissappears when I click one of the ships.  Can anyone help me?  I know this is a noob question but I'm a beginner at Flash


      Here is my flash file.  http://www.megaupload.com/?d=TPPUGS7Q

       

      THANK YOU

        • 1. Re: Adding score to shooting game
          Ned Murphy Adobe Community Professional & MVP

          Not everyone can/will download/open files here.  If you show the code and explain how you implement it in the file you increase the likelihood of getting help.

          • 2. Re: Adding score to shooting game
            flashhelpplease Level 1

            I just don't know where my problem is...so that's why I posted the whole file.  I have ships that fly around, and when you shoot the ships, I want to earn points.  Here is my gun code:

             

            on (press) {

            score = 0;
            mySound = new Sound();
            mySound.attachSound("tng_torpedo_clean.wav");
            mySound.start();
            if (this.hitTest(_root.turkey1)) {
            _root.score++;
            _root.scoreMessage.text = _root.score;
            _root.food1._x = _root.turkey1._x
            _root.food1._y = _root.turkey1._y
            _root.turkey1._x = int(Math.random()* 920) + 40;
            _root.turkey1._y = int(Math.random()* 650) + 60;
            mySound = new Sound();
            mySound.attachSound("largeexplosion2.wav");
            mySound.start();
            } else if (this.hitTest(_root.turkey2)) {
            _root.score += 5;
            _root.scoreMessage.text = _root.score;
            _root.food2._x = _root.turkey2._x
            _root.food2._y = _root.turkey2._y
            _root.turkey2._x = int(Math.random()* 900) + 1100;
            _root.turkey2._y = int(Math.random()* 650) + 60;
            mySound = new Sound();
            mySound.attachSound("largeexplosion2.wav");
            mySound.start();
            } else if (this.hitTest(_root.owl1) or this.hitTest(_root.owl2)) {
            _root.gun._x = -1000;
            _root.gun._x = -1000;
            _root.gotoAndPlay(4);
            }
            }

             

             

            I also have a dynamic text box on the second frame of my action layer with the variable 'score' applied to it.  Do I need to add any code to the ship movie clip itself?  Thank you for your time

            • 3. Re: Adding score to shooting game
              flashhelpplease Level 1

              I can provide any other information that is needed.  Thanks

              • 4. Re: Adding score to shooting game
                Ned Murphy Adobe Community Professional & MVP

                Have you tried using trace() commands to determine if your code is registering the hits or otherwise performing as expected?  How is it that your gun would hit any of those objects, as opposed to whatever projectile the gun is launching?

                1 person found this helpful
                • 5. Re: Adding score to shooting game
                  flashhelpplease Level 1

                  Well I know it's registering the hits because when I hit a target, it falls from the sky...I have never used the trace command before.

                  • 6. Re: Adding score to shooting game
                    Ned Murphy Adobe Community Professional & MVP

                    trace() is a basic tool for designing/troubleshooting that you should learn to use.  It helps you to see the status of things (variables, etc) at different stages of processing.  For instance, in your code you could check to make sure the score value is changing every time you adjust it.

                     

                    trace(_root.score);

                     

                    And if the textfield in frame 2 is the one that is not displaying, do not use the var aspect of that, give the textfield an instance name (tFieldName used here as example) and assigned the score to it using...

                     

                    tFieldName.text = _root.score;

                     

                    and also have a trace(_root.score); if needed to see if the value has scope in that frame.