From 3edb0f9c210864968e282109810018b6e50f8ff4 Mon Sep 17 00:00:00 2001 From: Stephen Seo Date: Thu, 19 Jan 2023 16:23:34 +0900 Subject: [PATCH] Use sfx_draw --- src/3d_renderer.cc | 20 ++++++++++++++++++++ src/3d_renderer.h | 2 ++ 2 files changed, 22 insertions(+) diff --git a/src/3d_renderer.cc b/src/3d_renderer.cc index 601472d..8ef3562 100644 --- a/src/3d_renderer.cc +++ b/src/3d_renderer.cc @@ -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(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': diff --git a/src/3d_renderer.h b/src/3d_renderer.h index 7a7babc..ada2754 100644 --- a/src/3d_renderer.h +++ b/src/3d_renderer.h @@ -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 paper_sfx; std::array scissors_sfx; std::array rock_sfx; + std::array draw_sfx; AnimSequence anims; -- 2.49.0