: re(std::random_device{}()), dist(0, FOOD_COUNT - 1), score(0),
highScore(0), areaSizeRatio(1.0F), currentFood(dist(re)),
blinkTimer(10.0F), cutTimer(0.0F), cutTimerRateInc(1.0F),
- postCutTimer(0.0F) {
+ postCutTimer(0.0F), audioNoticeTimer(7.0F) {
flags.set(0);
flags.set(3);
draw_impl();
}
+void Game::screen_resized() { flags.set(3); }
+
void Game::update_impl() {
const float dt = GetFrameTime();
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)) {
reset(!flags.test(2));
}
}
+
+ if (!flags.test(7)) {
+ InitAudioDevice();
+
+ if (IsAudioDeviceReady()) {
+ nicecut.at(0) = LoadSound("resources/nicecut0.ogg");
+ nicecut.at(1) = LoadSound("resources/nicecut1.ogg");
+ nicecut.at(2) = LoadSound("resources/nicecut2.ogg");
+ nicecut.at(3) = LoadSound("resources/nicecut3.ogg");
+ nicecut.at(4) = LoadSound("resources/nicecut4.ogg");
+ nicecut.at(5) = LoadSound("resources/nicecut5.ogg");
+ nicecut.at(6) = LoadSound("resources/nicecut6.ogg");
+
+ ohno.at(0) = LoadSound("resources/ohno0.ogg");
+ ohno.at(1) = LoadSound("resources/ohno1.ogg");
+ ohno.at(2) = LoadSound("resources/ohno2.ogg");
+ ohno.at(3) = LoadSound("resources/ohno3.ogg");
+ ohno.at(4) = LoadSound("resources/ohno4.ogg");
+ ohno.at(5) = LoadSound("resources/ohno5.ogg");
+ ohno.at(6) = LoadSound("resources/ohno6.ogg");
+ flags.set(7);
+ }
+ }
+
+ if (audioNoticeTimer > 0.0F) {
+ audioNoticeTimer -= dt;
+ }
}
void Game::draw_impl() {
DrawText(scoreString.c_str(), 2, 2, 32, BLACK);
DrawText(highScoreString.c_str(), 2, 34, 32, BLACK);
+ if (audioNoticeTimer > 0.0F) {
+ DrawText("Try refreshing if there is no audio", 2, 70, 32, BLACK);
+ }
EndDrawing();
}
#define LD52_HARVEST_FOOD_CUTS_GAME_H_
// standard library includes
+#include <array>
#include <bitset>
#include <random>
void do_update();
+ void screen_resized();
+
private:
void update_impl();
void draw_impl();
std::string scoreString;
std::string highScoreString;
Texture2D spriteSheet;
+ std::array<Sound, 7> nicecut;
+ std::array<Sound, 7> ohno;
unsigned long long score;
unsigned long long highScore;
/*
* 4 - cut has happened
* 5 - sad
* 6 - relativeCutPos is set
+ * 7 - audio loaded
*/
std::bitset<32> flags;
float areaSizeRatio;
float splitDY;
float splitDAngle;
float postCutTimer;
+ float audioNoticeTimer;
};
#endif
void *ud) {
if (event_type == EMSCRIPTEN_EVENT_RESIZE) {
SetWindowSize(call_js_get_canvas_width(), call_js_get_canvas_height());
+ ((Game *)ud)->screen_resized();
}
return false;
}
SetWindowSize(call_js_get_canvas_width(), call_js_get_canvas_height());
- emscripten_set_resize_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, nullptr, false,
+ emscripten_set_resize_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, &game, false,
resize_event_callback);
emscripten_set_main_loop_arg(game_update, &game, 0, 1);