]> git.seodisparate.com - jumpartifact.com_demo_0/commitdiff
Minor refactorings
authorStephen Seo <seo.disparate@gmail.com>
Tue, 15 Aug 2023 06:44:11 +0000 (15:44 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Tue, 15 Aug 2023 06:44:11 +0000 (15:44 +0900)
src/screen_trunner.cc
src/walker.cc
src/walker.h

index 8962617d736a59395409e6b4e1765331347439b5..0bc688274d053966a9611f7b68aad2af32d27844 100644 (file)
@@ -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:
index 252e2672c41d930e654dd3aa856790857fae2489..964913d77126ead782c2de70c5c073183518224a 100644 (file)
@@ -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,
index 447fbcd7dae3045cb5d0c7eb3656acc2cd237928..f26a915e08eee7fe86dacb453fd8c1cae0b8e593 100644 (file)
@@ -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;