Can now drag an item out of inventory and drop on the ground, then pick it back up, and put it in a loot container, and then back again. Still buggy but working for now.
This commit is contained in:
parent
68e50342e5
commit
119b3ed11d
7 changed files with 58 additions and 6 deletions
32
systems.cpp
32
systems.cpp
|
@ -460,3 +460,35 @@ std::shared_ptr<sf::Shader> System::sprite_effect(GameLevel &level, DinkyECS::En
|
|||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
DinkyECS::Entity System::spawn_item(GameLevel& level, const std::string& name) {
|
||||
Config config("assets/items.json");
|
||||
auto& item_config = config[name];
|
||||
auto item_id = level.world->entity();
|
||||
level.world->set<InventoryItem>(item_id, {1, item_config});
|
||||
components::configure_entity(*level.world, item_id, item_config["components"]);
|
||||
|
||||
return item_id;
|
||||
}
|
||||
|
||||
bool System::drop_item(GameLevel& level, DinkyECS::Entity item) {
|
||||
auto& world = *level.world;
|
||||
auto& map = *level.map;
|
||||
auto& collision = *level.collision;
|
||||
|
||||
auto player = world.get_the<Player>();
|
||||
auto player_pos = world.get<Position>(player.entity);
|
||||
|
||||
// doesn't compass already avoid walls?
|
||||
for(matrix::box it{map.walls(), player_pos.location.x, player_pos.location.y, 1}; it.next();) {
|
||||
Position pos{it.x, it.y};
|
||||
if(map.can_move(pos.location) && !collision.occupied(pos.location)) {
|
||||
world.set<Position>(item, pos);
|
||||
collision.insert(pos.location, item);
|
||||
level.world->send<Events::GUI>(Events::GUI::ENEMY_SPAWN, item, {});
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue