aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/crepe/CMakeLists.txt8
-rw-r--r--src/crepe/Particle.cpp4
-rw-r--r--src/crepe/Particle.h (renamed from src/crepe/Particle.hpp)4
-rw-r--r--src/crepe/ParticleEmitter.cpp10
-rw-r--r--src/crepe/ParticleEmitter.h32
-rw-r--r--src/crepe/ParticleEmitter.hpp25
-rw-r--r--src/crepe/ParticleSystem.cpp12
-rw-r--r--src/crepe/ParticleSystem.h (renamed from src/crepe/ParticleSystem.hpp)7
-rw-r--r--src/crepe/SDLApp.cpp6
-rw-r--r--src/crepe/SDLApp.h (renamed from src/crepe/SDLApp.hpp)6
-rw-r--r--src/example/particel.cpp10
11 files changed, 74 insertions, 50 deletions
diff --git a/src/crepe/CMakeLists.txt b/src/crepe/CMakeLists.txt
index 9c65e1e..399200b 100644
--- a/src/crepe/CMakeLists.txt
+++ b/src/crepe/CMakeLists.txt
@@ -21,10 +21,10 @@ target_sources(crepe PUBLIC FILE_SET HEADERS FILES
Asset.h
Sound.h
SoundContext.h
- ParticleEmitter.hpp
- ParticleSystem.hpp
- Particle.hpp
- SDLApp.hpp
+ ParticleEmitter.h
+ ParticleSystem.h
+ Particle.h
+ SDLApp.h
ComponentManager.h
ComponentManager.hpp
Component.h
diff --git a/src/crepe/Particle.cpp b/src/crepe/Particle.cpp
index 8cf7f7e..aa33606 100644
--- a/src/crepe/Particle.cpp
+++ b/src/crepe/Particle.cpp
@@ -1,6 +1,8 @@
-#include "Particle.hpp"
+#include "Particle.h"
#include <iostream>
+using namespace crepe;
+
Particle::Particle()
{
this->active = false;
diff --git a/src/crepe/Particle.hpp b/src/crepe/Particle.h
index 669a8ab..c408ed9 100644
--- a/src/crepe/Particle.hpp
+++ b/src/crepe/Particle.h
@@ -1,5 +1,7 @@
#pragma once
+namespace crepe {
+
struct Position {
float x;
float y;
@@ -18,3 +20,5 @@ public:
void update(float deltaTime);
float timeInLife;
};
+
+}
diff --git a/src/crepe/ParticleEmitter.cpp b/src/crepe/ParticleEmitter.cpp
index 3c9cc4e..9ae5e76 100644
--- a/src/crepe/ParticleEmitter.cpp
+++ b/src/crepe/ParticleEmitter.cpp
@@ -1,11 +1,13 @@
-#include "ParticleEmitter.hpp"
+#include "ParticleEmitter.h"
#include <ctime>
-#include "Particle.hpp"
+#include "Particle.h"
#include <iostream>
-ParticleEmitter::ParticleEmitter(unsigned int maxParticles, unsigned int emissionRate, unsigned int speed, unsigned int speedOffset, unsigned int angle, unsigned int angleOffset, float m_beginLifespan, float m_endLifespan)
+using namespace crepe;
+
+ParticleEmitter::ParticleEmitter(uint32_t maxParticles, uint32_t emissionRate, uint32_t speed, uint32_t speedOffset, uint32_t angle, uint32_t angleOffset, float m_beginLifespan, float m_endLifespan)
: 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<unsigned int>(std::time(nullptr))); // initialize random seed
+ 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
diff --git a/src/crepe/ParticleEmitter.h b/src/crepe/ParticleEmitter.h
new file mode 100644
index 0000000..477f492
--- /dev/null
+++ b/src/crepe/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 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/ParticleEmitter.hpp b/src/crepe/ParticleEmitter.hpp
deleted file mode 100644
index 5de5e1e..0000000
--- a/src/crepe/ParticleEmitter.hpp
+++ /dev/null
@@ -1,25 +0,0 @@
-#pragma once
-
-#include <vector>
-#include "Particle.hpp"
-
-
-
-class ParticleEmitter {
-public:
- ParticleEmitter(unsigned int maxParticles, unsigned int emissionRate, unsigned int speed, unsigned int speedOffset, unsigned int angle, unsigned int angleOffset,float m_beginLifespan,float m_endLifespan);
- ~ParticleEmitter();
-
- Position m_position; //position of the emitter
- unsigned int m_maxParticles; //maximum number of particles
- unsigned int m_emissionRate; //rate of particle emission
- unsigned int m_speed; //base speed of the particles
- unsigned int m_speedOffset; //offset for random speed variation
- unsigned int m_minAngle; //min angle of particle emission
- unsigned int 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/ParticleSystem.cpp b/src/crepe/ParticleSystem.cpp
index aff7a30..8891e2b 100644
--- a/src/crepe/ParticleSystem.cpp
+++ b/src/crepe/ParticleSystem.cpp
@@ -1,10 +1,12 @@
-#include "ParticleSystem.hpp"
+#include "ParticleSystem.h"
#include <cmath>
// #include <cstdlib>
#include <ctime>
#include <iostream> // include iostream for std::cout
-#include "ParticleEmitter.hpp"
-#include "Particle.hpp"
+#include "ParticleEmitter.h"
+#include "Particle.h"
+
+using namespace crepe;
ParticleSystem::ParticleSystem() : m_elapsedTime(0.0f) {} // Initialize m_elapsedTime to 0
@@ -39,11 +41,11 @@ void ParticleSystem::emitParticle(ParticleEmitter& emitter) {
//check if value is overthe 360 degrees
if(emitter.m_maxAngle < emitter.m_minAngle)
{
- randomAngle = ((emitter.m_minAngle + (std::rand() % (static_cast<int>(emitter.m_maxAngle + 360 - emitter.m_minAngle + 1))))%360);
+ randomAngle = ((emitter.m_minAngle + (std::rand() % (static_cast<uint32_t>(emitter.m_maxAngle + 360 - emitter.m_minAngle + 1))))%360);
}
else
{
- randomAngle = emitter.m_minAngle + (std::rand() % (static_cast<int>(emitter.m_maxAngle - emitter.m_minAngle + 1)));
+ randomAngle = emitter.m_minAngle + (std::rand() % (static_cast<uint32_t>(emitter.m_maxAngle - emitter.m_minAngle + 1)));
}
diff --git a/src/crepe/ParticleSystem.hpp b/src/crepe/ParticleSystem.h
index f670415..fd6d110 100644
--- a/src/crepe/ParticleSystem.hpp
+++ b/src/crepe/ParticleSystem.h
@@ -1,7 +1,10 @@
#pragma once
#include <vector>
-#include "ParticleEmitter.hpp"
+#include "ParticleEmitter.h"
+
+
+namespace crepe {
class ParticleSystem {
public:
@@ -12,3 +15,5 @@ private:
float m_elapsedTime; //elapsed time since the last emission
};
+
+}
diff --git a/src/crepe/SDLApp.cpp b/src/crepe/SDLApp.cpp
index 0779af1..715dd6f 100644
--- a/src/crepe/SDLApp.cpp
+++ b/src/crepe/SDLApp.cpp
@@ -1,8 +1,8 @@
-#include "SDLApp.hpp"
+#include "SDLApp.h"
#include <iostream>
#include <vector>
-#include "Particle.hpp"
-#include "ParticleEmitter.hpp"
+#include "Particle.h"
+#include "ParticleEmitter.h"
SDLApp::SDLApp(int windowWidth, int windowHeight)
: windowWidth(windowWidth), windowHeight(windowHeight), window(nullptr), renderer(nullptr) {}
diff --git a/src/crepe/SDLApp.hpp b/src/crepe/SDLApp.h
index f95d4bc..8915d30 100644
--- a/src/crepe/SDLApp.hpp
+++ b/src/crepe/SDLApp.h
@@ -2,8 +2,8 @@
#define SDLAPP_HPP
#include <SDL2/SDL.h>
-#include "Particle.hpp"
-#include "ParticleEmitter.hpp"
+#include "Particle.h"
+#include "ParticleEmitter.h"
class SDLApp {
public:
@@ -16,7 +16,7 @@ public:
void presentScreen();
void drawSquare(int x, int y, int size);
void cleanUp();
- void drawParticles(const std::vector<ParticleEmitter>& emitters);
+ void drawParticles(const std::vector<crepe::ParticleEmitter>& emitters);
void drawMultipleSquares(const std::vector<SDL_Rect>& squares);
private:
int windowWidth;
diff --git a/src/example/particel.cpp b/src/example/particel.cpp
index 58480a9..c66bbef 100644
--- a/src/example/particel.cpp
+++ b/src/example/particel.cpp
@@ -1,12 +1,14 @@
#include <iostream>
#include <thread>
#include <chrono>
-#include "SDLApp.hpp"
-#include "ParticleEmitter.hpp"
-#include "ParticleSystem.hpp"
-#include "Particle.hpp"
+#include "SDLApp.h"
+#include "ParticleEmitter.h"
+#include "ParticleSystem.h"
+#include "Particle.h"
#include <chrono>
+using namespace crepe;
+
const int WINDOW_WIDTH = 800;
const int WINDOW_HEIGHT = 600;