diff options
author | jaroWMR <jarorutjes07@gmail.com> | 2024-10-10 08:38:40 +0200 |
---|---|---|
committer | jaroWMR <jarorutjes07@gmail.com> | 2024-10-10 08:38:40 +0200 |
commit | d001c4ba95a72f13c942f1a24eb98fe1584d93a4 (patch) | |
tree | 8d72f1ddf9baf591fdf99397aa1495a219d35d35 /src/crepe | |
parent | 163c9e3eea437daa8ef6007fbdf2f91470066cbf (diff) |
Renamed files and Emitter is a component
Diffstat (limited to 'src/crepe')
-rw-r--r-- | src/crepe/CMakeLists.txt | 8 | ||||
-rw-r--r-- | src/crepe/Particle.cpp | 4 | ||||
-rw-r--r-- | src/crepe/Particle.h (renamed from src/crepe/Particle.hpp) | 4 | ||||
-rw-r--r-- | src/crepe/ParticleEmitter.cpp | 10 | ||||
-rw-r--r-- | src/crepe/ParticleEmitter.h | 32 | ||||
-rw-r--r-- | src/crepe/ParticleEmitter.hpp | 25 | ||||
-rw-r--r-- | src/crepe/ParticleSystem.cpp | 12 | ||||
-rw-r--r-- | src/crepe/ParticleSystem.h (renamed from src/crepe/ParticleSystem.hpp) | 7 | ||||
-rw-r--r-- | src/crepe/SDLApp.cpp | 6 | ||||
-rw-r--r-- | src/crepe/SDLApp.h (renamed from src/crepe/SDLApp.hpp) | 6 |
10 files changed, 68 insertions, 46 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; |