19 Replies Latest reply on May 9, 2011 12:39 PM by mpeluso386

    Help with flash game

    mpeluso386

      I've recently created a game where a ton of smiley faces run across the   screen and you have to shoot them. I've tried to add a scoring system  to  it so everytime you click and destroy a smiley face the score would  add  and if you miss it subtracts, but my coding doesn't seem to work;  not  to mention I'm not very good at the coding lol. I would also like  to if  you miss enough faces you lose the game; how would I go about  doing so?  Here is my coding so far:

      onClipEvent (load) {
      startDrag(this, true);
      Mouse.hide();
      this.swapDepths(9999);


      }
      onClipEvent(mouseDown)
      {
      playsounds = new Sound(this);
      playsounds.attachSound("shot");
      playsounds.start(0, 1);
      for(i=1;i<=5;i++)
      {
      if(this.hitTest(_root["face"+i])&&_root["face"+i].dead==0)
      {
      _root["face"+i].gotoAndPlay(2);
      _root.score+=10;
      }
      }
      }

      It was made in an upper version of CS4 and I used AS2. Please and thanks ahead of time, I hope to get some help.

        • 1. Re: Help with flash game
          Ned Murphy Adobe Community Professional & MVP

          Aside from not having done anything to subtract for misses, what is not working?

          • 2. Re: Help with flash game
            mpeluso386 Level 1

            When I actually hit the face it doesn't add to the score, and how would I code it for a miss? Like I said before my knowledge in flash is very limited.

            • 3. Re: Help with flash game
              Ned Murphy Adobe Community Professional & MVP

              It will adjust the score variable as is, so how are you trying to see it change?  Your code isn't doing anything to display it.  If you are using a textfield with a variable assigned to it for the score.... don't.  Assign the score variable to the timeline and assign an instance name to the textfield and assign the score value to its text property.

               

              Here's one way to code for adding/subtracting to the score (not for displaying it)....

               

              onClipEvent (load) {
                  startDrag(this, true);
                  Mouse.hide();
                  this.swapDepths(9999);
              }

               

              onClipEvent(mouseDown)
              {
                  playsounds = new Sound(this);
                  playsounds.attachSound("shot");
                  playsounds.start(0, 1);
                  var scoreValue = -10; // assume it's a miss
                  for(i=1;i<=5;i++)
                  {
                     if(this.hitTest(_root["face"+i])&&_root["face"+i].dead==0)
                     {
                        _root["face"+i].gotoAndPlay(2);
                        scoreValue = 10;
                        break;
                     }
                  }
                  _root.score+=scoreValue;
                  trace(_root.score);
              }

              1 person found this helpful
              • 4. Re: Help with flash game
                mpeluso386 Level 1

                That definitely help out, the score add/subtracts but it doesn't show it up on the score in the actually game, just in the flash program. How would I assign it to the timeline and all that? I don't really understand how to do that quite yet.

                • 5. Re: Help with flash game
                  Ned Murphy Adobe Community Professional & MVP

                  You have yet to mention how the score is supposed to be showing up in the game.  Explain what you have.

                  • 6. Re: Help with flash game
                    mpeluso386 Level 1

                    I have a text option I put within the game frame that displays (Score: 0) so when I hit a face I would like that to go either to 10 or -10 depending on a hit or miss. Also, if you miss enough faces like 5 or something I would like the game to come to an end to jump to like a game over screen or something like that.

                    • 7. Re: Help with flash game
                      Ned Murphy Adobe Community Professional & MVP

                      What is a text option?

                      • 8. Re: Help with flash game
                        mpeluso386 Level 1

                        I mean the option of text on the right hand side and you make a text box and inside that text box I have (Score:0). I could post the fla or swf for you, maybe that way you could look at it and get a better visual of what I'm trying to say.

                        • 9. Re: Help with flash game
                          Ned Murphy Adobe Community Professional & MVP

                          No, if you just say you added a textfield, that's a better explanation... just make sure it's a Dynamic textfield, not Static or Input.  In the timeline add a layer for actions and in the first frame add a variable named score as follows...

                           

                               var score = 0;

                           

                          Select the textfield and in the properties panel assign it an instance name (where it says <Instance Name>)  name it "scoreTxt"

                           

                          Replace the trace(_root.score); line I provided with the following...

                           

                              _root.scoreTxt.text = "Score: "+_root.score;

                          • 10. Re: Help with flash game
                            mpeluso386 Level 1

                            I replaced the line with the new one you provided me and it still doesn't seem to work, and it doesn't show up in output on the flash program anymore. Annd sometimes when enough faces are shot the score will come up at Score: 00 or even Score: 000. I also put a newl layer and inside the first frame I put the code var score = o; maybe I did something wrong in the crosshair coding here it is again:

                             

                            onClipEvent (load) {
                                startDrag(this, true);
                                Mouse.hide();
                                this.swapDepths(9999);
                            }

                             

                             

                             

                            onClipEvent(mouseDown)
                            {
                                playsounds = new Sound(this);
                                playsounds.attachSound("shot");
                                playsounds.start(0, 1);
                                var scoreValue = -10; // assume it's a miss
                                for(i=1;i<=5;i++)
                                {
                                   if(this.hitTest(_root["face"+i])&&_root["face"+i].dead==0)
                                   {
                                      _root["face"+i].gotoAndPlay(2);
                                      scoreValue = 10;
                                      break;
                                   }
                                }
                                _root.score+=scoreValue;
                                _root.scoreTxt.text = "Score: "+_root.score;
                            }

                             

                            Sorry to bother you so much lmao, I'm just trying to get a little bit better at this flash program and all. Thanks again for the time and patience you spent with me

                            • 11. Re: Help with flash game
                              Ned Murphy Adobe Community Professional & MVP

                              What did you do regarding the textfield?

                              • 12. Re: Help with flash game
                                mpeluso386 Level 1

                                It's dynamic text with classic text. And for the instance name I have it set up as scoreTxt. And it says Score: 0 inside the game frame.

                                • 13. Re: Help with flash game
                                  Ned Murphy Adobe Community Professional & MVP

                                  Put the trace line back in that I had you replace with the textfield code, but leave the textfield code as well.  If the output still shows the score value changing properly, then you have done something wrong with setting up the textfield.

                                  • 14. Re: Help with flash game
                                    mpeluso386 Level 1

                                    Thanks a lot I got it to work. How would I go about making the game end if the user misses like 5 times?

                                    • 15. Re: Help with flash game
                                      Ned Murphy Adobe Community Professional & MVP

                                      What you do to end the game is up to you.

                                      • 16. Re: Help with flash game
                                        mpeluso386 Level 1

                                        Yeah, I would like for the game to end after the player misses a face 5 times. I'll try a few things but I'm pretty sure I'll be back for help lol

                                        • 17. Re: Help with flash game
                                          mpeluso386 Level 1

                                          After I miss 5 faces how would I jump from a game ending frame?

                                           

                                          if(this.hitTest(_root["face"+i])&&_root["face"+i].miss=5)    is my code

                                          • 18. Re: Help with flash game
                                            Ned Murphy Adobe Community Professional & MVP

                                            In a conditional you need to use ==, not =

                                            • 19. Re: Help with flash game
                                              mpeluso386 Level 1

                                              After the crosshair has missed a number of 5 faces, how would I set it up so that the game jumps to my ending screen. I have it as my keyframe 4. How would the coding look?