aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/api
diff options
context:
space:
mode:
Diffstat (limited to 'src/crepe/api')
-rw-r--r--src/crepe/api/BehaviorScript.hpp1
-rw-r--r--src/crepe/api/BoxCollider.cpp7
-rw-r--r--src/crepe/api/BoxCollider.h24
-rw-r--r--src/crepe/api/CMakeLists.txt4
-rw-r--r--src/crepe/api/CircleCollider.cpp6
-rw-r--r--src/crepe/api/CircleCollider.h17
-rw-r--r--src/crepe/api/Event.h9
-rw-r--r--src/crepe/api/LoopManager.cpp11
-rw-r--r--src/crepe/api/Rigidbody.h10
9 files changed, 78 insertions, 11 deletions
diff --git a/src/crepe/api/BehaviorScript.hpp b/src/crepe/api/BehaviorScript.hpp
index bd59337..484c318 100644
--- a/src/crepe/api/BehaviorScript.hpp
+++ b/src/crepe/api/BehaviorScript.hpp
@@ -14,7 +14,6 @@ BehaviorScript & BehaviorScript::set_script(Args &&... args) {
dbg_trace();
static_assert(std::is_base_of<Script, T>::value);
Script * s = new T(std::forward<Args>(args)...);
-
s->game_object_id = this->game_object_id;
s->active = this->active;
s->component_manager = this->component_manager;
diff --git a/src/crepe/api/BoxCollider.cpp b/src/crepe/api/BoxCollider.cpp
new file mode 100644
index 0000000..eafbdb2
--- /dev/null
+++ b/src/crepe/api/BoxCollider.cpp
@@ -0,0 +1,7 @@
+#include "BoxCollider.h"
+#include "../Collider.h"
+
+using namespace crepe;
+
+
+BoxCollider::BoxCollider(game_object_id_t game_object_id,Vector2 offset, double width, double height) : Collider(game_object_id,offset), width(width), height(height) {}
diff --git a/src/crepe/api/BoxCollider.h b/src/crepe/api/BoxCollider.h
new file mode 100644
index 0000000..7f51cba
--- /dev/null
+++ b/src/crepe/api/BoxCollider.h
@@ -0,0 +1,24 @@
+#pragma once
+
+#include "Vector2.h"
+#include "../Collider.h"
+
+namespace crepe {
+
+/**
+ * \brief A class representing a box-shaped collider.
+ *
+ * This class is used for collision detection with other colliders (e.g., CircleCollider).
+ */
+class BoxCollider : public Collider {
+public:
+ BoxCollider(game_object_id_t game_object_id,Vector2 offset, double width, double height);
+
+ //! Width of box collider
+ double width;
+
+ //! Height of box collider
+ double height;
+};
+
+} // namespace crepe
diff --git a/src/crepe/api/CMakeLists.txt b/src/crepe/api/CMakeLists.txt
index c3e0b37..057f88c 100644
--- a/src/crepe/api/CMakeLists.txt
+++ b/src/crepe/api/CMakeLists.txt
@@ -16,6 +16,8 @@ target_sources(crepe PUBLIC
SceneManager.cpp
Camera.cpp
Animator.cpp
+ BoxCollider.cpp
+ CircleCollider.cpp
EventManager.cpp
IKeyListener.cpp
IMouseListener.cpp
@@ -49,6 +51,8 @@ target_sources(crepe PUBLIC FILE_SET HEADERS FILES
SceneManager.hpp
Camera.h
Animator.h
+ BoxCollider.h
+ CircleCollider.h
EventManager.h
EventManager.hpp
EventHandler.h
diff --git a/src/crepe/api/CircleCollider.cpp b/src/crepe/api/CircleCollider.cpp
new file mode 100644
index 0000000..04a4995
--- /dev/null
+++ b/src/crepe/api/CircleCollider.cpp
@@ -0,0 +1,6 @@
+#include "CircleCollider.h"
+
+using namespace crepe;
+
+
+CircleCollider::CircleCollider(game_object_id_t game_object_id,Vector2 offset, int radius) : Collider(game_object_id,offset), radius(radius) {}
diff --git a/src/crepe/api/CircleCollider.h b/src/crepe/api/CircleCollider.h
index e77a592..4e04fa4 100644
--- a/src/crepe/api/CircleCollider.h
+++ b/src/crepe/api/CircleCollider.h
@@ -1,14 +1,23 @@
#pragma once
+
+#include "Vector2.h"
+
#include "../Collider.h"
namespace crepe {
+/**
+ * \brief A class representing a circle-shaped collider.
+ *
+ * This class is used for collision detection with other colliders (e.g., BoxCollider).
+ */
class CircleCollider : public Collider {
public:
- CircleCollider(game_object_id_t game_object_id, int radius)
- : Collider(game_object_id),
- radius(radius) {}
- int radius;
+
+ CircleCollider(game_object_id_t game_object_id,Vector2 offset, int radius);
+
+ //! Radius of the circle collider.
+ double radius;
};
} // namespace crepe
diff --git a/src/crepe/api/Event.h b/src/crepe/api/Event.h
index b267e3e..259acba 100644
--- a/src/crepe/api/Event.h
+++ b/src/crepe/api/Event.h
@@ -3,6 +3,8 @@
#include <string>
+#include "system/CollisionSystem.h"
+
#include "KeyCodes.h"
namespace crepe {
@@ -93,7 +95,12 @@ public:
/**
* \brief Event triggered during a collision between objects.
*/
-class CollisionEvent : public Event {};
+class CollisionEvent : public Event {
+public:
+ crepe::CollisionSystem::CollisionInfo info;
+ CollisionEvent(const crepe::CollisionSystem::CollisionInfo& collisionInfo)
+ : info(collisionInfo) {}
+};
/**
* \brief Event triggered when text is submitted, e.g., from a text input.
diff --git a/src/crepe/api/LoopManager.cpp b/src/crepe/api/LoopManager.cpp
index a64366f..586919d 100644
--- a/src/crepe/api/LoopManager.cpp
+++ b/src/crepe/api/LoopManager.cpp
@@ -6,6 +6,8 @@
#include "../system/PhysicsSystem.h"
#include "../system/RenderSystem.h"
#include "../system/ScriptSystem.h"
+#include "..//system/PhysicsSystem.h"
+#include "..//system/CollisionSystem.h"
#include "LoopManager.h"
#include "LoopTimer.h"
@@ -32,7 +34,10 @@ void LoopManager::start() {
}
void LoopManager::set_running(bool running) { this->game_running = running; }
-void LoopManager::fixed_update() {}
+void LoopManager::fixed_update() {
+ this->get_system<PhysicsSystem>().update();
+ this->get_system<CollisionSystem>().update();
+}
void LoopManager::loop() {
LoopTimer & timer = LoopTimer::get_instance();
@@ -41,11 +46,11 @@ void LoopManager::loop() {
while (game_running) {
timer.update();
- while (timer.get_lag() >= timer.get_fixed_delta_time()) {
+ //while (timer.get_lag() >= timer.get_fixed_delta_time()) {
this->process_input();
this->fixed_update();
timer.advance_fixed_update();
- }
+ //}
this->update();
this->render();
diff --git a/src/crepe/api/Rigidbody.h b/src/crepe/api/Rigidbody.h
index 3b0588f..b96b463 100644
--- a/src/crepe/api/Rigidbody.h
+++ b/src/crepe/api/Rigidbody.h
@@ -1,5 +1,7 @@
#pragma once
+#include <cmath>
+
#include "../Component.h"
#include "types.h"
@@ -58,13 +60,13 @@ public:
//! linear velocity of object
vec2 linear_velocity;
//! maximum linear velocity of object
- vec2 max_linear_velocity;
+ vec2 max_linear_velocity = {INFINITY ,INFINITY};
//! linear damping of object
vec2 linear_damping;
//! angular velocity of object
double angular_velocity = 0.0;
//! max angular velocity of object
- double max_angular_velocity = 0.0;
+ double max_angular_velocity = INFINITY;
//! angular damping of object
double angular_damping = 0.0;
//! movements constraints of object
@@ -73,6 +75,10 @@ public:
bool use_gravity = true;
//! if object bounces
bool bounce = false;
+ //! bounce factor of material
+ double elastisity = 0.0;
+ //! offset of all colliders relative to transform position
+ Vector2 offset;
};
public: