-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEntity.h
More file actions
123 lines (104 loc) · 4.33 KB
/
Entity.h
File metadata and controls
123 lines (104 loc) · 4.33 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
class Entity
{
public: //who cares. all public!!!!!!!!!!!!
bool m_is_active = true;
// ––––– ANIMATION ––––– //
int* m_animation_right = NULL, // move to the right
* m_animation_left = NULL, // move to the left
* m_animation_up = NULL, // move upwards
* m_animation_down = NULL; // move downwards
// ––––– PHYSICS (GRAVITY) ––––– //
glm::vec3 m_position;
glm::vec3 m_velocity;
glm::vec3 m_acceleration;
// ————— TRANSFORMATIONS ————— //
float m_speed;
glm::vec3 m_movement;
glm::mat4 m_model_matrix;
float m_width = 1;
float m_height = 1;
public:
// ————— STATIC VARIABLES ————— //
static const int SECONDS_PER_FRAME = 4;
static const int LEFT = 0,
RIGHT = 1,
UP = 2,
DOWN = 3;
// ————— ANIMATION ————— //
int** m_walking = new int* [4]
{
m_animation_left,
m_animation_right,
m_animation_up,
m_animation_down
};
int m_animation_frames = 0,
m_animation_index = 0,
m_animation_cols = 0,
m_animation_rows = 0;
int* m_animation_indices = NULL;
float m_animation_time = 0.0f;
// ––––– PHYSICS (JUMPING) ––––– //
bool m_is_jumping = false;
float m_jumping_power = 0;
// ––––– PHYSICS (COLLISIONS) ––––– //
bool m_collided_top = false;
bool m_collided_bottom = false;
bool m_collided_left = false;
bool m_collided_right = false;
GLuint m_texture_id;
// ————— METHODS ————— //
Entity();
~Entity();
void draw_sprite_from_texture_atlas(ShaderProgram* program, GLuint texture_id, int index);
bool const check_collision(Entity* other) const;
void const check_collision_y(Entity* collidable_entities, int collidable_entity_count);
void const check_collision_x(Entity* collidable_entities, int collidable_entity_count);
void update(float delta_time, Entity* collidable_entities, int collidable_entity_count);
void render(ShaderProgram* program);
void move_left() { m_movement.x = -1.0f; };
void move_right() { m_movement.x = 1.0f; };
void move_up() { m_movement.y = 1.0f; };
void move_down() { m_movement.y = -1.0f; };
void activate() { m_is_active = true; };
void deactivate() { m_is_active = false; };
// ————— GETTERS ————— //
glm::vec3 const get_position() const { return m_position; };
glm::vec3 const get_velocity() const { return m_velocity; };
glm::vec3 const get_acceleration() const { return m_acceleration; };
glm::vec3 const get_movement() const { return m_movement; };
float const get_speed() const { return m_speed; };
int const get_width() const { return m_width; };
int const get_height() const { return m_height; };
// ————— SETTERS ————— //
void const set_position(glm::vec3 new_position) { m_position = new_position; };
void const set_velocity(glm::vec3 new_velocity) { m_velocity = new_velocity; };
void const set_acceleration(glm::vec3 new_position) { m_acceleration = new_position; };
void const set_movement(glm::vec3 new_movement) { m_movement = new_movement; };
void const set_speed(float new_speed) { m_speed = new_speed; };
void const set_width(float new_width) { m_width = new_width; };
void const set_height(float new_height) { m_height = new_height; };
void propel(char mode = 'i') //5 modes, idle, left, right, up, down. 5 chars
{
if('i'==mode){ //idle mode, no acceleration
m_acceleration.x = 0;
m_acceleration.y = -1;
}
if('l'==mode){
m_acceleration.x = -1;
m_acceleration.y = -1;
}
if('r'==mode){
m_acceleration.x = 1;
m_acceleration.y = -1;
}
if('u'==mode){
m_acceleration.x = 0;
m_acceleration.y = 1;
}
if('d'==mode){
m_acceleration.x = 0;
m_acceleration.y = -2;
}
}
};