From 1562dd67d16d328e919db28cfd48206c8c868fe4 Mon Sep 17 00:00:00 2001 From: BoredGuy Date: Sun, 31 Aug 2025 19:24:24 +0300 Subject: Added hitbox/hurtbox system - Made the entity struct much smaller --- include/barrel_data.h | 2 +- include/constants.h | 5 ++++- include/physics.h | 2 +- include/utils.h | 17 +++++++++++++++++ 4 files changed, 23 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/barrel_data.h b/include/barrel_data.h index 0db5fdd..97a13db 100644 --- a/include/barrel_data.h +++ b/include/barrel_data.h @@ -4,7 +4,7 @@ static const Rectangle physicsCollider = (Rectangle) { .x = NO_OFFSET, .y = NO_OFFSET, .width = 100, - .height = 100 + .height = 120 }; static const Rectangle destRect = (Rectangle) { diff --git a/include/constants.h b/include/constants.h index 2fd6ace..a2ea961 100644 --- a/include/constants.h +++ b/include/constants.h @@ -3,7 +3,7 @@ #define WINDOW_WIDTH 1280 #define WINDOW_HEIGHT 720 -#define MAX_ENTITY_COUNT 2048 +#define MAX_ENTITY_COUNT 128 #define MAX_AREA_COUNT 4 #define MAX_SPRITE_COUNT 4 //Maximum number of sprites per entity @@ -12,3 +12,6 @@ #define MAX_FRAMES 30 #define MAX_ANIMATIONS 20 + +#define FPS_POS_X 10 +#define FPS_POS_Y 10 diff --git a/include/physics.h b/include/physics.h index b393d08..8c50fb4 100644 --- a/include/physics.h +++ b/include/physics.h @@ -2,4 +2,4 @@ #include "game.h" -void MoveAndSlide(Entity* e, float dt); \ No newline at end of file +void MoveAndSlide(Entity* e, float dt); diff --git a/include/utils.h b/include/utils.h index 5a4a4ac..cb1770e 100644 --- a/include/utils.h +++ b/include/utils.h @@ -60,4 +60,21 @@ static inline Rectangle GetCurrentSourceRectangle(const Animation* animation) { return animation->srcRects[animation->currentFrame]; } +static inline Rectangle GetEntityHitboxGlobal(const Entity* e, int hbIndex) { + Rectangle hitBoxGlobal = e->hitBoxes[hbIndex]; + hitBoxGlobal.x += e->position.x; + hitBoxGlobal.y += e->position.y; + + return hitBoxGlobal; +} + +static inline Rectangle GetEntityHurtboxGlobal(const Entity* e, int hbIndex) { + Rectangle hurtBoxGlobal = e->hurtBoxes[hbIndex]; + hurtBoxGlobal.x += e->position.x; + hurtBoxGlobal.y += e->position.y; + + return hurtBoxGlobal; +} + + #endif // UTILS_H_ -- cgit v1.2.3