aboutsummaryrefslogtreecommitdiff
path: root/game/coins
diff options
context:
space:
mode:
Diffstat (limited to 'game/coins')
-rw-r--r--game/coins/CoinScript.cpp20
-rw-r--r--game/coins/CoinSubScene.cpp22
-rw-r--r--game/coins/CoinSystemScript.cpp4
3 files changed, 45 insertions, 1 deletions
diff --git a/game/coins/CoinScript.cpp b/game/coins/CoinScript.cpp
index 90150b6..514f4de 100644
--- a/game/coins/CoinScript.cpp
+++ b/game/coins/CoinScript.cpp
@@ -5,6 +5,8 @@
#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>
@@ -29,6 +31,24 @@ bool CoinScript::on_collision(const CollisionEvent & collisionData) {
.active
= false;
this->amount++;
+
+ AudioSource & audio = this->get_components_by_id<AudioSource>(
+ collisionData.info.other.metadata.game_object_id
+ )
+ .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 2c9feb6..d154819 100644
--- a/game/coins/CoinSubScene.cpp
+++ b/game/coins/CoinSubScene.cpp
@@ -39,6 +39,26 @@ int CoinSubScene::create(Scene & scn, int coin_counter) {
.looping = true,
}
);
- coin.add_component<AudioSource>(Asset {"asset/sfx/coin_pickup_1.ogg"});
+ 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