diff options
author | JAROWMR <jarorutjes07@gmail.com> | 2025-01-08 14:40:45 +0100 |
---|---|---|
committer | JAROWMR <jarorutjes07@gmail.com> | 2025-01-08 14:40:45 +0100 |
commit | e634f23fda2cea14aaa1b70b1e5e463eee9665a7 (patch) | |
tree | 4e71073df8d5e3e898c3c0e23c1cc8002375135f | |
parent | 3b6081d03300d353434fd4f6e91237fc8f1a4390 (diff) | |
parent | 91366375a7b2a9be670e4842604512254a9c116e (diff) |
Merge branch 'master' of github.com:lonkaars/crepe into jaro/game
-rw-r--r-- | game/GameScene.cpp | 2 | ||||
-rw-r--r-- | game/Random.cpp | 1 | ||||
-rw-r--r-- | game/Random.h | 2 | ||||
-rw-r--r-- | game/background/AquariumSubScene.cpp | 69 | ||||
-rw-r--r-- | game/background/AquariumSubScene.h | 7 | ||||
-rw-r--r-- | game/coins/CoinScript.cpp | 20 | ||||
-rw-r--r-- | game/coins/CoinSubScene.cpp | 22 | ||||
-rw-r--r-- | game/coins/CoinSystemScript.cpp | 4 |
8 files changed, 115 insertions, 12 deletions
diff --git a/game/GameScene.cpp b/game/GameScene.cpp index 9376eab..c84ec24 100644 --- a/game/GameScene.cpp +++ b/game/GameScene.cpp @@ -40,7 +40,7 @@ void GameScene::load_scene() { camera.add_component<Camera>( ivec2(990, 720), vec2(VIEWPORT_X, VIEWPORT_Y), Camera::Data { - .bg_color = Color::RED, + .bg_color = Color::BLACK, } ); camera.add_component<BehaviorScript>().set_script<MoveCameraManualyScript>(); 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/background/AquariumSubScene.cpp b/game/background/AquariumSubScene.cpp index 99466e3..2a07daf 100644 --- a/game/background/AquariumSubScene.cpp +++ b/game/background/AquariumSubScene.cpp @@ -4,6 +4,7 @@ #include <crepe/api/Animator.h> #include <crepe/api/GameObject.h> +#include <crepe/api/ParticleEmitter.h> #include <crepe/api/Scene.h> #include <crepe/api/Sprite.h> #include <crepe/types.h> @@ -41,6 +42,9 @@ float AquariumSubScene::create(Scene & scn, float begin_x) { begin_x += 400; this->add_background(scn, begin_x - 200); + this->add_bubbles(aquarium_middle_1, vec2(-400, 300), 2, 0.7f); + this->add_bubbles(aquarium_middle_1, vec2(-100, 300), 4, 1.0f); + this->add_bubbles(aquarium_middle_1, vec2(500, 300), 4, 0.9f); GameObject aquarium_middle_2 = scn.new_object("aquarium_middle", "background_aqua", vec2(begin_x, 0)); @@ -55,6 +59,8 @@ float AquariumSubScene::create(Scene & scn, float begin_x) { ); begin_x += 400; + this->add_bubbles(aquarium_middle_2, vec2(300, 300), 2, 0.6f); + GameObject aquarium_middle_3 = scn.new_object("aquarium_middle", "background_aqua", vec2(begin_x, 0)); Asset aquarium_middle_3_asset {"asset/background/aquarium/glassTubeFG_3_TVOS.png"}; @@ -84,6 +90,8 @@ float AquariumSubScene::create(Scene & scn, float begin_x) { begin_x += 600; this->add_background(scn, begin_x); + this->add_bubbles(aquarium_middle_4, vec2(175, 300), 4, 1.0f); + this->add_bubbles(aquarium_middle_4, vec2(200, 300), 4, 0.7f); GameObject aquarium_end = scn.new_object("aquarium_end", "background_aqua", vec2(begin_x, 0)); @@ -108,7 +116,7 @@ void AquariumSubScene::add_background(Scene & scn, float begin_x) { bg_1_1_asset, Sprite::Data { .sorting_in_layer = SORT_IN_LAY_BACK_BACKGROUND, - .order_in_layer = 2, + .order_in_layer = 5, .size = vec2(0, 400), .position_offset = vec2(-200, 100), } @@ -118,7 +126,7 @@ void AquariumSubScene::add_background(Scene & scn, float begin_x) { bg_1_2_asset, Sprite::Data { .sorting_in_layer = SORT_IN_LAY_BACK_BACKGROUND, - .order_in_layer = 2, + .order_in_layer = 5, .size = vec2(0, 400), .position_offset = vec2(200, 100), } @@ -129,7 +137,7 @@ void AquariumSubScene::add_background(Scene & scn, float begin_x) { bg_2_1_asset, Sprite::Data { .sorting_in_layer = SORT_IN_LAY_BACK_BACKGROUND, - .order_in_layer = 1, + .order_in_layer = 3, .size = vec2(0, 400), .position_offset = vec2(200, -50), } @@ -139,7 +147,7 @@ void AquariumSubScene::add_background(Scene & scn, float begin_x) { bg_2_2_asset, Sprite::Data { .sorting_in_layer = SORT_IN_LAY_BACK_BACKGROUND, - .order_in_layer = 1, + .order_in_layer = 3, .size = vec2(0, 400), .position_offset = vec2(-200, -50), } @@ -150,7 +158,7 @@ void AquariumSubScene::add_background(Scene & scn, float begin_x) { bg_3_1_asset, Sprite::Data { .sorting_in_layer = SORT_IN_LAY_BACK_BACKGROUND, - .order_in_layer = 0, + .order_in_layer = 1, .size = vec2(0, 400), .position_offset = vec2(200, -200), } @@ -160,9 +168,58 @@ void AquariumSubScene::add_background(Scene & scn, float begin_x) { bg_3_2_asset, Sprite::Data { .sorting_in_layer = SORT_IN_LAY_BACK_BACKGROUND, - .order_in_layer = 0, + .order_in_layer = 1, .size = vec2(0, 400), .position_offset = vec2(-200, -200), } ); } + +void AquariumSubScene::add_bubbles( + GameObject & obj, vec2 offset, int order_in_layer, float scale +) { + Sprite & sprite = obj.add_component<Sprite>( + Asset {"asset/background/aquarium/bubble.png"}, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_BACK_BACKGROUND, + .order_in_layer = order_in_layer, + .size = vec2(0, 12.5), + .scale_offset = scale, + } + ); + obj.add_component<ParticleEmitter>( + sprite, + ParticleEmitter::Data { + .offset = offset, + .max_particles = 20, + .emission_rate = 1.2, + .min_speed = 50, + .max_speed = 100, + .min_angle = 265, + .max_angle = 275, + .force_over_time = vec2(0, -50), + } + ); + Sprite & sprite_small = obj.add_component<Sprite>( + Asset {"asset/background/aquarium/bubble.png"}, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_BACK_BACKGROUND, + .order_in_layer = order_in_layer, + .size = vec2(0, 7.5), + .scale_offset = scale, + } + ); + obj.add_component<ParticleEmitter>( + sprite_small, + ParticleEmitter::Data { + .offset = offset, + .max_particles = 20, + .emission_rate = 0.8, + .min_speed = 50, + .max_speed = 100, + .min_angle = 265, + .max_angle = 275, + .force_over_time = vec2(0, -50), + } + ); +} diff --git a/game/background/AquariumSubScene.h b/game/background/AquariumSubScene.h index 2a188bc..9dbb04e 100644 --- a/game/background/AquariumSubScene.h +++ b/game/background/AquariumSubScene.h @@ -1,8 +1,11 @@ #pragma once +#include <crepe/types.h> + namespace crepe { class Scene; -} +class GameObject; +} // namespace crepe class AquariumSubScene { public: @@ -10,4 +13,6 @@ public: private: void add_background(crepe::Scene & scn, float begin_x); + void + add_bubbles(crepe::GameObject & obj, crepe::vec2 offset, int order_in_layer, float scale); }; 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 |