58 lines
1.0 KiB
C++
58 lines
1.0 KiB
C++
/*
|
|
* Projectile.h
|
|
*
|
|
* Created on: Apr 4, 2020
|
|
* Author: ayoungblood
|
|
*/
|
|
|
|
#ifndef SRC_ECS_PROJECTILECOMPONENT_H_
|
|
#define SRC_ECS_PROJECTILECOMPONENT_H_
|
|
|
|
#include "ECS.h"
|
|
#include "Components.h"
|
|
#include "../game/Vector2D.h"
|
|
|
|
class ProjectileComponent : public Component
|
|
{
|
|
public:
|
|
ProjectileComponent(int rng, int sp, Vector2D vel) : range(rng), speed(sp), velocity(vel)
|
|
{}
|
|
~ProjectileComponent()
|
|
{}
|
|
|
|
void init() override
|
|
{
|
|
transform = &entity->getComponent<TransformComponent>();
|
|
transform->velocity = velocity;
|
|
}
|
|
|
|
void update() override
|
|
{
|
|
distance += speed;
|
|
if (distance > range)
|
|
{
|
|
entity->destroy();
|
|
}
|
|
else if (transform->position.x > Game::camera.x + Game::camera.w ||
|
|
transform->position.x < Game::camera.x ||
|
|
transform->position.y > Game::camera.y +Game::camera.h ||
|
|
transform->position.y < Game::camera.y)
|
|
{
|
|
entity->destroy();
|
|
}
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
TransformComponent* transform;
|
|
|
|
int range;
|
|
int speed;
|
|
int distance;
|
|
Vector2D velocity;
|
|
|
|
};
|
|
|
|
#endif /* SRC_ECS_PROJECTILECOMPONENT_H_ */
|