aboutsummaryrefslogtreecommitdiff
path: root/src/example/replay.cpp
diff options
context:
space:
mode:
authormax-001 <maxsmits21@kpnmail.nl>2024-12-20 12:01:36 +0100
committermax-001 <maxsmits21@kpnmail.nl>2024-12-20 12:01:36 +0100
commit79d3a9f4311e6684b6df83a15ca7844f58c1959c (patch)
treeb2883e83f61cee9edf290a6a7228c7f0b1fbae8a /src/example/replay.cpp
parent9140b73e4af7aa925b53e4fb4e6aa7f4ea2e3385 (diff)
parent03aea832aa0bc2edba2cc5ab4d9f8eba42d355be (diff)
Merge remote-tracking branch 'origin/master' into max/game
Diffstat (limited to 'src/example/replay.cpp')
-rw-r--r--src/example/replay.cpp84
1 files changed, 84 insertions, 0 deletions
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();
+}