A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: using Lives??

  1. #1
    Senior Member
    Join Date
    May 2006
    Posts
    119

    using Lives??

    Im trying to make a "quiz game" where you have 3 lives ( a life = a wrong answer) but being a newbie I'm not sure how I can decrease the lives then send the user to a game over screen when all lives are lost.

    could anyone out there lend a hand?

    Thank you

    Mark

  2. #2
    M.D. mr_malee's Avatar
    Join Date
    Dec 2002
    Location
    Shelter
    Posts
    4,139
    code:

    //inital starting lives
    var lives = 3;
    //answers
    var answer = 10;
    var correctAnswer = 20;
    //check answer
    function checkAnswer(a, c) {
    //add checking functions here
    return a == c ? 0 : 1;
    }
    //temporray code to check answer
    onMouseDown = function () {
    lives -= checkAnswer(answer, correctAnswer);
    //check if lives are less or equal than 0,
    //if so delete this function and goto the frame labeled "game over"
    if (lives<=0) {
    delete onMouseDown;
    gotoAndStop("game over");
    }
    };

    lather yourself up with soap - soap arcade

  3. #3
    Senior Member
    Join Date
    May 2006
    Posts
    119
    I see, Thanks, but is you dont mind I would like to explain furthur.
    My answers que an animation according to the button you click. at the end of the animation is where score is awarded or lives taken away. Also I would like the lives to be represented by icons, not a number.....

    how would I do this?

  4. #4
    M.D. mr_malee's Avatar
    Join Date
    Dec 2002
    Location
    Shelter
    Posts
    4,139
    on the main timeline add this function:
    code:

    var lives = 3;
    liveIcons.gotoAndStop(lives);
    //
    function checkAnswer(success) {
    if (!success) {
    lives -= 1;
    if (lives<0) {
    gotoAndStop("game over");
    }
    liveIcons.gotoAndStop(lives);
    } else {
    gotoAndStop("congratulations");
    }
    }


    all you need to do is add this to your:

    - bad animations: _root.checkAnswer(false)

    - good animations: _root.checkAnswer(true)

    what thats doing is calling a function which will test for a right and wrong answer by simply using an "if statement", if that statement is true run the contents of that staement. In this case: subract one life and check if all our lives are gone, if all our lives are gone goto the game over screen. Which should be a frame label on your main timeline. Then make our liveIcons movieclip goto the correct frame. If we we're successful goto the "congratulations" frame.

    you can change those frames to whatever you want. You could tell another object to go to a specific frame instead so that you never leave frame 1 on your timeline.

    to show icons create your life icons movieclip. Inside make 3 frames (for 3 lives) on each frame have the correct amount of lives. name that movieclip "liveIcons". The function will make that clip goto the correct frame whenever a life is subracted.

    very simple stuff
    Last edited by mr_malee; 06-20-2006 at 04:51 AM.
    lather yourself up with soap - soap arcade

  5. #5
    Senior Member
    Join Date
    May 2006
    Posts
    119
    Alright! I got it to work! Thanks so much!

  6. #6
    Game Player - Developer scheletro's Avatar
    Join Date
    Mar 2005
    Location
    México living in Barcelona
    Posts
    1,121
    For lives I allways use a MC with the 3 icons and everytime I take a life I tell MC "lives" to move next frame


    "I love to make them as I love to play them"

  7. #7
    Senior Member Gloo pot's Avatar
    Join Date
    Aug 2005
    Location
    Australia Mate!
    Posts
    874
    For lives I allways use a MC with the 3 icons and everytime I take a life I tell MC "lives" to move next frame
    I do it like that but a little more complicated, i usealy animate my lives/hearts to when i loose one it runs the animation and when the animation is down it send it do the next frame.
    92.7 Fresh FM for all your South Aussies - Doof Doof music FTW people!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center