Add hitboxes
This commit is contained in:
27
game/main.c
27
game/main.c
@@ -128,7 +128,7 @@ bool init(void *userData) {
|
||||
input->queries.selected = ecs_query(ECS, {
|
||||
.filter.terms = {
|
||||
{ecs_id(Position)},
|
||||
{ecs_id(Size)},
|
||||
{ecs_id(HitBox)},
|
||||
{ecs_id(Selected)}
|
||||
}
|
||||
});
|
||||
@@ -382,21 +382,18 @@ static void renderGame(Game *game, float dt) {
|
||||
Rectangle camBounds = getCameraBounds(camera);
|
||||
while (ecs_iter_next(&it)) {
|
||||
Position *p = ecs_field(&it, Position, 1);
|
||||
Size *s = ecs_field(&it, Size, 2);
|
||||
Size *s = ecs_field(&it, Size , 2);
|
||||
Rotation *r = ecs_field(&it, Rotation, 3);
|
||||
TextureRegion *t = ecs_field(&it, TextureRegion, 4);
|
||||
for (i32 i = 0; i < it.count; i++) {
|
||||
Rectangle dst = {p[i].x, p[i].y, s[i].x, s[i].y};
|
||||
Vector2 origin = {dst.width * 0.5f, dst.height};
|
||||
dst.x += origin.x - dst.width * 0.5f;
|
||||
dst.y += origin.y - dst.height * 0.5f;
|
||||
Rectangle collider = {
|
||||
p[i].x - s[i].x * 0.5f,
|
||||
p[i].y - s[i].y * 0.5f,
|
||||
.width = s[i].x,
|
||||
.height = s[i].y
|
||||
};
|
||||
if (!CheckCollisionRecs(camBounds, collider))
|
||||
f32 sclX = s[i].x / t[i].rec.width;
|
||||
f32 sclY = s[i].y / t[i].rec.height;
|
||||
Rectangle dst = {p[i].x, p[i].y,
|
||||
t[i].rec.width * sclX, t[i].rec.height * sclY};
|
||||
Vector2 origin = {0.0f, 0.0f};
|
||||
//dst.x += origin.x - dst.width * 0.5f;
|
||||
//dst.y += origin.y - dst.height * 0.5f;
|
||||
if (!CheckCollisionRecs(camBounds, dst))
|
||||
continue;
|
||||
Rectangle src = t[i].rec;
|
||||
// Fixes texture bleeding issue
|
||||
@@ -432,7 +429,7 @@ static void renderGame(Game *game, float dt) {
|
||||
DrawData draw = drawData[i];
|
||||
Vector2 pos = {
|
||||
draw.dst.x,
|
||||
draw.dst.y - draw.dst.height * 0.5f,
|
||||
draw.dst.y,
|
||||
};
|
||||
Color c = WHITE;
|
||||
if (draw.canHaveAlpha) {
|
||||
@@ -572,7 +569,7 @@ void igInspectWindow(ecs_entity_t entity, bool *open) {
|
||||
igInspectComp("Owner", entity, ecs_id(Owner), igOwner);
|
||||
igInspectComp("SpatialGridID", entity, ecs_id(SpatialGridID), igSpatialGridID);
|
||||
igInspectComp("Position", entity, ecs_id(Position), igVec2Comp);
|
||||
igInspectComp("Size", entity, ecs_id(Size), igVec2Comp);
|
||||
//igInspectComp("Size", entity, ecs_id(Size), igVec2Comp);
|
||||
igInspectComp("Velocity", entity, ecs_id(Velocity), igVec2Comp);
|
||||
igInspectComp("TargetPosition", entity, ecs_id(TargetPosition), igVec2Comp);
|
||||
igInspectComp("Steering", entity, ecs_id(Steering), igVec2Comp);
|
||||
|
||||
Reference in New Issue
Block a user