polished like a polish plates

This commit is contained in:
Priec
2025-12-14 23:04:32 +01:00
parent 74dca27c06
commit 6b10d13695
8 changed files with 11 additions and 23 deletions

View File

@@ -14,7 +14,5 @@ public:
// Update animation, returns true if redraw needed // Update animation, returns true if redraw needed
bool tick(int speed); bool tick(int speed);
// Getters
int get_shift() const { return shift; } int get_shift() const { return shift; }
}; };

View File

@@ -5,7 +5,6 @@
#include "../assets/character_run_frames.h" #include "../assets/character_run_frames.h"
#include "../assets/character_crawl_frames.h" #include "../assets/character_crawl_frames.h"
// Obstacle representation
struct Obstacle { struct Obstacle {
int x; int x;
int y; int y;

View File

@@ -3,6 +3,6 @@
#include "mbed.h" #include "mbed.h"
#include "../hardware/button.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. // Takes a Timer that was measuring game duration.
void show_game_over_screen(int seconds, ButtonHandler& button); void show_game_over_screen(int seconds, ButtonHandler& button);

View File

@@ -5,7 +5,7 @@
#include "../render/player_positioning.h" #include "../render/player_positioning.h"
#include "../assets/obstacle_crawl_frames.h" #include "../assets/obstacle_crawl_frames.h"
// POZOR Z OBSTACLE MANAGERA // POZOR JE Z OBSTACLE MANAGERA
constexpr int MAX_RENDER_OBSTACLES = 6; constexpr int MAX_RENDER_OBSTACLES = 6;
struct ObstacleRenderData { struct ObstacleRenderData {
@@ -31,6 +31,6 @@ struct GameState {
bool need_redraw; bool need_redraw;
}; };
// Global shared state and mutex // Global shared
extern GameState g_state; extern GameState g_state;
extern Mutex g_state_mutex; extern Mutex g_state_mutex;

View File

@@ -13,7 +13,7 @@ struct MovingObstacle {
constexpr int MAX_OBSTACLES = 6; constexpr int MAX_OBSTACLES = 6;
static MovingObstacle obstacle_pool[MAX_OBSTACLES]; static MovingObstacle obstacle_pool[MAX_OBSTACLES];
// Create / reset obstacle in one slot // Create/reset obstacle
inline int spawn_obstacle(CrawlObstacleType type, int x_start) { inline int spawn_obstacle(CrawlObstacleType type, int x_start) {
for (int i = 0; i < MAX_OBSTACLES; i++) { for (int i = 0; i < MAX_OBSTACLES; i++) {
if (!obstacle_pool[i].active) { if (!obstacle_pool[i].active) {

View File

@@ -14,7 +14,6 @@ class ObstacleSystem {
public: public:
ObstacleSystem() : tick_counter_(0), spawn_index_(0) {} ObstacleSystem() : tick_counter_(0), spawn_index_(0) {}
// Called once per frame
bool update_and_draw(const CharacterPosition &player_pos, bool update_and_draw(const CharacterPosition &player_pos,
MovementType player_movement) { MovementType player_movement) {
// Update timers, move existing obstacles // Update timers, move existing obstacles
@@ -30,7 +29,7 @@ public:
spawn_obstacle(type, VIEW_WIDTH - w - 1); spawn_obstacle(type, VIEW_WIDTH - w - 1);
} }
// Draw & collision check // Draw n collision check
for (int i = 0; i < MAX_OBSTACLES; i++) { for (int i = 0; i < MAX_OBSTACLES; i++) {
if (!obstacle_pool[i].active) if (!obstacle_pool[i].active)
continue; continue;
@@ -47,7 +46,6 @@ public:
draw_clipped_obstacle(obstacle_pool[i], frame, height); draw_clipped_obstacle(obstacle_pool[i], frame, height);
// Collision check
if (check_collision(player_pos, player_movement, if (check_collision(player_pos, player_movement,
obstacle_pool[i].data)) { obstacle_pool[i].data)) {
printf("\033[2J\033[H"); printf("\033[2J\033[H");

View File

@@ -60,7 +60,7 @@ void logic_loop(void *arg) {
timing.set_ground_speed(speed); timing.set_ground_speed(speed);
speed_timer.reset(); speed_timer.reset();
// update player's animation mode // update players animation mode
if (speed < 4) if (speed < 4)
player_state.set_state(PlayerState::Walk); player_state.set_state(PlayerState::Walk);
else else
@@ -110,7 +110,7 @@ void logic_loop(void *arg) {
continue; 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 left_swept = (new_x < old_x) ? new_x : old_x;
int right_swept = ((new_x + obstacle_pool[i].data.width) > int right_swept = ((new_x + obstacle_pool[i].data.width) >
(old_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.width = right_swept - left_swept;
swept_obs.height = obstacle_pool[i].data.height; swept_obs.height = obstacle_pool[i].data.height;
// Perform continuous collision check
if (check_collision(pos, frame.movement, swept_obs)) { if (check_collision(pos, frame.movement, swept_obs)) {
collision = true; collision = true;
break; break;
} }
// Apply the actual movement after check
obstacle_pool[i].data.x = new_x; obstacle_pool[i].data.x = new_x;
} }

View File

@@ -5,16 +5,13 @@
#include <cstdio> #include <cstdio>
// Draws an obstacle using bottombased world coordinates. // Draws an obstacle using bottombased 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) { void draw_obstacle(int x, int y, CrawlObstacleType type) {
const char **obstacle_frame = nullptr; const char **obstacle_frame = nullptr;
int frame_total_height = 0; int frame_total_height = 0;
// Collisionmodel parameters for this obstacle int collision_top_offset = 0;
int collision_top_offset = 0; // rows from visual top to top of collision box int collision_height = 0;
int collision_height = 0; // rows tall int collision_left_offset = 0;
int collision_left_offset = 0; // columns from visual left to collision left
switch (type) { switch (type) {
case CrawlObstacleType::Crawl1: case CrawlObstacleType::Crawl1:
@@ -37,13 +34,11 @@ void draw_obstacle(int x, int y, CrawlObstacleType type) {
return; // no rendering for invalid type return; // no rendering for invalid type
} }
// Convert bottombased (world) coordinates to screen coordinates. // Convert bottombased coordinates to screen coordinates.
// Y of the collision bottom is given; translate to where to start drawing the visual frame.
const int frame_row_index_bottom = collision_top_offset + collision_height - 1; 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_world_y = y + frame_row_index_bottom;
const int frame_top_screen_row = VIEW_HEIGHT - frame_top_world_y; 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; const int frame_screen_x = x - collision_left_offset;
for (int i = 0; i < frame_total_height; i++) { for (int i = 0; i < frame_total_height; i++) {