There's now a Collision component that determines collision if its set. Closes #72.

This commit is contained in:
Zed A. Shaw 2025-08-06 11:43:39 -04:00
parent 9bf6926dc3
commit fc4eacadb0
6 changed files with 27 additions and 13 deletions

View file

@ -23,6 +23,12 @@ using namespace components;
using namespace DinkyECS;
using lighting::LightSource;
void System::set_position(World& world, SpatialMap& collision, Entity entity, Position pos) {
world.set<Position>(entity, pos);
bool has_collision = world.has<Collision>(entity);
collision.insert(pos.location, entity, has_collision);
}
void System::lighting(GameLevel &level) {
auto &light = *level.lights;
auto &world = *level.world;
@ -162,8 +168,9 @@ void System::distribute_loot(GameLevel &level, Position target_pos) {
world.set<ritual::JunkPile>(junk_entity, pile);
// BUG: inventory_count here isn't really used to remove it
world.set<InventoryItem>(junk_entity, {inventory_count, entity_data});
world.set<Position>(junk_entity, target_pos);
level.collision->insert(target_pos.location, junk_entity, false);
set_position(world, *level.collision, junk_entity, target_pos);
level.world->send<Events::GUI>(Events::GUI::ENTITY_SPAWN, junk_entity, {});
} else {
dbc::log("DEAD BODY NOT IMPLEMENTED, for now just removing enemy");
@ -442,7 +449,6 @@ Entity System::spawn_item(World& world, const std::string& name) {
void System::drop_item(GameLevel& level, Entity item) {
auto& world = *level.world;
auto& map = *level.map;
auto& collision = *level.collision;
auto player_pos = world.get<Position>(level.player);
@ -453,8 +459,8 @@ void System::drop_item(GameLevel& level, Entity item) {
// if they're aiming at a wall then drop at their feet
if(!map.can_move(drop_spot.location)) drop_spot = player_pos;
world.set<Position>(item, drop_spot);
collision.insert(drop_spot.location, item, false);
set_position(world, *level.collision, item, drop_spot);
level.world->not_constant(item);
level.world->send<Events::GUI>(Events::GUI::ENTITY_SPAWN, item, {});
}