first commit
This commit is contained in:
58
src/ecs/ProjectileComponent.h
Normal file
58
src/ecs/ProjectileComponent.h
Normal file
@ -0,0 +1,58 @@
|
||||
/*
|
||||
* 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;
|
||||
// std::cout << transform->position << std::endl;
|
||||
}
|
||||
|
||||
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_ */
|
Reference in New Issue
Block a user