aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/system
diff options
context:
space:
mode:
Diffstat (limited to 'src/crepe/system')
-rw-r--r--src/crepe/system/RenderSystem.cpp28
-rw-r--r--src/crepe/system/RenderSystem.h6
2 files changed, 28 insertions, 6 deletions
diff --git a/src/crepe/system/RenderSystem.cpp b/src/crepe/system/RenderSystem.cpp
index 3a1def5..3de8330 100644
--- a/src/crepe/system/RenderSystem.cpp
+++ b/src/crepe/system/RenderSystem.cpp
@@ -1,3 +1,4 @@
+#include <cmath>
#include <functional>
#include <vector>
@@ -6,7 +7,9 @@
#include "../api/Transform.h"
#include "../facade/SDLContext.h"
#include "../util/log.h"
+#include "Particle.h"
#include "api/ParticleEmitter.h"
+#include "api/Vector2.h"
#include "RenderSystem.h"
@@ -39,17 +42,32 @@ void RenderSystem::update_camera() {
this->curr_cam = &cam;
}
}
-void RenderSystem::render_sprites() const {
+
+
+void RenderSystem::render_particle(const ParticleEmitter& em, Transform & tm){
+ if (!em.active) return;
+
+ SDLContext & render = SDLContext::get_instance();
+ for (const Particle& p : em.data.particles) {
+ tm.position = p.position;
+ render.draw(em.data.sprite, tm , *curr_cam);
+ }
+}
+void RenderSystem::render_sprites() {
ComponentManager & mgr = ComponentManager::get_instance();
- auto sprites = mgr.get_components_by_type<Sprite>();
+ auto emitter = mgr.get_components_by_type<ParticleEmitter>();
SDLContext & render = SDLContext::get_instance();
- for (const Sprite & sprite : sprites) {
+ Transform test(1, Vector2{0,0},0,0);
+
+ for (const ParticleEmitter & em : emitter) {
auto transforms
- = mgr.get_components_by_id<Transform>(sprite.game_object_id);
- render.draw(sprite, transforms[0], *curr_cam);
+ = mgr.get_components_by_id<Transform>(em.game_object_id);
+ test.scale = transforms[0].get().scale;
+ test.rotation = transforms[0].get().rotation;
+ this->render_particle(em, test);
}
}
diff --git a/src/crepe/system/RenderSystem.h b/src/crepe/system/RenderSystem.h
index 70db21a..8dd8b7e 100644
--- a/src/crepe/system/RenderSystem.h
+++ b/src/crepe/system/RenderSystem.h
@@ -3,6 +3,8 @@
#include "api/Camera.h"
#include "System.h"
+#include "api/ParticleEmitter.h"
+#include "api/Transform.h"
namespace crepe {
@@ -44,7 +46,9 @@ private:
void update_camera();
//! Renders all active sprites to the screen.
- void render_sprites() const;
+ void render_sprites() ;
+
+ void render_particle(const ParticleEmitter& em, Transform & tm);
/**
* \todo Include color handling for sprites.