Damage.h 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. * 2D Game Engine
  3. * Damage.h:
  4. * Based on pikuma.com 2D game engine in C++ and Lua course
  5. * Copyright (c) 2021 986-Studio. All rights reserved.
  6. *
  7. * Created by Manoël Trapier on 16/02/2021.
  8. */
  9. #ifndef GAMEENGINE_SOURCE_INCLUDE_SYSTEMS_DAMAGE_H
  10. #define GAMEENGINE_SOURCE_INCLUDE_SYSTEMS_DAMAGE_H
  11. #include <ECS.h>
  12. #include <EventBus.h>
  13. #include <Logger.h>
  14. #include <Events/Collision.h>
  15. #include <Components/BoxCollider.h>
  16. class DamageSystem : public System
  17. {
  18. public:
  19. DamageSystem()
  20. {
  21. this->requireComponent<BoxColliderComponent>();
  22. }
  23. void subscriptToEvents(std::unique_ptr<EventBus> &eventBus)
  24. {
  25. eventBus->subscribeToEvent<CollisionEvent>(this, &DamageSystem::onCollision);
  26. }
  27. void onCollision(CollisionEvent &event)
  28. {
  29. Logger::Debug("Damage: Got an event from A id#%d and B id#%d", event.a.getId(), event.b.getId());
  30. event.a.kill();
  31. event.b.kill();
  32. }
  33. void Update()
  34. {
  35. }
  36. };
  37. #endif /* GAMEENGINE_SOURCE_INCLUDE_SYSTEMS_DAMAGE_H */