I am making a very simple clicker game, and whenever the user clicks, a ball will fall in the background from the top of the screen to the bottom. I store these falling balls (type FallingBall
, which has an x, y, radius, and speed, which is set to 1.0f by default) in an std::list
. When I iterate over these falling balls to move them, they simply just don't move.
FallingBall move method (returns true if the ball needs to be removed):
bool move(float frameTime) {
pos.y += speed * frameTime;
speed *= 1.98f;
if (pos.y - radius > GetScreenHeight()) {
return true;
}
return false;
}
Instantiating and moving falling balls:
if (IsMouseButtonPressed(0)) {
if (CheckCollisionPointCircle(mousePos, clicker.getPos(), clicker.getRadius())) {
clicker.click();
FallingBall newFallingBall = FallingBall();
newFallingBall.setX(GetRandomValue(newFallingBall.getRadius(), GetScreenWidth() - newFallingBall.getRadius()));
fallingBalls.push_back(newFallingBall);
std::cout << fallingBalls.size() << std::endl;
}
}
for (FallingBall fallingBall : fallingBalls) {
if (fallingBall.move(frameTime)) {
fallingBalls.pop_back();
}
}
The balls are definitely in the list and being instantiated as they appear on screen and the length of the list increments by one every time I click on the clicker. The balls simply just don't move. I assume it has something to do with the way I'm accessing the FallingBall objects?