From b5ed442444d7243935f7ba58c7d0e0ada743d230 Mon Sep 17 00:00:00 2001 From: Max-001 Date: Wed, 8 Jan 2025 12:52:52 +0100 Subject: Added coin pickup sound --- game/coins/CoinScript.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'game/coins/CoinScript.cpp') diff --git a/game/coins/CoinScript.cpp b/game/coins/CoinScript.cpp index 90150b6..c5ca62c 100644 --- a/game/coins/CoinScript.cpp +++ b/game/coins/CoinScript.cpp @@ -5,6 +5,7 @@ #include "../Config.h" #include "../hud/HudScript.h" +#include #include #include @@ -29,6 +30,13 @@ bool CoinScript::on_collision(const CollisionEvent & collisionData) { .active = false; this->amount++; + + AudioSource & audio = this->get_components_by_id( + collisionData.info.other.metadata.game_object_id + ) + .front(); + audio.play(); + return false; } -- cgit v1.2.3 From a5854e1346c96ade73ae1e69ee8b7a6c94c78b07 Mon Sep 17 00:00:00 2001 From: Max-001 Date: Wed, 8 Jan 2025 13:21:21 +0100 Subject: Added coin animation --- game/Random.cpp | 1 - game/Random.h | 2 -- game/coins/CoinScript.cpp | 12 ++++++++++++ game/coins/CoinSubScene.cpp | 20 ++++++++++++++++++++ game/coins/CoinSystemScript.cpp | 4 ++++ 5 files changed, 36 insertions(+), 3 deletions(-) (limited to 'game/coins/CoinScript.cpp') diff --git a/game/Random.cpp b/game/Random.cpp index 59be3c5..ace6245 100644 --- a/game/Random.cpp +++ b/game/Random.cpp @@ -25,4 +25,3 @@ unsigned Random::u(unsigned upper, unsigned lower) { unsigned x = rand() % range; return x + lower; } - diff --git a/game/Random.h b/game/Random.h index cf05e87..8af9669 100644 --- a/game/Random.h +++ b/game/Random.h @@ -6,6 +6,4 @@ public: static double d(double upper = 1.0, double lower = 0.0); static int i(int upper, int lower = 0); static unsigned u(unsigned upper, unsigned lower = 0); - }; - diff --git a/game/coins/CoinScript.cpp b/game/coins/CoinScript.cpp index c5ca62c..514f4de 100644 --- a/game/coins/CoinScript.cpp +++ b/game/coins/CoinScript.cpp @@ -5,6 +5,7 @@ #include "../Config.h" #include "../hud/HudScript.h" +#include #include #include #include @@ -37,6 +38,17 @@ bool CoinScript::on_collision(const CollisionEvent & collisionData) { .front(); audio.play(); + this->get_components_by_name(collisionData.info.other.metadata.name) + .back() + .get() + .active + = true; + this->get_components_by_name(collisionData.info.other.metadata.name) + .back() + .get() + .active + = true; + return false; } diff --git a/game/coins/CoinSubScene.cpp b/game/coins/CoinSubScene.cpp index 3bd6641..d154819 100644 --- a/game/coins/CoinSubScene.cpp +++ b/game/coins/CoinSubScene.cpp @@ -40,5 +40,25 @@ int CoinSubScene::create(Scene & scn, int coin_counter) { } ); coin.add_component(Asset {"asset/sfx/coin_pickup_1.ogg"}).volume = 3; + + Sprite & pick_up = coin.add_component( + Asset {"asset/coin/coinCollect1_TVOS.png"}, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_COINS, + .order_in_layer = 1, + .size = size * 2, + } + ); + pick_up.active = false; + coin.add_component( + pick_up, ivec2 {64, 64}, uvec2 {5, 1}, + Animator::Data { + .fps = 5, + .looping = false, + } + ) + .active + = false; + return coin_counter; } diff --git a/game/coins/CoinSystemScript.cpp b/game/coins/CoinSystemScript.cpp index 1634aa9..f9816c9 100644 --- a/game/coins/CoinSystemScript.cpp +++ b/game/coins/CoinSystemScript.cpp @@ -209,6 +209,10 @@ void CoinSystemScript::spawn_coins() { for (Sprite & coin_sprite : coin_sprites) { // Skip this sprite if it is already active if (coin_sprite.active) continue; + if (coin_sprite.data.order_in_layer == 1) { + coin_sprite.active = false; + continue; + } // Found an available (inactive) coin sprite // Retrieve its associated components -- cgit v1.2.3