diff --git a/game_root.cpp b/game_root.cpp index 163d5ad..e4522d5 100644 --- a/game_root.cpp +++ b/game_root.cpp @@ -185,11 +185,17 @@ Level3D *GameRoot3D::load_level_at(Ref level, Transform3D at) { this->levels.insert(level->get_path(), instance); // store and add to tree at desired transform // if this is the first level containing a game mode currently active use it's gamemode as a prototype - if(this->game_mode.is_null()) { + bool const switch_game_mode{this->game_mode.is_null()}; + if(switch_game_mode) { this->set_game_mode(instance->get_game_mode_prototype()); } this->add_child(instance); instance->set_global_transform(at); + if(switch_game_mode) { + for(KeyValue> const &kvp : this->players) { + this->place_player_at_spawnpoint(kvp.value.second); + } + } return instance; } @@ -209,6 +215,12 @@ void GameRoot3D::unregister_spawn_point(SpawnPoint3D *spawn_point) { this->spawn_points.erase(spawn_point); } +void GameRoot3D::place_player_at_spawnpoint(IPlayer *player) { + if(this->spawn_points.is_empty()) return; + SpawnPoint3D *spawn_point = *this->spawn_points.begin(); + player->spawn_at_position(spawn_point->get_global_transform()); +} + void GameRoot3D::set_first_boot_level(Ref level) { if(level.is_null() || !level.is_valid()) { this->first_boot_level.unref(); diff --git a/game_root.hpp b/game_root.hpp index 84c7243..1ae142c 100644 --- a/game_root.hpp +++ b/game_root.hpp @@ -78,6 +78,7 @@ public: void register_spawn_point(SpawnPoint3D *spawn_point); // remove a spawnpoint so it can't be used to spawn players void unregister_spawn_point(SpawnPoint3D *spawn_point); + void place_player_at_spawnpoint(IPlayer *player); // ----- getter / setters ----- void set_first_boot_level(Ref level);