diff --git a/src/constants.h b/src/constants.h index 60cee09..b70ceb9 100644 --- a/src/constants.h +++ b/src/constants.h @@ -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 diff --git a/src/game.cc b/src/game.cc index 642e4f3..f0798f0 100644 --- a/src/game.cc +++ b/src/game.cc @@ -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( - 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(0, ohno.size() - 1)(re))); - } else { - // before range - postCutTimer = POST_CUT_TIME; - PlaySound(ohno.at( - std::uniform_int_distribution(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( + 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( + 0, ohno.size() - 1)(re))); + } else { + // before range + postCutTimer = POST_CUT_TIME; + PlaySound(ohno.at(std::uniform_int_distribution( + 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(-SPLIT_DX, SPLIT_DX)(re); - splitDY = std::uniform_real_distribution(-SPLIT_DY, SPLIT_DY)(re); - splitDAngle = - std::uniform_real_distribution(-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(-SPLIT_DX, SPLIT_DX)(re); + splitDY = + std::uniform_real_distribution(-SPLIT_DY, SPLIT_DY)(re); + splitDAngle = + std::uniform_real_distribution(-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) { diff --git a/src/game.h b/src/game.h index b96fa6f..4a1e2a3 100644 --- a/src/game.h +++ b/src/game.h @@ -30,6 +30,7 @@ private: Texture2D spriteSheet; std::array nicecut; std::array 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; diff --git a/src/helpers.cc b/src/helpers.cc index 428d39a..36dfe3b 100644 --- a/src/helpers.cc +++ b/src/helpers.cc @@ -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); + } +} diff --git a/src/helpers.h b/src/helpers.h index 968eea8..f79ff76 100644 --- a/src/helpers.h +++ b/src/helpers.h @@ -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