diff --git a/src/screen_trunner.cc b/src/screen_trunner.cc index 8962617..0bc6882 100644 --- a/src/screen_trunner.cc +++ b/src/screen_trunner.cc @@ -241,29 +241,38 @@ bool TRunnerScreen::update(float dt) { if (controlled_walker_idx.has_value() && IsMouseButtonDown(0)) { // Check if clicked on button. - if (GetTouchX() >= 0 && GetTouchX() <= left_text_width && + if (!walkers[controlled_walker_idx.value()].player_is_turning_left() && + GetTouchX() >= 0 && GetTouchX() <= left_text_width && GetTouchY() >= GetScreenHeight() - BUTTON_FONT_SIZE && GetTouchY() <= GetScreenHeight()) { walkers[controlled_walker_idx.value()].player_turn_left(); goto post_check_click; - } else if (GetTouchX() >= left_text_width && + } else if (!walkers[controlled_walker_idx.value()] + .player_is_turning_right() && + GetTouchX() >= left_text_width && GetTouchX() <= left_text_width + right_text_width && GetTouchY() >= GetScreenHeight() - BUTTON_FONT_SIZE && GetTouchY() <= GetScreenHeight()) { walkers[controlled_walker_idx.value()].player_turn_right(); goto post_check_click; - } else if (int width_mid = (left_text_width + right_text_width) / 2 - - forward_text_width / 2; - GetTouchX() >= width_mid && - GetTouchX() <= width_mid + forward_text_width && - GetTouchY() >= GetScreenHeight() - BUTTON_FONT_SIZE * 2 && - GetTouchY() <= GetScreenHeight() - BUTTON_FONT_SIZE) { - walkers[controlled_walker_idx.value()].player_go_forward(); + } else if (!walkers[controlled_walker_idx.value()] + .player_is_going_forward()) { + if (int width_mid = + (left_text_width + right_text_width) / 2 - forward_text_width / 2; + GetTouchX() >= width_mid && + GetTouchX() <= width_mid + forward_text_width && + GetTouchY() >= GetScreenHeight() - BUTTON_FONT_SIZE * 2 && + GetTouchY() <= GetScreenHeight() - BUTTON_FONT_SIZE) { + walkers[controlled_walker_idx.value()].player_go_forward(); + goto post_check_click; + } + } + } else if (IsMouseButtonReleased(0)) { + if (controlled_walker_idx.has_value()) { + walkers[controlled_walker_idx.value()].player_idle(); goto post_check_click; } - } - - if (IsMouseButtonPressed(0)) { + } else if (IsMouseButtonPressed(0)) { float press_x = GetTouchX(); float press_y = GetTouchY(); Ray ray = GetMouseRay(Vector2{press_x, press_y}, camera); @@ -347,10 +356,6 @@ bool TRunnerScreen::update(float dt) { } } } - } else if (IsMouseButtonReleased(0)) { - if (controlled_walker_idx.has_value()) { - walkers[controlled_walker_idx.value()].player_idle(); - } } post_check_click: diff --git a/src/walker.cc b/src/walker.cc index 252e267..964913d 100644 --- a/src/walker.cc +++ b/src/walker.cc @@ -185,6 +185,14 @@ void Walker::player_turn_right() { void Walker::player_go_forward() { flags |= 0x30; } +bool Walker::player_is_idle() const { return (flags & 0x30) == 0; } + +bool Walker::player_is_turning_left() const { return (flags & 0x30) == 0x10; } + +bool Walker::player_is_turning_right() const { return (flags & 0x30) == 0x20; } + +bool Walker::player_is_going_forward() const { return (flags & 0x30) == 0x30; } + BoundingBox Walker::get_body_bb() const { return BoundingBox{ .min = body_pos - Vector3{0.5F, diff --git a/src/walker.h b/src/walker.h index 447fbcd..f26a915 100644 --- a/src/walker.h +++ b/src/walker.h @@ -49,6 +49,11 @@ class Walker { void player_turn_right(); void player_go_forward(); + bool player_is_idle() const; + bool player_is_turning_left() const; + bool player_is_turning_right() const; + bool player_is_going_forward() const; + BoundingBox get_body_bb() const; float get_rotation() const; Vector3 get_body_pos() const;