aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--game/AquariumSubScene.cpp (renamed from src/example/AquariumSubScene.cpp)0
-rw-r--r--game/AquariumSubScene.h (renamed from src/example/AquariumSubScene.h)0
-rw-r--r--game/BackgroundSubScene.cpp (renamed from src/example/BackgroundSubScene.cpp)0
-rw-r--r--game/BackgroundSubScene.h (renamed from src/example/BackgroundSubScene.h)0
-rw-r--r--game/CMakeLists.txt11
-rw-r--r--game/ForestParallaxScript.cpp (renamed from src/example/ForestParallaxScript.cpp)0
-rw-r--r--game/ForestParallaxScript.h (renamed from src/example/ForestParallaxScript.h)0
-rw-r--r--game/ForestSubScene.cpp (renamed from src/example/ForestSubScene.cpp)0
-rw-r--r--game/ForestSubScene.h (renamed from src/example/ForestSubScene.h)0
-rw-r--r--game/GameScene.cpp (renamed from src/example/GameScene.cpp)0
-rw-r--r--game/GameScene.h (renamed from src/example/GameScene.h)0
-rw-r--r--game/HallwaySubScene.cpp (renamed from src/example/HallwaySubScene.cpp)0
-rw-r--r--game/HallwaySubScene.h (renamed from src/example/HallwaySubScene.h)0
-rw-r--r--game/MoveCameraManualyScript.cpp (renamed from src/example/MoveCameraManualyScript.cpp)0
-rw-r--r--game/MoveCameraManualyScript.h (renamed from src/example/MoveCameraManualyScript.h)0
-rw-r--r--game/PlayerScript.cpp (renamed from src/example/PlayerScript.cpp)0
-rw-r--r--game/PlayerScript.h (renamed from src/example/PlayerScript.h)0
-rw-r--r--game/PlayerSubScene.cpp (renamed from src/example/PlayerSubScene.cpp)0
-rw-r--r--game/PlayerSubScene.h (renamed from src/example/PlayerSubScene.h)0
-rw-r--r--game/StartGameScript.cpp (renamed from src/example/StartGameScript.cpp)0
-rw-r--r--game/StartGameScript.h (renamed from src/example/StartGameScript.h)0
-rw-r--r--game/StartSubScene.cpp (renamed from src/example/StartSubScene.cpp)0
-rw-r--r--game/StartSubScene.h (renamed from src/example/StartSubScene.h)0
-rw-r--r--game/main.cpp325
-rw-r--r--src/example/AITest.cpp90
-rw-r--r--src/example/CMakeLists.txt49
-rw-r--r--src/example/button.cpp41
-rw-r--r--src/example/game.cpp324
-rw-r--r--src/example/loadfont.cpp49
-rw-r--r--src/example/rendering_particle.cpp76
-rw-r--r--src/example/replay.cpp84
31 files changed, 695 insertions, 354 deletions
diff --git a/src/example/AquariumSubScene.cpp b/game/AquariumSubScene.cpp
index 4f13acf..4f13acf 100644
--- a/src/example/AquariumSubScene.cpp
+++ b/game/AquariumSubScene.cpp
diff --git a/src/example/AquariumSubScene.h b/game/AquariumSubScene.h
index 2a188bc..2a188bc 100644
--- a/src/example/AquariumSubScene.h
+++ b/game/AquariumSubScene.h
diff --git a/src/example/BackgroundSubScene.cpp b/game/BackgroundSubScene.cpp
index 6fdc598..6fdc598 100644
--- a/src/example/BackgroundSubScene.cpp
+++ b/game/BackgroundSubScene.cpp
diff --git a/src/example/BackgroundSubScene.h b/game/BackgroundSubScene.h
index 06bdac4..06bdac4 100644
--- a/src/example/BackgroundSubScene.h
+++ b/game/BackgroundSubScene.h
diff --git a/game/CMakeLists.txt b/game/CMakeLists.txt
index 26d937a..dc55523 100644
--- a/game/CMakeLists.txt
+++ b/game/CMakeLists.txt
@@ -9,6 +9,17 @@ project(game C CXX)
add_subdirectory(../src crepe)
add_executable(main
+ AquariumSubScene.cpp
+ BackgroundSubScene.cpp
+ ForestParallaxScript.cpp
+ ForestSubScene.cpp
+ GameScene.cpp
+ HallwaySubScene.cpp
+ MoveCameraManualyScript.cpp
+ PlayerScript.cpp
+ PlayerSubScene.cpp
+ StartGameScript.cpp
+ StartSubScene.cpp
main.cpp
)
diff --git a/src/example/ForestParallaxScript.cpp b/game/ForestParallaxScript.cpp
index 27e30eb..27e30eb 100644
--- a/src/example/ForestParallaxScript.cpp
+++ b/game/ForestParallaxScript.cpp
diff --git a/src/example/ForestParallaxScript.h b/game/ForestParallaxScript.h
index a65a684..a65a684 100644
--- a/src/example/ForestParallaxScript.h
+++ b/game/ForestParallaxScript.h
diff --git a/src/example/ForestSubScene.cpp b/game/ForestSubScene.cpp
index 9be875d..9be875d 100644
--- a/src/example/ForestSubScene.cpp
+++ b/game/ForestSubScene.cpp
diff --git a/src/example/ForestSubScene.h b/game/ForestSubScene.h
index 0a04001..0a04001 100644
--- a/src/example/ForestSubScene.h
+++ b/game/ForestSubScene.h
diff --git a/src/example/GameScene.cpp b/game/GameScene.cpp
index c280474..c280474 100644
--- a/src/example/GameScene.cpp
+++ b/game/GameScene.cpp
diff --git a/src/example/GameScene.h b/game/GameScene.h
index 16e2919..16e2919 100644
--- a/src/example/GameScene.h
+++ b/game/GameScene.h
diff --git a/src/example/HallwaySubScene.cpp b/game/HallwaySubScene.cpp
index 4fe2267..4fe2267 100644
--- a/src/example/HallwaySubScene.cpp
+++ b/game/HallwaySubScene.cpp
diff --git a/src/example/HallwaySubScene.h b/game/HallwaySubScene.h
index acc9329..acc9329 100644
--- a/src/example/HallwaySubScene.h
+++ b/game/HallwaySubScene.h
diff --git a/src/example/MoveCameraManualyScript.cpp b/game/MoveCameraManualyScript.cpp
index 0181333..0181333 100644
--- a/src/example/MoveCameraManualyScript.cpp
+++ b/game/MoveCameraManualyScript.cpp
diff --git a/src/example/MoveCameraManualyScript.h b/game/MoveCameraManualyScript.h
index 5a09055..5a09055 100644
--- a/src/example/MoveCameraManualyScript.h
+++ b/game/MoveCameraManualyScript.h
diff --git a/src/example/PlayerScript.cpp b/game/PlayerScript.cpp
index 1c388f5..1c388f5 100644
--- a/src/example/PlayerScript.cpp
+++ b/game/PlayerScript.cpp
diff --git a/src/example/PlayerScript.h b/game/PlayerScript.h
index 84c4f7f..84c4f7f 100644
--- a/src/example/PlayerScript.h
+++ b/game/PlayerScript.h
diff --git a/src/example/PlayerSubScene.cpp b/game/PlayerSubScene.cpp
index 4f4ba9f..4f4ba9f 100644
--- a/src/example/PlayerSubScene.cpp
+++ b/game/PlayerSubScene.cpp
diff --git a/src/example/PlayerSubScene.h b/game/PlayerSubScene.h
index bf94c32..bf94c32 100644
--- a/src/example/PlayerSubScene.h
+++ b/game/PlayerSubScene.h
diff --git a/src/example/StartGameScript.cpp b/game/StartGameScript.cpp
index 50ba86c..50ba86c 100644
--- a/src/example/StartGameScript.cpp
+++ b/game/StartGameScript.cpp
diff --git a/src/example/StartGameScript.h b/game/StartGameScript.h
index ad62e1a..ad62e1a 100644
--- a/src/example/StartGameScript.h
+++ b/game/StartGameScript.h
diff --git a/src/example/StartSubScene.cpp b/game/StartSubScene.cpp
index 07738a4..07738a4 100644
--- a/src/example/StartSubScene.cpp
+++ b/game/StartSubScene.cpp
diff --git a/src/example/StartSubScene.h b/game/StartSubScene.h
index c83e3d5..c83e3d5 100644
--- a/src/example/StartSubScene.h
+++ b/game/StartSubScene.h
diff --git a/game/main.cpp b/game/main.cpp
index 237c8ce..a028791 100644
--- a/game/main.cpp
+++ b/game/main.cpp
@@ -1 +1,324 @@
-int main() {}
+#include "GameScene.h"
+
+#include <crepe/api/Engine.h>
+#include <crepe/api/Script.h>
+
+using namespace crepe;
+using namespace std;
+
+class ScriptBox : public Script {
+public:
+ bool oncollision(const CollisionEvent & test) {
+ Log::logf("Box {} on_collision() with {}", test.info.self.metadata.game_object_id,
+ test.info.other.metadata.game_object_id);
+ return true;
+ }
+
+ void init() {
+ subscribe<CollisionEvent>(
+ [this](const CollisionEvent & ev) -> bool { return this->oncollision(ev); });
+ }
+};
+
+class ScriptCircle : public Script {
+public:
+ bool oncollision(const CollisionEvent & test) {
+ Log::logf("Circle {} on_collision() with {}", test.info.self.metadata.game_object_id,
+ test.info.other.metadata.game_object_id);
+ return true;
+ }
+
+ void init() {
+ subscribe<CollisionEvent>(
+ [this](const CollisionEvent & ev) -> bool { return this->oncollision(ev); });
+ }
+};
+
+class ScriptMoveToLeft : public Script {
+public:
+ void update() {
+ Transform & transform = this->get_component<Transform>();
+ transform.position.x -= 0.02;
+ }
+};
+
+class ScriptMoveToRight : public Script {
+public:
+ void update() {
+ Transform & transform = this->get_component<Transform>();
+ transform.position.x += 0.02;
+ }
+};
+
+class ConcreteScene1 : public Scene {
+public:
+ void load_scene() {
+ GameObject camera = this->new_object("camera");
+ camera.add_component<Camera>(ivec2(1080, 720), vec2(10, 10),
+ Camera::Data{.bg_color = Color::WHITE, .zoom = 1});
+
+ GameObject reference = this->new_object("reference", "tag", vec2(0, 0), 0, 1);
+ Asset reference_asset = Asset("asset/texture/square.png");
+ reference.add_component<Sprite>(reference_asset, Sprite::Data{
+ .color = Color::RED,
+ .sorting_in_layer = 10,
+ .order_in_layer = 0,
+ .size = vec2(0.1, 0.1),
+ .angle_offset = 0,
+ .scale_offset = 1,
+ .position_offset = vec2(0, 0),
+ });
+
+ /*GameObject box_1 = this->new_object("box_1", "tag", vec2(0, 0), 0, 1);
+ Asset box_1_asset = Asset("asset/texture/square.png");
+ box_1.add_component<Sprite>(box_1_asset, Sprite::Data{
+ .sorting_in_layer = 0,
+ .order_in_layer = 0,
+ .size = vec2(1, 1),
+ .angle_offset = 0,
+ .scale_offset = 1,
+ .position_offset = vec2(0, 0.5),
+ });
+ Asset box_1_asset2 = Asset("asset/texture/test_ap43.png");
+ box_1.add_component<Sprite>(box_1_asset2, Sprite::Data{
+ .sorting_in_layer = 0,
+ .order_in_layer = 0,
+ .size = vec2(1, 1),
+ .angle_offset = 0,
+ .scale_offset = 1,
+ .position_offset = vec2(0, -0.5),
+ });*/
+
+ /*GameObject particles = this->new_object("particles", "tag", vec2(-1, 0), 180, 1);
+ Asset particles_asset = Asset("asset/texture/test_ap43.png");
+ Sprite & particles_sprite = particles.add_component<Sprite>(particles_asset, Sprite::Data{
+ .sorting_in_layer = 0,
+ .order_in_layer = 0,
+ .size = vec2(1, 1),
+ .angle_offset = 0,
+ .scale_offset = 1,
+ .position_offset = vec2(0, 0),
+ });
+ ParticleEmitter & particles_emitter = particles.add_component<ParticleEmitter>(particles_sprite, ParticleEmitter::Data{
+ .offset = vec2(0, 0),
+ .emission_rate = 1,
+ .min_speed = 1,
+ .max_speed = 1,
+ .min_angle = 0,
+ .max_angle = 0,
+ .end_lifespan = 4,
+ });*/
+
+ const bool SCRIPT = false;
+
+ const Rigidbody::BodyType BODYTYPE_LEFT = Rigidbody::BodyType::DYNAMIC;
+ const Rigidbody::BodyType BODYTYPE_RIGHT = Rigidbody::BodyType::DYNAMIC;
+ const bool BOUNCE_LEFT = false;
+ const bool BOUNCE_RIGHT = false;
+ const bool KINEMATIC_COLLISION = true;
+ const bool ONTOP = false;
+
+ const float SCALE = 0.5;
+ const float OFFSET_X_LEFT = 0;
+ const float OFFSET_X_RIGHT = 0;
+ const float OFFSET_Y_LEFT = 0;
+ const float OFFSET_Y_RIGHT = 0;
+
+ GameObject box_1 = this->new_object("box_1", "tag",
+ ONTOP ? vec2(-0.25, -4) : vec2(-2, -4), 0, SCALE);
+ Asset box_1_asset = Asset("asset/texture/square.png");
+ box_1.add_component<Sprite>(box_1_asset,
+ Sprite::Data{
+ .sorting_in_layer = 0,
+ .order_in_layer = 0,
+ .size = vec2(1, 1),
+ .angle_offset = 0,
+ .scale_offset = 1,
+ .position_offset = vec2(OFFSET_X_LEFT, OFFSET_Y_LEFT),
+ });
+ box_1.add_component<Rigidbody>(Rigidbody::Data{
+ .gravity_scale = 0,
+ .body_type = BODYTYPE_LEFT,
+ .linear_velocity = SCRIPT ? vec2{0, 0} : vec2{1, 0},
+ .elasticity_coefficient = BOUNCE_LEFT ? 0.5 : 0,
+ .kinematic_collision = KINEMATIC_COLLISION,
+ });
+ box_1.add_component<BehaviorScript>().set_script<ScriptMoveToRight>().active = SCRIPT;
+ box_1.add_component<BoxCollider>(vec2(1, 1), vec2(OFFSET_X_LEFT, OFFSET_Y_LEFT));
+ box_1.add_component<BehaviorScript>().set_script<ScriptBox>();
+
+ GameObject circle_1 = this->new_object("ricle_1", "tag",
+ ONTOP ? vec2(0.25, -4) : vec2(2, -4), 0, SCALE);
+ Asset circle_1_asset = Asset("asset/texture/circle.png");
+ circle_1.add_component<Sprite>(
+ circle_1_asset, Sprite::Data{
+ .sorting_in_layer = 0,
+ .order_in_layer = 0,
+ .size = vec2(1, 1),
+ .angle_offset = 0,
+ .scale_offset = 1,
+ .position_offset = vec2(OFFSET_X_RIGHT, OFFSET_Y_RIGHT),
+ });
+ circle_1.add_component<Rigidbody>(Rigidbody::Data{
+ .gravity_scale = 0,
+ .body_type = BODYTYPE_RIGHT,
+ .linear_velocity = SCRIPT ? vec2{0, 0} : vec2{-1, 0},
+ .elasticity_coefficient = BOUNCE_RIGHT ? 0.5 : 0,
+ .kinematic_collision = KINEMATIC_COLLISION,
+ });
+ circle_1.add_component<BehaviorScript>().set_script<ScriptMoveToLeft>().active
+ = SCRIPT;
+ circle_1.add_component<CircleCollider>(0.5, vec2(OFFSET_X_RIGHT, OFFSET_Y_RIGHT));
+ circle_1.add_component<BehaviorScript>().set_script<ScriptCircle>();
+
+ GameObject circle_2 = this->new_object(
+ "ricle_2", "tag", ONTOP ? vec2(-0.25, -1.5) : vec2(-2.5, -1.5), 0, SCALE);
+ Asset circle_2_asset = Asset("asset/texture/circle.png");
+ circle_2.add_component<Sprite>(
+ circle_2_asset, Sprite::Data{
+ .sorting_in_layer = 0,
+ .order_in_layer = 0,
+ .size = vec2(1, 1),
+ .angle_offset = 0,
+ .scale_offset = 1,
+ .position_offset = vec2(OFFSET_X_LEFT, OFFSET_Y_LEFT),
+ });
+ circle_2.add_component<Rigidbody>(Rigidbody::Data{
+ .gravity_scale = 0,
+ .body_type = BODYTYPE_LEFT,
+ .linear_velocity = SCRIPT ? vec2{0, 0} : vec2{1, 0},
+ .elasticity_coefficient = BOUNCE_LEFT ? 0.5 : 0,
+ .kinematic_collision = KINEMATIC_COLLISION,
+ });
+ circle_2.add_component<BehaviorScript>().set_script<ScriptMoveToRight>().active
+ = SCRIPT;
+ circle_2.add_component<CircleCollider>(0.5, vec2(OFFSET_X_LEFT, OFFSET_Y_LEFT));
+ circle_2.add_component<BehaviorScript>().set_script<ScriptCircle>();
+
+ GameObject box_2 = this->new_object(
+ "box_2", "tag", ONTOP ? vec2(0.25, -1.5) : vec2(2.5, -1.5), 0, SCALE);
+ Asset box_2_asset = Asset("asset/texture/square.png");
+ box_2.add_component<Sprite>(
+ box_2_asset, Sprite::Data{
+ .sorting_in_layer = 0,
+ .order_in_layer = 0,
+ .size = vec2(1, 1),
+ .angle_offset = 0,
+ .scale_offset = 1,
+ .position_offset = vec2(OFFSET_X_RIGHT, OFFSET_Y_RIGHT),
+ });
+ box_2.add_component<Rigidbody>(Rigidbody::Data{
+ .gravity_scale = 0,
+ .body_type = BODYTYPE_RIGHT,
+ .linear_velocity = SCRIPT ? vec2{0, 0} : vec2{-1, 0},
+ .elasticity_coefficient = BOUNCE_RIGHT ? 0.5 : 0,
+ .kinematic_collision = KINEMATIC_COLLISION,
+ });
+ box_2.add_component<BehaviorScript>().set_script<ScriptMoveToLeft>().active = SCRIPT;
+ box_2.add_component<BoxCollider>(vec2(1, 1), vec2(OFFSET_X_RIGHT, OFFSET_Y_RIGHT));
+ box_2.add_component<BehaviorScript>().set_script<ScriptBox>();
+
+ GameObject box_3 = this->new_object(
+ "box_3", "tag", ONTOP ? vec2(-0.25, 1.5) : vec2(-3, 1.5), 0, SCALE);
+ Asset box_3_asset = Asset("asset/texture/square.png");
+ box_3.add_component<Sprite>(box_3_asset,
+ Sprite::Data{
+ .sorting_in_layer = 0,
+ .order_in_layer = 0,
+ .size = vec2(1, 1),
+ .angle_offset = 0,
+ .scale_offset = 1,
+ .position_offset = vec2(OFFSET_X_LEFT, OFFSET_Y_LEFT),
+ });
+ box_3.add_component<Rigidbody>(Rigidbody::Data{
+ .gravity_scale = 0,
+ .body_type = BODYTYPE_LEFT,
+ .linear_velocity = SCRIPT ? vec2{0, 0} : vec2{1, 0},
+ .elasticity_coefficient = BOUNCE_LEFT ? 0.5 : 0,
+ .kinematic_collision = KINEMATIC_COLLISION,
+ });
+ box_3.add_component<BehaviorScript>().set_script<ScriptMoveToRight>().active = SCRIPT;
+ box_3.add_component<BoxCollider>(vec2(1, 1), vec2(OFFSET_X_LEFT, OFFSET_Y_LEFT));
+ box_3.add_component<BehaviorScript>().set_script<ScriptBox>();
+
+ GameObject box_4 = this->new_object("box_4", "tag",
+ ONTOP ? vec2(0.25, 1.5) : vec2(3, 1.5), 0, SCALE);
+ Asset box_4_asset = Asset("asset/texture/square.png");
+ box_4.add_component<Sprite>(
+ box_4_asset, Sprite::Data{
+ .sorting_in_layer = 0,
+ .order_in_layer = 0,
+ .size = vec2(1, 1),
+ .angle_offset = 0,
+ .scale_offset = 1,
+ .position_offset = vec2(OFFSET_X_RIGHT, OFFSET_Y_RIGHT),
+ });
+ box_4.add_component<Rigidbody>(Rigidbody::Data{
+ .gravity_scale = 0,
+ .body_type = BODYTYPE_RIGHT,
+ .linear_velocity = SCRIPT ? vec2{0, 0} : vec2{-1, 0},
+ .elasticity_coefficient = BOUNCE_RIGHT ? 0.5 : 0,
+ .kinematic_collision = KINEMATIC_COLLISION,
+ });
+ box_4.add_component<BehaviorScript>().set_script<ScriptMoveToLeft>().active = SCRIPT;
+ box_4.add_component<BoxCollider>(vec2(1, 1), vec2(OFFSET_X_RIGHT, OFFSET_Y_RIGHT));
+ box_4.add_component<BehaviorScript>().set_script<ScriptBox>();
+
+ GameObject circle_3 = this->new_object(
+ "ricle_3", "tag", ONTOP ? vec2(-0.25, 4) : vec2(-3.5, 4), 0, SCALE);
+ Asset circle_3_asset = Asset("asset/texture/circle.png");
+ circle_3.add_component<Sprite>(
+ circle_3_asset, Sprite::Data{
+ .sorting_in_layer = 0,
+ .order_in_layer = 0,
+ .size = vec2(1, 1),
+ .angle_offset = 0,
+ .scale_offset = 1,
+ .position_offset = vec2(OFFSET_X_LEFT, OFFSET_Y_LEFT),
+ });
+ circle_3.add_component<Rigidbody>(Rigidbody::Data{
+ .gravity_scale = 0,
+ .body_type = BODYTYPE_LEFT,
+ .linear_velocity = SCRIPT ? vec2{0, 0} : vec2{1, 0},
+ .elasticity_coefficient = BOUNCE_LEFT ? 0.5 : 0,
+ .kinematic_collision = KINEMATIC_COLLISION,
+ });
+ circle_3.add_component<BehaviorScript>().set_script<ScriptMoveToRight>().active
+ = SCRIPT;
+ circle_3.add_component<CircleCollider>(0.5, vec2(OFFSET_X_LEFT, OFFSET_Y_LEFT));
+ circle_3.add_component<BehaviorScript>().set_script<ScriptCircle>();
+
+ GameObject circle_4 = this->new_object("ricle_4", "tag",
+ ONTOP ? vec2(0.25, 4) : vec2(3.5, 4), 0, SCALE);
+ Asset circle_4_asset = Asset("asset/texture/circle.png");
+ circle_4.add_component<Sprite>(
+ circle_4_asset, Sprite::Data{
+ .sorting_in_layer = 0,
+ .order_in_layer = 0,
+ .size = vec2(1, 1),
+ .angle_offset = 0,
+ .scale_offset = 1,
+ .position_offset = vec2(OFFSET_X_RIGHT, OFFSET_Y_RIGHT),
+ });
+ circle_4.add_component<Rigidbody>(Rigidbody::Data{
+ .gravity_scale = 0,
+ .body_type = BODYTYPE_RIGHT,
+ .linear_velocity = SCRIPT ? vec2{0, 0} : vec2{-1, 0},
+ .elasticity_coefficient = BOUNCE_RIGHT ? 0.5 : 0,
+ .kinematic_collision = KINEMATIC_COLLISION,
+ });
+ circle_4.add_component<BehaviorScript>().set_script<ScriptMoveToLeft>().active
+ = SCRIPT;
+ circle_4.add_component<CircleCollider>(0.5, vec2(OFFSET_X_RIGHT, OFFSET_Y_RIGHT));
+ circle_4.add_component<BehaviorScript>().set_script<ScriptCircle>();
+ }
+
+ string get_name() const { return "scene1"; }
+};
+
+int main(int argc, char * argv[]) {
+ Engine gameloop;
+ gameloop.add_scene<GameScene>();
+
+ return gameloop.main();
+}
diff --git a/src/example/AITest.cpp b/src/example/AITest.cpp
new file mode 100644
index 0000000..93ba500
--- /dev/null
+++ b/src/example/AITest.cpp
@@ -0,0 +1,90 @@
+#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/CMakeLists.txt b/src/example/CMakeLists.txt
index 4b9f4f1..afe6cb7 100644
--- a/src/example/CMakeLists.txt
+++ b/src/example/CMakeLists.txt
@@ -1,32 +1,23 @@
-set(GAME_HEADERS
- AquariumSubScene.h
- BackgroundSubScene.h
- ForestSubScene.h
- ForestParallaxScript.h
- HallwaySubScene.h
- StartSubScene.h
- GameScene.h
- StartGameScript.h
- MoveCameraManualyScript.h
- PlayerSubScene.h
- PlayerScript.h
-)
+# all examples
+add_custom_target(examples)
-set(GAME_SOURCES
- game.cpp
- AquariumSubScene.cpp
- BackgroundSubScene.cpp
- ForestSubScene.cpp
- ForestParallaxScript.cpp
- HallwaySubScene.cpp
- StartSubScene.cpp
- GameScene.cpp
- StartGameScript.cpp
- MoveCameraManualyScript.cpp
- PlayerSubScene.cpp
- PlayerScript.cpp
-)
+# 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()
-add_executable(game ${GAME_SOURCES} ${GAME_HEADERS})
+ add_executable(${target_name} EXCLUDE_FROM_ALL ${sources})
+ target_link_libraries(${target_name} PUBLIC crepe)
+ add_dependencies(examples ${target_name})
+endfunction()
-target_link_libraries(game PUBLIC crepe)
+add_example(rendering_particle)
+add_example(button)
+add_example(replay)
+add_example(loadfont)
+add_example(AITest)
diff --git a/src/example/button.cpp b/src/example/button.cpp
new file mode 100644
index 0000000..4220588
--- /dev/null
+++ b/src/example/button.cpp
@@ -0,0 +1,41 @@
+#include <SDL2/SDL_timer.h>
+#include <chrono>
+#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/Sprite.h>
+#include <crepe/api/Texture.h>
+#include <crepe/api/Transform.h>
+#include <crepe/facade/SDLContext.h>
+#include <crepe/manager/ComponentManager.h>
+#include <crepe/manager/EventManager.h>
+#include <crepe/system/AnimatorSystem.h>
+#include <crepe/system/InputSystem.h>
+#include <crepe/system/RenderSystem.h>
+#include <crepe/types.h>
+using namespace crepe;
+using namespace std;
+
+int main(int argc, char * argv[]) {
+ Mediator mediator;
+ ComponentManager mgr{mediator};
+ RenderSystem sys{mediator};
+ EventManager event_mgr{mediator};
+ InputSystem input_sys{mediator};
+ SDLContext sdl_context{mediator};
+ GameObject obj = mgr.new_object("camera", "camera", vec2{0, 0}, 0, 1);
+ auto & camera = obj.add_component<Camera>(
+ ivec2{500, 500}, vec2{500, 500}, Camera::Data{.bg_color = Color::WHITE, .zoom = 1.0f});
+ auto start = std::chrono::steady_clock::now();
+ while (true) {
+ const keyboard_state_t & keyboard_state = sdl_context.get_keyboard_state();
+ input_sys.update();
+ sys.update();
+ event_mgr.dispatch_events();
+ SDL_Delay(30);
+ }
+ return 0;
+}
diff --git a/src/example/game.cpp b/src/example/game.cpp
deleted file mode 100644
index a028791..0000000
--- a/src/example/game.cpp
+++ /dev/null
@@ -1,324 +0,0 @@
-#include "GameScene.h"
-
-#include <crepe/api/Engine.h>
-#include <crepe/api/Script.h>
-
-using namespace crepe;
-using namespace std;
-
-class ScriptBox : public Script {
-public:
- bool oncollision(const CollisionEvent & test) {
- Log::logf("Box {} on_collision() with {}", test.info.self.metadata.game_object_id,
- test.info.other.metadata.game_object_id);
- return true;
- }
-
- void init() {
- subscribe<CollisionEvent>(
- [this](const CollisionEvent & ev) -> bool { return this->oncollision(ev); });
- }
-};
-
-class ScriptCircle : public Script {
-public:
- bool oncollision(const CollisionEvent & test) {
- Log::logf("Circle {} on_collision() with {}", test.info.self.metadata.game_object_id,
- test.info.other.metadata.game_object_id);
- return true;
- }
-
- void init() {
- subscribe<CollisionEvent>(
- [this](const CollisionEvent & ev) -> bool { return this->oncollision(ev); });
- }
-};
-
-class ScriptMoveToLeft : public Script {
-public:
- void update() {
- Transform & transform = this->get_component<Transform>();
- transform.position.x -= 0.02;
- }
-};
-
-class ScriptMoveToRight : public Script {
-public:
- void update() {
- Transform & transform = this->get_component<Transform>();
- transform.position.x += 0.02;
- }
-};
-
-class ConcreteScene1 : public Scene {
-public:
- void load_scene() {
- GameObject camera = this->new_object("camera");
- camera.add_component<Camera>(ivec2(1080, 720), vec2(10, 10),
- Camera::Data{.bg_color = Color::WHITE, .zoom = 1});
-
- GameObject reference = this->new_object("reference", "tag", vec2(0, 0), 0, 1);
- Asset reference_asset = Asset("asset/texture/square.png");
- reference.add_component<Sprite>(reference_asset, Sprite::Data{
- .color = Color::RED,
- .sorting_in_layer = 10,
- .order_in_layer = 0,
- .size = vec2(0.1, 0.1),
- .angle_offset = 0,
- .scale_offset = 1,
- .position_offset = vec2(0, 0),
- });
-
- /*GameObject box_1 = this->new_object("box_1", "tag", vec2(0, 0), 0, 1);
- Asset box_1_asset = Asset("asset/texture/square.png");
- box_1.add_component<Sprite>(box_1_asset, Sprite::Data{
- .sorting_in_layer = 0,
- .order_in_layer = 0,
- .size = vec2(1, 1),
- .angle_offset = 0,
- .scale_offset = 1,
- .position_offset = vec2(0, 0.5),
- });
- Asset box_1_asset2 = Asset("asset/texture/test_ap43.png");
- box_1.add_component<Sprite>(box_1_asset2, Sprite::Data{
- .sorting_in_layer = 0,
- .order_in_layer = 0,
- .size = vec2(1, 1),
- .angle_offset = 0,
- .scale_offset = 1,
- .position_offset = vec2(0, -0.5),
- });*/
-
- /*GameObject particles = this->new_object("particles", "tag", vec2(-1, 0), 180, 1);
- Asset particles_asset = Asset("asset/texture/test_ap43.png");
- Sprite & particles_sprite = particles.add_component<Sprite>(particles_asset, Sprite::Data{
- .sorting_in_layer = 0,
- .order_in_layer = 0,
- .size = vec2(1, 1),
- .angle_offset = 0,
- .scale_offset = 1,
- .position_offset = vec2(0, 0),
- });
- ParticleEmitter & particles_emitter = particles.add_component<ParticleEmitter>(particles_sprite, ParticleEmitter::Data{
- .offset = vec2(0, 0),
- .emission_rate = 1,
- .min_speed = 1,
- .max_speed = 1,
- .min_angle = 0,
- .max_angle = 0,
- .end_lifespan = 4,
- });*/
-
- const bool SCRIPT = false;
-
- const Rigidbody::BodyType BODYTYPE_LEFT = Rigidbody::BodyType::DYNAMIC;
- const Rigidbody::BodyType BODYTYPE_RIGHT = Rigidbody::BodyType::DYNAMIC;
- const bool BOUNCE_LEFT = false;
- const bool BOUNCE_RIGHT = false;
- const bool KINEMATIC_COLLISION = true;
- const bool ONTOP = false;
-
- const float SCALE = 0.5;
- const float OFFSET_X_LEFT = 0;
- const float OFFSET_X_RIGHT = 0;
- const float OFFSET_Y_LEFT = 0;
- const float OFFSET_Y_RIGHT = 0;
-
- GameObject box_1 = this->new_object("box_1", "tag",
- ONTOP ? vec2(-0.25, -4) : vec2(-2, -4), 0, SCALE);
- Asset box_1_asset = Asset("asset/texture/square.png");
- box_1.add_component<Sprite>(box_1_asset,
- Sprite::Data{
- .sorting_in_layer = 0,
- .order_in_layer = 0,
- .size = vec2(1, 1),
- .angle_offset = 0,
- .scale_offset = 1,
- .position_offset = vec2(OFFSET_X_LEFT, OFFSET_Y_LEFT),
- });
- box_1.add_component<Rigidbody>(Rigidbody::Data{
- .gravity_scale = 0,
- .body_type = BODYTYPE_LEFT,
- .linear_velocity = SCRIPT ? vec2{0, 0} : vec2{1, 0},
- .elasticity_coefficient = BOUNCE_LEFT ? 0.5 : 0,
- .kinematic_collision = KINEMATIC_COLLISION,
- });
- box_1.add_component<BehaviorScript>().set_script<ScriptMoveToRight>().active = SCRIPT;
- box_1.add_component<BoxCollider>(vec2(1, 1), vec2(OFFSET_X_LEFT, OFFSET_Y_LEFT));
- box_1.add_component<BehaviorScript>().set_script<ScriptBox>();
-
- GameObject circle_1 = this->new_object("ricle_1", "tag",
- ONTOP ? vec2(0.25, -4) : vec2(2, -4), 0, SCALE);
- Asset circle_1_asset = Asset("asset/texture/circle.png");
- circle_1.add_component<Sprite>(
- circle_1_asset, Sprite::Data{
- .sorting_in_layer = 0,
- .order_in_layer = 0,
- .size = vec2(1, 1),
- .angle_offset = 0,
- .scale_offset = 1,
- .position_offset = vec2(OFFSET_X_RIGHT, OFFSET_Y_RIGHT),
- });
- circle_1.add_component<Rigidbody>(Rigidbody::Data{
- .gravity_scale = 0,
- .body_type = BODYTYPE_RIGHT,
- .linear_velocity = SCRIPT ? vec2{0, 0} : vec2{-1, 0},
- .elasticity_coefficient = BOUNCE_RIGHT ? 0.5 : 0,
- .kinematic_collision = KINEMATIC_COLLISION,
- });
- circle_1.add_component<BehaviorScript>().set_script<ScriptMoveToLeft>().active
- = SCRIPT;
- circle_1.add_component<CircleCollider>(0.5, vec2(OFFSET_X_RIGHT, OFFSET_Y_RIGHT));
- circle_1.add_component<BehaviorScript>().set_script<ScriptCircle>();
-
- GameObject circle_2 = this->new_object(
- "ricle_2", "tag", ONTOP ? vec2(-0.25, -1.5) : vec2(-2.5, -1.5), 0, SCALE);
- Asset circle_2_asset = Asset("asset/texture/circle.png");
- circle_2.add_component<Sprite>(
- circle_2_asset, Sprite::Data{
- .sorting_in_layer = 0,
- .order_in_layer = 0,
- .size = vec2(1, 1),
- .angle_offset = 0,
- .scale_offset = 1,
- .position_offset = vec2(OFFSET_X_LEFT, OFFSET_Y_LEFT),
- });
- circle_2.add_component<Rigidbody>(Rigidbody::Data{
- .gravity_scale = 0,
- .body_type = BODYTYPE_LEFT,
- .linear_velocity = SCRIPT ? vec2{0, 0} : vec2{1, 0},
- .elasticity_coefficient = BOUNCE_LEFT ? 0.5 : 0,
- .kinematic_collision = KINEMATIC_COLLISION,
- });
- circle_2.add_component<BehaviorScript>().set_script<ScriptMoveToRight>().active
- = SCRIPT;
- circle_2.add_component<CircleCollider>(0.5, vec2(OFFSET_X_LEFT, OFFSET_Y_LEFT));
- circle_2.add_component<BehaviorScript>().set_script<ScriptCircle>();
-
- GameObject box_2 = this->new_object(
- "box_2", "tag", ONTOP ? vec2(0.25, -1.5) : vec2(2.5, -1.5), 0, SCALE);
- Asset box_2_asset = Asset("asset/texture/square.png");
- box_2.add_component<Sprite>(
- box_2_asset, Sprite::Data{
- .sorting_in_layer = 0,
- .order_in_layer = 0,
- .size = vec2(1, 1),
- .angle_offset = 0,
- .scale_offset = 1,
- .position_offset = vec2(OFFSET_X_RIGHT, OFFSET_Y_RIGHT),
- });
- box_2.add_component<Rigidbody>(Rigidbody::Data{
- .gravity_scale = 0,
- .body_type = BODYTYPE_RIGHT,
- .linear_velocity = SCRIPT ? vec2{0, 0} : vec2{-1, 0},
- .elasticity_coefficient = BOUNCE_RIGHT ? 0.5 : 0,
- .kinematic_collision = KINEMATIC_COLLISION,
- });
- box_2.add_component<BehaviorScript>().set_script<ScriptMoveToLeft>().active = SCRIPT;
- box_2.add_component<BoxCollider>(vec2(1, 1), vec2(OFFSET_X_RIGHT, OFFSET_Y_RIGHT));
- box_2.add_component<BehaviorScript>().set_script<ScriptBox>();
-
- GameObject box_3 = this->new_object(
- "box_3", "tag", ONTOP ? vec2(-0.25, 1.5) : vec2(-3, 1.5), 0, SCALE);
- Asset box_3_asset = Asset("asset/texture/square.png");
- box_3.add_component<Sprite>(box_3_asset,
- Sprite::Data{
- .sorting_in_layer = 0,
- .order_in_layer = 0,
- .size = vec2(1, 1),
- .angle_offset = 0,
- .scale_offset = 1,
- .position_offset = vec2(OFFSET_X_LEFT, OFFSET_Y_LEFT),
- });
- box_3.add_component<Rigidbody>(Rigidbody::Data{
- .gravity_scale = 0,
- .body_type = BODYTYPE_LEFT,
- .linear_velocity = SCRIPT ? vec2{0, 0} : vec2{1, 0},
- .elasticity_coefficient = BOUNCE_LEFT ? 0.5 : 0,
- .kinematic_collision = KINEMATIC_COLLISION,
- });
- box_3.add_component<BehaviorScript>().set_script<ScriptMoveToRight>().active = SCRIPT;
- box_3.add_component<BoxCollider>(vec2(1, 1), vec2(OFFSET_X_LEFT, OFFSET_Y_LEFT));
- box_3.add_component<BehaviorScript>().set_script<ScriptBox>();
-
- GameObject box_4 = this->new_object("box_4", "tag",
- ONTOP ? vec2(0.25, 1.5) : vec2(3, 1.5), 0, SCALE);
- Asset box_4_asset = Asset("asset/texture/square.png");
- box_4.add_component<Sprite>(
- box_4_asset, Sprite::Data{
- .sorting_in_layer = 0,
- .order_in_layer = 0,
- .size = vec2(1, 1),
- .angle_offset = 0,
- .scale_offset = 1,
- .position_offset = vec2(OFFSET_X_RIGHT, OFFSET_Y_RIGHT),
- });
- box_4.add_component<Rigidbody>(Rigidbody::Data{
- .gravity_scale = 0,
- .body_type = BODYTYPE_RIGHT,
- .linear_velocity = SCRIPT ? vec2{0, 0} : vec2{-1, 0},
- .elasticity_coefficient = BOUNCE_RIGHT ? 0.5 : 0,
- .kinematic_collision = KINEMATIC_COLLISION,
- });
- box_4.add_component<BehaviorScript>().set_script<ScriptMoveToLeft>().active = SCRIPT;
- box_4.add_component<BoxCollider>(vec2(1, 1), vec2(OFFSET_X_RIGHT, OFFSET_Y_RIGHT));
- box_4.add_component<BehaviorScript>().set_script<ScriptBox>();
-
- GameObject circle_3 = this->new_object(
- "ricle_3", "tag", ONTOP ? vec2(-0.25, 4) : vec2(-3.5, 4), 0, SCALE);
- Asset circle_3_asset = Asset("asset/texture/circle.png");
- circle_3.add_component<Sprite>(
- circle_3_asset, Sprite::Data{
- .sorting_in_layer = 0,
- .order_in_layer = 0,
- .size = vec2(1, 1),
- .angle_offset = 0,
- .scale_offset = 1,
- .position_offset = vec2(OFFSET_X_LEFT, OFFSET_Y_LEFT),
- });
- circle_3.add_component<Rigidbody>(Rigidbody::Data{
- .gravity_scale = 0,
- .body_type = BODYTYPE_LEFT,
- .linear_velocity = SCRIPT ? vec2{0, 0} : vec2{1, 0},
- .elasticity_coefficient = BOUNCE_LEFT ? 0.5 : 0,
- .kinematic_collision = KINEMATIC_COLLISION,
- });
- circle_3.add_component<BehaviorScript>().set_script<ScriptMoveToRight>().active
- = SCRIPT;
- circle_3.add_component<CircleCollider>(0.5, vec2(OFFSET_X_LEFT, OFFSET_Y_LEFT));
- circle_3.add_component<BehaviorScript>().set_script<ScriptCircle>();
-
- GameObject circle_4 = this->new_object("ricle_4", "tag",
- ONTOP ? vec2(0.25, 4) : vec2(3.5, 4), 0, SCALE);
- Asset circle_4_asset = Asset("asset/texture/circle.png");
- circle_4.add_component<Sprite>(
- circle_4_asset, Sprite::Data{
- .sorting_in_layer = 0,
- .order_in_layer = 0,
- .size = vec2(1, 1),
- .angle_offset = 0,
- .scale_offset = 1,
- .position_offset = vec2(OFFSET_X_RIGHT, OFFSET_Y_RIGHT),
- });
- circle_4.add_component<Rigidbody>(Rigidbody::Data{
- .gravity_scale = 0,
- .body_type = BODYTYPE_RIGHT,
- .linear_velocity = SCRIPT ? vec2{0, 0} : vec2{-1, 0},
- .elasticity_coefficient = BOUNCE_RIGHT ? 0.5 : 0,
- .kinematic_collision = KINEMATIC_COLLISION,
- });
- circle_4.add_component<BehaviorScript>().set_script<ScriptMoveToLeft>().active
- = SCRIPT;
- circle_4.add_component<CircleCollider>(0.5, vec2(OFFSET_X_RIGHT, OFFSET_Y_RIGHT));
- circle_4.add_component<BehaviorScript>().set_script<ScriptCircle>();
- }
-
- string get_name() const { return "scene1"; }
-};
-
-int main(int argc, char * argv[]) {
- Engine gameloop;
- gameloop.add_scene<GameScene>();
-
- return gameloop.main();
-}
diff --git a/src/example/loadfont.cpp b/src/example/loadfont.cpp
new file mode 100644
index 0000000..e459332
--- /dev/null
+++ b/src/example/loadfont.cpp
@@ -0,0 +1,49 @@
+#include <SDL2/SDL_ttf.h>
+#include <crepe/api/Asset.h>
+#include <crepe/api/Text.h>
+#include <crepe/facade/Font.h>
+#include <crepe/facade/FontFacade.h>
+#include <crepe/facade/SDLContext.h>
+#include <crepe/manager/Mediator.h>
+#include <crepe/manager/ResourceManager.h>
+#include <exception>
+#include <iostream>
+#include <memory>
+#include <optional>
+using namespace crepe;
+int main() {
+
+ // SDLFontContext font_facade;
+ Mediator mediator;
+ FontFacade font_facade{};
+ SDLContext sdl_context{mediator};
+ // ComponentManager component_manager{mediator};
+ ResourceManager resource_manager{mediator};
+ try {
+ // Correct way to create a unique pointer for Text
+ std::unique_ptr<Text> label = std::make_unique<Text>(
+ 1, vec2(100, 100), vec2(0, 0), "OpenSymbol", Text::Data{}, "test text");
+ // std::cout << "Path: " << label->font.get_path() << std::endl;
+ Asset asset1 = font_facade.get_font_asset("OpenSymbol");
+ std::cout << asset1.get_path() << std::endl;
+ std::unique_ptr<Text> label2 = std::make_unique<Text>(
+ 1, vec2(100, 100), vec2(0, 0), "fsaafdafsdafsdafsdasfdds", Text::Data{});
+ Asset asset = Asset("test test");
+ label->font.emplace(asset);
+ std::cout << label->font.value().get_path() << std::endl;
+ // label2->font = std::make_optional(asset);
+ // std::cout << "Path: " << label2->font.get_path() << std::endl;
+ ResourceManager & resource_mgr = mediator.resource_manager;
+ const Font & res = resource_manager.get<Font>(label->font.value());
+ // TTF_Font * test_font = res.get_font();
+ // if (test_font == NULL) {
+ // std::cout << "error with font" << std::endl;
+ // } else {
+ // std::cout << "correct font retrieved" << std::endl;
+ // }
+ } catch (const std::exception & e) {
+ std::cout << "Standard exception thrown: " << e.what() << std::endl;
+ }
+
+ return 0;
+}
diff --git a/src/example/rendering_particle.cpp b/src/example/rendering_particle.cpp
new file mode 100644
index 0000000..5440fdd
--- /dev/null
+++ b/src/example/rendering_particle.cpp
@@ -0,0 +1,76 @@
+
+
+#include "api/Asset.h"
+#include "api/Text.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>
+
+using namespace crepe;
+using namespace std;
+
+class TestScene : public Scene {
+public:
+ void load_scene() {
+ GameObject game_object = new_object("", "", vec2{0, 0}, 0, 1);
+
+ Color color(255, 255, 255, 255);
+
+ Asset img{"asset/texture/square.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 = {1, 1},
+ .angle_offset = 0,
+ .position_offset = {0, 1},
+ .world_space = false,
+ });
+ //auto & emitter = game_object.add_component<ParticleEmitter>(test_sprite, ParticleEmitter::Data{});
+
+ Sprite & test_sprite1
+ = game_object.add_component<Sprite>(img, Sprite::Data{
+ .color = color,
+ .size = {1, 1},
+ .position_offset = {0, -1},
+ .world_space = false,
+ });
+
+ auto & cam = game_object.add_component<Camera>(ivec2{1280, 720}, vec2{5, 5},
+ Camera::Data{
+ .bg_color = Color::WHITE,
+ .postion_offset = {1000, 1000},
+ });
+
+ /*
+ game_object.add_component<Text>(vec2{1, 1}, vec2{0, -0.5}, "ComicSansMS",
+ Text::Data{.text_color = Color::RED}, "test TEST");
+
+ game_object.add_component<Text>(vec2{1, 1}, vec2{0, 0.5}, "ComicSansMS",
+ Text::Data{.text_color = Color::BLACK}, "TEST test");
+ */
+ }
+
+ string get_name() const { return "TestScene"; };
+};
+
+int main(int argc, char * argv[]) {
+ LoopManager engine;
+ engine.add_scene<TestScene>();
+ engine.start();
+ return 0;
+}
diff --git a/src/example/replay.cpp b/src/example/replay.cpp
new file mode 100644
index 0000000..82fd478
--- /dev/null
+++ b/src/example/replay.cpp
@@ -0,0 +1,84 @@
+#include <crepe/api/Config.h>
+#include <crepe/api/Engine.h>
+#include <crepe/api/Script.h>
+
+using namespace crepe;
+using namespace std;
+
+class AnimationScript : public Script {
+ Transform * transform;
+ float t = 0;
+
+ void init() { transform = &get_component<Transform>(); }
+
+ void update() {
+ t += 0.05;
+ transform->position = {sin(t), cos(t)};
+ }
+};
+
+class Timeline : public Script {
+ unsigned i = 0;
+ recording_t recording;
+
+ void update() {
+ switch (i++) {
+ default:
+ break;
+ case 10:
+ logf("record start");
+ replay.record_start();
+ break;
+ case 60:
+ logf("record end, playing recording");
+ this->recording = replay.record_end();
+ replay.play(this->recording);
+ break;
+ case 61:
+ logf("done, releasing recording");
+ replay.release(this->recording);
+ break;
+ case 72:
+ logf("exit");
+ queue_event<ShutDownEvent>();
+ break;
+ };
+ }
+};
+
+class TestScene : public Scene {
+public:
+ using Scene::Scene;
+
+ void load_scene() {
+ Mediator & mediator = this->mediator;
+ ComponentManager & mgr = mediator.component_manager;
+
+ GameObject cam = mgr.new_object("cam");
+ cam.add_component<Camera>(ivec2{640, 480}, vec2{3, 3},
+ Camera::Data{
+ .bg_color = Color::WHITE,
+ });
+
+ GameObject square = mgr.new_object("square");
+ square.add_component<Sprite>(Asset{"asset/texture/square.png"}, Sprite::Data{
+ .size = {0.5, 0.5},
+ });
+ square.add_component<BehaviorScript>().set_script<AnimationScript>();
+
+ GameObject scapegoat = mgr.new_object("");
+ scapegoat.add_component<BehaviorScript>().set_script<Timeline>();
+ }
+
+ string get_name() const { return "scene1"; }
+};
+
+int main(int argc, char * argv[]) {
+ Config & cfg = Config::get_instance();
+ cfg.log.level = Log::Level::DEBUG;
+
+ Engine engine;
+
+ engine.add_scene<TestScene>();
+ return engine.main();
+}