aboutsummaryrefslogtreecommitdiff
path: root/src/example
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-12-12 19:23:25 +0100
committerLoek Le Blansch <loek@pipeframe.xyz>2024-12-12 19:23:25 +0100
commitcd5f6b542f9cb447e3a9f500713c556a3d034bf3 (patch)
tree1d3372f30305e9f7a567b220a9b51464ba8ba272 /src/example
parented90fde01c38b878645bb68d3aa7353349f3b300 (diff)
parentfd403d038b017ec8976023471073329896035e36 (diff)
merge master
Diffstat (limited to 'src/example')
-rw-r--r--src/example/AITest.cpp24
-rw-r--r--src/example/game.cpp45
-rw-r--r--src/example/rendering_particle.cpp14
3 files changed, 58 insertions, 25 deletions
diff --git a/src/example/AITest.cpp b/src/example/AITest.cpp
index f4efc9f..93ba500 100644
--- a/src/example/AITest.cpp
+++ b/src/example/AITest.cpp
@@ -8,7 +8,6 @@
#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>
@@ -47,14 +46,19 @@ public:
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},
- });
+ 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();
@@ -63,7 +67,7 @@ public:
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},
+ .max_linear_velocity = 40,
});
game_object1.add_component<BehaviorScript>().set_script<Script1>();
diff --git a/src/example/game.cpp b/src/example/game.cpp
index 4239c15..5361f3a 100644
--- a/src/example/game.cpp
+++ b/src/example/game.cpp
@@ -2,6 +2,7 @@
#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>
@@ -11,7 +12,6 @@
#include <crepe/api/Rigidbody.h>
#include <crepe/api/Script.h>
#include <crepe/api/Sprite.h>
-#include <crepe/api/Texture.h>
#include <crepe/api/Transform.h>
#include <crepe/api/Vector2.h>
@@ -66,6 +66,11 @@ class MyScript1 : public Script {
//add collider switch
break;
}
+ case Keycode::Q: {
+ Rigidbody & rg = this->get_component<Rigidbody>();
+ rg.data.angular_velocity = 1;
+ break;
+ }
default:
break;
}
@@ -184,15 +189,18 @@ public:
world.add_component<BoxCollider>(vec2{screen_size_width / 2 + world_collider / 2, 0},
vec2{world_collider, world_collider}); // right
world.add_component<Camera>(
- Color::WHITE,
ivec2{static_cast<int>(screen_size_width), static_cast<int>(screen_size_height)},
- vec2{screen_size_width, screen_size_height}, 1.0f);
+ vec2{screen_size_width, screen_size_height},
+ Camera::Data{
+ .bg_color = Color::WHITE,
+ .zoom = 1,
+ });
GameObject game_object1 = mgr.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 = 0,
+ .gravity_scale = 1,
.body_type = Rigidbody::BodyType::DYNAMIC,
.linear_velocity = {0, 0},
.constraints = {0, 0, 0},
@@ -203,15 +211,20 @@ public:
// add box with boxcollider
game_object1.add_component<BoxCollider>(vec2{0, 0}, vec2{20, 20});
game_object1.add_component<BehaviorScript>().set_script<MyScript1>();
- auto img1 = Texture("asset/texture/square.png");
- game_object1.add_component<Sprite>(img1, color, Sprite::FlipSettings{false, false}, 1,
- 1, 20);
+
+ 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;
- auto img2 = Texture("asset/texture/circle.png");
+ Asset img2{"asset/texture/circle.png"};
game_object1
- .add_component<Sprite>(img2, color, Sprite::FlipSettings{false, false}, 1, 1, 20)
+ .add_component<Sprite>(img2,
+ Sprite::Data{
+ .size = {20, 20},
+ })
.active
= false;
@@ -230,15 +243,19 @@ public:
// add box with boxcollider
game_object2.add_component<BoxCollider>(vec2{0, 0}, vec2{20, 20});
game_object2.add_component<BehaviorScript>().set_script<MyScript2>();
- auto img3 = Texture("asset/texture/square.png");
- game_object2.add_component<Sprite>(img3, color, Sprite::FlipSettings{false, false}, 1,
- 1, 20);
+
+ 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;
- auto img4 = Texture("asset/texture/circle.png");
+
game_object2
- .add_component<Sprite>(img4, color, Sprite::FlipSettings{false, false}, 1, 1, 20)
+ .add_component<Sprite>(img2,
+ Sprite::Data{
+ .size = {20, 20},
+ })
.active
= false;
}
diff --git a/src/example/rendering_particle.cpp b/src/example/rendering_particle.cpp
index bd4ef95..13e625f 100644
--- a/src/example/rendering_particle.cpp
+++ b/src/example/rendering_particle.cpp
@@ -1,6 +1,7 @@
#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>
@@ -66,10 +67,21 @@ public:
//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},
+ 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"; };