Fix hitboxes for entities

This commit is contained in:
2024-01-28 14:09:27 +01:00
parent a61768e912
commit 5d96a02284
11 changed files with 67 additions and 49 deletions

View File

@@ -2,7 +2,7 @@
#include "../game_state.h"
bool getEntityHitBox(ecs_entity_t entity, Position *outPos, Rectangle *outHitBox) {
bool entityGetHitBox(ecs_entity_t entity, Position *outPos, Rectangle *outHitBox) {
if (!ecs_is_alive(ECS, entity))
return false;
@@ -18,11 +18,25 @@ bool getEntityHitBox(ecs_entity_t entity, Position *outPos, Rectangle *outHitBox
if (outHitBox) {
*outHitBox = *hitbox;
outHitBox->x += pos->x;
outHitBox->y += pos->y;
outHitBox->y = pos->y - hitbox->y - hitbox->height;
}
return true;
}
Rectangle entityTransformHitBox(Position position, HitBox hitBox) {
return (Rectangle) {
position.x + hitBox.x,
position.y - hitBox.y - hitBox.height,
hitBox.width,
hitBox.height
};
}
Vector2 entityGetCenter(Position position, HitBox hitBox) {
return (Vector2) {
position.x + hitBox.x + hitBox.width * 0.5f,
position.y - hitBox.y - hitBox.height * 0.5f
};
}
ecs_entity_t renderCollidersSystem;
ecs_entity_t renderOrientDirSystem;