@ -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 ;
}