1234567891011121314151617181920212223242526272829303132333435363738394041 |
- /*
- * 2D Game Engine
- * ProjectileLifeCycle.h:
- * Based on pikuma.com 2D game engine in C++ and Lua course
- * Copyright (c) 2021 986-Studio. All rights reserved.
- *
- * Created by Manoël Trapier on 27/02/2021.
- */
- #ifndef GAMEENGINE_SOURCE_INCLUDE_SYSTEMS_PROJECTILELIFECYCLE_H
- #define GAMEENGINE_SOURCE_INCLUDE_SYSTEMS_PROJECTILELIFECYCLE_H
- #include <SDL.h>
- #include <ECS.h>
- #include <Components/Projectile.h>
- class ProjectileLifeCycleSystem: public System
- {
- public:
- ProjectileLifeCycleSystem()
- {
- this->requireComponent<ProjectileComponent>();
- }
- void update()
- {
- for (auto entity: this->getSystemEntities())
- {
- auto &projectile = entity.getComponent<ProjectileComponent>();
- if ((SDL_GetTicks() - projectile.startTime) > projectile.projectileDuration)
- {
- entity.kill();
- }
- }
- }
- };
- #endif /* GAMEENGINE_SOURCE_INCLUDE_SYSTEMS_PROJECTILELIFECYCLE_H */
|