aboutsummaryrefslogtreecommitdiff
path: root/src/example
diff options
context:
space:
mode:
Diffstat (limited to 'src/example')
-rw-r--r--src/example/AITest.cpp90
-rw-r--r--src/example/Aquarium.cpp148
-rw-r--r--src/example/Aquarium.h13
-rw-r--r--src/example/Background.cpp54
-rw-r--r--src/example/Background.h10
-rw-r--r--src/example/CMakeLists.txt36
-rw-r--r--src/example/Forest.cpp172
-rw-r--r--src/example/Forest.h15
-rw-r--r--src/example/Hallway.cpp140
-rw-r--r--src/example/Hallway.h21
-rw-r--r--src/example/Start.cpp69
-rw-r--r--src/example/Start.h16
-rw-r--r--src/example/button.cpp54
-rw-r--r--src/example/game.cpp496
-rw-r--r--src/example/rendering_particle.cpp95
15 files changed, 677 insertions, 752 deletions
diff --git a/src/example/AITest.cpp b/src/example/AITest.cpp
deleted file mode 100644
index 93ba500..0000000
--- a/src/example/AITest.cpp
+++ /dev/null
@@ -1,90 +0,0 @@
-#include <crepe/api/AI.h>
-#include <crepe/api/BehaviorScript.h>
-#include <crepe/api/Camera.h>
-#include <crepe/api/Color.h>
-#include <crepe/api/GameObject.h>
-#include <crepe/api/LoopManager.h>
-#include <crepe/api/Rigidbody.h>
-#include <crepe/api/Scene.h>
-#include <crepe/api/Script.h>
-#include <crepe/api/Sprite.h>
-#include <crepe/manager/Mediator.h>
-#include <crepe/types.h>
-
-using namespace crepe;
-using namespace std;
-
-class Script1 : public Script {
- bool shutdown(const ShutDownEvent & event) {
- // Very dirty way of shutting down the game
- throw "ShutDownEvent";
- return true;
- }
-
- bool mousemove(const MouseMoveEvent & event) {
- /*RefVector<AI> aivec = this->get_components<AI>();
- AI & ai = aivec.front().get();
- ai.flee_target
- = vec2{static_cast<float>(event.mouse_x), static_cast<float>(event.mouse_y)};*/
- return true;
- }
-
- void init() {
- subscribe<ShutDownEvent>(
- [this](const ShutDownEvent & ev) -> bool { return this->shutdown(ev); });
- subscribe<MouseMoveEvent>(
- [this](const MouseMoveEvent & ev) -> bool { return this->mousemove(ev); });
- }
-};
-
-class Scene1 : public Scene {
-public:
- void load_scene() override {
- Mediator & mediator = this->mediator;
- ComponentManager & mgr = mediator.component_manager;
-
- GameObject game_object1 = mgr.new_object("", "", vec2{0, 0}, 0, 1);
- GameObject game_object2 = mgr.new_object("", "", vec2{0, 0}, 0, 1);
-
- Asset img{"asset/texture/test_ap43.png"};
-
- Sprite & test_sprite = game_object1.add_component<Sprite>(
- img, Sprite::Data{
- .color = Color::MAGENTA,
- .flip = Sprite::FlipSettings{false, false},
- .sorting_in_layer = 2,
- .order_in_layer = 2,
- .size = {0, 100},
- .angle_offset = 0,
- .position_offset = {0, 0},
- });
-
- AI & ai = game_object1.add_component<AI>(3000);
- // ai.arrive_on();
- // ai.flee_on();
- ai.path_follow_on();
- ai.make_oval_path(500, 1000, {0, -1000}, 1.5708, true);
- ai.make_oval_path(1000, 500, {0, 500}, 4.7124, false);
- game_object1.add_component<Rigidbody>(Rigidbody::Data{
- .mass = 0.1f,
- .max_linear_velocity = 40,
- });
- game_object1.add_component<BehaviorScript>().set_script<Script1>();
-
- game_object2.add_component<Camera>(ivec2{1080, 720}, vec2{5000, 5000},
- Camera::Data{
- .bg_color = Color::WHITE,
- .zoom = 1,
- });
- }
-
- string get_name() const override { return "Scene1"; }
-};
-
-int main() {
- LoopManager engine;
- engine.add_scene<Scene1>();
- engine.start();
-
- return 0;
-}
diff --git a/src/example/Aquarium.cpp b/src/example/Aquarium.cpp
new file mode 100644
index 0000000..7cd9017
--- /dev/null
+++ b/src/example/Aquarium.cpp
@@ -0,0 +1,148 @@
+#include "Aquarium.h"
+
+#include <crepe/api/Animator.h>
+#include <crepe/api/Asset.h>
+#include <crepe/api/BehaviorScript.h>
+#include <crepe/api/BoxCollider.h>
+#include <crepe/api/Camera.h>
+#include <crepe/api/CircleCollider.h>
+#include <crepe/api/Color.h>
+#include <crepe/api/Event.h>
+#include <crepe/api/GameObject.h>
+#include <crepe/api/LoopManager.h>
+#include <crepe/api/Rigidbody.h>
+#include <crepe/api/Scene.h>
+#include <crepe/api/Script.h>
+#include <crepe/api/Sprite.h>
+#include <crepe/api/Transform.h>
+#include <crepe/api/Vector2.h>
+#include <crepe/types.h>
+#include <iostream>
+
+using namespace crepe;
+using namespace std;
+
+float Aquarium::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));
+ Asset aquarium_begin_asset{
+ "asset/jetpack_joyride/background/aquarium/glassTubeFG_1_TVOS.png"};
+ aquarium_begin.add_component<Sprite>(aquarium_begin_asset, Sprite::Data{
+ .sorting_in_layer = 4,
+ .order_in_layer = 0,
+ .size = vec2(0, 800),
+ });
+ begin_x += 600;
+
+ GameObject aquarium_middle_1
+ = scn.new_object("aquarium_middle", "background", vec2(begin_x, 0));
+ Asset aquarium_middle_1_asset{
+ "asset/jetpack_joyride/background/aquarium/glassTubeFG_3_TVOS.png"};
+ aquarium_middle_1.add_component<Sprite>(aquarium_middle_1_asset, Sprite::Data{
+ .sorting_in_layer = 4,
+ .order_in_layer = 2,
+ .size = vec2(0, 800),
+ });
+ begin_x += 400;
+
+ this->add_background(scn, begin_x - 200);
+
+ GameObject aquarium_middle_2
+ = scn.new_object("aquarium_middle", "background", vec2(begin_x, 0));
+ Asset aquarium_middle_2_asset{
+ "asset/jetpack_joyride/background/aquarium/glassTubeFG_3_TVOS.png"};
+ aquarium_middle_2.add_component<Sprite>(aquarium_middle_2_asset, Sprite::Data{
+ .sorting_in_layer = 4,
+ .order_in_layer = 3,
+ .size = vec2(0, 800),
+ });
+ begin_x += 400;
+
+ GameObject aquarium_middle_3
+ = scn.new_object("aquarium_middle", "background", vec2(begin_x, 0));
+ Asset aquarium_middle_3_asset{
+ "asset/jetpack_joyride/background/aquarium/glassTubeFG_3_TVOS.png"};
+ aquarium_middle_3.add_component<Sprite>(aquarium_middle_3_asset, Sprite::Data{
+ .sorting_in_layer = 4,
+ .order_in_layer = 4,
+ .size = vec2(0, 800),
+ });
+ begin_x += 400;
+
+ this->add_background(scn, begin_x - 200);
+
+ GameObject aquarium_middle_4
+ = scn.new_object("aquarium_middle", "background", vec2(begin_x, 0));
+ Asset aquarium_middle_4_asset{
+ "asset/jetpack_joyride/background/aquarium/glassTubeFG_3_TVOS.png"};
+ aquarium_middle_4.add_component<Sprite>(aquarium_middle_4_asset, Sprite::Data{
+ .sorting_in_layer = 4,
+ .order_in_layer = 5,
+ .size = vec2(0, 800),
+ });
+ begin_x += 600;
+
+ this->add_background(scn, begin_x);
+
+ GameObject aquarium_end = scn.new_object("aquarium_end", "background", vec2(begin_x, 0));
+ Asset aquarium_end_asset{
+ "asset/jetpack_joyride/background/aquarium/glassTubeFG_2_TVOS.png"};
+ aquarium_end.add_component<Sprite>(aquarium_end_asset, Sprite::Data{
+ .sorting_in_layer = 4,
+ .order_in_layer = 1,
+ .size = vec2(0, 800),
+ });
+ begin_x += 600;
+
+ return begin_x;
+}
+
+void Aquarium::add_background(Scene & scn, float begin_x) {
+ GameObject bg_1 = scn.new_object("aquarium_bg_1", "aquarium_background", vec2(begin_x, 0));
+ Asset bg_1_1_asset{"asset/jetpack_joyride/background/aquarium/AquariumBG1_1_TVOS.png"};
+ bg_1.add_component<Sprite>(bg_1_1_asset, Sprite::Data{
+ .sorting_in_layer = 3,
+ .order_in_layer = 2,
+ .size = vec2(0, 400),
+ .position_offset = vec2(-200, 100),
+ });
+ Asset bg_1_2_asset{"asset/jetpack_joyride/background/aquarium/AquariumBG1_2_TVOS.png"};
+ bg_1.add_component<Sprite>(bg_1_2_asset, Sprite::Data{
+ .sorting_in_layer = 3,
+ .order_in_layer = 2,
+ .size = vec2(0, 400),
+ .position_offset = vec2(200, 100),
+ });
+ GameObject bg_2 = scn.new_object("aquarium_bg_2", "aquarium_background", vec2(begin_x, 0));
+ Asset bg_2_1_asset{"asset/jetpack_joyride/background/aquarium/AquariumBG2_1_TVOS.png"};
+ bg_2.add_component<Sprite>(bg_2_1_asset, Sprite::Data{
+ .sorting_in_layer = 3,
+ .order_in_layer = 1,
+ .size = vec2(0, 400),
+ .position_offset = vec2(200, -50),
+ });
+ Asset bg_2_2_asset{"asset/jetpack_joyride/background/aquarium/AquariumBG2_2_TVOS.png"};
+ bg_2.add_component<Sprite>(bg_2_2_asset, Sprite::Data{
+ .sorting_in_layer = 3,
+ .order_in_layer = 1,
+ .size = vec2(0, 400),
+ .position_offset = vec2(-200, -50),
+ });
+ GameObject bg_3 = scn.new_object("aquarium_bg_3", "aquarium_background", vec2(begin_x, 0));
+ Asset bg_3_1_asset{"asset/jetpack_joyride/background/aquarium/AquariumBG3_1_TVOS.png"};
+ bg_3.add_component<Sprite>(bg_3_1_asset, Sprite::Data{
+ .sorting_in_layer = 3,
+ .order_in_layer = 0,
+ .size = vec2(0, 400),
+ .position_offset = vec2(200, -200),
+ });
+ Asset bg_3_2_asset{"asset/jetpack_joyride/background/aquarium/AquariumBG3_2_TVOS.png"};
+ bg_3.add_component<Sprite>(bg_3_2_asset, Sprite::Data{
+ .sorting_in_layer = 3,
+ .order_in_layer = 0,
+ .size = vec2(0, 400),
+ .position_offset = vec2(-200, -200),
+ });
+}
diff --git a/src/example/Aquarium.h b/src/example/Aquarium.h
new file mode 100644
index 0000000..8815e9c
--- /dev/null
+++ b/src/example/Aquarium.h
@@ -0,0 +1,13 @@
+#pragma once
+
+namespace crepe {
+class Scene;
+}
+
+class Aquarium {
+public:
+ float create(crepe::Scene & scn, float begin_x);
+
+private:
+ void add_background(crepe::Scene & scn, float begin_x);
+};
diff --git a/src/example/Background.cpp b/src/example/Background.cpp
new file mode 100644
index 0000000..f935d90
--- /dev/null
+++ b/src/example/Background.cpp
@@ -0,0 +1,54 @@
+#include "Background.h"
+#include "Aquarium.h"
+#include "Forest.h"
+#include "Hallway.h"
+#include "Start.h"
+
+#include <crepe/api/Animator.h>
+#include <crepe/api/Asset.h>
+#include <crepe/api/BehaviorScript.h>
+#include <crepe/api/BoxCollider.h>
+#include <crepe/api/Camera.h>
+#include <crepe/api/CircleCollider.h>
+#include <crepe/api/Color.h>
+#include <crepe/api/Event.h>
+#include <crepe/api/GameObject.h>
+#include <crepe/api/LoopManager.h>
+#include <crepe/api/Rigidbody.h>
+#include <crepe/api/Scene.h>
+#include <crepe/api/Script.h>
+#include <crepe/api/Sprite.h>
+#include <crepe/api/Transform.h>
+#include <crepe/api/Vector2.h>
+#include <crepe/types.h>
+#include <iostream>
+
+using namespace crepe;
+using namespace std;
+
+Background::Background(Scene & scn) {
+ Start start;
+ Hallway hallway;
+ Forest forest;
+ Aquarium aquarium;
+
+ float begin_x = 0;
+
+ begin_x = start.create(scn, begin_x);
+
+ begin_x = hallway.create(scn, begin_x, 1, Color::YELLOW);
+
+ begin_x = forest.create(scn, begin_x, "1");
+
+ 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 = forest.create(scn, begin_x, "2");
+
+ begin_x = hallway.create(scn, begin_x, 4, Color::GREEN);
+
+ begin_x = aquarium.create(scn, begin_x);
+}
diff --git a/src/example/Background.h b/src/example/Background.h
new file mode 100644
index 0000000..7c5a2bb
--- /dev/null
+++ b/src/example/Background.h
@@ -0,0 +1,10 @@
+#pragma once
+
+namespace crepe {
+class Scene;
+}
+
+class Background {
+public:
+ Background(crepe::Scene & scn);
+};
diff --git a/src/example/CMakeLists.txt b/src/example/CMakeLists.txt
index 187ed46..911a99c 100644
--- a/src/example/CMakeLists.txt
+++ b/src/example/CMakeLists.txt
@@ -1,22 +1,20 @@
-# all examples
-add_custom_target(examples)
+set(GAME_HEADERS
+ Aquarium.h
+ Background.h
+ Forest.h
+ Hallway.h
+ Start.h
+)
-# add_example(target_name [SOURCES...])
-function(add_example target_name)
- # if SOURCES is not specified
- if(NOT ARGV1)
- # A .cpp file with target_name exists, and should be used
- set(sources ${target_name}.cpp)
- else()
- set(sources ${ARGV})
- endif()
+set(GAME_SOURCES
+ game.cpp
+ Aquarium.cpp
+ Background.cpp
+ Forest.cpp
+ Hallway.cpp
+ Start.cpp
+)
- add_executable(${target_name} EXCLUDE_FROM_ALL ${sources})
- target_link_libraries(${target_name} PUBLIC crepe)
- add_dependencies(examples ${target_name})
-endfunction()
+add_executable(game ${GAME_SOURCES} ${GAME_HEADERS})
-add_example(rendering_particle)
-add_example(game)
-add_example(button)
-add_example(AITest)
+target_link_libraries(game PUBLIC crepe)
diff --git a/src/example/Forest.cpp b/src/example/Forest.cpp
new file mode 100644
index 0000000..3f1f5d8
--- /dev/null
+++ b/src/example/Forest.cpp
@@ -0,0 +1,172 @@
+#include "Forest.h"
+
+#include <crepe/api/Animator.h>
+#include <crepe/api/Asset.h>
+#include <crepe/api/BehaviorScript.h>
+#include <crepe/api/BoxCollider.h>
+#include <crepe/api/Camera.h>
+#include <crepe/api/CircleCollider.h>
+#include <crepe/api/Color.h>
+#include <crepe/api/Event.h>
+#include <crepe/api/GameObject.h>
+#include <crepe/api/LoopManager.h>
+#include <crepe/api/Rigidbody.h>
+#include <crepe/api/Scene.h>
+#include <crepe/api/Script.h>
+#include <crepe/api/Sprite.h>
+#include <crepe/api/Transform.h>
+#include <crepe/api/Vector2.h>
+#include <crepe/types.h>
+#include <iostream>
+
+using namespace crepe;
+using namespace std;
+
+class ParallaxScript : public Script {
+public:
+ ParallaxScript(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 Forest::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<ParallaxScript>(
+ 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));
+ Asset begin_asset{"asset/jetpack_joyride/background/forest/forestFG_1_TVOS.png"};
+ begin.add_component<Sprite>(begin_asset, Sprite::Data{
+ .sorting_in_layer = 4,
+ .order_in_layer = 0,
+ .size = vec2(0, 800),
+ });
+ begin_x += 800;
+
+ this->add_background(scn, begin_x, unique_bg_name);
+
+ GameObject middle_1 = scn.new_object("forest_middle", "background", vec2(begin_x, 0));
+ Asset middle_1_asset{"asset/jetpack_joyride/background/forest/forestFG_3_TVOS.png"};
+ middle_1.add_component<Sprite>(middle_1_asset, Sprite::Data{
+ .sorting_in_layer = 4,
+ .order_in_layer = 2,
+ .size = vec2(0, 800),
+ });
+ begin_x += 800;
+
+ this->add_background(scn, begin_x, unique_bg_name);
+
+ GameObject middle_2 = scn.new_object("forest_middle", "background", vec2(begin_x, 0));
+ Asset middle_2_asset{"asset/jetpack_joyride/background/forest/forestFG_3_TVOS.png"};
+ middle_2.add_component<Sprite>(middle_2_asset, Sprite::Data{
+ .sorting_in_layer = 4,
+ .order_in_layer = 3,
+ .size = vec2(0, 800),
+ });
+ begin_x += 800;
+
+ this->add_background(scn, begin_x, unique_bg_name);
+
+ GameObject end = scn.new_object("forest_end", "background", vec2(begin_x, 0));
+ Asset end_asset{"asset/jetpack_joyride/background/forest/forestFG_2_TVOS.png"};
+ end.add_component<Sprite>(end_asset, Sprite::Data{
+ .sorting_in_layer = 4,
+ .order_in_layer = 1,
+ .size = vec2(0, 800),
+ });
+ begin_x += 600;
+
+ this->add_background(scn, begin_x + 200, unique_bg_name);
+
+ return begin_x;
+}
+
+void Forest::add_background(Scene & scn, float begin_x, std::string name) {
+ GameObject bg_1
+ = scn.new_object("forest_bg_1_" + name, "forest_background", vec2(begin_x, 0));
+ Asset bg_1_asset{"asset/jetpack_joyride/background/forest/forestBG1_1_TVOS.png"};
+ bg_1.add_component<Sprite>(bg_1_asset, Sprite::Data{
+ .sorting_in_layer = 3,
+ .order_in_layer = 2,
+ .size = vec2(0, 800),
+ });
+ GameObject bg_2
+ = scn.new_object("forest_bg_2_" + name, "forest_background", vec2(begin_x, 0));
+ Asset bg_2_1_asset{"asset/jetpack_joyride/background/forest/forestBG2_1_TVOS.png"};
+ bg_2.add_component<Sprite>(bg_2_1_asset, Sprite::Data{
+ .sorting_in_layer = 3,
+ .order_in_layer = 1,
+ .size = vec2(0, 400),
+ .position_offset = vec2(200, 0),
+ });
+ Asset bg_2_2_asset{"asset/jetpack_joyride/background/forest/forestBG2_2_TVOS.png"};
+ bg_2.add_component<Sprite>(bg_2_2_asset, Sprite::Data{
+ .sorting_in_layer = 3,
+ .order_in_layer = 1,
+ .size = vec2(0, 400),
+ .position_offset = vec2(-200, 0),
+ });
+ GameObject bg_3
+ = scn.new_object("forest_bg_3_" + name, "forest_background", vec2(begin_x, 0));
+ Asset bg_3_1_asset{"asset/jetpack_joyride/background/forest/forestBG3_1_TVOS.png"};
+ bg_3.add_component<Sprite>(bg_3_1_asset, Sprite::Data{
+ .sorting_in_layer = 3,
+ .order_in_layer = 0,
+ .size = vec2(0, 200),
+ .position_offset = vec2(300, 0),
+ });
+ Asset bg_3_2_asset{"asset/jetpack_joyride/background/forest/forestBG3_2_TVOS.png"};
+ bg_3.add_component<Sprite>(bg_3_2_asset, Sprite::Data{
+ .sorting_in_layer = 3,
+ .order_in_layer = 0,
+ .size = vec2(0, 200),
+ .position_offset = vec2(100, 0),
+ });
+ Asset bg_3_3_asset{"asset/jetpack_joyride/background/forest/forestBG3_3_TVOS.png"};
+ bg_3.add_component<Sprite>(bg_3_3_asset, Sprite::Data{
+ .sorting_in_layer = 3,
+ .order_in_layer = 0,
+ .size = vec2(0, 200),
+ .position_offset = vec2(-100, 0),
+ });
+ Asset bg_3_4_asset{"asset/jetpack_joyride/background/forest/forestBG3_4_TVOS.png"};
+ bg_3.add_component<Sprite>(bg_3_4_asset, Sprite::Data{
+ .sorting_in_layer = 3,
+ .order_in_layer = 0,
+ .size = vec2(0, 200),
+ .position_offset = vec2(-300, 0),
+ });
+
+ bg_2.add_component<Rigidbody>(Rigidbody::Data{
+ .linear_velocity = vec2(30, 0),
+ });
+ bg_3.add_component<Rigidbody>(Rigidbody::Data{
+ .linear_velocity = vec2(40, 0),
+ });
+}
diff --git a/src/example/Forest.h b/src/example/Forest.h
new file mode 100644
index 0000000..f612c91
--- /dev/null
+++ b/src/example/Forest.h
@@ -0,0 +1,15 @@
+#pragma once
+
+#include <string>
+
+namespace crepe {
+class Scene;
+}
+
+class Forest {
+public:
+ float create(crepe::Scene & scn, float begin_x, std::string unique_bg_name);
+
+private:
+ void add_background(crepe::Scene & scn, float begin_x, std::string name);
+};
diff --git a/src/example/Hallway.cpp b/src/example/Hallway.cpp
new file mode 100644
index 0000000..5d01a96
--- /dev/null
+++ b/src/example/Hallway.cpp
@@ -0,0 +1,140 @@
+#include "Hallway.h"
+
+#include <crepe/api/Animator.h>
+#include <crepe/api/Asset.h>
+#include <crepe/api/BehaviorScript.h>
+#include <crepe/api/BoxCollider.h>
+#include <crepe/api/Camera.h>
+#include <crepe/api/CircleCollider.h>
+#include <crepe/api/Color.h>
+#include <crepe/api/Event.h>
+#include <crepe/api/GameObject.h>
+#include <crepe/api/LoopManager.h>
+#include <crepe/api/Rigidbody.h>
+#include <crepe/api/Scene.h>
+#include <crepe/api/Script.h>
+#include <crepe/api/Sprite.h>
+#include <crepe/api/Transform.h>
+#include <crepe/api/Vector2.h>
+#include <iostream>
+
+using namespace crepe;
+using namespace std;
+
+float Hallway::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));
+ Asset begin_asset{"asset/jetpack_joyride/background/hallway/hallway1FG_1_TVOS.png"};
+ begin.add_component<Sprite>(begin_asset, Sprite::Data{
+ .sorting_in_layer = 4,
+ .order_in_layer = 0,
+ .size = vec2(0, 800),
+ });
+ begin_x += 600;
+
+ this->add_sector_number(begin, vec2(-200, 0), sector_num, sector_color);
+ this->add_lamp(begin, vec2(-70, -120), 11);
+ this->add_lamp(begin, vec2(30, -120), 9);
+
+ GameObject middle_1 = scn.new_object("hallway_middle", "background", vec2(begin_x, 0));
+ Asset middle_asset{"asset/jetpack_joyride/background/hallway/hallway1FG_2_TVOS.png"};
+ middle_1.add_component<Sprite>(middle_asset, Sprite::Data{
+ .sorting_in_layer = 4,
+ .order_in_layer = 2,
+ .size = vec2(0, 800),
+ });
+ begin_x += 600;
+
+ GameObject middle_2 = scn.new_object("hallway_middle", "background", vec2(begin_x, 0));
+ Asset middle_asset_2{"asset/jetpack_joyride/background/hallway/hallway1FG_2_TVOS.png"};
+ middle_2.add_component<Sprite>(middle_asset_2, Sprite::Data{
+ .sorting_in_layer = 4,
+ .order_in_layer = 3,
+ .size = vec2(0, 800),
+ });
+ begin_x += 200;
+
+ GameObject middle_3 = scn.new_object("hallway_middle", "background", vec2(begin_x, 0));
+ Asset middle_asset_3{"asset/jetpack_joyride/background/hallway/hallway1FG_2_TVOS.png"};
+ middle_3.add_component<Sprite>(middle_asset_3, Sprite::Data{
+ .sorting_in_layer = 4,
+ .order_in_layer = 4,
+ .size = vec2(0, 800),
+ });
+ begin_x += 400;
+
+ this->add_lamp(middle_3, vec2(0, -120));
+
+ GameObject middle_4 = scn.new_object("hallway_middle", "background", vec2(begin_x, 0));
+ Asset middle_asset_4{"asset/jetpack_joyride/background/hallway/hallway1FG_2_TVOS.png"};
+ middle_4.add_component<Sprite>(middle_asset_4, Sprite::Data{
+ .sorting_in_layer = 4,
+ .order_in_layer = 5,
+ .size = vec2(0, 800),
+ });
+ begin_x += 600;
+
+ GameObject end = scn.new_object("hallway_end", "background", vec2(begin_x, 0));
+ Asset end_asset{"asset/jetpack_joyride/background/hallway/hallway1FG_1_TVOS.png"};
+ end.add_component<Sprite>(end_asset, Sprite::Data{
+ .sorting_in_layer = 4,
+ .order_in_layer = 1,
+ .size = vec2(0, 800),
+ });
+ begin_x += 600;
+
+ return begin_x;
+}
+
+void Hallway::add_lamp(GameObject & obj, vec2 offset, unsigned int fps) {
+ Asset lamp_asset{"asset/jetpack_joyride/background/hallway/alarmLight_TVOS.png"};
+ obj.add_component<Sprite>(lamp_asset, Sprite::Data{
+ .sorting_in_layer = 5,
+ .order_in_layer = 0,
+ .size = vec2(0, 100),
+ .position_offset = offset,
+ });
+ Asset lamp_glow_asset{"asset/jetpack_joyride/background/hallway/alarmGlow_TVOS.png"};
+ Sprite & lamp_glow_sprite = obj.add_component<Sprite>(
+ lamp_glow_asset, Sprite::Data{
+ .sorting_in_layer = 5,
+ .order_in_layer = 1,
+ .size = vec2(0, 300),
+ .position_offset = offset - vec2(65, -30),
+ });
+ obj.add_component<Animator>(lamp_glow_sprite, ivec2(422, 384), uvec2(6, 1),
+ Animator::Data{
+ .fps = fps,
+ .looping = true,
+ });
+}
+
+void Hallway::add_sector_number(GameObject & obj, vec2 offset, unsigned int sector_num,
+ Color sector_color) {
+ Asset sector_text_asset{"asset/jetpack_joyride/background/hallway/sectorText_TVOS.png"};
+ obj.add_component<Sprite>(sector_text_asset, Sprite::Data{
+ .color = sector_color,
+ .sorting_in_layer = 5,
+ .order_in_layer = 0,
+ .size = vec2(0, 100),
+ .position_offset = offset,
+ });
+ Asset sector_num_asset{"asset/jetpack_joyride/background/hallway/sectorNumbers_TVOS.png"};
+ Sprite & sector_num_sprite = obj.add_component<Sprite>(
+ sector_num_asset, Sprite::Data{
+ .color = sector_color,
+ .sorting_in_layer = 5,
+ .order_in_layer = 0,
+ .size = vec2(0, 100),
+ .position_offset = offset + vec2(200, 0),
+ });
+ Animator & sector_num_anim = obj.add_component<Animator>(
+ sector_num_sprite, ivec2(256, 128), uvec2(4, 4), Animator::Data{});
+ int column = (sector_num - 1) / 4;
+ int row = (sector_num - 1) % 4;
+ sector_num_anim.set_anim(column);
+ for (int i = 0; i < row; i++) {
+ sector_num_anim.next_anim();
+ }
+ sector_num_anim.pause();
+}
diff --git a/src/example/Hallway.h b/src/example/Hallway.h
new file mode 100644
index 0000000..f173313
--- /dev/null
+++ b/src/example/Hallway.h
@@ -0,0 +1,21 @@
+#pragma once
+
+#include <crepe/types.h>
+
+namespace crepe {
+class Scene;
+class GameObject;
+class Color;
+} // namespace crepe
+
+class Hallway {
+public:
+ float create(crepe::Scene & scn, float begin_x, unsigned int sector_num,
+ crepe::Color sector_color);
+
+private:
+ void add_lamp(crepe::GameObject & obj, crepe::vec2 offset, unsigned int fps = 10);
+
+ void add_sector_number(crepe::GameObject & obj, crepe::vec2 offset,
+ unsigned int sector_num, crepe::Color sector_color);
+};
diff --git a/src/example/Start.cpp b/src/example/Start.cpp
new file mode 100644
index 0000000..a8d86ec
--- /dev/null
+++ b/src/example/Start.cpp
@@ -0,0 +1,69 @@
+#include "Start.h"
+
+#include <crepe/api/Animator.h>
+#include <crepe/api/Asset.h>
+#include <crepe/api/BehaviorScript.h>
+#include <crepe/api/BoxCollider.h>
+#include <crepe/api/Camera.h>
+#include <crepe/api/CircleCollider.h>
+#include <crepe/api/Color.h>
+#include <crepe/api/Event.h>
+#include <crepe/api/GameObject.h>
+#include <crepe/api/LoopManager.h>
+#include <crepe/api/Rigidbody.h>
+#include <crepe/api/Scene.h>
+#include <crepe/api/Script.h>
+#include <crepe/api/Sprite.h>
+#include <crepe/api/Transform.h>
+#include <crepe/api/Vector2.h>
+#include <iostream>
+
+using namespace crepe;
+using namespace std;
+
+float Start::create(Scene & scn, float begin_x) {
+ GameObject begin = scn.new_object("start_begin", "background", vec2(begin_x, 0));
+ Asset begin_asset{"asset/jetpack_joyride/background/start/titleFG_1_TVOS.png"};
+ begin.add_component<Sprite>(begin_asset, Sprite::Data{
+ .sorting_in_layer = 4,
+ .order_in_layer = 0,
+ .size = vec2(0, 800),
+ });
+ begin_x += 700;
+
+ GameObject end = scn.new_object("start_end", "background", vec2(begin_x, 0));
+ Asset end_asset{"asset/jetpack_joyride/background/start/titleFG_2_TVOS.png"};
+ end.add_component<Sprite>(end_asset, Sprite::Data{
+ .sorting_in_layer = 4,
+ .order_in_layer = 1,
+ .size = vec2(0, 800),
+ });
+ begin_x += 100;
+
+ this->add_lamp(end, vec2(-350, -95));
+
+ return begin_x;
+}
+
+void Start::add_lamp(GameObject & obj, vec2 offset, unsigned int fps) {
+ Asset lamp_asset{"asset/jetpack_joyride/background/start/alarmLight_TVOS.png"};
+ obj.add_component<Sprite>(lamp_asset, Sprite::Data{
+ .sorting_in_layer = 5,
+ .order_in_layer = 0,
+ .size = vec2(0, 100),
+ .position_offset = offset,
+ });
+ Asset lamp_glow_asset{"asset/jetpack_joyride/background/start/alarmGlow_TVOS.png"};
+ Sprite & lamp_glow_sprite = obj.add_component<Sprite>(
+ lamp_glow_asset, Sprite::Data{
+ .sorting_in_layer = 5,
+ .order_in_layer = 1,
+ .size = vec2(0, 300),
+ .position_offset = offset - vec2(65, -55),
+ });
+ obj.add_component<Animator>(lamp_glow_sprite, ivec2(422, 384), uvec2(6, 1),
+ Animator::Data{
+ .fps = fps,
+ .looping = true,
+ });
+}
diff --git a/src/example/Start.h b/src/example/Start.h
new file mode 100644
index 0000000..37d1141
--- /dev/null
+++ b/src/example/Start.h
@@ -0,0 +1,16 @@
+#pragma once
+
+#include <crepe/types.h>
+
+namespace crepe {
+class Scene;
+class GameObject;
+} // namespace crepe
+
+class Start {
+public:
+ float create(crepe::Scene & scn, float begin_x);
+
+private:
+ void add_lamp(crepe::GameObject & obj, crepe::vec2 offset, unsigned int fps = 10);
+};
diff --git a/src/example/button.cpp b/src/example/button.cpp
deleted file mode 100644
index 00bdc28..0000000
--- a/src/example/button.cpp
+++ /dev/null
@@ -1,54 +0,0 @@
-#include <SDL2/SDL_timer.h>
-#include <chrono>
-#include <crepe/Component.h>
-#include <crepe/ComponentManager.h>
-#include <crepe/api/Animator.h>
-#include <crepe/api/Button.h>
-#include <crepe/api/Camera.h>
-#include <crepe/api/Color.h>
-#include <crepe/api/EventManager.h>
-#include <crepe/api/GameObject.h>
-#include <crepe/api/Sprite.h>
-#include <crepe/api/Texture.h>
-#include <crepe/api/Transform.h>
-#include <crepe/system/AnimatorSystem.h>
-#include <crepe/system/InputSystem.h>
-#include <crepe/system/RenderSystem.h>
-#include <crepe/types.h>
-#include <iostream>
-using namespace crepe;
-using namespace std;
-
-int main(int argc, char * argv[]) {
- ComponentManager mgr;
- RenderSystem sys{mgr};
- EventManager & event_mgr = EventManager::get_instance();
- InputSystem input_sys{mgr};
- AnimatorSystem asys{mgr};
- GameObject camera_obj = mgr.new_object("", "", vec2{1000, 1000}, 0, 1);
- camera_obj.add_component<Camera>(Color::WHITE, ivec2{1080, 720}, vec2{2000, 2000}, 1.0f);
-
- GameObject button_obj = mgr.new_object("body", "person", vec2{0, 0}, 0, 1);
- auto s2 = Texture("asset/texture/test_ap43.png");
- bool button_clicked = false;
- auto & sprite2 = button_obj.add_component<Sprite>(
- s2, Color::GREEN, Sprite::FlipSettings{false, false}, 2, 1, 100);
- std::function<void()> on_click = [&]() { std::cout << "button clicked" << std::endl; };
- std::function<void()> on_enter = [&]() { std::cout << "enter" << std::endl; };
- std::function<void()> on_exit = [&]() { std::cout << "exit" << std::endl; };
- auto & button
- = button_obj.add_component<Button>(vec2{100, 100}, vec2{0, 0}, on_click, false);
- button.on_mouse_enter = on_enter;
- button.on_mouse_exit = on_exit;
- button.is_toggle = true;
- button.active = true;
- auto start = std::chrono::steady_clock::now();
- while (true) {
- input_sys.update();
- sys.update();
- asys.update();
- event_mgr.dispatch_events();
- SDL_Delay(30);
- }
- return 0;
-}
diff --git a/src/example/game.cpp b/src/example/game.cpp
index 71dd42b..6446256 100644
--- a/src/example/game.cpp
+++ b/src/example/game.cpp
@@ -1,3 +1,5 @@
+#include "Background.h"
+
#include <crepe/api/Animator.h>
#include <crepe/api/Asset.h>
#include <crepe/api/BehaviorScript.h>
@@ -20,500 +22,6 @@
using namespace crepe;
using namespace std;
-class ParallaxScript : public Script {
-public:
- ParallaxScript(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;
-};
-
-class Start {
-public:
- float create(Scene & scn, float begin_x) {
- GameObject begin = scn.new_object("start_begin", "background", vec2(begin_x, 0));
- Asset begin_asset{"asset/jetpack_joyride/background/start/titleFG_1_TVOS.png"};
- begin.add_component<Sprite>(begin_asset, Sprite::Data{
- .sorting_in_layer = 4,
- .order_in_layer = 0,
- .size = vec2(0, 800),
- });
- begin_x += 700;
-
- GameObject end = scn.new_object("start_end", "background", vec2(begin_x, 0));
- Asset end_asset{"asset/jetpack_joyride/background/start/titleFG_2_TVOS.png"};
- end.add_component<Sprite>(end_asset, Sprite::Data{
- .sorting_in_layer = 4,
- .order_in_layer = 1,
- .size = vec2(0, 800),
- });
- begin_x += 100;
-
- this->add_lamp(end, vec2(-350, -95));
-
- return begin_x;
- }
-
-private:
- void add_lamp(GameObject & obj, vec2 offset, unsigned int fps = 10) {
- Asset lamp_asset{"asset/jetpack_joyride/background/start/alarmLight_TVOS.png"};
- obj.add_component<Sprite>(lamp_asset, Sprite::Data{
- .sorting_in_layer = 5,
- .order_in_layer = 0,
- .size = vec2(0, 100),
- .position_offset = offset,
- });
- Asset lamp_glow_asset{"asset/jetpack_joyride/background/start/alarmGlow_TVOS.png"};
- Sprite & lamp_glow_sprite = obj.add_component<Sprite>(
- lamp_glow_asset, Sprite::Data{
- .sorting_in_layer = 5,
- .order_in_layer = 1,
- .size = vec2(0, 300),
- .position_offset = offset - vec2(65, -55),
- });
- obj.add_component<Animator>(lamp_glow_sprite, ivec2(422, 384), uvec2(6, 1),
- Animator::Data{
- .fps = fps,
- .looping = true,
- });
- }
-};
-
-class Hallway {
-public:
- float 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));
- Asset begin_asset{"asset/jetpack_joyride/background/hallway/hallway1FG_1_TVOS.png"};
- begin.add_component<Sprite>(begin_asset, Sprite::Data{
- .sorting_in_layer = 4,
- .order_in_layer = 0,
- .size = vec2(0, 800),
- });
- begin_x += 600;
-
- this->add_sector_number(begin, vec2(-200, 0), sector_num, sector_color);
- this->add_lamp(begin, vec2(-70, -120), 11);
- this->add_lamp(begin, vec2(30, -120), 9);
-
- GameObject middle_1 = scn.new_object("hallway_middle", "background", vec2(begin_x, 0));
- Asset middle_asset{"asset/jetpack_joyride/background/hallway/hallway1FG_2_TVOS.png"};
- middle_1.add_component<Sprite>(middle_asset, Sprite::Data{
- .sorting_in_layer = 4,
- .order_in_layer = 2,
- .size = vec2(0, 800),
- });
- begin_x += 600;
-
- GameObject middle_2 = scn.new_object("hallway_middle", "background", vec2(begin_x, 0));
- Asset middle_asset_2{"asset/jetpack_joyride/background/hallway/hallway1FG_2_TVOS.png"};
- middle_2.add_component<Sprite>(middle_asset_2, Sprite::Data{
- .sorting_in_layer = 4,
- .order_in_layer = 3,
- .size = vec2(0, 800),
- });
- begin_x += 200;
-
- GameObject middle_3 = scn.new_object("hallway_middle", "background", vec2(begin_x, 0));
- Asset middle_asset_3{"asset/jetpack_joyride/background/hallway/hallway1FG_2_TVOS.png"};
- middle_3.add_component<Sprite>(middle_asset_3, Sprite::Data{
- .sorting_in_layer = 4,
- .order_in_layer = 4,
- .size = vec2(0, 800),
- });
- begin_x += 400;
-
- this->add_lamp(middle_3, vec2(0, -120));
-
- GameObject middle_4 = scn.new_object("hallway_middle", "background", vec2(begin_x, 0));
- Asset middle_asset_4{"asset/jetpack_joyride/background/hallway/hallway1FG_2_TVOS.png"};
- middle_4.add_component<Sprite>(middle_asset_4, Sprite::Data{
- .sorting_in_layer = 4,
- .order_in_layer = 5,
- .size = vec2(0, 800),
- });
- begin_x += 600;
-
- GameObject end = scn.new_object("hallway_end", "background", vec2(begin_x, 0));
- Asset end_asset{"asset/jetpack_joyride/background/hallway/hallway1FG_1_TVOS.png"};
- end.add_component<Sprite>(end_asset, Sprite::Data{
- .sorting_in_layer = 4,
- .order_in_layer = 1,
- .size = vec2(0, 800),
- });
- begin_x += 600;
-
- return begin_x;
- }
-
-private:
- void add_lamp(GameObject & obj, vec2 offset, unsigned int fps = 10) {
- Asset lamp_asset{"asset/jetpack_joyride/background/hallway/alarmLight_TVOS.png"};
- obj.add_component<Sprite>(lamp_asset, Sprite::Data{
- .sorting_in_layer = 5,
- .order_in_layer = 0,
- .size = vec2(0, 100),
- .position_offset = offset,
- });
- Asset lamp_glow_asset{"asset/jetpack_joyride/background/hallway/alarmGlow_TVOS.png"};
- Sprite & lamp_glow_sprite = obj.add_component<Sprite>(
- lamp_glow_asset, Sprite::Data{
- .sorting_in_layer = 5,
- .order_in_layer = 1,
- .size = vec2(0, 300),
- .position_offset = offset - vec2(65, -30),
- });
- obj.add_component<Animator>(lamp_glow_sprite, ivec2(422, 384), uvec2(6, 1),
- Animator::Data{
- .fps = fps,
- .looping = true,
- });
- }
-
- void add_sector_number(GameObject & obj, vec2 offset, unsigned int sector_num,
- Color sector_color) {
- Asset sector_text_asset{
- "asset/jetpack_joyride/background/hallway/sectorText_TVOS.png"};
- obj.add_component<Sprite>(sector_text_asset, Sprite::Data{
- .color = sector_color,
- .sorting_in_layer = 5,
- .order_in_layer = 0,
- .size = vec2(0, 100),
- .position_offset = offset,
- });
- Asset sector_num_asset{
- "asset/jetpack_joyride/background/hallway/sectorNumbers_TVOS.png"};
- Sprite & sector_num_sprite = obj.add_component<Sprite>(
- sector_num_asset, Sprite::Data{
- .color = sector_color,
- .sorting_in_layer = 5,
- .order_in_layer = 0,
- .size = vec2(0, 100),
- .position_offset = offset + vec2(200, 0),
- });
- Animator & sector_num_anim = obj.add_component<Animator>(
- sector_num_sprite, ivec2(256, 128), uvec2(4, 4), Animator::Data{});
- int column = (sector_num - 1) / 4;
- int row = (sector_num - 1) % 4;
- sector_num_anim.set_anim(column);
- for (int i = 0; i < row; i++) {
- sector_num_anim.next_anim();
- }
- sector_num_anim.pause();
- }
-};
-
-class Forest {
-public:
- float 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<ParallaxScript>(
- 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));
- Asset begin_asset{"asset/jetpack_joyride/background/forest/forestFG_1_TVOS.png"};
- begin.add_component<Sprite>(begin_asset, Sprite::Data{
- .sorting_in_layer = 4,
- .order_in_layer = 0,
- .size = vec2(0, 800),
- });
- begin_x += 800;
-
- this->add_background(scn, begin_x, unique_bg_name);
-
- GameObject middle_1 = scn.new_object("forest_middle", "background", vec2(begin_x, 0));
- Asset middle_1_asset{"asset/jetpack_joyride/background/forest/forestFG_3_TVOS.png"};
- middle_1.add_component<Sprite>(middle_1_asset, Sprite::Data{
- .sorting_in_layer = 4,
- .order_in_layer = 2,
- .size = vec2(0, 800),
- });
- begin_x += 800;
-
- this->add_background(scn, begin_x, unique_bg_name);
-
- GameObject middle_2 = scn.new_object("forest_middle", "background", vec2(begin_x, 0));
- Asset middle_2_asset{"asset/jetpack_joyride/background/forest/forestFG_3_TVOS.png"};
- middle_2.add_component<Sprite>(middle_2_asset, Sprite::Data{
- .sorting_in_layer = 4,
- .order_in_layer = 3,
- .size = vec2(0, 800),
- });
- begin_x += 800;
-
- this->add_background(scn, begin_x, unique_bg_name);
-
- GameObject end = scn.new_object("forest_end", "background", vec2(begin_x, 0));
- Asset end_asset{"asset/jetpack_joyride/background/forest/forestFG_2_TVOS.png"};
- end.add_component<Sprite>(end_asset, Sprite::Data{
- .sorting_in_layer = 4,
- .order_in_layer = 1,
- .size = vec2(0, 800),
- });
- begin_x += 600;
-
- this->add_background(scn, begin_x + 200, unique_bg_name);
-
- return begin_x;
- }
-
-private:
- void add_background(Scene & scn, float begin_x, std::string name) {
- GameObject bg_1
- = scn.new_object("forest_bg_1_" + name, "forest_background", vec2(begin_x, 0));
- Asset bg_1_asset{"asset/jetpack_joyride/background/forest/forestBG1_1_TVOS.png"};
- bg_1.add_component<Sprite>(bg_1_asset, Sprite::Data{
- .sorting_in_layer = 3,
- .order_in_layer = 2,
- .size = vec2(0, 800),
- });
- GameObject bg_2
- = scn.new_object("forest_bg_2_" + name, "forest_background", vec2(begin_x, 0));
- Asset bg_2_1_asset{"asset/jetpack_joyride/background/forest/forestBG2_1_TVOS.png"};
- bg_2.add_component<Sprite>(bg_2_1_asset, Sprite::Data{
- .sorting_in_layer = 3,
- .order_in_layer = 1,
- .size = vec2(0, 400),
- .position_offset = vec2(200, 0),
- });
- Asset bg_2_2_asset{"asset/jetpack_joyride/background/forest/forestBG2_2_TVOS.png"};
- bg_2.add_component<Sprite>(bg_2_2_asset, Sprite::Data{
- .sorting_in_layer = 3,
- .order_in_layer = 1,
- .size = vec2(0, 400),
- .position_offset = vec2(-200, 0),
- });
- GameObject bg_3
- = scn.new_object("forest_bg_3_" + name, "forest_background", vec2(begin_x, 0));
- Asset bg_3_1_asset{"asset/jetpack_joyride/background/forest/forestBG3_1_TVOS.png"};
- bg_3.add_component<Sprite>(bg_3_1_asset, Sprite::Data{
- .sorting_in_layer = 3,
- .order_in_layer = 0,
- .size = vec2(0, 200),
- .position_offset = vec2(300, 0),
- });
- Asset bg_3_2_asset{"asset/jetpack_joyride/background/forest/forestBG3_2_TVOS.png"};
- bg_3.add_component<Sprite>(bg_3_2_asset, Sprite::Data{
- .sorting_in_layer = 3,
- .order_in_layer = 0,
- .size = vec2(0, 200),
- .position_offset = vec2(100, 0),
- });
- Asset bg_3_3_asset{"asset/jetpack_joyride/background/forest/forestBG3_3_TVOS.png"};
- bg_3.add_component<Sprite>(bg_3_3_asset, Sprite::Data{
- .sorting_in_layer = 3,
- .order_in_layer = 0,
- .size = vec2(0, 200),
- .position_offset = vec2(-100, 0),
- });
- Asset bg_3_4_asset{"asset/jetpack_joyride/background/forest/forestBG3_4_TVOS.png"};
- bg_3.add_component<Sprite>(bg_3_4_asset, Sprite::Data{
- .sorting_in_layer = 3,
- .order_in_layer = 0,
- .size = vec2(0, 200),
- .position_offset = vec2(-300, 0),
- });
-
- bg_2.add_component<Rigidbody>(Rigidbody::Data{
- .linear_velocity = vec2(30, 0),
- });
- bg_3.add_component<Rigidbody>(Rigidbody::Data{
- .linear_velocity = vec2(40, 0),
- });
- }
-};
-
-class Aquarium {
-public:
- float 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));
- Asset aquarium_begin_asset{
- "asset/jetpack_joyride/background/aquarium/glassTubeFG_1_TVOS.png"};
- aquarium_begin.add_component<Sprite>(aquarium_begin_asset, Sprite::Data{
- .sorting_in_layer = 4,
- .order_in_layer = 0,
- .size = vec2(0, 800),
- });
- begin_x += 600;
-
- GameObject aquarium_middle_1
- = scn.new_object("aquarium_middle", "background", vec2(begin_x, 0));
- Asset aquarium_middle_1_asset{
- "asset/jetpack_joyride/background/aquarium/glassTubeFG_3_TVOS.png"};
- aquarium_middle_1.add_component<Sprite>(aquarium_middle_1_asset,
- Sprite::Data{
- .sorting_in_layer = 4,
- .order_in_layer = 2,
- .size = vec2(0, 800),
- });
- begin_x += 400;
-
- this->add_background(scn, begin_x - 200);
-
- GameObject aquarium_middle_2
- = scn.new_object("aquarium_middle", "background", vec2(begin_x, 0));
- Asset aquarium_middle_2_asset{
- "asset/jetpack_joyride/background/aquarium/glassTubeFG_3_TVOS.png"};
- aquarium_middle_2.add_component<Sprite>(aquarium_middle_2_asset,
- Sprite::Data{
- .sorting_in_layer = 4,
- .order_in_layer = 3,
- .size = vec2(0, 800),
- });
- begin_x += 400;
-
- GameObject aquarium_middle_3
- = scn.new_object("aquarium_middle", "background", vec2(begin_x, 0));
- Asset aquarium_middle_3_asset{
- "asset/jetpack_joyride/background/aquarium/glassTubeFG_3_TVOS.png"};
- aquarium_middle_3.add_component<Sprite>(aquarium_middle_3_asset,
- Sprite::Data{
- .sorting_in_layer = 4,
- .order_in_layer = 4,
- .size = vec2(0, 800),
- });
- begin_x += 400;
-
- this->add_background(scn, begin_x - 200);
-
- GameObject aquarium_middle_4
- = scn.new_object("aquarium_middle", "background", vec2(begin_x, 0));
- Asset aquarium_middle_4_asset{
- "asset/jetpack_joyride/background/aquarium/glassTubeFG_3_TVOS.png"};
- aquarium_middle_4.add_component<Sprite>(aquarium_middle_4_asset,
- Sprite::Data{
- .sorting_in_layer = 4,
- .order_in_layer = 5,
- .size = vec2(0, 800),
- });
- begin_x += 600;
-
- this->add_background(scn, begin_x);
-
- GameObject aquarium_end
- = scn.new_object("aquarium_end", "background", vec2(begin_x, 0));
- Asset aquarium_end_asset{
- "asset/jetpack_joyride/background/aquarium/glassTubeFG_2_TVOS.png"};
- aquarium_end.add_component<Sprite>(aquarium_end_asset, Sprite::Data{
- .sorting_in_layer = 4,
- .order_in_layer = 1,
- .size = vec2(0, 800),
- });
- begin_x += 600;
-
- return begin_x;
- }
-
-private:
- void add_background(Scene & scn, float begin_x) {
- GameObject bg_1
- = scn.new_object("aquarium_bg_1", "aquarium_background", vec2(begin_x, 0));
- Asset bg_1_1_asset{"asset/jetpack_joyride/background/aquarium/AquariumBG1_1_TVOS.png"};
- bg_1.add_component<Sprite>(bg_1_1_asset, Sprite::Data{
- .sorting_in_layer = 3,
- .order_in_layer = 2,
- .size = vec2(0, 400),
- .position_offset = vec2(-200, 100),
- });
- Asset bg_1_2_asset{"asset/jetpack_joyride/background/aquarium/AquariumBG1_2_TVOS.png"};
- bg_1.add_component<Sprite>(bg_1_2_asset, Sprite::Data{
- .sorting_in_layer = 3,
- .order_in_layer = 2,
- .size = vec2(0, 400),
- .position_offset = vec2(200, 100),
- });
- GameObject bg_2
- = scn.new_object("aquarium_bg_2", "aquarium_background", vec2(begin_x, 0));
- Asset bg_2_1_asset{"asset/jetpack_joyride/background/aquarium/AquariumBG2_1_TVOS.png"};
- bg_2.add_component<Sprite>(bg_2_1_asset, Sprite::Data{
- .sorting_in_layer = 3,
- .order_in_layer = 1,
- .size = vec2(0, 400),
- .position_offset = vec2(200, -50),
- });
- Asset bg_2_2_asset{"asset/jetpack_joyride/background/aquarium/AquariumBG2_2_TVOS.png"};
- bg_2.add_component<Sprite>(bg_2_2_asset, Sprite::Data{
- .sorting_in_layer = 3,
- .order_in_layer = 1,
- .size = vec2(0, 400),
- .position_offset = vec2(-200, -50),
- });
- GameObject bg_3
- = scn.new_object("aquarium_bg_3", "aquarium_background", vec2(begin_x, 0));
- Asset bg_3_1_asset{"asset/jetpack_joyride/background/aquarium/AquariumBG3_1_TVOS.png"};
- bg_3.add_component<Sprite>(bg_3_1_asset, Sprite::Data{
- .sorting_in_layer = 3,
- .order_in_layer = 0,
- .size = vec2(0, 400),
- .position_offset = vec2(200, -200),
- });
- Asset bg_3_2_asset{"asset/jetpack_joyride/background/aquarium/AquariumBG3_2_TVOS.png"};
- bg_3.add_component<Sprite>(bg_3_2_asset, Sprite::Data{
- .sorting_in_layer = 3,
- .order_in_layer = 0,
- .size = vec2(0, 400),
- .position_offset = vec2(-200, -200),
- });
- }
-};
-
-class Background {
-public:
- Background(Scene & scn) {
- Start start;
- Hallway hallway;
- Forest forest;
- Aquarium aquarium;
-
- float begin_x = 0;
-
- begin_x = start.create(scn, begin_x);
-
- begin_x = hallway.create(scn, begin_x, 1, Color::YELLOW);
-
- begin_x = forest.create(scn, begin_x, "1");
-
- 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 = forest.create(scn, begin_x, "2");
-
- begin_x = hallway.create(scn, begin_x, 4, Color::GREEN);
-
- begin_x = aquarium.create(scn, begin_x);
- }
-};
-
class MoveCameraScript : public Script {
public:
void init() {
diff --git a/src/example/rendering_particle.cpp b/src/example/rendering_particle.cpp
deleted file mode 100644
index 13e625f..0000000
--- a/src/example/rendering_particle.cpp
+++ /dev/null
@@ -1,95 +0,0 @@
-#include "api/Asset.h"
-#include <crepe/Component.h>
-#include <crepe/api/Animator.h>
-#include <crepe/api/Button.h>
-#include <crepe/api/Camera.h>
-#include <crepe/api/Color.h>
-#include <crepe/api/GameObject.h>
-#include <crepe/api/LoopManager.hpp>
-#include <crepe/api/ParticleEmitter.h>
-#include <crepe/api/Rigidbody.h>
-#include <crepe/api/Sprite.h>
-#include <crepe/api/Transform.h>
-#include <crepe/manager/ComponentManager.h>
-#include <crepe/manager/Mediator.h>
-#include <crepe/types.h>
-#include <iostream>
-
-using namespace crepe;
-using namespace std;
-
-/*
- auto & test = game_object.add_component<ParticleEmitter>(ParticleEmitter::Data{
- .position = {0, 0},
- .max_particles = 10,
- .emission_rate = 0.1,
- .min_speed = 6,
- .max_speed = 20,
- .min_angle = -20,
- .max_angle = 20,
- .begin_lifespan = 0,
- .end_lifespan = 60,
- .force_over_time = vec2{0, 0},
- .boundary{
- .width = 1000,
- .height = 1000,
- .offset = vec2{0, 0},
- .reset_on_exit = false,
- },
- .sprite = test_sprite,
- });
- */
-
-class TestScene : public Scene {
-public:
- void load_scene() {
-
- cout << "TestScene" << endl;
- Mediator & mediator = this->mediator;
- ComponentManager & mgr = mediator.component_manager;
- GameObject game_object = mgr.new_object("", "", vec2{0, 0}, 0, 1);
-
- Color color(255, 255, 255, 255);
-
- Asset img{"asset/spritesheet/spritesheet_test.png"};
-
- Sprite & test_sprite = game_object.add_component<Sprite>(
- img, Sprite::Data{
- .color = color,
- .flip = Sprite::FlipSettings{false, false},
- .sorting_in_layer = 2,
- .order_in_layer = 2,
- .size = {0, 100},
- .angle_offset = 0,
- .position_offset = {0, 0},
- });
-
- //auto & anim = game_object.add_component<Animator>(test_sprite,ivec2{32, 64}, uvec2{4,1}, Animator::Data{});
- //anim.set_anim(0);
-
- auto & cam = game_object.add_component<Camera>(ivec2{720, 1280}, vec2{400, 400},
- Camera::Data{
- .bg_color = Color::WHITE,
- });
-
- function<void()> on_click = [&]() { cout << "button clicked" << std::endl; };
- function<void()> on_enter = [&]() { cout << "enter" << std::endl; };
- function<void()> on_exit = [&]() { cout << "exit" << std::endl; };
-
- auto & button
- = game_object.add_component<Button>(vec2{200, 200}, vec2{0, 0}, on_click, false);
- button.on_mouse_enter = on_enter;
- button.on_mouse_exit = on_exit;
- button.is_toggle = true;
- button.active = true;
- }
-
- string get_name() const { return "TestScene"; };
-};
-
-int main(int argc, char * argv[]) {
- LoopManager engine;
- engine.add_scene<TestScene>();
- engine.start();
- return 0;
-}