diff options
| author | BoredGuy <osome3717@gmail.com> | 2026-03-15 17:30:54 +0300 |
|---|---|---|
| committer | BoredGuy <osome3717@gmail.com> | 2026-03-15 17:30:54 +0300 |
| commit | 2c2be83a370318ca69824538ed3e61784295a772 (patch) | |
| tree | 67f1a4f83193d6de3afd79167170fcf1eaac070e | |
| parent | 77c6850d28134638d75a539bb8094e828a47d93f (diff) | |
More work
| -rw-r--r-- | src/constants.h | 3 | ||||
| -rw-r--r-- | src/entity.c | 2 | ||||
| -rw-r--r-- | src/entity.h | 36 |
3 files changed, 37 insertions, 4 deletions
diff --git a/src/constants.h b/src/constants.h index a21402a..0c08dfd 100644 --- a/src/constants.h +++ b/src/constants.h @@ -7,4 +7,7 @@ #define MAX_ENTITY_COUNT 500 +#define ENTITY_MAX_ANIMATIONS 10 +#define ANIMATION_MAX_FRAMES 4 + #endif diff --git a/src/entity.c b/src/entity.c index 4dc32f2..7a9db49 100644 --- a/src/entity.c +++ b/src/entity.c @@ -24,7 +24,7 @@ void entity_handle_collision } void draw_entity(const struct entity* entity) { - DrawRectangleRec(get_entity_collider_world(entity), RED); + } void add_entity(const struct entity* e) { 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 |
