diff options
Diffstat (limited to 'src/crepe/api')
-rw-r--r-- | src/crepe/api/AudioSource.cpp | 4 | ||||
-rw-r--r-- | src/crepe/api/AudioSource.h | 4 | ||||
-rw-r--r-- | src/crepe/api/BehaviorScript.cpp | 3 | ||||
-rw-r--r-- | src/crepe/api/BehaviorScript.h | 2 | ||||
-rw-r--r-- | src/crepe/api/CMakeLists.txt | 19 | ||||
-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/ParticleEmitter.cpp | 28 | ||||
-rw-r--r-- | src/crepe/api/ParticleEmitter.h | 32 | ||||
-rw-r--r-- | src/crepe/api/Rigidbody.cpp | 7 | ||||
-rw-r--r-- | src/crepe/api/Rigidbody.h | 24 |
15 files changed, 201 insertions, 11 deletions
diff --git a/src/crepe/api/AudioSource.cpp b/src/crepe/api/AudioSource.cpp index 90c1b07..10b3b49 100644 --- a/src/crepe/api/AudioSource.cpp +++ b/src/crepe/api/AudioSource.cpp @@ -1,6 +1,8 @@ +#include <memory> + #include "AudioSource.h" -#include "Sound.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 1f236b4..74788ec 100644 --- a/src/crepe/api/BehaviorScript.cpp +++ b/src/crepe/api/BehaviorScript.cpp @@ -1,8 +1,7 @@ #include "../util/log.h" #include "BehaviorScript.h" -#include "Script.h" using namespace crepe::api; -BehaviorScript::BehaviorScript() { dbg_trace(); } +BehaviorScript::BehaviorScript() : Component(gameObjectId) { dbg_trace(); } 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 d29a771..f6de96e 100644 --- a/src/crepe/api/CMakeLists.txt +++ b/src/crepe/api/CMakeLists.txt @@ -2,10 +2,14 @@ target_sources(crepe PUBLIC # AudioSource.cpp BehaviorScript.cpp Script.cpp - Color.cpp - Texture.cpp + GameObject.cpp + Rigidbody.cpp Sprite.cpp + Force.cpp + ParticleEmitter.cpp Transform.cpp + Color.cpp + Texture.cpp AssetManager.cpp ) @@ -13,10 +17,15 @@ target_sources(crepe PUBLIC FILE_SET HEADERS FILES # AudioSource.h BehaviorScript.h Script.h - Point.h - Transform.h - Color.h + GameObject.h + GameObject.hpp + Rigidbody.h Sprite.h + Force.h + ParticleEmitter.h + Transform.h + Point.h + Color.h Texture.h AssetManager.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/ParticleEmitter.cpp b/src/crepe/api/ParticleEmitter.cpp new file mode 100644 index 0000000..318c6db --- /dev/null +++ b/src/crepe/api/ParticleEmitter.cpp @@ -0,0 +1,28 @@ +#include "ParticleEmitter.h" +#include <ctime> +#include "Particle.h" +#include <iostream> + +using namespace crepe; + +ParticleEmitter::ParticleEmitter(uint32_t gameObjectId ,uint32_t maxParticles, uint32_t emissionRate, uint32_t speed, uint32_t speedOffset, uint32_t angle, uint32_t angleOffset, float m_beginLifespan, float m_endLifespan) + : Component(gameObjectId), m_maxParticles(maxParticles), m_emissionRate(emissionRate), m_speed(speed), m_speedOffset(speedOffset), m_position{0, 0}, m_beginLifespan(m_beginLifespan),m_endLifespan(m_endLifespan) { + std::srand(static_cast<uint32_t>(std::time(nullptr))); // initialize random seed + std::cout << "Create emitter" << std::endl; + m_minAngle = (360 + angle - (angleOffset % 360)) % 360; // calculate minAngle + m_maxAngle = (360 + angle + (angleOffset % 360)) % 360; // calculate maxAngle + m_position.x = 400; + m_position.y = 400; + for (size_t i = 0; i < m_maxParticles; i++) + { + this->particles.emplace_back(); + } + +} + +ParticleEmitter::~ParticleEmitter() { + std::vector<Particle>::iterator it = this->particles.begin(); + while (it != this->particles.end()) { + it = this->particles.erase(it); + } +} diff --git a/src/crepe/api/ParticleEmitter.h b/src/crepe/api/ParticleEmitter.h new file mode 100644 index 0000000..8cd78a9 --- /dev/null +++ b/src/crepe/api/ParticleEmitter.h @@ -0,0 +1,32 @@ +#pragma once + +#include <vector> +#include "Particle.h" +#include <cstdint> +#include "Component.h" +# + +namespace crepe { + +class ParticleEmitter : public Component { +public: + ParticleEmitter(uint32_t gameObjectId, uint32_t maxParticles, uint32_t emissionRate, uint32_t speed, uint32_t speedOffset, uint32_t angle, uint32_t angleOffset,float m_beginLifespan,float m_endLifespan); + ~ParticleEmitter(); + + Position m_position; //position of the emitter + uint32_t m_maxParticles; //maximum number of particles + uint32_t m_emissionRate; //rate of particle emission + uint32_t m_speed; //base speed of the particles + uint32_t m_speedOffset; //offset for random speed variation + uint32_t m_minAngle; //min angle of particle emission + uint32_t m_maxAngle; //max angle of particle emission + float m_beginLifespan; //begin Lifespan of particle (only visual) + float m_endLifespan; //begin Lifespan of particle + + std::vector<Particle> particles; //collection of particles + +}; + +} + + 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 |