diff options
Diffstat (limited to 'src/crepe/api')
-rw-r--r-- | src/crepe/api/BehaviorScript.cpp | 2 | ||||
-rw-r--r-- | src/crepe/api/CMakeLists.txt | 4 | ||||
-rw-r--r-- | src/crepe/api/CircleCollider.h | 12 | ||||
-rw-r--r-- | src/crepe/api/Collider.cpp | 5 | ||||
-rw-r--r-- | src/crepe/api/Collider.h | 14 | ||||
-rw-r--r-- | src/crepe/api/Force.cpp | 14 | ||||
-rw-r--r-- | src/crepe/api/Force.h | 17 | ||||
-rw-r--r-- | src/crepe/api/Rigidbody.cpp | 5 | ||||
-rw-r--r-- | src/crepe/api/Rigidbody.h | 14 | ||||
-rw-r--r-- | src/crepe/api/Sprite.cpp | 2 | ||||
-rw-r--r-- | src/crepe/api/Sprite.h | 2 |
11 files changed, 62 insertions, 29 deletions
diff --git a/src/crepe/api/BehaviorScript.cpp b/src/crepe/api/BehaviorScript.cpp index 84bfd4c..74788ec 100644 --- a/src/crepe/api/BehaviorScript.cpp +++ b/src/crepe/api/BehaviorScript.cpp @@ -4,4 +4,4 @@ using namespace crepe::api; -BehaviorScript::BehaviorScript() { dbg_trace(); } +BehaviorScript::BehaviorScript() : Component(gameObjectId) { dbg_trace(); } diff --git a/src/crepe/api/CMakeLists.txt b/src/crepe/api/CMakeLists.txt index ae92f3d..c97423d 100644 --- a/src/crepe/api/CMakeLists.txt +++ b/src/crepe/api/CMakeLists.txt @@ -3,9 +3,9 @@ target_sources(crepe PUBLIC BehaviorScript.cpp Script.cpp GameObject.cpp - Collider.cpp Rigidbody.cpp Sprite.cpp + Force.cpp ) target_sources(crepe PUBLIC FILE_SET HEADERS FILES @@ -14,8 +14,8 @@ target_sources(crepe PUBLIC FILE_SET HEADERS FILES Script.h GameObject.h GameObject.hpp - Collider.h Rigidbody.h Sprite.h + Force.h ) diff --git a/src/crepe/api/CircleCollider.h b/src/crepe/api/CircleCollider.h new file mode 100644 index 0000000..4a4883c --- /dev/null +++ b/src/crepe/api/CircleCollider.h @@ -0,0 +1,12 @@ +#pragma once +#include "../Collider.h" + +namespace crepe::api { + +class CircleCollider : public Collider { +public: + CircleCollider(uint32_t gameObjectId,int radius) : Collider(gameObjectId), radius(radius) {} + int radius; +}; + +} // namespace crepe diff --git a/src/crepe/api/Collider.cpp b/src/crepe/api/Collider.cpp deleted file mode 100644 index 6370a42..0000000 --- a/src/crepe/api/Collider.cpp +++ /dev/null @@ -1,5 +0,0 @@ -#include "Collider.h" - -using namespace crepe::api; - -Collider::Collider(int size) : size(size) {} diff --git a/src/crepe/api/Collider.h b/src/crepe/api/Collider.h deleted file mode 100644 index 72d8e77..0000000 --- a/src/crepe/api/Collider.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include "../Component.h" - -namespace crepe::api { - -class Collider : public Component { -public: - Collider(int size); - - int size; -}; - -} // namespace crepe::api diff --git a/src/crepe/api/Force.cpp b/src/crepe/api/Force.cpp new file mode 100644 index 0000000..1b4c81a --- /dev/null +++ b/src/crepe/api/Force.cpp @@ -0,0 +1,14 @@ +#include "Force.h" +#include <cmath> + +namespace crepe::api { + +Force::Force(uint32_t gameObjectId, uint32_t forceMagnitude, uint32_t direction): Component(gameObjectId) +{ + // Convert direction from degrees to radians + float radian_direction = static_cast<float>(direction) * (M_PI / 180.0f); + force_x = static_cast<int32_t>(std::round(forceMagnitude * std::cos(radian_direction))); + force_y = static_cast<int32_t>(std::round(forceMagnitude * std::sin(radian_direction))); +} + +} // namespace crepe::api diff --git a/src/crepe/api/Force.h b/src/crepe/api/Force.h new file mode 100644 index 0000000..0b06da1 --- /dev/null +++ b/src/crepe/api/Force.h @@ -0,0 +1,17 @@ +#pragma once + +#include "../Component.h" +#include <cstdint> +#include <utility> + +namespace crepe::api { + +class Force : public Component { +public: + Force(uint32_t gameObjectId, uint32_t forceMagnitude, uint32_t direction); + + int32_t force_x; + int32_t force_y; +}; + +} // namespace crepe diff --git a/src/crepe/api/Rigidbody.cpp b/src/crepe/api/Rigidbody.cpp index 98d1d60..30a2cff 100644 --- a/src/crepe/api/Rigidbody.cpp +++ b/src/crepe/api/Rigidbody.cpp @@ -2,5 +2,6 @@ using namespace crepe::api; -Rigidbody::Rigidbody(int mass, int gravityScale, int bodyType) - : mass(mass), gravity_scale(gravityScale), body_type(bodyType) {} +Rigidbody::Rigidbody(uint32_t gameObjectId,int mass, int gravityScale, BodyType bodyType) + : Component(gameObjectId), mass(mass), gravity_scale(gravityScale), body_type(bodyType) {} + diff --git a/src/crepe/api/Rigidbody.h b/src/crepe/api/Rigidbody.h index 6cae579..b7a0064 100644 --- a/src/crepe/api/Rigidbody.h +++ b/src/crepe/api/Rigidbody.h @@ -1,16 +1,24 @@ #pragma once #include "../Component.h" +#include <cstdint> namespace crepe::api { +enum class BodyType { + Static, // Does not move (e.g. walls, ground ...) + Dynamic, // Moves and responds to forces (e.g. player, physics objects ...) + Kinematic // Moves but does not respond to forces (e.g. moving platforms ...) +}; + class Rigidbody : public Component { public: - Rigidbody(int mass, int gravityScale, int bodyType); - + Rigidbody(uint32_t gameObjectId,int mass, int gravityScale, BodyType bodyType); + int32_t velocity_x; + int32_t velocity_y; int mass; int gravity_scale; - int body_type; + BodyType body_type; }; } // namespace crepe::api diff --git a/src/crepe/api/Sprite.cpp b/src/crepe/api/Sprite.cpp index aa7dbb0..4eda466 100644 --- a/src/crepe/api/Sprite.cpp +++ b/src/crepe/api/Sprite.cpp @@ -5,4 +5,4 @@ using namespace crepe::api; using namespace std; -Sprite::Sprite(string path) : path(path) {} +Sprite::Sprite(uint32_t gameObjectId, string path) : Component(gameObjectId), path(path) {} diff --git a/src/crepe/api/Sprite.h b/src/crepe/api/Sprite.h index 580f825..c06e76c 100644 --- a/src/crepe/api/Sprite.h +++ b/src/crepe/api/Sprite.h @@ -8,7 +8,7 @@ namespace crepe::api { class Sprite : public Component { public: - Sprite(std::string path); + Sprite(uint32_t gameObjectId,std::string path); std::string path; }; |