-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEntity.h
More file actions
183 lines (153 loc) · 3.58 KB
/
Entity.h
File metadata and controls
183 lines (153 loc) · 3.58 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#pragma once
#include "HitboxComponent.h"
#include "MovementComponent.h"
#include "AnimationComponent.h"
#include "AttributeComponent.h"
#include "SkillComponent.h"
#include "DirectionComponent.h"
#include "VisionComponent.h"
namespace Textures
{
//Max number of texture sheets for each entity, change if required.
const int indexMax = 60;
/*
enum class Players
{
PlayerOne = 0,
PlayerTwo
};
enum class Enemies
{
Rat = 0,
Fly
};
enum class Bosses
{
BossOne = 0,
BossTwo
};
enum class TextureSheets
{
Idle = 0,
Move,
Attack,
DodgeRoll,
Dash,
Skill,
Death
};
enum class Animations
{
Idle_Left = 0,
Idle_Left_Up,
Idle_Left_Down,
Idle_Right,
Idle_Right_Up,
Idle_Right_Down,
Idle_Up,
Idle_Down
};
*/
namespace Players
{
enum PlayerOne
{
Idle_Down_Left = 0,
Idle_Down_Right,
Idle_Down,
Idle_Up_Left,
Idle_Up_Right,
Idle_Up,
Idle_Left,
Idle_Right,
PLAYER_MAX = Textures::indexMax - 1
};
}
namespace Enemies
{
namespace Rats
{
enum Rat
{
Idle_Down_Left = Textures::indexMax,
Idle_Down_Right,
Idle_Down,
Idle_Up_Left,
Idle_Up_Right,
Idle_Up,
Idle_Left,
Idle_Right,
RAT_MAX = (Textures::indexMax * 2) - 1
};
}
namespace Flyes
{
enum Fly
{
Idle_Down_Left = Textures::indexMax * 2,
Idle_Down_Right,
Idle_Down,
Idle_Up_Left,
Idle_Up_Right,
Idle_Up,
Idle_Left,
Idle_Right,
FLY_MAX = (Textures::indexMax * 3) - 1
};
}
}
}
class Entity
{
private:
//private: Functions:
void initVariables();
protected:
//sf::Texture* texture;
sf::Sprite sprite;
HitboxComponent* hitboxComponent;
MovementComponent* movementComponent;
AnimationComponent* animationComponent;
AttributeComponent* attributeComponent;
SkillComponent* skillComponent;
DirectionComponent* directionComponent;
VisionComponent* visionComponent;
int expReward;
public:
//Constructors and Destructor:
Entity();
virtual ~Entity();
//Component functions:
void setTexture(sf::Texture& texture);
void createHitboxComponent(sf::Sprite& sprite, float offset_x, float offset_y, float width, float height);
void createMovementComponent(const float max_velocity, const float acceleration, const float deceleration);
void createAnimationComponent(sf::Texture& texture_sheet);
void createAttributeComponent(const int level);
void createSkillComponent();
void createDirectionComponent(sf::Vector2f direction_vector);
void createVisionComponent(sf::Vector2f position, const float range, sf::Vector2f direction);
//Accessors:
const sf::Vector2f& getPosition() const;
const sf::Vector2f getCenter() const;
const sf::Vector2i getGridPosition(const int grid_size_i) const;
const sf::FloatRect getGlobalBounds() const;
const sf::FloatRect getNextPositionBounds(const float& dt) const;
const float getDistance(const Entity& entity) const;
const AttributeComponent* getAttributeComponent() const;
VisionComponent* getVisionComponent() const;
const bool isDead() const;
const int& getExpReward() const;
//Modifiers:
void setPosition(const float x, const float y);
void loseHp(const int hp);
void gainHp(const int hp);
void loseExp(const int exp);
void gainExp(const int exp);
//Functions:
void move(const float dir_x, const float dir_y, const float& dt);
void stopVelocity();
void stopVelocityX();
void stopVelocityY();
virtual void update(const float& dt, sf::Vector2f& mouse_position_view) = 0;
virtual void render(sf::RenderTarget& target, sf::Shader* shader = nullptr, const sf::Vector2f shader_position = sf::Vector2f(), const bool show_hitbox = false) = 0;
};