Page 1 of 2 12 LastLast
Results 1 to 15 of 19

Thread: Extra life every 1000 points

  1. #1
    364
    posts
    Inquisitorial Boot

    Extra life every 1000 points

    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?

  2. #2
    hmm Im lost... why can't it be:

    Code:
    onEnterFrame = function() {
     if(score >= 1000) {
      life++;
    }
    }
    ??
    maybe im missing something

    :. Kirupa Nintendo Cult Member 14 .:
    tetris: 3rd place, 4190 @ 5:32pm Aug 9 in 689 secs

  3. #3
    Adam's Avatar
    2,715
    posts
    RIP Adam14 Dec03 - Aug08
    I would assume that on entering a frame if the score was greater than 1000...it would keep adding lives, no?

  4. #4
    oh good point
    hmm lemme think...

    :. Kirupa Nintendo Cult Member 14 .:
    tetris: 3rd place, 4190 @ 5:32pm Aug 9 in 689 secs

  5. 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.
    Skype Me?
    hitTest on my system does 4250 hitTests in 1/12 of a second.

  6. #6
    364
    posts
    Inquisitorial Boot
    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?

  7. id on't know about temporary variables so wait a sec i'll see what ic an find
    Skype Me?
    hitTest on my system does 4250 hitTests in 1/12 of a second.

  8. #8
    364
    posts
    Inquisitorial Boot
    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.

  9. ohh ithought you meant one that works once then die thats what you need
    Skype Me?
    hitTest on my system does 4250 hitTests in 1/12 of a second.

  10. #10
    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:

    Code:
    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.

    :. Kirupa Nintendo Cult Member 14 .:
    tetris: 3rd place, 4190 @ 5:32pm Aug 9 in 689 secs

  11. #11
    Code:
    Math.floor(points/1000);
    Wait, what?

  12. #12
    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.

    :. Kirupa Nintendo Cult Member 14 .:
    tetris: 3rd place, 4190 @ 5:32pm Aug 9 in 689 secs

  13. its ok radio i'm kinda lost too becasue i don't know what the "Math" funcution does
    Skype Me?
    hitTest on my system does 4250 hitTests in 1/12 of a second.

  14. #14
    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

    :. Kirupa Nintendo Cult Member 14 .:
    tetris: 3rd place, 4190 @ 5:32pm Aug 9 in 689 secs

  15. #15
    Code:
       temp = 0;
       onEnterFrame = function () {	
       	if (Math.floor(points/1000) != temp) {
       		life++;
       		temp = Math.floor(points/1000);
       	}
       };
    Problem solved

    .....

Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012