View Full Version : Extra life every 1000 points
Blackspirit
May 23rd, 2004, 04:27 AM
Hi, long time browser, first time poster
I'm making a pong game, just wondering how to add a life every time you reach 1000 points. Yes, I've used the mod operator, but that doesn't always work....
Say I'm on 999 points, then I hit a block and get 2 points. Thats 1001, and my mod operator doesn't count it.
current if statement to add life:
if(score%1000==0)
anybody got any ideas?
radioxromance
May 23rd, 2004, 04:33 AM
hmm Im lost... why can't it be:
onEnterFrame = function() {
if(score >= 1000) {
life++;
}
}
??
maybe im missing something :P
Adam
May 23rd, 2004, 04:35 AM
I would assume that on entering a frame if the score was greater than 1000...it would keep adding lives, no?
radioxromance
May 23rd, 2004, 04:36 AM
oh good point :P
hmm lemme think...
signifer123
May 23rd, 2004, 04:39 AM
how about
onEnterFrame = function() {
if(score >= 1000) {
life++;
}
}
but with a timer and when the timer reaches 1 it gives you a life point so then it stop giving live after 1 in the timer is past.
Blackspirit
May 23rd, 2004, 04:44 AM
hmm, yes I spose timer could do it. kind of messy though?
hehe, I was thinking of doing it with a temporary variable so..
if(temp<1 && score%1000>=1<SCORE%1000 score%1000 &&> ){
life++;
temp=score%1000;
}
does that sound right?
signifer123
May 23rd, 2004, 04:48 AM
id on't know about temporary variables so wait a sec i'll see what ic an find
Blackspirit
May 23rd, 2004, 04:57 AM
by temporary, i just mean a normal var, but keeps a history of another var.
eg A timer variable that keeps total time, and a variable that keeps the current level time, if you kow what i mean.
signifer123
May 23rd, 2004, 05:13 AM
ohh ithought you meant one that works once then die thats what you need
radioxromance
May 23rd, 2004, 05:14 AM
yah I was thinking same thing. cant think of the way to do it though. maybe try something like this? anotehr possible solution:
instead of checking points, you have accPoints (accumulative Points). Okay so this is sorta the same idea haha. But, this happens:
points = 0;
accPoints = 0;
//points are made, points are made...
points += 10 //blah blah blah
accPoints = accPoints+points //... get it..?
onEnterFrame = function() {
if(points>=1000) {
lives++;
points = 0;
} }
this way, the acc points would be what you display. hope it made sense.
Voetsjoeba
May 23rd, 2004, 05:34 AM
Math.floor(points/1000);
radioxromance
May 23rd, 2004, 05:47 AM
dang it voets, I was all excited that I had answered in a way I thought might work. then you answer with one sentence I don't even understand. Ugh.
signifer123
May 23rd, 2004, 05:52 AM
its ok radio i'm kinda lost too becasue i don't know what the "Math" funcution does
radioxromance
May 23rd, 2004, 05:55 AM
well i know that this basically says:
take points, divide by 1000, then drop it to the next lowest whole integer. math.floor means lower it to whole integer. but for some reason I can't understand what it does for this. Too tired :P
Johnny64
May 23rd, 2004, 06:01 AM
temp = 0;
onEnterFrame = function () {
if (Math.floor(points/1000) != temp) {
life++;
temp = Math.floor(points/1000);
}
};
Problem solved :)
signifer123
May 23rd, 2004, 06:05 AM
yay i wasn't confused by that one
Johnny64
May 23rd, 2004, 06:06 AM
It uses Voets basic idea :sure:
signifer123
May 23rd, 2004, 06:07 AM
iknow but i didn't know how to use it in a funcional action
Blackspirit
May 23rd, 2004, 08:06 PM
Coolies, thanks guys, got it done:
if (Math.floor(tempscore2/50)<Math.floor(score/1000)){
lifes++
_root.tempscore2=score;
}
Many thanks to all, and beers all round
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.