Use music, add music button, minor tweaks

This commit is contained in:
Stephen Seo 2023-01-07 18:20:58 +09:00
parent bcc726dfd5
commit a3f267bba6
5 changed files with 78 additions and 34 deletions

View file

@ -56,4 +56,6 @@ constexpr float SPLIT_DA = 100.0F;
constexpr float POST_CUT_TIME = 1.7F; constexpr float POST_CUT_TIME = 1.7F;
constexpr float MUSIC_NOTE_WH = 80.0F;
#endif #endif

View file

@ -106,40 +106,53 @@ void Game::update_impl() {
cutPos = cutTimer * height + offsetY - height / 3.0F; cutPos = cutTimer * height + offsetY - height / 3.0F;
if (!flags.test(4) && IsMouseButtonPressed(0)) { if (IsMouseButtonPressed(0)) {
flags.set(4); if (flags.test(7) && GetTouchX() >= GetScreenWidth() - MUSIC_NOTE_WH &&
if (cutPos >= offsetY && cutPos <= offsetY + height / 3.0F) { GetTouchX() <= GetScreenWidth() && GetTouchY() >= 0 &&
// in correct range GetTouchY() <= MUSIC_NOTE_WH) {
flags.set(2); flags.flip(8);
++score; if (flags.test(8)) {
flags.set(0); PlayMusicStream(music);
PlaySound(nicecut.at(std::uniform_int_distribution<unsigned int>( } else {
0, nicecut.size() - 1)(re))); PauseMusicStream(music);
} else if (cutPos > offsetY + height / 3.0F) { }
// past range } else if (!flags.test(4)) {
flags.set(5); flags.set(4);
postCutTimer = POST_CUT_TIME; if (cutPos >= offsetY && cutPos <= offsetY + height / 3.0F) {
PlaySound(ohno.at( // in correct range
std::uniform_int_distribution<unsigned int>(0, ohno.size() - 1)(re))); flags.set(2);
} else { ++score;
// before range flags.set(0);
postCutTimer = POST_CUT_TIME; PlaySound(nicecut.at(std::uniform_int_distribution<unsigned int>(
PlaySound(ohno.at( 0, nicecut.size() - 1)(re)));
std::uniform_int_distribution<unsigned int>(0, ohno.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)) { if (flags.test(4) && (flags.test(2) || flags.test(5)) && !flags.test(6)) {
flags.set(6); flags.set(6);
relativeCutRatio = (cutPos - offsetY) / height; relativeCutRatio = (cutPos - offsetY) / height;
splitX = offsetX; splitX = offsetX;
splitY = offsetY; splitY = offsetY;
splitAngle = 0.0F; splitAngle = 0.0F;
splitDX = std::uniform_real_distribution<float>(-SPLIT_DX, SPLIT_DX)(re); splitDX =
splitDY = std::uniform_real_distribution<float>(-SPLIT_DY, SPLIT_DY)(re); std::uniform_real_distribution<float>(-SPLIT_DX, SPLIT_DX)(re);
splitDAngle = splitDY =
std::uniform_real_distribution<float>(-SPLIT_DA, SPLIT_DA)(re); std::uniform_real_distribution<float>(-SPLIT_DY, SPLIT_DY)(re);
postCutTimer = POST_CUT_TIME; splitDAngle =
cutTimerRateInc += CUT_TIMER_RATE_INC_AMT; 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(4) = LoadSound("resources/ohno4.ogg");
ohno.at(5) = LoadSound("resources/ohno5.ogg"); ohno.at(5) = LoadSound("resources/ohno5.ogg");
ohno.at(6) = LoadSound("resources/ohno6.ogg"); ohno.at(6) = LoadSound("resources/ohno6.ogg");
music = LoadMusicStream("resources/LD52_00.ogg");
SetMusicVolume(music, 0.4F);
flags.set(7); flags.set(7);
} }
} }
@ -181,6 +198,10 @@ void Game::update_impl() {
if (audioNoticeTimer > 0.0F) { if (audioNoticeTimer > 0.0F) {
audioNoticeTimer -= dt; audioNoticeTimer -= dt;
} }
if (flags.test(7)) {
UpdateMusicStream(music);
}
} }
void Game::draw_impl() { void Game::draw_impl() {
@ -220,7 +241,7 @@ void Game::draw_impl() {
} }
DrawRectangle(0, offsetY, GetScreenWidth(), height / 3.0F, DrawRectangle(0, offsetY, GetScreenWidth(), height / 3.0F,
{255, 255, 255, 127}); {255, 255, 255, 160});
DrawLine(0, cutPos, GetScreenWidth(), cutPos, BLACK); DrawLine(0, cutPos, GetScreenWidth(), cutPos, BLACK);
@ -238,6 +259,11 @@ void Game::draw_impl() {
OPEN_MOUTH_RADIUS, (FoodType)currentFood); 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(scoreString.c_str(), 2, 2, 32, BLACK);
DrawText(highScoreString.c_str(), 2, 34, 32, BLACK); DrawText(highScoreString.c_str(), 2, 34, 32, BLACK);
if (audioNoticeTimer > 0.0F) { if (audioNoticeTimer > 0.0F) {

View file

@ -30,6 +30,7 @@ private:
Texture2D spriteSheet; Texture2D spriteSheet;
std::array<Sound, 7> nicecut; std::array<Sound, 7> nicecut;
std::array<Sound, 7> ohno; std::array<Sound, 7> ohno;
Music music;
unsigned long long score; unsigned long long score;
unsigned long long highScore; unsigned long long highScore;
/* /*
@ -41,6 +42,7 @@ private:
* 5 - sad * 5 - sad
* 6 - relativeCutPos is set * 6 - relativeCutPos is set
* 7 - audio loaded * 7 - audio loaded
* 8 - is music playing
*/ */
std::bitset<32> flags; std::bitset<32> flags;
float areaSizeRatio; float areaSizeRatio;

View file

@ -153,3 +153,15 @@ void Helpers::get_fruit_coords(int coords[4], FoodType foodType) {
break; 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);
}
}

View 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 get_fruit_coords(int coords[4], FoodType foodType);
extern void draw_music_note(float x, float y, float wh, bool enabled);
} // namespace Helpers } // namespace Helpers
#endif #endif