aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--game/CMakeLists.txt1
-rw-r--r--game/background/BackgroundSubScene.cpp14
-rw-r--r--game/background/HallwayScript.cpp70
-rw-r--r--game/background/HallwayScript.h13
-rw-r--r--game/background/HallwaySubScene.cpp16
5 files changed, 105 insertions, 9 deletions
diff --git a/game/CMakeLists.txt b/game/CMakeLists.txt
index 475d6e1..a0e09de 100644
--- a/game/CMakeLists.txt
+++ b/game/CMakeLists.txt
@@ -15,6 +15,7 @@ add_executable(main
background/ForestSubScene.cpp
GameScene.cpp
background/HallwaySubScene.cpp
+ background/HallwayScript.cpp
MoveCameraManualyScript.cpp
player/PlayerScript.cpp
player/PlayerSubScene.cpp
diff --git a/game/background/BackgroundSubScene.cpp b/game/background/BackgroundSubScene.cpp
index 0f54800..a954f0b 100644
--- a/game/background/BackgroundSubScene.cpp
+++ b/game/background/BackgroundSubScene.cpp
@@ -1,10 +1,13 @@
#include "BackgroundSubScene.h"
#include "AquariumSubScene.h"
#include "ForestSubScene.h"
+#include "HallwayScript.h"
#include "HallwaySubScene.h"
#include "StartSubScene.h"
+#include <crepe/api/BehaviorScript.h>
#include <crepe/api/Color.h>
+#include <crepe/api/Scene.h>
using namespace crepe;
using namespace std;
@@ -23,15 +26,17 @@ BackgroundSubScene::BackgroundSubScene(Scene & scn) {
begin_x = forest.create(scn, begin_x, "1");
- begin_x = hallway.create(scn, begin_x, 2, Color::MAGENTA);
+ begin_x += 3000;
+ //begin_x = hallway.create(scn, begin_x, 2, Color::MAGENTA);
begin_x = aquarium.create(scn, begin_x);
- begin_x = hallway.create(scn, begin_x, 3, Color::CYAN);
+ begin_x += 3000;
+ //begin_x = hallway.create(scn, begin_x, 3, Color::CYAN);
begin_x = forest.create(scn, begin_x, "2");
- begin_x = hallway.create(scn, begin_x, 4, Color::GREEN);
+ //begin_x = hallway.create(scn, begin_x, 4, Color::GREEN);
/*begin_x = aquarium.create(scn, begin_x);
@@ -80,4 +85,7 @@ BackgroundSubScene::BackgroundSubScene(Scene & scn) {
begin_x = forest.create(scn, begin_x, "8");
begin_x = hallway.create(scn, begin_x, 16, Color::MAGENTA);*/
+
+ GameObject scripts = scn.new_object("scrips_background", "background");
+ scripts.add_component<BehaviorScript>().set_script<HallwayScript>();
}
diff --git a/game/background/HallwayScript.cpp b/game/background/HallwayScript.cpp
new file mode 100644
index 0000000..a5bb94c
--- /dev/null
+++ b/game/background/HallwayScript.cpp
@@ -0,0 +1,70 @@
+#include "HallwayScript.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 HallwayScript::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 6000 to the right
+ RefVector<Transform> trans = this->get_components_by_tag<Transform>("background_hall");
+ for (Transform & tran : trans) {
+ tran.position.x += 6000;
+ }
+ this->start_x += 6000;
+
+ //Change sector number
+ Animator & anim = this->get_components_by_name<Animator>("hallway_begin").front();
+ int column = (current_sector - 1) / 4;
+ int row = (current_sector - 1) % 4;
+ anim.set_anim(column);
+ for (int i = 0; i < row; i++) {
+ anim.next_anim();
+ }
+ RefVector<Sprite> sprites = this->get_components_by_name<Sprite>("hallway_begin");
+ switch (current_sector % 7) {
+ case 0:
+ sprites[1].get().data.color = Color::YELLOW;
+ sprites[2].get().data.color = Color::YELLOW;
+ break;
+ case 1:
+ sprites[1].get().data.color = Color::MAGENTA;
+ sprites[2].get().data.color = Color::MAGENTA;
+ break;
+ case 2:
+ sprites[1].get().data.color = Color::CYAN;
+ sprites[2].get().data.color = Color::CYAN;
+ break;
+ case 3:
+ sprites[1].get().data.color = Color::GREEN;
+ sprites[2].get().data.color = Color::GREEN;
+ break;
+ case 4:
+ sprites[1].get().data.color = Color::RED;
+ sprites[2].get().data.color = Color::RED;
+ break;
+ case 5:
+ sprites[1].get().data.color = Color::BLUE;
+ sprites[2].get().data.color = Color::BLUE;
+ break;
+ case 6:
+ sprites[1].get().data.color = Color::WHITE;
+ sprites[2].get().data.color = Color::WHITE;
+ break;
+ }
+ current_sector++;
+ if (current_sector > 16) {
+ current_sector = 1;
+ }
+ }
+}
diff --git a/game/background/HallwayScript.h b/game/background/HallwayScript.h
new file mode 100644
index 0000000..04b2933
--- /dev/null
+++ b/game/background/HallwayScript.h
@@ -0,0 +1,13 @@
+#pragma once
+
+#include <crepe/api/Script.h>
+
+class HallwayScript : public crepe::Script {
+public:
+ void fixed_update(crepe::duration_t dt);
+
+private:
+ float start_x = 1200;
+ const float lenght = 3000;
+ int current_sector = 2;
+};
diff --git a/game/background/HallwaySubScene.cpp b/game/background/HallwaySubScene.cpp
index 4d96c94..31af2d5 100644
--- a/game/background/HallwaySubScene.cpp
+++ b/game/background/HallwaySubScene.cpp
@@ -14,7 +14,7 @@ using namespace std;
float HallwaySubScene::create(
Scene & scn, float begin_x, unsigned int sector_num, Color sector_color
) {
- GameObject begin = scn.new_object("hallway_begin", "background", vec2(begin_x, 0));
+ GameObject begin = scn.new_object("hallway_begin", "background_hall", vec2(begin_x, 0));
Asset begin_asset {"asset/background/hallway/hallway1FG_1_TVOS.png"};
begin.add_component<Sprite>(
begin_asset,
@@ -30,7 +30,8 @@ float HallwaySubScene::create(
this->add_lamp(begin, vec2(330, -120), 11);
this->add_lamp(begin, vec2(430, -120), 9);
- GameObject middle_1 = scn.new_object("hallway_middle", "background", vec2(begin_x, 0));
+ GameObject middle_1
+ = scn.new_object("hallway_middle", "background_hall", vec2(begin_x, 0));
Asset middle_asset {"asset/background/hallway/hallway1FG_2_TVOS.png"};
middle_1.add_component<Sprite>(
middle_asset,
@@ -42,7 +43,8 @@ float HallwaySubScene::create(
);
begin_x += 600;
- GameObject middle_2 = scn.new_object("hallway_middle", "background", vec2(begin_x, 0));
+ GameObject middle_2
+ = scn.new_object("hallway_middle", "background_hall", vec2(begin_x, 0));
Asset middle_asset_2 {"asset/background/hallway/hallway1FG_2_TVOS.png"};
middle_2.add_component<Sprite>(
middle_asset_2,
@@ -54,7 +56,8 @@ float HallwaySubScene::create(
);
begin_x += 200;
- GameObject middle_3 = scn.new_object("hallway_middle", "background", vec2(begin_x, 0));
+ GameObject middle_3
+ = scn.new_object("hallway_middle", "background_hall", vec2(begin_x, 0));
Asset middle_asset_3 {"asset/background/hallway/hallway1FG_2_TVOS.png"};
middle_3.add_component<Sprite>(
middle_asset_3,
@@ -68,7 +71,8 @@ float HallwaySubScene::create(
this->add_lamp(middle_3, vec2(0, -120));
- GameObject middle_4 = scn.new_object("hallway_middle", "background", vec2(begin_x, 0));
+ GameObject middle_4
+ = scn.new_object("hallway_middle", "background_hall", vec2(begin_x, 0));
Asset middle_asset_4 {"asset/background/hallway/hallway1FG_2_TVOS.png"};
middle_4.add_component<Sprite>(
middle_asset_4,
@@ -80,7 +84,7 @@ float HallwaySubScene::create(
);
begin_x += 600;
- GameObject end = scn.new_object("hallway_end", "background", vec2(begin_x, 0));
+ GameObject end = scn.new_object("hallway_end", "background_hall", vec2(begin_x, 0));
Asset end_asset {"asset/background/hallway/hallway1FG_1_TVOS.png"};
end.add_component<Sprite>(
end_asset,