aboutsummaryrefslogtreecommitdiff
path: root/game/background
diff options
context:
space:
mode:
Diffstat (limited to 'game/background')
-rw-r--r--game/background/AquariumScript.cpp26
-rw-r--r--game/background/AquariumScript.h12
-rw-r--r--game/background/AquariumSubScene.cpp88
-rw-r--r--game/background/AquariumSubScene.h7
-rw-r--r--game/background/BackgroundSubScene.cpp16
-rw-r--r--game/background/ForestParallaxScript.cpp26
-rw-r--r--game/background/ForestParallaxScript.h6
-rw-r--r--game/background/ForestSubScene.cpp12
-rw-r--r--game/background/HallwayScript.cpp70
-rw-r--r--game/background/HallwayScript.h13
-rw-r--r--game/background/HallwaySubScene.cpp16
11 files changed, 255 insertions, 37 deletions
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..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>
@@ -15,7 +16,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 +29,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,
@@ -41,9 +42,12 @@ 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", 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,
@@ -55,8 +59,10 @@ 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", 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 +77,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,
@@ -84,8 +90,11 @@ 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", 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,13 +110,13 @@ 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,
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),
}
@@ -117,18 +126,18 @@ 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),
}
);
- 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,
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),
}
@@ -138,18 +147,18 @@ 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),
}
);
- 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,
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),
}
@@ -159,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/background/BackgroundSubScene.cpp b/game/background/BackgroundSubScene.cpp
index 6fdc598..4bbd977 100644
--- a/game/background/BackgroundSubScene.cpp
+++ b/game/background/BackgroundSubScene.cpp
@@ -1,10 +1,14 @@
#include "BackgroundSubScene.h"
+#include "AquariumScript.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 +27,11 @@ 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 = aquarium.create(scn, begin_x);
- 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 = aquarium.create(scn, begin_x);
+ GameObject scripts = scn.new_object("scrips_background", "background");
+ scripts.add_component<BehaviorScript>().set_script<HallwayScript>();
+ scripts.add_component<BehaviorScript>().set_script<AquariumScript>();
}
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,
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,