obstacles comming properly well

This commit is contained in:
Priec
2025-11-17 21:24:10 +01:00
parent 2af725bfe7
commit cf30946c0d
3 changed files with 33 additions and 24 deletions

View File

@@ -45,19 +45,12 @@ void render_loop(int speed) {
player_state.set_state(PlayerState::Run);
{
CrawlObstacleType type = CrawlObstacleType::Crawl1;
int obstacle_width = OBSTACLE_CRAWL1_COLLISION_WIDTH;
CrawlObstacleType type = CrawlObstacleType::Crawl1;
int start_x = VIEW_WIDTH + 10;
spawn_obstacle(type, start_x);
// 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;
}
Timer spawn_timer;
spawn_timer.start();
while (!game_over) {
tick_counter++;
@@ -65,6 +58,16 @@ void render_loop(int speed) {
mover.update_position(player_speed, timing.get_ground_speed());
pos.x = mover.get_position();
if (spawn_timer.elapsed_time() > 2s) {
spawn_timer.reset();
CrawlObstacleType s_type = CrawlObstacleType::Crawl1;
int spawn_x = VIEW_WIDTH;
int idx = spawn_obstacle(s_type, spawn_x);
if (idx >= 0) {
obstacle_pool[idx].active = true;
}
}
need_redraw = false;
UartEvent uart_event = uart.poll();
@@ -112,11 +115,8 @@ void render_loop(int speed) {
draw_character(draw_pos.x, draw_pos.y, frame.movement, frame.frame_index);
for (int i = 0; i < MAX_OBSTACLES; i++) {
if (!obstacle_pool[i].active)
continue;
draw_obstacle(obstacle_pool[i].data.x,
obstacle_pool[i].data.y,
obstacle_pool[i].type);
if (!obstacle_pool[i].active) continue;
draw_obstacle(obstacle_pool[i].data.x, obstacle_pool[i].data.y, obstacle_pool[i].type);
}
if (game_over)