-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSmartEntity.h
More file actions
143 lines (115 loc) · 5.66 KB
/
SmartEntity.h
File metadata and controls
143 lines (115 loc) · 5.66 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
#include "Map.h"
enum EntityType { PLATFORM, PLAYER, ENEMY };
enum AIType { WALKER, GUARD, COWARD, CHARGER, ROCKET };
enum AIState { WALKING, IDLE, ATTACKING, FLEEING, RUSHING, LAUNCHING };
class Entity
{
public: //public everything!!!!!
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;
// ————— ENEMY AI ————— //
EntityType m_entity_type;
AIType m_ai_type;
AIState m_ai_state;
float m_width = 1;
float m_height = 1;
public:
// bool dead = false; //this becomes true when entity falls out of map, position -4 or -5
// ————— 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;
volatile int consistency = 0; //check for three frames of collision for death
GLuint m_texture_id;
// ————— METHODS ————— //
Entity();
~Entity();
void draw_sprite_from_texture_atlas(ShaderProgram* program, GLuint texture_id, int index);
void update(float delta_time, Entity* player, Entity* objects, int object_count, Map* map); // Now, update should check for both objects in the game AND the map
void render(ShaderProgram* program);
bool const check_collision(Entity* other) const;
EntityType check_collision_y(Entity* collidable_entities, int collidable_entity_count);
EntityType check_collision_x(Entity* collidable_entities, int collidable_entity_count);
// Overloading our methods to check for only the map
void const check_collision_y(Map* map);
void const check_collision_x(Map* map);
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 ai_activate(Entity* player);
void ai_walk();
void ai_guard(Entity* player);
void ai_runaway(Entity* player);
void ai_launchSequence(Entity* player);
void ai_rush_toward(Entity* player);
void activate() { m_is_active = true; };
void deactivate() { m_is_active = false; };
// ————— GETTERS ————— //
EntityType const get_entity_type() const { return m_entity_type; };
AIType const get_ai_type() const { return m_ai_type; };
AIState const get_ai_state() const { return m_ai_state; };
glm::vec3 const get_position() const { return m_position; };
glm::vec3 const get_movement() const { return m_movement; };
glm::vec3 const get_velocity() const { return m_velocity; };
glm::vec3 const get_acceleration() const { return m_acceleration; };
float const get_jumping_power() const { return m_jumping_power; };
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_entity_type(EntityType new_entity_type) {
m_entity_type = new_entity_type;
if (m_entity_type == ENEMY){
m_width = 0;
}else if(m_entity_type == PLAYER){
m_width =0;
}
};
void const set_ai_type(AIType new_ai_type) { m_ai_type = new_ai_type; };
void const set_ai_state(AIState new_state) { m_ai_state = new_state; };
void const set_position(glm::vec3 new_position) { m_position = new_position; };
void const set_movement(glm::vec3 new_movement) { m_movement = new_movement; };
void const set_velocity(glm::vec3 new_velocity) { m_velocity = new_velocity; };
void const set_speed(float new_speed) { m_speed = new_speed; };
void const set_jumping_power(float new_jumping_power) { m_jumping_power = new_jumping_power; };
void const set_acceleration(glm::vec3 new_acceleration) { m_acceleration = new_acceleration; };
void const set_width(float new_width) { m_width = new_width; };
void const set_height(float new_height) { m_height = new_height; };
};