]> git.seodisparate.com - RockPaperScissorsDuel/commitdiff
Use sfx_draw
authorStephen Seo <seo.disparate@gmail.com>
Thu, 19 Jan 2023 07:23:34 +0000 (16:23 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Thu, 19 Jan 2023 07:23:34 +0000 (16:23 +0900)
src/3d_renderer.cc
src/3d_renderer.h

index 601472d74cba9655060cc5ff4fa8f275702fa014..8ef3562139ffe4be753810e1cba0070e9f4e1616 100644 (file)
@@ -745,6 +745,14 @@ int Renderer3D::setup_anims(int idx, int score) {
   if (result != 0) {
     newAnim->push_anim(std::move(seqAnim));
     anims.push_anim(std::move(newAnim));
+  } else {
+    newAnim->set_end_callback(
+        [](void *ud) {
+          auto *sfx = (Sound *)ud;
+          PlaySound(*sfx);
+        },
+        get_random_draw_sfx());
+    anims.push_anim(std::move(newAnim));
   }
 
   newAnim = std::make_unique<AnimConcurrent>(nullptr);
@@ -834,6 +842,10 @@ void Renderer3D::load_sounds() {
     rock_sfx.at(1) = LoadSound("resources/sfx_rock1.ogg");
     rock_sfx.at(2) = LoadSound("resources/sfx_rock2.ogg");
     rock_sfx.at(3) = LoadSound("resources/sfx_rock3.ogg");
+
+    draw_sfx.at(0) = LoadSound("resources/sfx_draw0.ogg");
+    draw_sfx.at(1) = LoadSound("resources/sfx_draw1.ogg");
+    draw_sfx.at(2) = LoadSound("resources/sfx_draw2.ogg");
   }
 }
 
@@ -861,6 +873,14 @@ Sound *Renderer3D::get_random_scissors_sfx() {
 #endif
 }
 
+Sound *Renderer3D::get_random_draw_sfx() {
+#ifdef __EMSCRIPTEN__
+  return &draw_sfx.at(call_js_get_random() * draw_sfx.size());
+#else
+  return &draw_sfx.at(GetRandomValue(0, draw_sfx.size() - 1));
+#endif
+}
+
 Sound *Renderer3D::type_to_sfx(char type) {
   switch (type) {
     case 'r':
index 7a7babcdfc178b958677ef4a2f314f24fee3fe0e..ada2754f032bdb5fd80ae4abfea0d1a8ed2dc27e 100644 (file)
@@ -53,6 +53,7 @@ class Renderer3D : public GameRenderer {
   Sound *get_random_rock_sfx();
   Sound *get_random_paper_sfx();
   Sound *get_random_scissors_sfx();
+  Sound *get_random_draw_sfx();
 
   Sound *type_to_sfx(char type);
 
@@ -80,6 +81,7 @@ class Renderer3D : public GameRenderer {
   std::array<Sound, 5> paper_sfx;
   std::array<Sound, 5> scissors_sfx;
   std::array<Sound, 4> rock_sfx;
+  std::array<Sound, 3> draw_sfx;
 
   AnimSequence anims;