R-Type 0.1
Loading...
Searching...
No Matches
BulletSystem.hpp
1#pragma once
2
3#include "Logger/Logger.hpp"
4#include "components/Bullet.hpp"
5#include "components/Dead.hpp"
6#include "components/Transform.hpp"
7#include <ISystem.hpp>
8
9namespace rtk::systems {
18class BulletSystem final : public rtk::ecs::ISystem {
19public:
20 BulletSystem() = default;
21 ~BulletSystem() override = default;
22
26 void onStart(rtk::ecs::Registry &) override {
27 LOG_INFO("Load Bullet System");
28 }
29
34 void update(rtk::ecs::Registry &reg, float) override {
35 auto view = reg.view<component::Transform, component::Bullet>();
36 auto &transforms = reg.get_components<component::Transform>();
37
38 for (auto entity : view) {
39 auto *transform = transforms.get(entity);
40 if (!transform)
41 continue;
42
43 if (transform->position.x > 1920.0f) {
44 reg.get_components<component::Dead>().insert_at(entity, {});
45 }
46 }
47 }
48
52 void onStop(rtk::ecs::Registry &) override {}
53};
54
56} // namespace rtk::systems
Marks bullets that went past the right edge of the world as dead.
Definition BulletSystem.hpp:18
void onStart(rtk::ecs::Registry &) override
Logs that the system is loaded.
Definition BulletSystem.hpp:26
void onStop(rtk::ecs::Registry &) override
Does nothing.
Definition BulletSystem.hpp:52
void update(rtk::ecs::Registry &reg, float) override
Adds Dead to every bullet whose x is greater than 1920.
Definition BulletSystem.hpp:34
Marks an entity as a projectile.
Definition Bullet.hpp:17
Tag marking an entity for destruction at the end of the frame.
Definition Dead.hpp:17
Position, rotation and scale of an entity in world space.
Definition Transform.hpp:22