diff options
Diffstat (limited to 'src/crepe/api')
-rw-r--r-- | src/crepe/api/AudioSource.cpp | 3 | ||||
-rw-r--r-- | src/crepe/api/AudioSource.h | 4 | ||||
-rw-r--r-- | src/crepe/api/BehaviorScript.cpp | 1 | ||||
-rw-r--r-- | src/crepe/api/BehaviorScript.h | 2 | ||||
-rw-r--r-- | src/crepe/api/CMakeLists.txt | 9 | ||||
-rw-r--r-- | src/crepe/api/CircleCollider.h | 12 | ||||
-rw-r--r-- | src/crepe/api/Force.cpp | 14 | ||||
-rw-r--r-- | src/crepe/api/Force.h | 17 | ||||
-rw-r--r-- | src/crepe/api/GameObject.cpp | 7 | ||||
-rw-r--r-- | src/crepe/api/GameObject.h | 24 | ||||
-rw-r--r-- | src/crepe/api/GameObject.hpp | 15 | ||||
-rw-r--r-- | src/crepe/api/Rigidbody.cpp | 7 | ||||
-rw-r--r-- | src/crepe/api/Rigidbody.h | 24 | ||||
-rw-r--r-- | src/crepe/api/Sprite.cpp | 8 | ||||
-rw-r--r-- | src/crepe/api/Sprite.h | 16 |
15 files changed, 158 insertions, 5 deletions
diff --git a/src/crepe/api/AudioSource.cpp b/src/crepe/api/AudioSource.cpp index b512d27..bb067dc 100644 --- a/src/crepe/api/AudioSource.cpp +++ b/src/crepe/api/AudioSource.cpp @@ -1,7 +1,8 @@ +#include <memory> + #include "AudioSource.h" #include "../Sound.h" -#include <memory> using namespace crepe::api; diff --git a/src/crepe/api/AudioSource.h b/src/crepe/api/AudioSource.h index 2d26cda..7980212 100644 --- a/src/crepe/api/AudioSource.h +++ b/src/crepe/api/AudioSource.h @@ -2,8 +2,8 @@ #include <memory> -#include "Asset.h" -#include "Component.h" +#include "../Asset.h" +#include "../Component.h" namespace crepe { class Sound; diff --git a/src/crepe/api/BehaviorScript.cpp b/src/crepe/api/BehaviorScript.cpp index 063d225..74788ec 100644 --- a/src/crepe/api/BehaviorScript.cpp +++ b/src/crepe/api/BehaviorScript.cpp @@ -1,7 +1,6 @@ #include "../util/log.h" #include "BehaviorScript.h" -#include "Script.h" using namespace crepe::api; diff --git a/src/crepe/api/BehaviorScript.h b/src/crepe/api/BehaviorScript.h index 6ce6798..25d3cc5 100644 --- a/src/crepe/api/BehaviorScript.h +++ b/src/crepe/api/BehaviorScript.h @@ -2,7 +2,7 @@ #include <memory> -#include "Component.h" +#include "../Component.h" #include "Script.h" namespace crepe { diff --git a/src/crepe/api/CMakeLists.txt b/src/crepe/api/CMakeLists.txt index 6b337be..c97423d 100644 --- a/src/crepe/api/CMakeLists.txt +++ b/src/crepe/api/CMakeLists.txt @@ -2,11 +2,20 @@ target_sources(crepe PUBLIC # AudioSource.cpp BehaviorScript.cpp Script.cpp + GameObject.cpp + Rigidbody.cpp + Sprite.cpp + Force.cpp ) target_sources(crepe PUBLIC FILE_SET HEADERS FILES # AudioSource.h BehaviorScript.h Script.h + GameObject.h + GameObject.hpp + 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/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/GameObject.cpp b/src/crepe/api/GameObject.cpp new file mode 100644 index 0000000..b167187 --- /dev/null +++ b/src/crepe/api/GameObject.cpp @@ -0,0 +1,7 @@ +#include "GameObject.h" + +using namespace crepe::api; +using namespace std; + +GameObject::GameObject(uint32_t id, string name, string tag, int layer) + : id(id), name(name), tag(tag), active(true), layer(layer) {} diff --git a/src/crepe/api/GameObject.h b/src/crepe/api/GameObject.h new file mode 100644 index 0000000..57508c5 --- /dev/null +++ b/src/crepe/api/GameObject.h @@ -0,0 +1,24 @@ +#pragma once + +#include <cstdint> +#include <string> + +namespace crepe::api { + +class GameObject { +public: + GameObject(uint32_t id, std::string name, std::string tag, int layer); + + template <typename T, typename... Args> + T & add_component(Args &&... args); + + uint32_t id; + std::string name; + std::string tag; + bool active; + int layer; +}; + +} // namespace crepe::api + +#include "GameObject.hpp" diff --git a/src/crepe/api/GameObject.hpp b/src/crepe/api/GameObject.hpp new file mode 100644 index 0000000..8295ea3 --- /dev/null +++ b/src/crepe/api/GameObject.hpp @@ -0,0 +1,15 @@ +#pragma once + +#include "../ComponentManager.h" + +#include "GameObject.h" + +namespace crepe::api { + +template <typename T, typename... Args> +T & GameObject::add_component(Args &&... args) { + auto & mgr = ComponentManager::get_instance(); + return mgr.add_component<T>(id, std::forward<Args>(args)...); +} + +} // namespace crepe::api diff --git a/src/crepe/api/Rigidbody.cpp b/src/crepe/api/Rigidbody.cpp new file mode 100644 index 0000000..30a2cff --- /dev/null +++ b/src/crepe/api/Rigidbody.cpp @@ -0,0 +1,7 @@ +#include "Rigidbody.h" + +using namespace crepe::api; + +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 new file mode 100644 index 0000000..b7a0064 --- /dev/null +++ b/src/crepe/api/Rigidbody.h @@ -0,0 +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(uint32_t gameObjectId,int mass, int gravityScale, BodyType bodyType); + int32_t velocity_x; + int32_t velocity_y; + int mass; + int gravity_scale; + BodyType body_type; +}; + +} // namespace crepe::api diff --git a/src/crepe/api/Sprite.cpp b/src/crepe/api/Sprite.cpp new file mode 100644 index 0000000..4eda466 --- /dev/null +++ b/src/crepe/api/Sprite.cpp @@ -0,0 +1,8 @@ +#include <string> + +#include "Sprite.h" + +using namespace crepe::api; +using namespace std; + +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 new file mode 100644 index 0000000..c06e76c --- /dev/null +++ b/src/crepe/api/Sprite.h @@ -0,0 +1,16 @@ +#pragma once + +#include <string> + +#include "../Component.h" + +namespace crepe::api { + +class Sprite : public Component { +public: + Sprite(uint32_t gameObjectId,std::string path); + + std::string path; +}; + +} // namespace crepe::api |