]> git.seodisparate.com - RockPaperScissorsDuel/commitdiff
Change to ready behavior, replace text, tune shake
authorStephen Seo <seo.disparate@gmail.com>
Thu, 2 Feb 2023 07:27:39 +0000 (16:27 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Thu, 2 Feb 2023 07:27:39 +0000 (16:27 +0900)
Picking third r/p/s automatically sets the player to be "ready".

Text has been replaced. There is no READY? button, and the "Waiting..."
has been replaced with a spinner.

Screen shake has been tuned to wind down as time progresses.

src/3d_renderer.cc
src/3d_renderer.h
src/constants.h

index 55bfd53c448ed2201a3dc6ebb48b9f4aee27c006..c5f49e2bc078322894dd0ad0a4b58de65eb07292 100644 (file)
@@ -30,6 +30,7 @@ Renderer3D::Renderer3D()
       button_color_timer(BUTTON_COLOR_TIME),
       screen_shake_factor(SCREEN_SHAKE_DEFAULT_FACTOR),
       screen_shake_timer(0.0F),
+      waiting_spinner_timer(0.0F),
       received_pos(0),
       prev_pos(0),
       choices{'?', '?', '?'},
@@ -276,6 +277,7 @@ void Renderer3D::update_impl() {
           choices.at(1) = 'r';
         } else {
           choices.at(2) = 'r';
+          flags.set(8);
         }
       } else if (GetTouchX() >=
                      triple_single_width +
@@ -291,6 +293,7 @@ void Renderer3D::update_impl() {
           choices.at(1) = 'p';
         } else {
           choices.at(2) = 'p';
+          flags.set(8);
         }
       } else if (GetTouchX() >=
                      GetScreenWidth() - triple_single_width +
@@ -306,6 +309,7 @@ void Renderer3D::update_impl() {
           choices.at(1) = 's';
         } else {
           choices.at(2) = 's';
+          flags.set(8);
         }
       } else if (GetTouchX() >= (triple_single_width - actual_width2) / 2.0F &&
                  GetTouchX() <=
@@ -332,14 +336,6 @@ void Renderer3D::update_impl() {
                  GetTouchY() >= GetScreenHeight() - height - height2 &&
                  GetTouchY() <= GetScreenHeight() - height) {
         choices.at(2) = '?';
-      } else if (choices.at(0) != '?' && choices.at(1) != '?' &&
-                 choices.at(2) != '?' && GetTouchX() >= 0 &&
-                 GetTouchX() <= GetScreenWidth() && GetTouchY() >= 0 &&
-                 GetTouchY() <= triple_single_width) {
-        flags.set(8);
-        if (!flags.test(14)) {
-          call_js_set_ready();
-        }
       }
     }
   }
@@ -428,11 +424,26 @@ void Renderer3D::update_impl() {
 
   if (flags.test(21)) {
     screen_shake_timer -= dt;
-    if (screen_shake_timer <= 0.0F) {
+    if (screen_shake_timer < 0.0F) {
       flags.reset(20);
       flags.reset(21);
+    } else {
+      screen_shake_factor =
+          screen_shake_timer / SCREEN_SHAKE_TIME * SCREEN_SHAKE_DEFAULT_FACTOR;
     }
   }
+
+  if (flags.test(8) && ((flags.test(2) && !flags.test(9)) ||
+                        (!flags.test(2) && !flags.test(10)))) {
+    if (!flags.test(14)) {
+      call_js_set_ready();
+    }
+  }
+
+  waiting_spinner_timer -= dt;
+  if (waiting_spinner_timer < 0.0F) {
+    waiting_spinner_timer += WAITING_SPINNER_TIME;
+  }
 }
 
 void Renderer3D::draw_impl() {
@@ -499,19 +510,6 @@ void Renderer3D::draw_impl() {
       DrawRectangle(0, GetScreenHeight() - height, GetScreenWidth(), height,
                     {color_value, color_value, 255, 255});
     }
-    if (choices.at(0) != '?' && choices.at(1) != '?' && choices.at(2) != '?') {
-      DrawTexturePro(
-          spriteSheet,
-          {READY_DIMS[0], READY_DIMS[1], READY_DIMS[2], READY_DIMS[3]},
-          {0, 0, GetScreenWidth() * 4.0F / 5.0F, triple_single_width},
-          {0.0F, 0.0F}, 0.0F, WHITE);
-      DrawTexturePro(spriteSheet,
-                     {QUESTIONMARK_DIMS[0], QUESTIONMARK_DIMS[1],
-                      QUESTIONMARK_DIMS[2], QUESTIONMARK_DIMS[3]},
-                     {GetScreenWidth() * 4.0F / 5.0F, 0,
-                      GetScreenWidth() / 5.0F, triple_single_width},
-                     {0.0F, 0.0F}, 0.0F, WHITE);
-    }
 
     DrawRectangleLines((triple_single_width - actual_width) / 2.0F,
                        GetScreenHeight() - height, actual_width, height, BLACK);
@@ -587,8 +585,8 @@ void Renderer3D::draw_impl() {
           break;
       }
     }
-  } else {
-    DrawText("Waiting...", 0, 0, 20, RAYWHITE);
+  } else if (anims.is_done()) {
+    draw_waiting_spinner();
   }
 
   for (auto &iter : deferred_2d_draw_map) {
@@ -971,3 +969,17 @@ Sound *Renderer3D::type_to_sfx(char type) {
   }
   return nullptr;
 }
+
+void Renderer3D::draw_waiting_spinner() {
+  float radius = GetScreenWidth() / SPINNER_RADIUS_WIDTH_FRAC;
+  if (waiting_spinner_timer >= WAITING_SPINNER_TIME / 2.0F) {
+    float time = (waiting_spinner_timer - WAITING_SPINNER_TIME / 2.0F) /
+                 (WAITING_SPINNER_TIME / 2.0F);
+    DrawCircleSector(Vector2{radius, radius}, radius, 180.0F,
+                     360.0F * time + 180.0F, 16, Color{255, 255, 255, 100});
+  } else {
+    float time = waiting_spinner_timer / (WAITING_SPINNER_TIME / 2.0F);
+    DrawCircleSector(Vector2{radius, radius}, radius, 180.0F + 360.0F * time,
+                     180.0F + 360.0F, 16, Color{255, 255, 255, 100});
+  }
+}
index a74f6e5540af7d1a130ba2c21dfea8ddb6a6fe2c..274d20c46b46a63ea597947dd4cab246c5890c8e 100644 (file)
@@ -58,6 +58,8 @@ class Renderer3D : public GameRenderer {
 
   Sound *type_to_sfx(char type);
 
+  void draw_waiting_spinner();
+
   std::array<QuestionMark, 2> qms;
 
   Deferred2DMap deferred_2d_draw_map;
@@ -128,6 +130,7 @@ class Renderer3D : public GameRenderer {
   float button_color_timer;
   float screen_shake_factor;
   float screen_shake_timer;
+  float waiting_spinner_timer;
 
   int received_pos;
   int prev_pos;
index 54beff0be87a4ecd3d71133049449de3f36f5b95..2d31cc3ff3ca0b0b18de41ee883f47555c125388 100644 (file)
@@ -74,6 +74,9 @@ constexpr float SCREEN_SHAKE_TIME = 0.3F;
 constexpr int ANIM_FALLING_AMT = 7;
 constexpr int ANIM_FALLING_OPP_THRESHOLD = 5;
 
+constexpr float WAITING_SPINNER_TIME = 2.0F;
+constexpr float SPINNER_RADIUS_WIDTH_FRAC = 20.0F;
+
 // src/3D/
 
 constexpr float QM_ANGLE_TIMER_VARIANCE = 2.0F;