|
-
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
-
M.D.
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");
}
};
-
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?
-
M.D.
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.
-
Alright! I got it to work! Thanks so much!
-
Game Player - Developer
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"
-
Senior Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|