diff options
author | Max-001 <maxsmits21@kpnmail.nl> | 2025-01-08 11:51:22 +0100 |
---|---|---|
committer | Max-001 <maxsmits21@kpnmail.nl> | 2025-01-08 11:51:22 +0100 |
commit | d9bde56d64ec9154d99425015ca1f9d5ce1ebb0f (patch) | |
tree | 495b178b44aa783d8b44b22b67938a10effdc2a6 | |
parent | 8fc12804f7f0203564cd6352cf47da13a4f46641 (diff) |
Made background forest
-rw-r--r-- | game/background/ForestParallaxScript.cpp | 26 | ||||
-rw-r--r-- | game/background/ForestParallaxScript.h | 6 | ||||
-rw-r--r-- | game/background/ForestSubScene.cpp | 12 |
3 files changed, 37 insertions, 7 deletions
diff --git a/game/background/ForestParallaxScript.cpp b/game/background/ForestParallaxScript.cpp index c72f85d..7470da2 100644 --- a/game/background/ForestParallaxScript.cpp +++ b/game/background/ForestParallaxScript.cpp @@ -1,5 +1,7 @@ #include "ForestParallaxScript.h" +#include "../Config.h" + using namespace crepe; using namespace std; @@ -26,4 +28,28 @@ void ForestParallaxScript::fixed_update(crepe::duration_t dt) { t.position.x = begin_x - 400; } } + + //Move whole background 12000 to the right + Transform & trans_cam = this->get_components_by_name<Transform>("camera").front(); + + float cam_left_x = trans_cam.position.x - VIEWPORT_X / 2; + + if (cam_left_x > this->start_x + this->lenght) { + //Move whole background 12000 to the right + RefVector<Transform> trans + = this->get_components_by_tag<Transform>("background_forest"); + for (Transform & tran : trans) { + tran.position.x += 12000; + } + this->start_x += 12000; + + RefVector<Transform> trans_back + = this->get_components_by_tag<Transform>("forest_background"); + for (Transform & tran : trans_back) { + tran.position.x += 12000; + } + + begin_x += 12000; + end_x += 12000; + } } diff --git a/game/background/ForestParallaxScript.h b/game/background/ForestParallaxScript.h index a65a684..d45fdd9 100644 --- a/game/background/ForestParallaxScript.h +++ b/game/background/ForestParallaxScript.h @@ -9,7 +9,9 @@ public: void fixed_update(crepe::duration_t dt); private: - const float begin_x; - const float end_x; + float begin_x; + float end_x; const std::string name; + float start_x = 4200; + const float lenght = 3000; }; diff --git a/game/background/ForestSubScene.cpp b/game/background/ForestSubScene.cpp index a807a36..83e48dd 100644 --- a/game/background/ForestSubScene.cpp +++ b/game/background/ForestSubScene.cpp @@ -15,14 +15,14 @@ using namespace crepe; using namespace std; float ForestSubScene::create(Scene & scn, float begin_x, std::string unique_bg_name) { - GameObject script = scn.new_object("forest_script", "background"); + GameObject script = scn.new_object("forest_script", "background_forest"); script.add_component<BehaviorScript>().set_script<ForestParallaxScript>( begin_x - 400, begin_x + 3000 + 400, unique_bg_name ); this->add_background(scn, begin_x, unique_bg_name); - GameObject begin = scn.new_object("forest_begin", "background", vec2(begin_x, 0)); + GameObject begin = scn.new_object("forest_begin", "background_forest", vec2(begin_x, 0)); Asset begin_asset {"asset/background/forest/forestFG_1_TVOS.png"}; begin.add_component<Sprite>( begin_asset, @@ -36,7 +36,8 @@ float ForestSubScene::create(Scene & scn, float begin_x, std::string unique_bg_n this->add_background(scn, begin_x, unique_bg_name); - GameObject middle_1 = scn.new_object("forest_middle", "background", vec2(begin_x, 0)); + GameObject middle_1 + = scn.new_object("forest_middle", "background_forest", vec2(begin_x, 0)); Asset middle_1_asset {"asset/background/forest/forestFG_3_TVOS.png"}; middle_1.add_component<Sprite>( middle_1_asset, @@ -50,7 +51,8 @@ float ForestSubScene::create(Scene & scn, float begin_x, std::string unique_bg_n this->add_background(scn, begin_x, unique_bg_name); - GameObject middle_2 = scn.new_object("forest_middle", "background", vec2(begin_x, 0)); + GameObject middle_2 + = scn.new_object("forest_middle", "background_forest", vec2(begin_x, 0)); Asset middle_2_asset {"asset/background/forest/forestFG_3_TVOS.png"}; middle_2.add_component<Sprite>( middle_2_asset, @@ -64,7 +66,7 @@ float ForestSubScene::create(Scene & scn, float begin_x, std::string unique_bg_n this->add_background(scn, begin_x, unique_bg_name); - GameObject end = scn.new_object("forest_end", "background", vec2(begin_x, 0)); + GameObject end = scn.new_object("forest_end", "background_forest", vec2(begin_x, 0)); Asset end_asset {"asset/background/forest/forestFG_2_TVOS.png"}; end.add_component<Sprite>( end_asset, |