starting outside of the view and bringing that bad boy in

This commit is contained in:
Priec
2025-11-17 19:28:06 +01:00
parent c56dac3b6a
commit 2af725bfe7

View File

@@ -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;
{
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;
}