aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormax-001 <maxsmits21@kpnmail.nl>2024-12-19 11:13:31 +0100
committermax-001 <maxsmits21@kpnmail.nl>2024-12-19 11:13:31 +0100
commitedd5fd83f4a5337ba06955bd59a136f7eb699234 (patch)
tree34df11d1c15816840a0542e3789d7c7eae92fdd4
parent067aa2536f9f43d07e22696c618258a26ae928b3 (diff)
Moved ForestParallaxScript to seperate file
-rw-r--r--src/example/CMakeLists.txt2
-rw-r--r--src/example/ForestParallaxScript.cpp28
-rw-r--r--src/example/ForestParallaxScript.h15
-rw-r--r--src/example/ForestSubScene.cpp32
4 files changed, 46 insertions, 31 deletions
diff --git a/src/example/CMakeLists.txt b/src/example/CMakeLists.txt
index f1d165a..cd7407f 100644
--- a/src/example/CMakeLists.txt
+++ b/src/example/CMakeLists.txt
@@ -2,6 +2,7 @@ set(GAME_HEADERS
AquariumSubScene.h
BackgroundSubScene.h
ForestSubScene.h
+ ForestParallaxScript.h
HallwaySubScene.h
StartSubScene.h
GameScene.h
@@ -14,6 +15,7 @@ set(GAME_SOURCES
AquariumSubScene.cpp
BackgroundSubScene.cpp
ForestSubScene.cpp
+ ForestParallaxScript.cpp
HallwaySubScene.cpp
StartSubScene.cpp
GameScene.cpp
diff --git a/src/example/ForestParallaxScript.cpp b/src/example/ForestParallaxScript.cpp
new file mode 100644
index 0000000..782cdf0
--- /dev/null
+++ b/src/example/ForestParallaxScript.cpp
@@ -0,0 +1,28 @@
+#include "ForestParallaxScript.h"
+
+using namespace crepe;
+using namespace std;
+
+ForestParallaxScript::ForestParallaxScript(float begin_x, float end_x,
+ std::string unique_bg_name)
+ : begin_x(begin_x),
+ end_x(end_x),
+ name(unique_bg_name) {}
+
+void ForestParallaxScript::update() {
+ RefVector<Transform> vec_2
+ = this->get_components_by_name<Transform>("forest_bg_2_" + name);
+ RefVector<Transform> vec_3
+ = this->get_components_by_name<Transform>("forest_bg_3_" + name);
+
+ for (Transform & t : vec_2) {
+ if (t.position.x > end_x - 400) {
+ t.position.x = begin_x - 400;
+ }
+ }
+ for (Transform & t : vec_3) {
+ if (t.position.x > end_x - 400) {
+ t.position.x = begin_x - 400;
+ }
+ }
+}
diff --git a/src/example/ForestParallaxScript.h b/src/example/ForestParallaxScript.h
new file mode 100644
index 0000000..39b7ecb
--- /dev/null
+++ b/src/example/ForestParallaxScript.h
@@ -0,0 +1,15 @@
+#pragma once
+
+#include <crepe/api/Script.h>
+
+class ForestParallaxScript : public crepe::Script {
+public:
+ ForestParallaxScript(float begin_x, float end_x, std::string unique_bg_name);
+
+ void update();
+
+private:
+ const float begin_x;
+ const float end_x;
+ const std::string name;
+};
diff --git a/src/example/ForestSubScene.cpp b/src/example/ForestSubScene.cpp
index 713d95f..9be875d 100644
--- a/src/example/ForestSubScene.cpp
+++ b/src/example/ForestSubScene.cpp
@@ -1,4 +1,5 @@
#include "ForestSubScene.h"
+#include "ForestParallaxScript.h"
#include <crepe/api/Animator.h>
#include <crepe/api/BehaviorScript.h>
@@ -11,37 +12,6 @@
using namespace crepe;
using namespace std;
-class ForestParallaxScript : public Script {
-public:
- ForestParallaxScript(float begin_x, float end_x, std::string unique_bg_name)
- : begin_x(begin_x),
- end_x(end_x),
- name(unique_bg_name) {}
-
- void update() {
- RefVector<Transform> vec_2
- = this->get_components_by_name<Transform>("forest_bg_2_" + name);
- RefVector<Transform> vec_3
- = this->get_components_by_name<Transform>("forest_bg_3_" + name);
-
- for (Transform & t : vec_2) {
- if (t.position.x > end_x - 400) {
- t.position.x = begin_x - 400;
- }
- }
- for (Transform & t : vec_3) {
- if (t.position.x > end_x - 400) {
- t.position.x = begin_x - 400;
- }
- }
- }
-
-private:
- const float begin_x;
- const float end_x;
- const std::string name;
-};
-
float ForestSubScene::create(Scene & scn, float begin_x, std::string unique_bg_name) {
GameObject script = scn.new_object("forest_script", "background");
script.add_component<BehaviorScript>().set_script<ForestParallaxScript>(