1
Graphics / [solved]Collision counter, count increses 1 time per collision
« on: January 09, 2015, 01:35:45 pm »
Hello fellas!
I'm woundering how can I make a collision counter that only increses 1 time per collision. I want to know how to get around the game loop because everytime I hit an object the counter looks like this
All the spam is ofcourse the game loop but how can I controll it to only increse one time, I've been tring to use a bool.
game.cpp
Regards Stolle
I'm woundering how can I make a collision counter that only increses 1 time per collision. I want to know how to get around the game loop because everytime I hit an object the counter looks like this
0
110
110
110
110
220
220
220
330
...
110
110
110
110
220
220
220
330
...
All the spam is ofcourse the game loop but how can I controll it to only increse one time, I've been tring to use a bool.
game.cpp
cout << handler.showHighScore() << endl;
handler.update();
window.draw(handler);
window.display();
show functionhandler.update();
window.draw(handler);
window.display();
int gameHandler::showHighScore()
{
if (this->collided == true)
{
this->collided = false;
this->score.addScore();
}
return this->score.showHighScore();
}
When the collision is true I'm setting a bool to not increse the score any more THE COLLISION FUNCTION IS CALLED IN THE UPDATE FUNCTION{
if (this->collided == true)
{
this->collided = false;
this->score.addScore();
}
return this->score.showHighScore();
}
bool gameHandler::collisionCoin(Obstacle &o)
{
if (player.getSprite().getGlobalBounds().intersects(o.getSprite().getGlobalBounds()))
{
this->show = false;
this->collided = true;
return true;
}
return false;
}
{
if (player.getSprite().getGlobalBounds().intersects(o.getSprite().getGlobalBounds()))
{
this->show = false;
this->collided = true;
return true;
}
return false;
}
Regards Stolle