PDA

View Full Version : Score function



Martendeman
May 15th, 2009, 08:44 AM
Hello All,
I made a little game like brick breaker.
Now i get 20 points for evry brick i break, and there will be 100 points taken when it hits the bottom.
so when i break 2 bricks i have 40 points, but if i lose a ball by hitting the bottom the score is going to be -60.
How do i prevent this wil become a number below 0, so it will go from 40 to 0 in stead of -60.

Many thanks

Charleh
May 15th, 2009, 08:53 AM
After you set it to 40, if it's negative, set it to 0.

e.g.




// points = -100, score = 40
score = score + points;

if(score < 0) {
score = 0;
}

// Points = 0 instead of -40

Martendeman
May 15th, 2009, 09:12 AM
Thanks, that fixed it.
Pretty simple now i see it but many thanks anyway.