diff --git a/semestralka1/src/game/animation.h b/semestralka1/src/game/animation.h index c775fdd..f9f3a50 100644 --- a/semestralka1/src/game/animation.h +++ b/semestralka1/src/game/animation.h @@ -14,7 +14,5 @@ public: // Update animation, returns true if redraw needed bool tick(int speed); - - // Getters int get_shift() const { return shift; } }; diff --git a/semestralka1/src/game/collision.h b/semestralka1/src/game/collision.h index a35cd56..e047037 100644 --- a/semestralka1/src/game/collision.h +++ b/semestralka1/src/game/collision.h @@ -5,7 +5,6 @@ #include "../assets/character_run_frames.h" #include "../assets/character_crawl_frames.h" -// Obstacle representation struct Obstacle { int x; int y; diff --git a/semestralka1/src/game/game_over.h b/semestralka1/src/game/game_over.h index f1cd0a9..b56bd54 100644 --- a/semestralka1/src/game/game_over.h +++ b/semestralka1/src/game/game_over.h @@ -3,6 +3,6 @@ #include "mbed.h" #include "../hardware/button.h" -// Displays game over message with elapsed time. +// Displays GAME OVER message with elapsed time. // Takes a Timer that was measuring game duration. void show_game_over_screen(int seconds, ButtonHandler& button); diff --git a/semestralka1/src/game/game_state.h b/semestralka1/src/game/game_state.h index c60d65c..f428e2f 100644 --- a/semestralka1/src/game/game_state.h +++ b/semestralka1/src/game/game_state.h @@ -5,7 +5,7 @@ #include "../render/player_positioning.h" #include "../assets/obstacle_crawl_frames.h" -// POZOR Z OBSTACLE MANAGERA +// POZOR JE Z OBSTACLE MANAGERA constexpr int MAX_RENDER_OBSTACLES = 6; struct ObstacleRenderData { @@ -31,6 +31,6 @@ struct GameState { bool need_redraw; }; -// Global shared state and mutex +// Global shared extern GameState g_state; extern Mutex g_state_mutex; diff --git a/semestralka1/src/game/obstacle_manager.h b/semestralka1/src/game/obstacle_manager.h index bf2981d..672cafe 100644 --- a/semestralka1/src/game/obstacle_manager.h +++ b/semestralka1/src/game/obstacle_manager.h @@ -13,7 +13,7 @@ struct MovingObstacle { constexpr int MAX_OBSTACLES = 6; static MovingObstacle obstacle_pool[MAX_OBSTACLES]; -// Create / reset obstacle in one slot +// Create/reset obstacle inline int spawn_obstacle(CrawlObstacleType type, int x_start) { for (int i = 0; i < MAX_OBSTACLES; i++) { if (!obstacle_pool[i].active) { diff --git a/semestralka1/src/game/obstacle_system.h b/semestralka1/src/game/obstacle_system.h index cfaa321..1484a8c 100644 --- a/semestralka1/src/game/obstacle_system.h +++ b/semestralka1/src/game/obstacle_system.h @@ -14,7 +14,6 @@ class ObstacleSystem { public: ObstacleSystem() : tick_counter_(0), spawn_index_(0) {} - // Called once per frame bool update_and_draw(const CharacterPosition &player_pos, MovementType player_movement) { // Update timers, move existing obstacles @@ -30,7 +29,7 @@ public: spawn_obstacle(type, VIEW_WIDTH - w - 1); } - // Draw & collision check + // Draw n collision check for (int i = 0; i < MAX_OBSTACLES; i++) { if (!obstacle_pool[i].active) continue; @@ -47,7 +46,6 @@ public: draw_clipped_obstacle(obstacle_pool[i], frame, height); - // Collision check if (check_collision(player_pos, player_movement, obstacle_pool[i].data)) { printf("\033[2J\033[H"); diff --git a/semestralka1/src/render/loop.cpp b/semestralka1/src/render/loop.cpp index 864200d..048935b 100644 --- a/semestralka1/src/render/loop.cpp +++ b/semestralka1/src/render/loop.cpp @@ -60,7 +60,7 @@ void logic_loop(void *arg) { timing.set_ground_speed(speed); speed_timer.reset(); - // update player's animation mode + // update players animation mode if (speed < 4) player_state.set_state(PlayerState::Walk); else @@ -110,7 +110,7 @@ void logic_loop(void *arg) { continue; } - // Compute swept region = min..max + // Swept for collision detections at speeds > 1 int left_swept = (new_x < old_x) ? new_x : old_x; int right_swept = ((new_x + obstacle_pool[i].data.width) > (old_x + obstacle_pool[i].data.width)) @@ -124,13 +124,11 @@ void logic_loop(void *arg) { swept_obs.width = right_swept - left_swept; swept_obs.height = obstacle_pool[i].data.height; - // Perform continuous collision check if (check_collision(pos, frame.movement, swept_obs)) { collision = true; break; } - // Apply the actual movement after check obstacle_pool[i].data.x = new_x; } diff --git a/semestralka1/src/render/obstacle.cpp b/semestralka1/src/render/obstacle.cpp index f545f94..0f1fcf0 100644 --- a/semestralka1/src/render/obstacle.cpp +++ b/semestralka1/src/render/obstacle.cpp @@ -5,16 +5,13 @@ #include // Draws an obstacle using bottom‑based world coordinates. -// x = left edge of the collision box in world space -// y = bottom edge of the collision box in world space (0 = ground) void draw_obstacle(int x, int y, CrawlObstacleType type) { const char **obstacle_frame = nullptr; int frame_total_height = 0; - // Collision‑model parameters for this obstacle - int collision_top_offset = 0; // rows from visual top to top of collision box - int collision_height = 0; // rows tall - int collision_left_offset = 0; // columns from visual left to collision left + int collision_top_offset = 0; + int collision_height = 0; + int collision_left_offset = 0; switch (type) { case CrawlObstacleType::Crawl1: @@ -37,13 +34,11 @@ void draw_obstacle(int x, int y, CrawlObstacleType type) { return; // no rendering for invalid type } - // Convert bottom‑based (world) coordinates to screen coordinates. - // Y of the collision bottom is given; translate to where to start drawing the visual frame. + // Convert bottom‑based coordinates to screen coordinates. const int frame_row_index_bottom = collision_top_offset + collision_height - 1; const int frame_top_world_y = y + frame_row_index_bottom; const int frame_top_screen_row = VIEW_HEIGHT - frame_top_world_y; - // X of the collision box is given; shift left to the visual frame's starting column. const int frame_screen_x = x - collision_left_offset; for (int i = 0; i < frame_total_height; i++) {