Update the scrolling speed in each update function

This commit is contained in:
brxxh 2025-05-31 00:06:06 +02:00
parent ccd0697ab3
commit c82dcc9081

View file

@ -81,6 +81,8 @@ struct Background {
} }
void update() { void update() {
scrolling_speed *= SCROLLING_SPEED_INC_FACTOR;
for (auto& sprite : sprites) { for (auto& sprite : sprites) {
sprite.pivot.x() -= scrolling_speed; sprite.pivot.x() -= scrolling_speed;
if (sprite.pivot.x() <= -2.0f) { if (sprite.pivot.x() <= -2.0f) {
@ -139,6 +141,8 @@ struct Ground {
} }
void update() { void update() {
scrolling_speed *= SCROLLING_SPEED_INC_FACTOR;
for (auto& sprite : sprites) { for (auto& sprite : sprites) {
sprite.pivot.x() -= scrolling_speed; sprite.pivot.x() -= scrolling_speed;
if (sprite.pivot.x() <= -2.0f) { if (sprite.pivot.x() <= -2.0f) {
@ -252,6 +256,8 @@ struct Rocks {
} }
void update() { void update() {
scrolling_speed *= SCROLLING_SPEED_INC_FACTOR;
top_sprite.pivot.x() -= scrolling_speed; top_sprite.pivot.x() -= scrolling_speed;
bottom_sprite.pivot.x() -= scrolling_speed; bottom_sprite.pivot.x() -= scrolling_speed;
@ -653,18 +659,11 @@ struct App {
} else if (game_state == GameState::Playing) { } else if (game_state == GameState::Playing) {
background.update(); background.update();
ground.update(); ground.update();
rocks1.update(); rocks1.update();
rocks2.update(); rocks2.update();
plane.update(window.keyboard_input()); plane.update(window.keyboard_input());
// @ToDo: Should we really do this here?
background.scrolling_speed *= SCROLLING_SPEED_INC_FACTOR;
ground.scrolling_speed *= SCROLLING_SPEED_INC_FACTOR;
rocks1.scrolling_speed *= SCROLLING_SPEED_INC_FACTOR;
rocks2.scrolling_speed *= SCROLLING_SPEED_INC_FACTOR;
if (plane.aabb.is_colliding_with(rocks1.top_aabb) || if (plane.aabb.is_colliding_with(rocks1.top_aabb) ||
plane.aabb.is_colliding_with(rocks1.bottom_aabb) || plane.aabb.is_colliding_with(rocks1.bottom_aabb) ||
plane.aabb.is_colliding_with(rocks2.top_aabb) || plane.aabb.is_colliding_with(rocks2.top_aabb) ||
@ -693,12 +692,9 @@ struct App {
context.clear(); context.clear();
background.draw(shader); background.draw(shader);
plane.draw(shader); plane.draw(shader);
rocks1.draw(shader); rocks1.draw(shader);
rocks2.draw(shader); rocks2.draw(shader);
ground.draw(shader); ground.draw(shader);
// Kinda dumb that we check the game state here the second time but // Kinda dumb that we check the game state here the second time but