aboutsummaryrefslogtreecommitdiff
path: root/src/example/FontExample.cpp
diff options
context:
space:
mode:
authorWBoerenkamps <wrj.boerenkamps@student.avans.nl>2024-12-17 19:16:25 +0100
committerWBoerenkamps <wrj.boerenkamps@student.avans.nl>2024-12-17 19:16:25 +0100
commitb421eec1073c1fb4b99d46cc36c5c9cbd8d3c4a7 (patch)
tree461e290e0c2c3adf588f02d24031edc7f8114390 /src/example/FontExample.cpp
parentc4c896c2995f2b74fca322736aa944b28b14a1f6 (diff)
parenta8ccf7fe8662086bb223aa4eafd0f85e717d16cf (diff)
Merge branch 'master' of https://github.com/lonkaars/crepe into wouter/button-improvement
Diffstat (limited to 'src/example/FontExample.cpp')
-rw-r--r--src/example/FontExample.cpp55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/example/FontExample.cpp b/src/example/FontExample.cpp
new file mode 100644
index 0000000..6a334b1
--- /dev/null
+++ b/src/example/FontExample.cpp
@@ -0,0 +1,55 @@
+#include <SDL2/SDL_ttf.h>
+#include <chrono>
+#include <crepe/api/Camera.h>
+#include <crepe/api/Config.h>
+#include <crepe/api/GameObject.h>
+#include <crepe/api/LoopManager.h>
+#include <crepe/api/Scene.h>
+#include <crepe/api/Script.h>
+#include <crepe/api/Text.h>
+#include <crepe/facade/Font.h>
+#include <crepe/facade/SDLContext.h>
+#include <crepe/manager/EventManager.h>
+#include <crepe/manager/Mediator.h>
+#include <crepe/manager/ResourceManager.h>
+#include <exception>
+#include <iostream>
+#include <memory>
+using namespace crepe;
+using namespace std;
+using namespace std::chrono;
+class TestScript : public Script {
+public:
+ steady_clock::time_point start_time;
+ virtual void init() override { start_time = steady_clock::now(); }
+ virtual void update() override {
+ auto now = steady_clock::now();
+ auto elapsed = duration_cast<seconds>(now - start_time).count();
+
+ if (elapsed >= 5) {
+ Mediator & med = mediator;
+ EventManager & event_mgr = med.event_manager;
+ event_mgr.trigger_event<ShutDownEvent>();
+ }
+ }
+};
+class TestScene : public Scene {
+public:
+ void load_scene() override {
+ GameObject text_object = this->new_object("test", "test", vec2{0, 0}, 0, 1);
+ text_object.add_component<Text>(vec2(100, 100), vec2(0, 0), "OpenSymbol",
+ Text::Data{});
+ text_object.add_component<BehaviorScript>().set_script<TestScript>();
+ text_object.add_component<Camera>(ivec2{300, 300}, vec2{100, 100}, Camera::Data{});
+ }
+ std::string get_name() const override { return "hey"; }
+};
+int main() {
+ // Config& config = Config::get_instance();
+ // config.log.level = Log::Level::TRACE;
+ LoopManager engine;
+ engine.add_scene<TestScene>();
+ engine.start();
+
+ return 0;
+}