aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/crepe/api/Camera.cpp4
-rw-r--r--src/crepe/api/Camera.h9
-rw-r--r--src/crepe/facade/SDLContext.cpp28
-rw-r--r--src/example/AITest.cpp90
-rw-r--r--src/example/CMakeLists.txt6
-rw-r--r--src/example/button.cpp54
-rw-r--r--src/example/demo.cpp24
-rw-r--r--src/example/game.cpp293
-rw-r--r--src/example/rendering_particle.cpp73
-rw-r--r--src/example/replay.cpp84
10 files changed, 42 insertions, 623 deletions
diff --git a/src/crepe/api/Camera.cpp b/src/crepe/api/Camera.cpp
index 19a3296..9befc3f 100644
--- a/src/crepe/api/Camera.cpp
+++ b/src/crepe/api/Camera.cpp
@@ -6,10 +6,8 @@
using namespace crepe;
-Camera::Camera(game_object_id_t id, const ivec2 & screen, const vec2 & viewport_size,
- const Data & data)
+Camera::Camera(game_object_id_t id, const vec2 & viewport_size, const Data & data)
: Component(id),
- screen(screen),
viewport_size(viewport_size),
data(data) {
dbg_trace();
diff --git a/src/crepe/api/Camera.h b/src/crepe/api/Camera.h
index 54d9a73..48f2ff2 100644
--- a/src/crepe/api/Camera.h
+++ b/src/crepe/api/Camera.h
@@ -30,7 +30,7 @@ public:
* zoom < 1 --> zoom out
* zoom > 1 --> zoom in
*/
- double zoom = 1;
+ float zoom = 1.0;
//! offset postion from the game object transform component
vec2 postion_offset;
@@ -40,20 +40,15 @@ public:
/**
* \brief Constructs a Camera with the specified ID and background color.
* \param id Unique identifier for the camera component.
- * \param screen is the actual screen size in pixels
* \param viewport_size is the view of the world in game units
* \param data the camera component data
*/
- Camera(game_object_id_t id, const ivec2 & screen, const vec2 & viewport_size,
- const Camera::Data & data);
+ Camera(game_object_id_t id, const vec2 & viewport_size, const Data & data);
~Camera(); // dbg_trace only
public:
Camera::Data data;
- //! screen the display size in pixels ( output resolution )
- const ivec2 screen;
-
//! viewport is the area of the world visible through the camera (in world units)
const vec2 viewport_size;
diff --git a/src/crepe/facade/SDLContext.cpp b/src/crepe/facade/SDLContext.cpp
index fccc15f..18f40f9 100644
--- a/src/crepe/facade/SDLContext.cpp
+++ b/src/crepe/facade/SDLContext.cpp
@@ -279,13 +279,13 @@ void SDLContext::draw(const RenderContext & ctx) {
}
void SDLContext::update_camera_view(const Camera & cam, const vec2 & new_pos) {
-
const Camera::Data & cam_data = cam.data;
+ const Config & config = Config::get_instance();
// resize window
int w, h;
SDL_GetWindowSize(this->game_window.get(), &w, &h);
- if (w != cam.screen.x || h != cam.screen.y) {
- SDL_SetWindowSize(this->game_window.get(), cam.screen.x, cam.screen.y);
+ if (w != config.window_settings.default_size.x || h != config.window_settings.default_size.y) {
+ SDL_SetWindowSize(this->game_window.get(), config.window_settings.default_size.x, config.window_settings.default_size.y);
}
vec2 & zoomed_viewport = this->cam_aux_data.zoomed_viewport;
@@ -294,28 +294,28 @@ void SDLContext::update_camera_view(const Camera & cam, const vec2 & new_pos) {
this->cam_aux_data.cam_pos = new_pos;
zoomed_viewport = cam.viewport_size * cam_data.zoom;
- float screen_aspect = static_cast<float>(cam.screen.x) / cam.screen.y;
+ float screen_aspect = static_cast<float>(config.window_settings.default_size.x) / config.window_settings.default_size.y;
float viewport_aspect = zoomed_viewport.x / zoomed_viewport.y;
// calculate black bars
if (screen_aspect > viewport_aspect) {
// pillarboxing
- float scale = cam.screen.y / zoomed_viewport.y;
+ float scale = config.window_settings.default_size.y / zoomed_viewport.y;
float adj_width = zoomed_viewport.x * scale;
- float bar_width = (cam.screen.x - adj_width) / 2;
- this->black_bars[0] = {0, 0, bar_width, (float) cam.screen.y};
- this->black_bars[1] = {(cam.screen.x - bar_width), 0, bar_width, (float) cam.screen.y};
+ float bar_width = (config.window_settings.default_size.x - adj_width) / 2;
+ this->black_bars[0] = {0, 0, bar_width, (float) config.window_settings.default_size.y};
+ this->black_bars[1] = {(config.window_settings.default_size.x - bar_width), 0, bar_width, (float) config.window_settings.default_size.y};
bar_size = {bar_width, 0};
render_scale.x = render_scale.y = scale;
} else {
// letterboxing
- float scale = cam.screen.x / (cam.viewport_size.x * cam_data.zoom);
+ float scale = config.window_settings.default_size.x / (cam.viewport_size.x * cam_data.zoom);
float adj_height = cam.viewport_size.y * scale;
- float bar_height = (cam.screen.y - adj_height) / 2;
- this->black_bars[0] = {0, 0, (float) cam.screen.x, bar_height};
+ float bar_height = (config.window_settings.default_size.y - adj_height) / 2;
+ this->black_bars[0] = {0, 0, (float) config.window_settings.default_size.x, bar_height};
this->black_bars[1]
- = {0, (cam.screen.y - bar_height), (float) cam.screen.x, bar_height};
+ = {0, (config.window_settings.default_size.y - bar_height), (float) config.window_settings.default_size.x, bar_height};
bar_size = {0, bar_height};
render_scale.x = render_scale.y = scale;
@@ -327,8 +327,8 @@ void SDLContext::update_camera_view(const Camera & cam, const vec2 & new_pos) {
SDL_Rect bg = {
.x = 0,
.y = 0,
- .w = cam.screen.x,
- .h = cam.screen.y,
+ .w = config.window_settings.default_size.x,
+ .h = config.window_settings.default_size.y,
};
// fill bg color
diff --git a/src/example/AITest.cpp b/src/example/AITest.cpp
deleted file mode 100644
index 93ba500..0000000
--- a/src/example/AITest.cpp
+++ /dev/null
@@ -1,90 +0,0 @@
-#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 1bc31d8..f35f38f 100644
--- a/src/example/CMakeLists.txt
+++ b/src/example/CMakeLists.txt
@@ -16,8 +16,4 @@ function(add_example target_name)
add_dependencies(examples ${target_name})
endfunction()
-add_example(rendering_particle)
-add_example(game)
-add_example(button)
-add_example(replay)
-add_example(AITest)
+add_example(demo)
diff --git a/src/example/button.cpp b/src/example/button.cpp
deleted file mode 100644
index 00bdc28..0000000
--- a/src/example/button.cpp
+++ /dev/null
@@ -1,54 +0,0 @@
-#include <SDL2/SDL_timer.h>
-#include <chrono>
-#include <crepe/Component.h>
-#include <crepe/ComponentManager.h>
-#include <crepe/api/Animator.h>
-#include <crepe/api/Button.h>
-#include <crepe/api/Camera.h>
-#include <crepe/api/Color.h>
-#include <crepe/api/EventManager.h>
-#include <crepe/api/GameObject.h>
-#include <crepe/api/Sprite.h>
-#include <crepe/api/Texture.h>
-#include <crepe/api/Transform.h>
-#include <crepe/system/AnimatorSystem.h>
-#include <crepe/system/InputSystem.h>
-#include <crepe/system/RenderSystem.h>
-#include <crepe/types.h>
-#include <iostream>
-using namespace crepe;
-using namespace std;
-
-int main(int argc, char * argv[]) {
- ComponentManager mgr;
- RenderSystem sys{mgr};
- EventManager & event_mgr = EventManager::get_instance();
- InputSystem input_sys{mgr};
- AnimatorSystem asys{mgr};
- GameObject camera_obj = mgr.new_object("", "", vec2{1000, 1000}, 0, 1);
- camera_obj.add_component<Camera>(Color::WHITE, ivec2{1080, 720}, vec2{2000, 2000}, 1.0f);
-
- GameObject button_obj = mgr.new_object("body", "person", vec2{0, 0}, 0, 1);
- auto s2 = Texture("asset/texture/test_ap43.png");
- bool button_clicked = false;
- auto & sprite2 = button_obj.add_component<Sprite>(
- s2, Color::GREEN, Sprite::FlipSettings{false, false}, 2, 1, 100);
- std::function<void()> on_click = [&]() { std::cout << "button clicked" << std::endl; };
- std::function<void()> on_enter = [&]() { std::cout << "enter" << std::endl; };
- std::function<void()> on_exit = [&]() { std::cout << "exit" << std::endl; };
- auto & button
- = button_obj.add_component<Button>(vec2{100, 100}, vec2{0, 0}, on_click, false);
- button.on_mouse_enter = on_enter;
- button.on_mouse_exit = on_exit;
- button.is_toggle = true;
- button.active = true;
- auto start = std::chrono::steady_clock::now();
- while (true) {
- input_sys.update();
- sys.update();
- asys.update();
- event_mgr.dispatch_events();
- SDL_Delay(30);
- }
- return 0;
-}
diff --git a/src/example/demo.cpp b/src/example/demo.cpp
new file mode 100644
index 0000000..a7d784e
--- /dev/null
+++ b/src/example/demo.cpp
@@ -0,0 +1,24 @@
+#include <crepe/util/Log.h>
+#include <crepe/api/Engine.h>
+#include <crepe/api/Scene.h>
+#include <crepe/api/Camera.h>
+
+using namespace crepe;
+using namespace std;
+
+class DemoScene : public Scene {
+ string get_name() const override { return "DemoScene"; }
+ void load_scene() override {
+ GameObject camera = new_object("camera");
+ camera.add_component<Camera>(vec2{10, 10}, Camera::Data{});
+ }
+};
+
+int main() {
+ Engine demo;
+
+ demo.add_scene<DemoScene>();
+
+ return demo.main();
+}
+
diff --git a/src/example/game.cpp b/src/example/game.cpp
deleted file mode 100644
index f8520f4..0000000
--- a/src/example/game.cpp
+++ /dev/null
@@ -1,293 +0,0 @@
-#include "api/CircleCollider.h"
-#include "api/ParticleEmitter.h"
-#include "api/Scene.h"
-#include "manager/ComponentManager.h"
-#include "manager/Mediator.h"
-#include "types.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/Script.h>
-#include <crepe/api/Sprite.h>
-#include <crepe/api/Transform.h>
-#include <crepe/api/Vector2.h>
-
-using namespace crepe;
-
-using namespace std;
-
-class MyScript1 : public Script {
- bool flip = false;
- bool oncollision(const CollisionEvent & test) {
- Log::logf("Box {} script on_collision()", test.info.this_collider.game_object_id);
- return true;
- }
- bool keypressed(const KeyPressEvent & test) {
- Log::logf("Box script keypressed()");
- switch (test.key) {
- case Keycode::A: {
- Rigidbody & tf = this->get_component<Rigidbody>();
- tf.data.linear_velocity.x -= 1;
- break;
- }
- case Keycode::W: {
- Rigidbody & tf = this->get_component<Rigidbody>();
- tf.data.linear_velocity.y -= 1;
- break;
- }
- case Keycode::S: {
- Rigidbody & tf = this->get_component<Rigidbody>();
- tf.data.linear_velocity.y += 1;
- break;
- }
- case Keycode::D: {
- Rigidbody & tf = this->get_component<Rigidbody>();
- tf.data.linear_velocity.x += 1;
- break;
- }
- case Keycode::E: {
- if (flip) {
- flip = false;
- this->get_component<BoxCollider>().active = true;
- this->get_components<Sprite>()[0].get().active = true;
- this->get_component<CircleCollider>().active = false;
- this->get_components<Sprite>()[1].get().active = false;
- } else {
- flip = true;
- this->get_component<BoxCollider>().active = false;
- this->get_components<Sprite>()[0].get().active = false;
- this->get_component<CircleCollider>().active = true;
- this->get_components<Sprite>()[1].get().active = true;
- }
-
- //add collider switch
- break;
- }
- case Keycode::Q: {
- Rigidbody & rg = this->get_component<Rigidbody>();
- rg.data.angular_velocity = 1;
- break;
- }
- default:
- break;
- }
- return false;
- }
-
- void init() {
- Log::logf("init");
- subscribe<CollisionEvent>(
- [this](const CollisionEvent & ev) -> bool { return this->oncollision(ev); });
- subscribe<KeyPressEvent>(
- [this](const KeyPressEvent & ev) -> bool { return this->keypressed(ev); });
- }
- void update() {
- Rigidbody & tf = this->get_component<Rigidbody>();
- Log::logf("linear_velocity.x {}", tf.data.linear_velocity.x);
- Log::logf("linear_velocity.y {}", tf.data.linear_velocity.y);
- // tf.data.linear_velocity = {0,0};
- }
-};
-
-class MyScript2 : public Script {
- bool flip = false;
- bool oncollision(const CollisionEvent & test) {
- Log::logf("Box {} script on_collision()", test.info.this_collider.game_object_id);
- return true;
- }
- bool keypressed(const KeyPressEvent & test) {
- Log::logf("Box script keypressed()");
- switch (test.key) {
- case Keycode::LEFT: {
- Transform & tf = this->get_component<Transform>();
- tf.position.x -= 1;
- break;
- }
- case Keycode::UP: {
- Transform & tf = this->get_component<Transform>();
- tf.position.y -= 1;
- break;
- }
- case Keycode::DOWN: {
- Transform & tf = this->get_component<Transform>();
- tf.position.y += 1;
- break;
- }
- case Keycode::RIGHT: {
- Transform & tf = this->get_component<Transform>();
- tf.position.x += 1;
- break;
- }
- case Keycode::PAUSE: {
- if (flip) {
- flip = false;
- this->get_component<BoxCollider>().active = true;
- this->get_components<Sprite>()[0].get().active = true;
- this->get_component<CircleCollider>().active = false;
- this->get_components<Sprite>()[1].get().active = false;
- } else {
- flip = true;
- this->get_component<BoxCollider>().active = false;
- this->get_components<Sprite>()[0].get().active = false;
- this->get_component<CircleCollider>().active = true;
- this->get_components<Sprite>()[1].get().active = true;
- }
-
- //add collider switch
- break;
- }
- default:
- break;
- }
- return false;
- }
-
- void init() {
- Log::logf("init");
- subscribe<CollisionEvent>(
- [this](const CollisionEvent & ev) -> bool { return this->oncollision(ev); });
- subscribe<KeyPressEvent>(
- [this](const KeyPressEvent & ev) -> bool { return this->keypressed(ev); });
- }
- void update() {
- // Retrieve component from the same GameObject this script is on
- }
-};
-
-class ConcreteScene1 : public Scene {
-public:
- using Scene::Scene;
-
- void load_scene() {
-
- Color color(0, 0, 0, 255);
-
- float screen_size_width = 320;
- float screen_size_height = 240;
- float world_collider = 1000;
- //define playable world
- GameObject world = new_object(
- "Name", "Tag", vec2{screen_size_width / 2, screen_size_height / 2}, 0, 1);
- world.add_component<Rigidbody>(Rigidbody::Data{
- .mass = 0,
- .gravity_scale = 0,
- .body_type = Rigidbody::BodyType::STATIC,
- .offset = {0, 0},
- .collision_layers = {0},
- });
- world.add_component<BoxCollider>(
- vec2{0, 0 - (screen_size_height / 2 + world_collider / 2)},
- vec2{world_collider, world_collider});
- ; // Top
- world.add_component<BoxCollider>(vec2{0, screen_size_height / 2 + world_collider / 2},
- vec2{world_collider, world_collider}); // Bottom
- world.add_component<BoxCollider>(
- vec2{0 - (screen_size_width / 2 + world_collider / 2), 0},
- vec2{world_collider, world_collider}); // Left
- world.add_component<BoxCollider>(vec2{screen_size_width / 2 + world_collider / 2, 0},
- vec2{world_collider, world_collider}); // right
- world.add_component<Camera>(
- ivec2{static_cast<int>(screen_size_width), static_cast<int>(screen_size_height)},
- vec2{screen_size_width, screen_size_height},
- Camera::Data{
- .bg_color = Color::WHITE,
- .zoom = 1,
- });
-
- GameObject game_object1 = new_object(
- "Name", "Tag", vec2{screen_size_width / 2, screen_size_height / 2}, 0, 1);
- game_object1.add_component<Rigidbody>(Rigidbody::Data{
- .mass = 1,
- .gravity_scale = 1,
- .body_type = Rigidbody::BodyType::DYNAMIC,
- .linear_velocity = {0, 1},
- .constraints = {0, 0, 0},
- .elastisity_coefficient = 1,
- .offset = {0, 0},
- .collision_layers = {0},
- });
- // add box with boxcollider
- game_object1.add_component<BoxCollider>(vec2{0, 0}, vec2{20, 20});
- game_object1.add_component<BehaviorScript>().set_script<MyScript1>();
-
- Asset img1{"asset/texture/square.png"};
- game_object1.add_component<Sprite>(img1, Sprite::Data{
- .size = {20, 20},
- });
-
- //add circle with cirlcecollider deactiveated
- game_object1.add_component<CircleCollider>(vec2{0, 0}, 10).active = false;
- Asset img2{"asset/texture/circle.png"};
- game_object1
- .add_component<Sprite>(img2,
- Sprite::Data{
- .size = {20, 20},
- })
- .active
- = false;
-
- GameObject game_object2 = new_object(
- "Name", "Tag", vec2{screen_size_width / 2, screen_size_height / 2}, 0, 1);
- game_object2.add_component<Rigidbody>(Rigidbody::Data{
- .mass = 1,
- .gravity_scale = 0,
- .body_type = Rigidbody::BodyType::STATIC,
- .linear_velocity = {0, 0},
- .constraints = {0, 0, 0},
- .elastisity_coefficient = 1,
- .offset = {0, 0},
- .collision_layers = {0},
- });
- // add box with boxcollider
- game_object2.add_component<BoxCollider>(vec2{0, 0}, vec2{20, 20});
- game_object2.add_component<BehaviorScript>().set_script<MyScript2>();
-
- game_object2.add_component<Sprite>(img1, Sprite::Data{
- .size = {20, 20},
- });
-
- //add circle with cirlcecollider deactiveated
- game_object2.add_component<CircleCollider>(vec2{0, 0}, 10).active = false;
-
- game_object2
- .add_component<Sprite>(img2,
- Sprite::Data{
- .size = {20, 20},
- })
- .active
- = false;
- Asset img5{"asset/texture/square.png"};
-
- GameObject particle = mgr.new_object(
- "Name", "Tag", vec2{screen_size_width / 2, screen_size_height / 2}, 0, 1);
- auto & particle_image = particle.add_component<Sprite>(img5, Sprite::Data{
- .size = {5, 5},
- });
- auto & test
- = particle.add_component<ParticleEmitter>(particle_image, ParticleEmitter::Data{
- .position = {0, 0},
- .max_particles = 256,
- .emission_rate = 50,
- .min_speed = 10,
- .max_speed = 20,
- .min_angle = -20,
- .max_angle = 20,
- .begin_lifespan = 0,
- .end_lifespan = 5,
- });
- }
-
- string get_name() const { return "scene1"; }
-};
-
-int main(int argc, char * argv[]) {
-
- LoopManager gameloop;
- gameloop.add_scene<ConcreteScene1>();
- gameloop.start();
- return 0;
-}
diff --git a/src/example/rendering_particle.cpp b/src/example/rendering_particle.cpp
deleted file mode 100644
index add43f4..0000000
--- a/src/example/rendering_particle.cpp
+++ /dev/null
@@ -1,73 +0,0 @@
-#include "api/Asset.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>
-#include <iostream>
-
-using namespace crepe;
-using namespace std;
-
-class TestScene : public Scene {
-public:
- void load_scene() {
-
- cout << "TestScene" << endl;
- Mediator & mediator = this->mediator;
- ComponentManager & mgr = mediator.component_manager;
- GameObject game_object = mgr.new_object("", "", vec2{0, 0}, 0, 1);
-
- Color color(255, 255, 255, 255);
-
- Asset img{"asset/spritesheet/spritesheet_test.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 = {0, 100},
- .angle_offset = 0,
- .position_offset = {0, 0},
- });
-
- //auto & anim = game_object.add_component<Animator>(test_sprite,ivec2{32, 64}, uvec2{4,1}, Animator::Data{});
- //anim.set_anim(0);
-
- auto & cam = game_object.add_component<Camera>(ivec2{720, 1280}, vec2{400, 400},
- Camera::Data{
- .bg_color = Color::WHITE,
- });
-
- function<void()> on_click = [&]() { cout << "button clicked" << std::endl; };
- function<void()> on_enter = [&]() { cout << "enter" << std::endl; };
- function<void()> on_exit = [&]() { cout << "exit" << std::endl; };
-
- auto & button
- = game_object.add_component<Button>(vec2{200, 200}, vec2{0, 0}, on_click, false);
- button.on_mouse_enter = on_enter;
- button.on_mouse_exit = on_exit;
- button.is_toggle = true;
- button.active = true;
- }
-
- 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
deleted file mode 100644
index 82fd478..0000000
--- a/src/example/replay.cpp
+++ /dev/null
@@ -1,84 +0,0 @@
-#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();
-}