From 770496ee9d0e45480c0e0f8951adb8eee247bfe1 Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Tue, 10 Dec 2024 19:50:26 +0100 Subject: big WIP --- src/example/CMakeLists.txt | 1 + src/example/replay.cpp | 69 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 src/example/replay.cpp (limited to 'src/example') diff --git a/src/example/CMakeLists.txt b/src/example/CMakeLists.txt index 73fc512..7260f35 100644 --- a/src/example/CMakeLists.txt +++ b/src/example/CMakeLists.txt @@ -20,3 +20,4 @@ add_example(savemgr) add_example(rendering_particle) add_example(game) add_example(button) +add_example(replay) diff --git a/src/example/replay.cpp b/src/example/replay.cpp new file mode 100644 index 0000000..6b1ed46 --- /dev/null +++ b/src/example/replay.cpp @@ -0,0 +1,69 @@ +#include "util/OptionalRef.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace crepe; +using namespace std; + +class AnimationScript : public Script { + Transform * transform; + float t = 0; + + void init() { + Log::logf("AnimationScript init"); + transform = &get_component(); + } + + void update() { + Log::logf("AnimationScript update"); + t += 0.01; + transform->position = { sin(t), cos(t) }; + } +}; + +class TestScene : public Scene { +public: + using Scene::Scene; + + void load_scene() { + Log::logf("Initializing scene..."); + Mediator & m = this->mediator; + ComponentManager & mgr = m.component_manager; + + + GameObject cam = mgr.new_object("cam"); + cam.add_component(ivec2{640,480},vec2{3,3}, Camera::Data{ + .bg_color = Color::WHITE, + }); + + GameObject square = mgr.new_object("square"); + Texture texture{"asset/texture/square.png"}; + square.add_component(texture, Sprite::Data{ + .size = { 0.5, 0.5 }, + }); + square.add_component().set_script(); + Log::logf("Done initializing scene"); + } + + string get_name() const { return "scene1"; } +}; + +int main(int argc, char * argv[]) { + LoopManager gameloop; + + gameloop.add_scene(); + gameloop.start(); + return 0; +} -- cgit v1.2.3