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

@@ -8,6 +8,7 @@
#include "game_state.h"
#include "map_layers.h"
#include "utils.h"
#include "systems/systems.h"
bool initGameObjectsLayer(BzTileMap *map, BzTileObjectGroup *objectGroup) {
Game *game = ecs_singleton_get_mut(ECS, Game);
@@ -163,10 +164,12 @@ bool initTreesLayer(BzTileMap *map, BzTileLayer *layer) {
f32 sizeY = tileset->tileHeight;
f32 posX = layer->offsetX + x * sizeX;
f32 posY = layer->offsetY + y * sizeY;
posY += sizeY;
ecs_entity_t e = entityCreateEmpty();
HitBox tHitBox = entityTransformHitBox((Position) {posX, posY}, hb);
SpatialGridID gridID = bzSpatialGridInsert(game->entityGrid, &e,
posX + hb.x, posY + hb.y,
hb.width, hb.height);
tHitBox.x, tHitBox.y,
tHitBox.width, tHitBox.height);
ecs_set(ECS, e, SpatialGridID, {gridID});
ecs_set(ECS, e, Position, {posX, posY});
ecs_set(ECS, e, Size, {sizeX, sizeY});