diff --git a/semestralka1/src/game/obstacle_manager.h b/semestralka1/src/game/obstacle_manager.h index 0e6eee7..bf2981d 100644 --- a/semestralka1/src/game/obstacle_manager.h +++ b/semestralka1/src/game/obstacle_manager.h @@ -4,14 +4,12 @@ #include "../assets/obstacle_crawl_frames.h" #include "../assets/background_frame.h" -// Movable obstacle struct MovingObstacle { Obstacle data; CrawlObstacleType type; bool active; }; -// Fixed obstacle pool constexpr int MAX_OBSTACLES = 6; static MovingObstacle obstacle_pool[MAX_OBSTACLES]; @@ -45,7 +43,7 @@ inline int spawn_obstacle(CrawlObstacleType type, int x_start) { return -1; } -// Update X positions; mark inactive if offscreen +// Update X positions, mark inactive if offscreen inline void update_obstacles(int shift_speed) { for (int i = 0; i < MAX_OBSTACLES; i++) { if (!obstacle_pool[i].active) continue; diff --git a/semestralka1/src/game/state.cpp b/semestralka1/src/game/state.cpp index 6ade839..300fbde 100644 --- a/semestralka1/src/game/state.cpp +++ b/semestralka1/src/game/state.cpp @@ -130,7 +130,6 @@ void MovementState::set_motion_state_for_speed(int player_speed, int ground_spee current_state = new_state; } -// TODO THIS NEEDS REDESIGN FOR WALK/RUN void MovementState::toggle_walk_frame(float player_speed, int tick_counter) { switch (current_state) { case PlayerState::Run: diff --git a/semestralka1/src/main.cpp b/semestralka1/src/main.cpp index 01ab922..98f6b25 100644 --- a/semestralka1/src/main.cpp +++ b/semestralka1/src/main.cpp @@ -21,5 +21,5 @@ int main(void) { serial_port.set_format(8, BufferedSerial::None, 1); printf("Baud: %d, Format: 8-N-1\r\n", BAUD_RATE); - render_loop(6); + render_loop(2); } diff --git a/semestralka1/src/render/loop.cpp b/semestralka1/src/render/loop.cpp index bd574aa..6bdf4b1 100644 --- a/semestralka1/src/render/loop.cpp +++ b/semestralka1/src/render/loop.cpp @@ -27,16 +27,20 @@ constexpr int STACK_SIZE = 4096; Thread logic_thread(osPriorityNormal, STACK_SIZE); Thread render_thread(osPriorityNormal, STACK_SIZE); -void logic_loop() { +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(6); + timing.set_ground_speed(speed); CharacterPosition pos = {PLAYER_X, PLAYER_Y}; - player_state.set_state(PlayerState::Walk); + if (speed < 3) + player_state.set_state(PlayerState::Run); + else + player_state.set_state(PlayerState::Walk); Timer spawn_timer; spawn_timer.start(); @@ -51,11 +55,11 @@ void logic_loop() { while (!game_over) { tick_counter++; - mover.update_position(6, timing.get_ground_speed()); + mover.update_position(speed, timing.get_ground_speed()); pos.x = mover.get_position(); // Spawn periodically - if (spawn_timer.elapsed_time() > 2s) { + if (spawn_timer.elapsed_time() > 5s) { spawn_timer.reset(); spawn_obstacle(CrawlObstacleType::Crawl1, VIEW_WIDTH); } @@ -71,7 +75,7 @@ void logic_loop() { player_state.update(); - bool anim_tick = animation.tick(6); + bool anim_tick = animation.tick(speed); if (anim_tick) { anim_tick_counter++; // move obstacles @@ -84,7 +88,7 @@ void logic_loop() { } } - player_state.toggle_walk_frame(6, anim_tick_counter); + 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); @@ -166,9 +170,13 @@ void render_loop(int speed) { g_state.game_over = false; g_state_mutex.unlock(); - logic_thread.start(logic_loop); + int *speed_ptr = new int(speed); + + logic_thread.start(callback(logic_loop, (void *)speed_ptr)); render_thread.start(render_loop_thread); logic_thread.join(); render_thread.join(); + + delete speed_ptr; }