diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-12-10 19:50:26 +0100 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-12-10 19:50:26 +0100 |
commit | 770496ee9d0e45480c0e0f8951adb8eee247bfe1 (patch) | |
tree | 98c68b0d37d8a1c0c8b8013ea7884d56f04aaa28 /src/example | |
parent | 0cb7f2f82ca167656b3c5cb9f0cc3b44c59cb0eb (diff) |
big WIP
Diffstat (limited to 'src/example')
-rw-r--r-- | src/example/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/example/replay.cpp | 69 |
2 files changed, 70 insertions, 0 deletions
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 <crepe/api/BoxCollider.h> +#include <crepe/api/Camera.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/Texture.h> +#include <crepe/api/Transform.h> +#include <crepe/manager/ComponentManager.h> +#include <crepe/manager/Mediator.h> + +using namespace crepe; +using namespace std; + +class AnimationScript : public Script { + Transform * transform; + float t = 0; + + void init() { + Log::logf("AnimationScript init"); + transform = &get_component<Transform>(); + } + + 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<Camera>(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<Sprite>(texture, Sprite::Data{ + .size = { 0.5, 0.5 }, + }); + square.add_component<BehaviorScript>().set_script<AnimationScript>(); + Log::logf("Done initializing scene"); + } + + string get_name() const { return "scene1"; } +}; + +int main(int argc, char * argv[]) { + LoopManager gameloop; + + gameloop.add_scene<TestScene>(); + gameloop.start(); + return 0; +} |