diff --git a/semestralka1/src/assets/obstacle_crawl_frames.h b/semestralka1/src/assets/obstacle_crawl_frames.h index d818847..71d039a 100644 --- a/semestralka1/src/assets/obstacle_crawl_frames.h +++ b/semestralka1/src/assets/obstacle_crawl_frames.h @@ -4,16 +4,24 @@ // Crawl obstacle for CRAWL1 (2 lines tall) static const char *OBSTACLE_CRAWL1_FRAME[] = { + "#######", + "#######", + "#######", + "#######", "#######", "#######" }; // Crawl obstacle for CRAWL2 (4 lines tall) static const char *OBSTACLE_CRAWL2_FRAME[] = { - "########", - "########", - "########", - "########" + "#######", + "#######", + "#######", + "#######", + "#######", + "#######", + "#######", + "#######" }; enum class CrawlObstacleType { Crawl1 = 0, Crawl2, COUNT }; diff --git a/semestralka1/src/game/obstacle_manager.h b/semestralka1/src/game/obstacle_manager.h index 933eb79..747a8e9 100644 --- a/semestralka1/src/game/obstacle_manager.h +++ b/semestralka1/src/game/obstacle_manager.h @@ -15,13 +15,13 @@ constexpr int MAX_OBSTACLES = 6; static MovingObstacle obstacle_pool[MAX_OBSTACLES]; // Create / reset obstacle in one slot -inline void spawn_obstacle(CrawlObstacleType type, int x_start) { +inline int spawn_obstacle(CrawlObstacleType type, int x_start) { for (int i = 0; i < MAX_OBSTACLES; i++) { if (!obstacle_pool[i].active) { obstacle_pool[i].active = true; obstacle_pool[i].type = type; obstacle_pool[i].data.x = x_start; - obstacle_pool[i].data.y = 10; // hangs from ceiling + obstacle_pool[i].data.y = 0; if (type == CrawlObstacleType::Crawl1) { obstacle_pool[i].data.width = OBSTACLE_CRAWL1_COLLISION_WIDTH; obstacle_pool[i].data.height = OBSTACLE_CRAWL1_COLLISION_HEIGHT; @@ -29,9 +29,10 @@ inline void spawn_obstacle(CrawlObstacleType type, int x_start) { obstacle_pool[i].data.width = OBSTACLE_CRAWL2_COLLISION_WIDTH; obstacle_pool[i].data.height = OBSTACLE_CRAWL2_COLLISION_HEIGHT; } - break; + return i; } } + return -1; } // Update X positions; mark inactive if offscreen diff --git a/semestralka1/src/render/loop.cpp b/semestralka1/src/render/loop.cpp index 31657bb..5c2d079 100644 --- a/semestralka1/src/render/loop.cpp +++ b/semestralka1/src/render/loop.cpp @@ -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)