#include #include #include #include "game.h" #include "entity.h" //Entities #include "player.h" extern struct game game; Rectangle get_entity_collider_world(const struct entity* entity) { return (Rectangle) { .x = entity->collider.x + entity->position.x, .y = entity->collider.y + entity->position.y, .width = entity->collider.width, .height = entity->collider.height }; } Rectangle get_entity_dest_rect_world(const struct entity* entity) { return (Rectangle) { .x = entity->sprite_dest_rect.x + entity->position.x, .y = entity->sprite_dest_rect.y + entity->position.y, .width = entity->sprite_dest_rect.width, .height = entity->sprite_dest_rect.height }; } void entity_handle_collision ( struct entity*, struct entity*, enum direction ) { } static inline bool entity_animated(const struct entity* e) { return (e->flags & ENTITY_ANIMATED) != 0; } void update_animation(struct animation* animation, float dt) { if (animation->is_completed) return; animation->current_frame_time += dt; while (animation->current_frame_time >= animation->frame_times[animation->current_frame]) { bool animation_completed = animation->current_frame >= animation->frame_count-1; if (animation_completed && animation->is_looping) { animation->current_frame = 0; animation->current_frame_time = 0; return; } else if (animation_completed) { animation->is_completed = true; return; } animation->current_frame_time -= animation->frame_times[animation->current_frame]; animation->current_frame++; } } Rectangle animation_get_source_rect(const struct animation* animation) { return animation->source_rects[animation->current_frame]; } void draw_entity(const struct entity* entity) { if (entity_animated(entity)) { const struct animation* current_animation = &entity->animations[entity->current_animation]; DrawTexturePro(entity->texture, animation_get_source_rect(current_animation), get_entity_dest_rect_world(entity), (Vector2) {0.0, 0.0}, 0, WHITE); } else { DrawTexturePro(entity->texture, entity->sprite_source_rect, get_entity_dest_rect_world(entity), (Vector2) {0.0, 0.0}, 0, WHITE); } } void add_entity(const struct entity* e) { static int entity_id = 0; for (int i = 0; i < MAX_ENTITY_COUNT; i++) { struct entity* current = &game.entities[i]; if (entity_active(current)) continue; memcpy(current, e, sizeof(struct entity)); current->entity_id = entity_id++; return; } } void update_entity(struct entity* entity, float dt) { update_player(entity, dt); }