Fix hitboxes for entities
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user