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/coins/CoinScript.cpp | 12 ++++++++++++ game/coins/CoinSubScene.cpp | 20 ++++++++++++++++++++ game/coins/CoinSystemScript.cpp | 4 ++++ 3 files changed, 36 insertions(+) (limited to 'game/coins') 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