summaryrefslogtreecommitdiff
path: root/src/entity.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/entity.h')
-rw-r--r--src/entity.h36
1 files changed, 33 insertions, 3 deletions
diff --git a/src/entity.h b/src/entity.h
index 2ed443f..94eb00f 100644
--- a/src/entity.h
+++ b/src/entity.h
@@ -4,11 +4,21 @@
#include <raylib.h>
#include <stdbool.h>
#include <stdint.h>
+#include "constants.h"
+
+#define ENTITY_ACTIVE 1
+#define ENTITY_COLLISION_ACTIVE (1 << 1)
+#define ENTITY_VISIBLE (1 << 2)
enum entity_type {
Player_Entity
};
+enum draw_layer {
+ Foreground_Layer,
+ Background_Layer
+};
+
enum direction {
Direction_Up,
Direction_Down,
@@ -16,8 +26,17 @@ enum direction {
Direction_Right
};
-#define ENTITY_ACTIVE 1
-#define ENTITY_COLLISION_ACTIVE (1 << 1)
+struct animation {
+ int frame_count;
+ bool is_looping;
+ bool is_completed;
+
+ Rectangle source_rects[ANIMATION_MAX_FRAMES];
+ float frame_times[ANIMATION_MAX_FRAMES];
+
+ int current_frame;
+ float current_frame_time;
+};
struct entity {
int entity_id;
@@ -27,6 +46,12 @@ struct entity {
Vector2 position; //The position of the entity(roughly the center)
Vector2 velocity;
Rectangle collider;
+
+ Texture texture;
+ Rectangle sprite_dest_rect; //Relative to the position of entity (roughly the center)
+ struct animation animations[ENTITY_MAX_ANIMATIONS];
+ int current_animation;
+ enum draw_layer draw_layer;
};
void update_entity(struct entity* entity, float dt);
@@ -38,7 +63,8 @@ void entity_handle_collision
(
struct entity* self,
struct entity* other,
- enum direction collision_direction);
+ enum direction collision_direction
+ );
void add_entity(const struct entity* e);
@@ -50,4 +76,8 @@ static inline bool same_entity(const struct entity* a, const struct entity* b) {
return a->entity_id == b->entity_id;
}
+static inline bool entity_visible(const struct entity* e) {
+ return e->flags & ENTITY_VISIBLE;
+}
+
#endif