aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/api
diff options
context:
space:
mode:
Diffstat (limited to 'src/crepe/api')
-rw-r--r--src/crepe/api/AudioSource.cpp2
-rw-r--r--src/crepe/api/CMakeLists.txt14
-rw-r--r--src/crepe/api/CircleCollider.h12
-rw-r--r--src/crepe/api/Collider.cpp5
-rw-r--r--src/crepe/api/Collider.h14
-rw-r--r--src/crepe/api/Force.cpp14
-rw-r--r--src/crepe/api/Force.h17
-rw-r--r--src/crepe/api/ParticleEmitter.cpp28
-rw-r--r--src/crepe/api/ParticleEmitter.h32
-rw-r--r--src/crepe/api/Rigidbody.h2
10 files changed, 111 insertions, 29 deletions
diff --git a/src/crepe/api/AudioSource.cpp b/src/crepe/api/AudioSource.cpp
index b246cc9..10b3b49 100644
--- a/src/crepe/api/AudioSource.cpp
+++ b/src/crepe/api/AudioSource.cpp
@@ -2,7 +2,7 @@
#include "AudioSource.h"
-#include "Sound.h"
+#include "../Sound.h"
#include <memory>
using namespace crepe::api;
diff --git a/src/crepe/api/CMakeLists.txt b/src/crepe/api/CMakeLists.txt
index 37c194d..f2d45eb 100644
--- a/src/crepe/api/CMakeLists.txt
+++ b/src/crepe/api/CMakeLists.txt
@@ -2,14 +2,15 @@ target_sources(crepe PUBLIC
# AudioSource.cpp
BehaviorScript.cpp
Script.cpp
+ GameObject.cpp
+ Rigidbody.cpp
+ Force.cpp
+ ParticleEmitter.cpp
+ Transform.cpp
Color.cpp
Texture.cpp
- Sprite.cpp
- Transform.cpp
AssetManager.cpp
- GameObject.cpp
Collider.cpp
- Rigidbody.cpp
Sprite.cpp
)
@@ -19,13 +20,10 @@ target_sources(crepe PUBLIC FILE_SET HEADERS FILES
Script.h
GameObject.h
GameObject.hpp
- Collider.h
Rigidbody.h
Sprite.h
Point.h
- Transform.h
- Color.h
- Sprite.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/Collider.cpp b/src/crepe/api/Collider.cpp
deleted file mode 100644
index c3e4929..0000000
--- a/src/crepe/api/Collider.cpp
+++ /dev/null
@@ -1,5 +0,0 @@
-#include "Collider.h"
-
-using namespace crepe::api;
-
-Collider::Collider(uint32_t gameObjectId) : Component(gameObjectId){}
diff --git a/src/crepe/api/Collider.h b/src/crepe/api/Collider.h
deleted file mode 100644
index 1d540de..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(uint32_t gameObjectId);
-
- 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/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.h b/src/crepe/api/Rigidbody.h
index c16a300..e59e217 100644
--- a/src/crepe/api/Rigidbody.h
+++ b/src/crepe/api/Rigidbody.h
@@ -1,6 +1,6 @@
#pragma once
-#include "Component.h"
+#include "../Component.h"
#include <cstdint>
namespace crepe::api{