aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/crepe/main.cpp')
-rw-r--r--src/crepe/main.cpp37
1 files changed, 23 insertions, 14 deletions
diff --git a/src/crepe/main.cpp b/src/crepe/main.cpp
index fc307cc..40eb04f 100644
--- a/src/crepe/main.cpp
+++ b/src/crepe/main.cpp
@@ -3,6 +3,8 @@
#include <chrono>
#include "SDLApp.hpp"
#include "ParticleEmitter.hpp"
+#include "ParticleSystem.hpp"
+#include "Particle.hpp"
const int WINDOW_WIDTH = 800;
const int WINDOW_HEIGHT = 600;
@@ -15,37 +17,44 @@ int main(int argc, char* argv[]) {
return 1;
}
+ ParticleSystem particleSystem;
- unsigned int maxParticles = 100; //maximum number of particles
- unsigned int emissionRate = 10; //particles created per second
- unsigned int speed = 50; //base speed of particles
- unsigned int speedOffset = 10; //random offset for particle speed
- unsigned int angle = 180; //base angle of particle emission
- unsigned int angleOffset = 30; //random offset for particle angle
+ unsigned int maxParticles = 100; // maximum number of particles
+ unsigned int emissionRate = 10; // particles created per second
+ unsigned int speed = 50; // base speed of particles
+ unsigned int speedOffset = 10; // random offset for particle speed
+ unsigned int angle = 90; // base angle of particle emission
+ unsigned int angleOffset = 30; // random offset for particle angle
+ ParticleEmitter emitter1(maxParticles, emissionRate, speed, speedOffset, angle, angleOffset);
+ emitter1.m_position = {200, 200}; // set the position of the first emitter
- ParticleEmitter emitter(maxParticles, emissionRate, speed, speedOffset, angle, angleOffset);
+ ParticleEmitter emitter2(maxParticles, emissionRate, speed, speedOffset, angle - 90, angleOffset); // Another emitter
+ emitter2.m_position = {200, 150}; // set the position of the second emitter
- emitter.setPosition(400, 300);
+ std::vector<ParticleEmitter> emitters = { emitter2 }; // array of emitters
float deltaTime = 0.1f;
bool running = true;
while (running) {
app.handleEvents(running);
- emitter.update(deltaTime);
+
+ particleSystem.update(deltaTime, emitters); // update particle system with delta time and emitters
app.clearScreen();
- //render particles using the drawSquare method
- const std::vector<Particle>& particles = emitter.getParticles();
- for (std::size_t i = 0; i < particles.size(); ++i) {
- app.drawSquare(particles[i].position.x, particles[i].position.y, 5);
+ // render particles using the drawSquare method from SDLApp
+ for (const ParticleEmitter& emitter : emitters) {
+ for (const Particle& particle : emitter.particles) {
+
+ app.drawSquare(particle.position.x, particle.position.y, 5); // draw each particle
+ }
}
app.presentScreen();
- std::this_thread::sleep_for(std::chrono::milliseconds(17));
+ std::this_thread::sleep_for(std::chrono::milliseconds(20)); // simulate ~50 FPS
}
app.cleanUp();