Game score is updating too much
in
Programming Questions
•
6 months ago
I'm making a game involving hit detection. Simply put, when a rectangle controlled by the player hits a circle, the score is supposed to increase by one. However what is happening right now is that instead of the score going from, let's say, 1 to 2 when there's a hit, it goes 1 to 2 to 3 to... 25, etc depending on how long the rectangle is overlapping with the circle.
How can I get it to increase by ONLY 1 each time there's a hit?
Here is my code:
// this function is in my player (rectangle) class
void collision(Object o) {
if (abs(x - o.x) < w/2 + o.w/2 && abs(y - o.y) < h/2 + o.h/2) {
hit = true;
// sb.score is an integer from the scoreboard class, it represents the score
sb.score += 1;
}
else {
hit = false;
}
}
Thanks in advance :)
How can I get it to increase by ONLY 1 each time there's a hit?
Here is my code:
// this function is in my player (rectangle) class
void collision(Object o) {
if (abs(x - o.x) < w/2 + o.w/2 && abs(y - o.y) < h/2 + o.h/2) {
hit = true;
// sb.score is an integer from the scoreboard class, it represents the score
sb.score += 1;
}
else {
hit = false;
}
}
Thanks in advance :)
1