diff --git a/semestralka1/src/render/loop.cpp b/semestralka1/src/render/loop.cpp index 410fbe2..31657bb 100644 --- a/semestralka1/src/render/loop.cpp +++ b/semestralka1/src/render/loop.cpp @@ -45,9 +45,20 @@ void render_loop(int speed) { player_state.set_state(PlayerState::Run); - spawn_obstacle(CrawlObstacleType::Crawl1, 40); - obstacle_pool[0].data.y = 8; - obstacle_pool[0].active = true; + { + CrawlObstacleType type = CrawlObstacleType::Crawl1; + int obstacle_width = OBSTACLE_CRAWL1_COLLISION_WIDTH; + + // The obstacle should start just outside right edge, e.g. +10 px + int start_x = VIEW_WIDTH + 10; + int start_y = 8; // vertical position within visible area + + spawn_obstacle(type, start_x); + // override y manually (spawn sets y=10 high by default) + obstacle_pool[0].data.y = start_y; + obstacle_pool[0].active = true; + } + while (!game_over) { tick_counter++; @@ -79,6 +90,16 @@ void render_loop(int speed) { if (animation.tick(speed)) { anim_tick_counter++; + int ground_speed = timing.get_ground_speed(); + for (int i = 0; i < MAX_OBSTACLES; i++) { + if (obstacle_pool[i].active) { + obstacle_pool[i].data.x -= ground_speed; + // deactivate when offscreen + if (obstacle_pool[i].data.x + obstacle_pool[i].data.width < 0) + obstacle_pool[i].active = false; + } + } + need_redraw = true; }