button scuffed
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
#include "../game/obstacle_system.h"
|
||||
|
||||
extern DigitalOut led;
|
||||
ButtonHandler button(BUTTON1, LED1);
|
||||
|
||||
// Constants
|
||||
// constexpr int PLAYER_X = 9;
|
||||
@@ -30,7 +31,6 @@ void logic_loop(void *arg) {
|
||||
int speed = *(int *)arg;
|
||||
MovementState player_state;
|
||||
AnimationController animation;
|
||||
ButtonHandler button;
|
||||
MovementController mover(PLAYER_X, VIEW_WIDTH);
|
||||
SpeedController timing;
|
||||
timing.set_ground_speed(speed);
|
||||
@@ -89,30 +89,52 @@ void logic_loop(void *arg) {
|
||||
bool anim_tick = animation.tick(speed);
|
||||
if (anim_tick) {
|
||||
anim_tick_counter++;
|
||||
// move obstacles
|
||||
int ground_speed = timing.get_ground_speed();
|
||||
for (int i = 0; i < MAX_OBSTACLES; i++) {
|
||||
if (obstacle_pool[i].active) {
|
||||
obstacle_pool[i].data.x -= ground_speed;
|
||||
if (obstacle_pool[i].data.x + obstacle_pool[i].data.width < 0)
|
||||
obstacle_pool[i].active = false;
|
||||
}
|
||||
}
|
||||
|
||||
player_state.toggle_walk_frame(speed, anim_tick_counter);
|
||||
FrameSelection frame = player_state.get_frame_selection();
|
||||
CharacterPosition draw_pos = get_aligned_frame_position(pos, frame.movement, frame.frame_index);
|
||||
|
||||
// check collision
|
||||
int ground_speed = timing.get_ground_speed();
|
||||
bool collision = false;
|
||||
|
||||
for (int i = 0; i < MAX_OBSTACLES; i++) {
|
||||
if (obstacle_pool[i].active &&
|
||||
check_collision(pos, frame.movement, obstacle_pool[i].data)) {
|
||||
if (!obstacle_pool[i].active)
|
||||
continue;
|
||||
|
||||
// Keep original position
|
||||
int old_x = obstacle_pool[i].data.x;
|
||||
int new_x = old_x - ground_speed;
|
||||
|
||||
// Remove if fully offscreen after movement
|
||||
if (new_x + obstacle_pool[i].data.width < 0) {
|
||||
obstacle_pool[i].active = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Compute swept region = min..max
|
||||
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))
|
||||
? (new_x + obstacle_pool[i].data.width)
|
||||
: (old_x + obstacle_pool[i].data.width);
|
||||
|
||||
// Temporarily create a synthetic obstacle covering the swept range
|
||||
Obstacle swept_obs{};
|
||||
swept_obs.x = left_swept;
|
||||
swept_obs.y = obstacle_pool[i].data.y;
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
g_state_mutex.lock();
|
||||
|
||||
g_state.player_pos = draw_pos;
|
||||
@@ -158,7 +180,7 @@ void render_loop_thread() {
|
||||
g_state_mutex.unlock();
|
||||
|
||||
if (over) {
|
||||
show_game_over_screen(local.elapsed_seconds);
|
||||
show_game_over_screen(local.elapsed_seconds, button);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user