-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProjectileComponent.h
75 lines (67 loc) · 1.64 KB
/
ProjectileComponent.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#pragma once
#include "ECS.h"
#include "Components.h"
#include "Vector2D.h"
#include "Game.h"
#include <Windows.h>
class ProjectileComponent : public Component
{
public:
ProjectileComponent(int rng, int sp, Vector2D vel, int l) : range(rng), speed(sp), velocity(vel), line(l)
{}
~ProjectileComponent()
{}
void init() override
{
transform = &entity->getComponent<TransformComponent>();
transform->velocity = velocity;
}
void update() override
{
distance += speed;
switch (line)
{
case 1:
if (transform->position.x < -64)
{
std::cout << "Out of Range Line 1" << std::endl;
entity->getComponent<TransformComponent>().position.x = 949;
entity->getComponent<ProjectileComponent>().distance = 0;
}
break;
case 2:
if (transform->position.x < -64)
{
std::cout << "Out of Range Line 2" << std::endl;
entity->getComponent<TransformComponent>().position.x = 1038;
entity->getComponent<ProjectileComponent>().distance = 0;
}
break;
case 3:
if (transform->position.x > 832)
{
std::cout << "Out of Range Line 3" << std::endl;
entity->getComponent<TransformComponent>().position.x = -337;
entity->getComponent<ProjectileComponent>().distance = 0;
}
break;
case 4:
if (transform->position.x > 832)
{
std::cout << "Out of Range Line 4" << std::endl;
entity->getComponent<TransformComponent>().position.x = -337;
entity->getComponent<ProjectileComponent>().distance = 0;
}
break;
default:
break;
}
}
private:
TransformComponent* transform = nullptr;
int range = 0;
int speed = 0;
int distance = 0;
int line = 0;
Vector2D velocity = Vector2D(0,0);
};