Use music, add music button, minor tweaks
This commit is contained in:
parent
bcc726dfd5
commit
a3f267bba6
5 changed files with 78 additions and 34 deletions
|
@ -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
|
||||||
|
|
42
src/game.cc
42
src/game.cc
|
@ -106,7 +106,17 @@ 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)) {
|
||||||
|
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);
|
flags.set(4);
|
||||||
if (cutPos >= offsetY && cutPos <= offsetY + height / 3.0F) {
|
if (cutPos >= offsetY && cutPos <= offsetY + height / 3.0F) {
|
||||||
// in correct range
|
// in correct range
|
||||||
|
@ -119,13 +129,13 @@ void Game::update_impl() {
|
||||||
// past range
|
// past range
|
||||||
flags.set(5);
|
flags.set(5);
|
||||||
postCutTimer = POST_CUT_TIME;
|
postCutTimer = POST_CUT_TIME;
|
||||||
PlaySound(ohno.at(
|
PlaySound(ohno.at(std::uniform_int_distribution<unsigned int>(
|
||||||
std::uniform_int_distribution<unsigned int>(0, ohno.size() - 1)(re)));
|
0, ohno.size() - 1)(re)));
|
||||||
} else {
|
} else {
|
||||||
// before range
|
// before range
|
||||||
postCutTimer = POST_CUT_TIME;
|
postCutTimer = POST_CUT_TIME;
|
||||||
PlaySound(ohno.at(
|
PlaySound(ohno.at(std::uniform_int_distribution<unsigned int>(
|
||||||
std::uniform_int_distribution<unsigned int>(0, ohno.size() - 1)(re)));
|
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)) {
|
||||||
|
@ -134,14 +144,17 @@ void Game::update_impl() {
|
||||||
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);
|
||||||
|
splitDY =
|
||||||
|
std::uniform_real_distribution<float>(-SPLIT_DY, SPLIT_DY)(re);
|
||||||
splitDAngle =
|
splitDAngle =
|
||||||
std::uniform_real_distribution<float>(-SPLIT_DA, SPLIT_DA)(re);
|
std::uniform_real_distribution<float>(-SPLIT_DA, SPLIT_DA)(re);
|
||||||
postCutTimer = POST_CUT_TIME;
|
postCutTimer = POST_CUT_TIME;
|
||||||
cutTimerRateInc += CUT_TIMER_RATE_INC_AMT;
|
cutTimerRateInc += CUT_TIMER_RATE_INC_AMT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (flags.test(6)) {
|
if (flags.test(6)) {
|
||||||
splitX += splitDX * dt;
|
splitX += splitDX * dt;
|
||||||
|
@ -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) {
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue