aboutsummaryrefslogtreecommitdiff
path: root/src/example
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-12-11 18:37:23 +0100
committerLoek Le Blansch <loek@pipeframe.xyz>2024-12-11 18:37:23 +0100
commitca6c4f30df6612f60db0fdfe4c2d366d7e4da8ea (patch)
tree199878898c2ddcdd2f7f6a1b76c165c2c7db5c8d /src/example
parentf0ecbea57a4d75905c4ee79608807187cd8f3e72 (diff)
parent30c17c98e54c1534664de08ca3838c40c859d166 (diff)
merge master
Diffstat (limited to 'src/example')
-rw-r--r--src/example/AITest.cpp86
-rw-r--r--src/example/CMakeLists.txt1
-rw-r--r--src/example/rendering_particle.cpp18
-rw-r--r--src/example/replay.cpp19
4 files changed, 105 insertions, 19 deletions
diff --git a/src/example/AITest.cpp b/src/example/AITest.cpp
new file mode 100644
index 0000000..f4efc9f
--- /dev/null
+++ b/src/example/AITest.cpp
@@ -0,0 +1,86 @@
+#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/api/Texture.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);
+
+ Texture img = Texture("asset/texture/test_ap43.png");
+ game_object1.add_component<Sprite>(img, Sprite::Data{
+ .color = Color::MAGENTA,
+ .flip = Sprite::FlipSettings{false, false},
+ .sorting_in_layer = 1,
+ .order_in_layer = 1,
+ .size = {0, 195},
+ });
+ 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, 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 791001e..1bc31d8 100644
--- a/src/example/CMakeLists.txt
+++ b/src/example/CMakeLists.txt
@@ -20,3 +20,4 @@ add_example(rendering_particle)
add_example(game)
add_example(button)
add_example(replay)
+add_example(AITest)
diff --git a/src/example/rendering_particle.cpp b/src/example/rendering_particle.cpp
index 29d475d..bd4ef95 100644
--- a/src/example/rendering_particle.cpp
+++ b/src/example/rendering_particle.cpp
@@ -1,3 +1,4 @@
+#include "api/Asset.h"
#include <crepe/Component.h>
#include <crepe/api/Animator.h>
#include <crepe/api/Camera.h>
@@ -7,11 +8,11 @@
#include <crepe/api/ParticleEmitter.h>
#include <crepe/api/Rigidbody.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>
#include <crepe/types.h>
+#include <iostream>
using namespace crepe;
using namespace std;
@@ -41,13 +42,15 @@ 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);
- auto img = Texture("asset/spritesheet/pokemon_spritesheet.png");
+ Asset img{"asset/spritesheet/spritesheet_test.png"};
Sprite & test_sprite = game_object.add_component<Sprite>(
img, Sprite::Data{
@@ -57,16 +60,11 @@ public:
.order_in_layer = 2,
.size = {0, 100},
.angle_offset = 0,
- .position_offset = {100, 0},
+ .position_offset = {0, 0},
});
- auto & anim = game_object.add_component<Animator>(test_sprite, 4, 4,
- Animator::Data{
- .fps = 1,
- .looping = false,
- });
- anim.set_anim(2);
- anim.active = false;
+ //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{1280, 720}, vec2{400, 400},
Camera::Data{
diff --git a/src/example/replay.cpp b/src/example/replay.cpp
index a3c7fba..0c4f9b3 100644
--- a/src/example/replay.cpp
+++ b/src/example/replay.cpp
@@ -9,7 +9,6 @@
#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>
@@ -41,19 +40,19 @@ class Timeline : public Script {
switch (i++) {
default: break;
case 10:
- mgr.record_start();
+ // mgr.record_start();
Log::logf("start");
break;
case 60:
- this->recording = mgr.record_end();
+ // this->recording = mgr.record_end();
Log::logf("stop");
break;
case 70:
- mgr.play(this->recording);
+ // mgr.play(this->recording);
Log::logf("play");
break;
case 71:
- mgr.release(this->recording);
+ // mgr.release(this->recording);
Log::logf("end");
break;
case 72:
@@ -78,10 +77,12 @@ public:
});
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<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("");