speed bug fixed now properly well

This commit is contained in:
Filipriec
2025-12-11 17:10:55 +01:00
parent 50f523b52d
commit 17c53ace99
5 changed files with 26 additions and 24 deletions

View File

@@ -37,29 +37,39 @@ void logic_loop(void *arg) {
timing.set_ground_speed(speed);
CharacterPosition pos = {PLAYER_X, PLAYER_Y};
if (speed < 3)
player_state.set_state(PlayerState::Run);
else
player_state.set_state(PlayerState::Walk);
Timer spawn_timer;
spawn_timer.start();
Timer speed_timer;
speed_timer.start();
int anim_tick_counter = 0;
int tick_counter = 0;
bool game_over = false;
// Spawn first obstacle
spawn_obstacle(CrawlObstacleType::Crawl1, VIEW_WIDTH + 10);
if (speed >= 5)
spawn_obstacle(CrawlObstacleType::Crawl1, VIEW_WIDTH + 10);
while (!game_over) {
tick_counter++;
if (speed_timer.elapsed_time() >= 6s) {
speed++;
timing.set_ground_speed(speed);
speed_timer.reset();
// update player's animation mode
if (speed < 4)
player_state.set_state(PlayerState::Walk);
else
player_state.set_state(PlayerState::Run);
}
mover.update_position(speed, timing.get_ground_speed());
pos.x = mover.get_position();
// Spawn periodically
if (spawn_timer.elapsed_time() > 5s) {
if (speed >= 5 && spawn_timer.elapsed_time() > 6s) {
spawn_timer.reset();
spawn_obstacle(CrawlObstacleType::Crawl1, VIEW_WIDTH);
}
@@ -90,8 +100,7 @@ void logic_loop(void *arg) {
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);
CharacterPosition draw_pos = get_aligned_frame_position(pos, frame.movement, frame.frame_index);
// check collision
bool collision = false;
@@ -106,6 +115,7 @@ void logic_loop(void *arg) {
g_state_mutex.lock();
g_state.player_pos = draw_pos;
g_state.current_speed = speed;
g_state.movement = frame.movement;
g_state.frame_index = frame.frame_index;
g_state.background_shift = animation.get_shift();
@@ -153,10 +163,12 @@ void render_loop_thread() {
draw_mask("background", local.background_shift);
draw_character(local.player_pos.x, local.player_pos.y, local.movement,
local.frame_index);
for (int i = 0; i < MAX_RENDER_OBSTACLES; i++) {
if (local.obstacles[i].active)
draw_obstacle(local.obstacles[i].x, local.obstacles[i].y,
local.obstacles[i].type);
if (local.current_speed >= 5) {
for (int i = 0; i < MAX_RENDER_OBSTACLES; i++) {
if (local.obstacles[i].active)
draw_obstacle(local.obstacles[i].x, local.obstacles[i].y,
local.obstacles[i].type);
}
}
}