This commit is contained in:
Filipriec
2025-11-20 16:45:50 +01:00
parent dd410c6f6c
commit 3e47f855ed
6 changed files with 8 additions and 16 deletions

View File

@@ -49,7 +49,7 @@ static const int CHARACTER_CRAWL1_COLLISION_RIGHT_OFFSET = 1;
static const int CHARACTER_CRAWL1_COLLISION_WIDTH = CHARACTER_CRAWL1_FRAME_WIDTH - (CHARACTER_CRAWL1_COLLISION_LEFT_OFFSET + CHARACTER_CRAWL1_COLLISION_RIGHT_OFFSET); static const int CHARACTER_CRAWL1_COLLISION_WIDTH = CHARACTER_CRAWL1_FRAME_WIDTH - (CHARACTER_CRAWL1_COLLISION_LEFT_OFFSET + CHARACTER_CRAWL1_COLLISION_RIGHT_OFFSET);
static const int CHARACTER_CRAWL1_COLLISION_HEIGHT = CHARACTER_CRAWL1_FRAME_HEIGHT - 2; static const int CHARACTER_CRAWL1_COLLISION_HEIGHT = CHARACTER_CRAWL1_FRAME_HEIGHT - 2;
// Crawl2 collision box (lower posture smaller collision height) // Crawl2 collision box (lower posture - smaller collision height)
static const int CHARACTER_CRAWL2_FRAME_WIDTH = 8; static const int CHARACTER_CRAWL2_FRAME_WIDTH = 8;
static const int CHARACTER_CRAWL2_COLLISION_LEFT_OFFSET = 1; static const int CHARACTER_CRAWL2_COLLISION_LEFT_OFFSET = 1;
static const int CHARACTER_CRAWL2_COLLISION_RIGHT_OFFSET = 0; static const int CHARACTER_CRAWL2_COLLISION_RIGHT_OFFSET = 0;

View File

@@ -5,7 +5,7 @@
#include "../assets/character_run_frames.h" #include "../assets/character_run_frames.h"
#include "../assets/character_crawl_frames.h" #include "../assets/character_crawl_frames.h"
// Simple obstacle representation // Obstacle representation
struct Obstacle { struct Obstacle {
int x; int x;
int y; int y;
@@ -48,7 +48,7 @@ inline bool check_collision(const CharacterPosition& player,
break; break;
} }
// Player's bounding box // Player bounding box
const int player_left = box_x; const int player_left = box_x;
const int player_right = player_left + box_w; const int player_right = player_left + box_w;
const int player_top = player_bottom + box_h; const int player_top = player_bottom + box_h;
@@ -59,7 +59,7 @@ inline bool check_collision(const CharacterPosition& player,
const int obs_bottom = obs.y; const int obs_bottom = obs.y;
const int obs_top = obs_bottom + obs.height; const int obs_top = obs_bottom + obs.height;
// Simple overlap check // Overlap check
bool horizontal = player_left < obs_right && player_right > obs_left; bool horizontal = player_left < obs_right && player_right > obs_left;
bool vertical = player_bottom < obs_top && player_top > obs_bottom; bool vertical = player_bottom < obs_top && player_top > obs_bottom;
return horizontal && vertical; return horizontal && vertical;

View File

@@ -4,7 +4,7 @@
#include "../assets/obstacle_crawl_frames.h" #include "../assets/obstacle_crawl_frames.h"
#include "../assets/background_frame.h" #include "../assets/background_frame.h"
// One movable obstacle // Movable obstacle
struct MovingObstacle { struct MovingObstacle {
Obstacle data; Obstacle data;
CrawlObstacleType type; CrawlObstacleType type;
@@ -26,7 +26,7 @@ inline int spawn_obstacle(CrawlObstacleType type, int x_start) {
obstacle_pool[i].data.width = (type == CrawlObstacleType::Crawl1) ? OBSTACLE_CRAWL1_COLLISION_WIDTH : OBSTACLE_CRAWL2_COLLISION_WIDTH; obstacle_pool[i].data.width = (type == CrawlObstacleType::Crawl1) ? OBSTACLE_CRAWL1_COLLISION_WIDTH : OBSTACLE_CRAWL2_COLLISION_WIDTH;
obstacle_pool[i].data.height = (type == CrawlObstacleType::Crawl1) ? OBSTACLE_CRAWL1_COLLISION_HEIGHT : OBSTACLE_CRAWL2_COLLISION_HEIGHT; obstacle_pool[i].data.height = (type == CrawlObstacleType::Crawl1) ? OBSTACLE_CRAWL1_COLLISION_HEIGHT : OBSTACLE_CRAWL2_COLLISION_HEIGHT;
// Default Y so that the SPRITE touches the top of the screen. // Default Y so that the character touches the top of the screen.
// We store Y as the bottom of the COLLISION BOX in bottom-based world coords. // We store Y as the bottom of the COLLISION BOX in bottom-based world coords.
int top_offset = 0; int top_offset = 0;
if (type == CrawlObstacleType::Crawl1) { if (type == CrawlObstacleType::Crawl1) {

View File

@@ -6,7 +6,6 @@
#include "collision.h" #include "collision.h"
#include "mbed.h" #include "mbed.h"
// Small helper for minimal mbed-safe clamp
inline int clamp_min(int a, int b) { return (a > b) ? a : b; } inline int clamp_min(int a, int b) { return (a > b) ? a : b; }
inline int clamp_max(int a, int b) { return (a < b) ? a : b; } inline int clamp_max(int a, int b) { return (a < b) ? a : b; }
@@ -26,12 +25,8 @@ public:
// Periodically spawn new obstacle // Periodically spawn new obstacle
if (tick_counter_ % SPAWN_EVERY_TICKS == 0) { if (tick_counter_ % SPAWN_EVERY_TICKS == 0) {
auto type = (spawn_index_++ % 2 == 0) auto type = (spawn_index_++ % 2 == 0) ? CrawlObstacleType::Crawl1 : CrawlObstacleType::Crawl2;
? CrawlObstacleType::Crawl1 const int w = (type == CrawlObstacleType::Crawl1) ? OBSTACLE_CRAWL1_FRAME_WIDTH : OBSTACLE_CRAWL2_FRAME_WIDTH;
: CrawlObstacleType::Crawl2;
const int w = (type == CrawlObstacleType::Crawl1)
? OBSTACLE_CRAWL1_FRAME_WIDTH
: OBSTACLE_CRAWL2_FRAME_WIDTH;
spawn_obstacle(type, VIEW_WIDTH - w - 1); spawn_obstacle(type, VIEW_WIDTH - w - 1);
} }

View File

@@ -21,6 +21,5 @@ int main(void) {
serial_port.set_format(8, BufferedSerial::None, 1); serial_port.set_format(8, BufferedSerial::None, 1);
printf("Baud: %d, Format: 8-N-1\r\n", BAUD_RATE); printf("Baud: %d, Format: 8-N-1\r\n", BAUD_RATE);
// Just call into render feature
render_loop(6); render_loop(6);
} }

View File

@@ -13,7 +13,5 @@ public:
int get_ground_speed() const { return ground_speed; } int get_ground_speed() const { return ground_speed; }
// Calculates how many frames to advance for current tick. // Calculates how many frames to advance for current tick.
// Takes objects current speed and a global tick counter
// to automatically handle slower "wait" behavior.
int frame_advance_for(int object_speed, int tick_counter) const; int frame_advance_for(int object_speed, int tick_counter) const;
}; };