]> git.seodisparate.com - LD52/commitdiff
Use music, add music button, minor tweaks
authorStephen Seo <seo.disparate@gmail.com>
Sat, 7 Jan 2023 09:20:58 +0000 (18:20 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Sat, 7 Jan 2023 09:20:58 +0000 (18:20 +0900)
src/constants.h
src/game.cc
src/game.h
src/helpers.cc
src/helpers.h

index 60cee0922f8dc55ca5ef7bf463bcfae3b5417f46..b70ceb9aac9fb93025dbc983f98315dc67a3468f 100644 (file)
@@ -56,4 +56,6 @@ constexpr float SPLIT_DA = 100.0F;
 
 constexpr float POST_CUT_TIME = 1.7F;
 
+constexpr float MUSIC_NOTE_WH = 80.0F;
+
 #endif
index 642e4f3327f20b6dcd87012218b7f722d32dc6fd..f0798f014c53c9ce24211a3c772438251980e1be 100644 (file)
@@ -106,40 +106,53 @@ void Game::update_impl() {
 
   cutPos = cutTimer * height + offsetY - height / 3.0F;
 
-  if (!flags.test(4) && IsMouseButtonPressed(0)) {
-    flags.set(4);
-    if (cutPos >= offsetY && cutPos <= offsetY + height / 3.0F) {
-      // in correct range
-      flags.set(2);
-      ++score;
-      flags.set(0);
-      PlaySound(nicecut.at(std::uniform_int_distribution<unsigned int>(
-          0, nicecut.size() - 1)(re)));
-    } else if (cutPos > offsetY + height / 3.0F) {
-      // past range
-      flags.set(5);
-      postCutTimer = POST_CUT_TIME;
-      PlaySound(ohno.at(
-          std::uniform_int_distribution<unsigned int>(0, ohno.size() - 1)(re)));
-    } else {
-      // before range
-      postCutTimer = POST_CUT_TIME;
-      PlaySound(ohno.at(
-          std::uniform_int_distribution<unsigned int>(0, ohno.size() - 1)(re)));
-    }
+  if (IsMouseButtonPressed(0)) {
+    if (flags.test(7) && GetTouchX() >= GetScreenWidth() - MUSIC_NOTE_WH &&
+        GetTouchX() <= GetScreenWidth() && GetTouchY() >= 0 &&
+        GetTouchY() <= MUSIC_NOTE_WH) {
+      flags.flip(8);
+      if (flags.test(8)) {
+        PlayMusicStream(music);
+      } else {
+        PauseMusicStream(music);
+      }
+    } else if (!flags.test(4)) {
+      flags.set(4);
+      if (cutPos >= offsetY && cutPos <= offsetY + height / 3.0F) {
+        // in correct range
+        flags.set(2);
+        ++score;
+        flags.set(0);
+        PlaySound(nicecut.at(std::uniform_int_distribution<unsigned int>(
+            0, nicecut.size() - 1)(re)));
+      } else if (cutPos > offsetY + height / 3.0F) {
+        // past range
+        flags.set(5);
+        postCutTimer = POST_CUT_TIME;
+        PlaySound(ohno.at(std::uniform_int_distribution<unsigned int>(
+            0, ohno.size() - 1)(re)));
+      } else {
+        // before range
+        postCutTimer = POST_CUT_TIME;
+        PlaySound(ohno.at(std::uniform_int_distribution<unsigned int>(
+            0, ohno.size() - 1)(re)));
+      }
 
-    if (flags.test(4) && (flags.test(2) || flags.test(5)) && !flags.test(6)) {
-      flags.set(6);
-      relativeCutRatio = (cutPos - offsetY) / height;
-      splitX = offsetX;
-      splitY = offsetY;
-      splitAngle = 0.0F;
-      splitDX = std::uniform_real_distribution<float>(-SPLIT_DX, SPLIT_DX)(re);
-      splitDY = std::uniform_real_distribution<float>(-SPLIT_DY, SPLIT_DY)(re);
-      splitDAngle =
-          std::uniform_real_distribution<float>(-SPLIT_DA, SPLIT_DA)(re);
-      postCutTimer = POST_CUT_TIME;
-      cutTimerRateInc += CUT_TIMER_RATE_INC_AMT;
+      if (flags.test(4) && (flags.test(2) || flags.test(5)) && !flags.test(6)) {
+        flags.set(6);
+        relativeCutRatio = (cutPos - offsetY) / height;
+        splitX = offsetX;
+        splitY = offsetY;
+        splitAngle = 0.0F;
+        splitDX =
+            std::uniform_real_distribution<float>(-SPLIT_DX, SPLIT_DX)(re);
+        splitDY =
+            std::uniform_real_distribution<float>(-SPLIT_DY, SPLIT_DY)(re);
+        splitDAngle =
+            std::uniform_real_distribution<float>(-SPLIT_DA, SPLIT_DA)(re);
+        postCutTimer = POST_CUT_TIME;
+        cutTimerRateInc += CUT_TIMER_RATE_INC_AMT;
+      }
     }
   }
 
@@ -174,6 +187,10 @@ void Game::update_impl() {
       ohno.at(4) = LoadSound("resources/ohno4.ogg");
       ohno.at(5) = LoadSound("resources/ohno5.ogg");
       ohno.at(6) = LoadSound("resources/ohno6.ogg");
+
+      music = LoadMusicStream("resources/LD52_00.ogg");
+      SetMusicVolume(music, 0.4F);
+
       flags.set(7);
     }
   }
@@ -181,6 +198,10 @@ void Game::update_impl() {
   if (audioNoticeTimer > 0.0F) {
     audioNoticeTimer -= dt;
   }
+
+  if (flags.test(7)) {
+    UpdateMusicStream(music);
+  }
 }
 
 void Game::draw_impl() {
@@ -220,7 +241,7 @@ void Game::draw_impl() {
   }
 
   DrawRectangle(0, offsetY, GetScreenWidth(), height / 3.0F,
-                {255, 255, 255, 127});
+                {255, 255, 255, 160});
 
   DrawLine(0, cutPos, GetScreenWidth(), cutPos, BLACK);
 
@@ -238,6 +259,11 @@ void Game::draw_impl() {
                              OPEN_MOUTH_RADIUS, (FoodType)currentFood);
   }
 
+  if (flags.test(7)) {
+    Helpers::draw_music_note(GetScreenWidth() - MUSIC_NOTE_WH, 0, MUSIC_NOTE_WH,
+                             flags.test(8));
+  }
+
   DrawText(scoreString.c_str(), 2, 2, 32, BLACK);
   DrawText(highScoreString.c_str(), 2, 34, 32, BLACK);
   if (audioNoticeTimer > 0.0F) {
index b96fa6ff7378ba65a3499a615894f611105b3e56..4a1e2a3f1b27539951f79f24e16b18cd634833a2 100644 (file)
@@ -30,6 +30,7 @@ private:
   Texture2D spriteSheet;
   std::array<Sound, 7> nicecut;
   std::array<Sound, 7> ohno;
+  Music music;
   unsigned long long score;
   unsigned long long highScore;
   /*
@@ -41,6 +42,7 @@ private:
    * 5 - sad
    * 6 - relativeCutPos is set
    * 7 - audio loaded
+   * 8 - is music playing
    */
   std::bitset<32> flags;
   float areaSizeRatio;
index 428d39af35e53f65a620b95e04f7f2e20bffaabd..36dfe3b90048cd467e1b57d80d45cdc6087d0228 100644 (file)
@@ -153,3 +153,15 @@ void Helpers::get_fruit_coords(int coords[4], FoodType foodType) {
     break;
   }
 }
+
+void Helpers::draw_music_note(float x, float y, float wh, bool enabled) {
+  float radiusx = wh * 2.7F / 10.0F;
+  DrawEllipse(x + wh / 2.0F, y + wh * 2.0F / 3.0F, radiusx, wh * 2.0F / 10.0F,
+              WHITE);
+  DrawLineEx({x + wh / 2.0F + radiusx - 2.0F, y + wh / 8.0F},
+             {x + wh / 2.0F + radiusx - 2.0F, y + wh * 3.0F / 4.2F}, 4.0F,
+             WHITE);
+  if (!enabled) {
+    draw_x_eye(x + wh / 2.0F, y + wh / 2.0F, wh / 2.0F);
+  }
+}
index 968eea894baeb068fa5a1b433ffb35459e953683..f79ff76a96b67c9d4082f7ce9a0c2774effe11e2 100644 (file)
@@ -21,6 +21,8 @@ extern float get_cut_pos(float timer, FoodType foodType);
 
 extern void get_fruit_coords(int coords[4], FoodType foodType);
 
+extern void draw_music_note(float x, float y, float wh, bool enabled);
+
 } // namespace Helpers
 
 #endif