ProjectileLifeCycle.h 975 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /*
  2. * 2D Game Engine
  3. * ProjectileLifeCycle.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 27/02/2021.
  8. */
  9. #ifndef GAMEENGINE_SOURCE_INCLUDE_SYSTEMS_PROJECTILELIFECYCLE_H
  10. #define GAMEENGINE_SOURCE_INCLUDE_SYSTEMS_PROJECTILELIFECYCLE_H
  11. #include <SDL.h>
  12. #include <ECS.h>
  13. #include <Components/Projectile.h>
  14. class ProjectileLifeCycleSystem: public System
  15. {
  16. public:
  17. ProjectileLifeCycleSystem()
  18. {
  19. this->requireComponent<ProjectileComponent>();
  20. }
  21. void update()
  22. {
  23. for (auto entity: this->getSystemEntities())
  24. {
  25. auto &projectile = entity.getComponent<ProjectileComponent>();
  26. if ((SDL_GetTicks() - projectile.startTime) > projectile.projectileDuration)
  27. {
  28. entity.kill();
  29. }
  30. }
  31. }
  32. };
  33. #endif /* GAMEENGINE_SOURCE_INCLUDE_SYSTEMS_PROJECTILELIFECYCLE_H */