diff options
-rw-r--r-- | game/Random.cpp | 1 | ||||
-rw-r--r-- | game/Random.h | 2 | ||||
-rw-r--r-- | game/coins/CoinScript.cpp | 12 | ||||
-rw-r--r-- | game/coins/CoinSubScene.cpp | 20 | ||||
-rw-r--r-- | game/coins/CoinSystemScript.cpp | 4 |
5 files changed, 36 insertions, 3 deletions
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 <crepe/api/Animator.h> #include <crepe/api/AudioSource.h> #include <crepe/api/CircleCollider.h> #include <crepe/api/Sprite.h> @@ -37,6 +38,17 @@ bool CoinScript::on_collision(const CollisionEvent & collisionData) { .front(); audio.play(); + this->get_components_by_name<Sprite>(collisionData.info.other.metadata.name) + .back() + .get() + .active + = true; + this->get_components_by_name<Animator>(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<AudioSource>(Asset {"asset/sfx/coin_pickup_1.ogg"}).volume = 3; + + Sprite & pick_up = coin.add_component<Sprite>( + 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<Animator>( + 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 |