aboutsummaryrefslogtreecommitdiff
path: root/game
diff options
context:
space:
mode:
authorMax-001 <maxsmits21@kpnmail.nl>2025-01-08 11:22:53 +0100
committerMax-001 <maxsmits21@kpnmail.nl>2025-01-08 11:22:53 +0100
commit8fc12804f7f0203564cd6352cf47da13a4f46641 (patch)
tree069c7ffe36fee345cb6532a15435f3fab03371e3 /game
parentb2fb4028f13f47d89487d48a1cc1e3e062d81e35 (diff)
Made background aquarium move
Diffstat (limited to 'game')
-rw-r--r--game/CMakeLists.txt1
-rw-r--r--game/background/AquariumScript.cpp26
-rw-r--r--game/background/AquariumScript.h12
-rw-r--r--game/background/AquariumSubScene.cpp19
-rw-r--r--game/background/BackgroundSubScene.cpp6
5 files changed, 53 insertions, 11 deletions
diff --git a/game/CMakeLists.txt b/game/CMakeLists.txt
index a0e09de..662a5e7 100644
--- a/game/CMakeLists.txt
+++ b/game/CMakeLists.txt
@@ -10,6 +10,7 @@ project(game C CXX)
add_subdirectory(../src crepe)
add_executable(main
background/AquariumSubScene.cpp
+ background/AquariumScript.cpp
background/BackgroundSubScene.cpp
background/ForestParallaxScript.cpp
background/ForestSubScene.cpp
diff --git a/game/background/AquariumScript.cpp b/game/background/AquariumScript.cpp
new file mode 100644
index 0000000..e698e3a
--- /dev/null
+++ b/game/background/AquariumScript.cpp
@@ -0,0 +1,26 @@
+#include "AquariumScript.h"
+
+#include "../Config.h"
+
+#include <crepe/api/Animator.h>
+#include <crepe/api/Sprite.h>
+#include <crepe/api/Transform.h>
+#include <crepe/types.h>
+
+using namespace crepe;
+using namespace std;
+
+void AquariumScript::fixed_update(crepe::duration_t dt) {
+ 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_aqua");
+ for (Transform & tran : trans) {
+ tran.position.x += 12000;
+ }
+ this->start_x += 12000;
+ }
+}
diff --git a/game/background/AquariumScript.h b/game/background/AquariumScript.h
new file mode 100644
index 0000000..b068628
--- /dev/null
+++ b/game/background/AquariumScript.h
@@ -0,0 +1,12 @@
+#pragma once
+
+#include <crepe/api/Script.h>
+
+class AquariumScript : public crepe::Script {
+public:
+ void fixed_update(crepe::duration_t dt);
+
+private:
+ float start_x = 10200;
+ const float lenght = 3000;
+};
diff --git a/game/background/AquariumSubScene.cpp b/game/background/AquariumSubScene.cpp
index 8d5202a..99466e3 100644
--- a/game/background/AquariumSubScene.cpp
+++ b/game/background/AquariumSubScene.cpp
@@ -15,7 +15,7 @@ float AquariumSubScene::create(Scene & scn, float begin_x) {
this->add_background(scn, begin_x);
GameObject aquarium_begin
- = scn.new_object("aquarium_begin", "background", vec2(begin_x, 0));
+ = scn.new_object("aquarium_begin", "background_aqua", vec2(begin_x, 0));
Asset aquarium_begin_asset {"asset/background/aquarium/glassTubeFG_1_TVOS.png"};
aquarium_begin.add_component<Sprite>(
aquarium_begin_asset,
@@ -28,7 +28,7 @@ float AquariumSubScene::create(Scene & scn, float begin_x) {
begin_x += 600;
GameObject aquarium_middle_1
- = scn.new_object("aquarium_middle", "background", vec2(begin_x, 0));
+ = scn.new_object("aquarium_middle", "background_aqua", vec2(begin_x, 0));
Asset aquarium_middle_1_asset {"asset/background/aquarium/glassTubeFG_3_TVOS.png"};
aquarium_middle_1.add_component<Sprite>(
aquarium_middle_1_asset,
@@ -43,7 +43,7 @@ float AquariumSubScene::create(Scene & scn, float begin_x) {
this->add_background(scn, begin_x - 200);
GameObject aquarium_middle_2
- = scn.new_object("aquarium_middle", "background", vec2(begin_x, 0));
+ = scn.new_object("aquarium_middle", "background_aqua", vec2(begin_x, 0));
Asset aquarium_middle_2_asset {"asset/background/aquarium/glassTubeFG_3_TVOS.png"};
aquarium_middle_2.add_component<Sprite>(
aquarium_middle_2_asset,
@@ -56,7 +56,7 @@ float AquariumSubScene::create(Scene & scn, float begin_x) {
begin_x += 400;
GameObject aquarium_middle_3
- = scn.new_object("aquarium_middle", "background", vec2(begin_x, 0));
+ = scn.new_object("aquarium_middle", "background_aqua", vec2(begin_x, 0));
Asset aquarium_middle_3_asset {"asset/background/aquarium/glassTubeFG_3_TVOS.png"};
aquarium_middle_3.add_component<Sprite>(
aquarium_middle_3_asset,
@@ -71,7 +71,7 @@ float AquariumSubScene::create(Scene & scn, float begin_x) {
this->add_background(scn, begin_x - 200);
GameObject aquarium_middle_4
- = scn.new_object("aquarium_middle", "background", vec2(begin_x, 0));
+ = scn.new_object("aquarium_middle", "background_aqua", vec2(begin_x, 0));
Asset aquarium_middle_4_asset {"asset/background/aquarium/glassTubeFG_3_TVOS.png"};
aquarium_middle_4.add_component<Sprite>(
aquarium_middle_4_asset,
@@ -85,7 +85,8 @@ float AquariumSubScene::create(Scene & scn, float begin_x) {
this->add_background(scn, begin_x);
- GameObject aquarium_end = scn.new_object("aquarium_end", "background", vec2(begin_x, 0));
+ GameObject aquarium_end
+ = scn.new_object("aquarium_end", "background_aqua", vec2(begin_x, 0));
Asset aquarium_end_asset {"asset/background/aquarium/glassTubeFG_2_TVOS.png"};
aquarium_end.add_component<Sprite>(
aquarium_end_asset,
@@ -101,7 +102,7 @@ float AquariumSubScene::create(Scene & scn, float begin_x) {
}
void AquariumSubScene::add_background(Scene & scn, float begin_x) {
- GameObject bg_1 = scn.new_object("aquarium_bg_1", "aquarium_background", vec2(begin_x, 0));
+ GameObject bg_1 = scn.new_object("aquarium_bg_1", "background_aqua", vec2(begin_x, 0));
Asset bg_1_1_asset {"asset/background/aquarium/AquariumBG1_1_TVOS.png"};
bg_1.add_component<Sprite>(
bg_1_1_asset,
@@ -122,7 +123,7 @@ void AquariumSubScene::add_background(Scene & scn, float begin_x) {
.position_offset = vec2(200, 100),
}
);
- GameObject bg_2 = scn.new_object("aquarium_bg_2", "aquarium_background", vec2(begin_x, 0));
+ GameObject bg_2 = scn.new_object("aquarium_bg_2", "background_aqua", vec2(begin_x, 0));
Asset bg_2_1_asset {"asset/background/aquarium/AquariumBG2_1_TVOS.png"};
bg_2.add_component<Sprite>(
bg_2_1_asset,
@@ -143,7 +144,7 @@ void AquariumSubScene::add_background(Scene & scn, float begin_x) {
.position_offset = vec2(-200, -50),
}
);
- GameObject bg_3 = scn.new_object("aquarium_bg_3", "aquarium_background", vec2(begin_x, 0));
+ GameObject bg_3 = scn.new_object("aquarium_bg_3", "background_aqua", vec2(begin_x, 0));
Asset bg_3_1_asset {"asset/background/aquarium/AquariumBG3_1_TVOS.png"};
bg_3.add_component<Sprite>(
bg_3_1_asset,
diff --git a/game/background/BackgroundSubScene.cpp b/game/background/BackgroundSubScene.cpp
index a954f0b..14258be 100644
--- a/game/background/BackgroundSubScene.cpp
+++ b/game/background/BackgroundSubScene.cpp
@@ -1,4 +1,5 @@
#include "BackgroundSubScene.h"
+#include "AquariumScript.h"
#include "AquariumSubScene.h"
#include "ForestSubScene.h"
#include "HallwayScript.h"
@@ -31,10 +32,10 @@ BackgroundSubScene::BackgroundSubScene(Scene & scn) {
begin_x = aquarium.create(scn, begin_x);
- begin_x += 3000;
+ //begin_x += 3000;
//begin_x = hallway.create(scn, begin_x, 3, Color::CYAN);
- begin_x = forest.create(scn, begin_x, "2");
+ //begin_x = forest.create(scn, begin_x, "2");
//begin_x = hallway.create(scn, begin_x, 4, Color::GREEN);
@@ -88,4 +89,5 @@ BackgroundSubScene::BackgroundSubScene(Scene & scn) {
GameObject scripts = scn.new_object("scrips_background", "background");
scripts.add_component<BehaviorScript>().set_script<HallwayScript>();
+ scripts.add_component<BehaviorScript>().set_script<AquariumScript>();
}