Add hitboxes
This commit is contained in:
@@ -2,37 +2,25 @@
|
||||
|
||||
#include "../game_state.h"
|
||||
|
||||
Rectangle calculateEntityBounds(Position pos, Size size) {
|
||||
return (Rectangle) {
|
||||
pos.x - size.x * 0.5f,
|
||||
pos.y - size.x * 0.5f,
|
||||
size.x, size.y
|
||||
};
|
||||
}
|
||||
|
||||
bool getEntityBounds(ecs_entity_t entity, Position *outPos, Size *outSize, Rectangle *outBounds) {
|
||||
bool getEntityHitBox(ecs_entity_t entity, Position *outPos, Rectangle *outHitBox) {
|
||||
if (!ecs_is_alive(ECS, entity))
|
||||
return false;
|
||||
|
||||
const Position *pos = ecs_get(ECS, entity, Position);
|
||||
if (!pos)
|
||||
return false;
|
||||
const Size *size = ecs_get(ECS, entity, Size);
|
||||
if (!size)
|
||||
return false;
|
||||
|
||||
if (outPos) {
|
||||
if (outPos)
|
||||
*outPos = *pos;
|
||||
|
||||
const HitBox *hitbox = ecs_get(ECS, entity, HitBox);
|
||||
if (!hitbox)
|
||||
return false;
|
||||
if (outHitBox) {
|
||||
*outHitBox = *hitbox;
|
||||
outHitBox->x += pos->x;
|
||||
outHitBox->y += pos->y;
|
||||
}
|
||||
if (outSize) {
|
||||
*outSize = *size;
|
||||
}
|
||||
if (outBounds) {
|
||||
*outBounds = (Rectangle) {
|
||||
pos->x - size->x * 0.5f,
|
||||
pos->y - size->y * 0.5f,
|
||||
size->x, size->y
|
||||
};
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -115,7 +103,7 @@ void setupSystems() {
|
||||
ECS_OBSERVER(ECS, entityConsumePopCapacity, EcsOnSet, ConsumePopCapacity, Owner);
|
||||
ECS_OBSERVER(ECS, entityUnConsumePopCapacity, EcsOnRemove, ConsumePopCapacity, Owner);
|
||||
|
||||
ECS_SYSTEM(ECS, entityUpdateSpatialID, EcsOnUpdate, Position, Size, Velocity, SpatialGridID);
|
||||
ECS_SYSTEM(ECS, entityUpdateSpatialID, EcsOnUpdate, Position, HitBox, Velocity, SpatialGridID);
|
||||
ECS_SYSTEM(ECS, entityUpdateKinematic, EcsOnUpdate, Position, Velocity, Steering, Unit);
|
||||
|
||||
ECS_SYSTEM(ECS, entityMoveToTarget, EcsOnUpdate, Position, Velocity, TargetPosition, Steering);
|
||||
@@ -126,11 +114,11 @@ void setupSystems() {
|
||||
|
||||
ECS_SYSTEM(ECS, updateAnimationState, EcsOnUpdate, Animation, TextureRegion);
|
||||
ECS_SYSTEM(ECS, updateAnimation, EcsOnUpdate, Animation, TextureRegion);
|
||||
ECS_SYSTEM(ECS, updateEasingSystem, EcsOnUpdate, Easing, Position, Size, Rotation);
|
||||
ECS_SYSTEM(ECS, updateEasingSystem, EcsOnUpdate, Easing, Position, HitBox, Rotation);
|
||||
|
||||
ECS_SYSTEM(ECS, renderDebugPath, EcsOnUpdate, Path);
|
||||
|
||||
ECS_SYSTEM(ECS, renderColliders, EcsOnUpdate, Position, Size);
|
||||
ECS_SYSTEM(ECS, renderColliders, EcsOnUpdate, Position, HitBox);
|
||||
ECS_SYSTEM(ECS, renderOrientationDirection, EcsOnUpdate, Position, Orientation);
|
||||
ECS_SYSTEM(ECS, renderArmPosition, EcsOnUpdate, Position, Arm);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user