feat: gameroot will now spawn players using spawn_at_position

stripped
Sara 2024-04-16 11:45:46 +02:00
parent 90d8d626a0
commit d81ad91a88
2 changed files with 14 additions and 1 deletions

View File

@ -185,11 +185,17 @@ Level3D *GameRoot3D::load_level_at(Ref<PackedScene> 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<uint32_t, Pair<PlayerInput *, IPlayer *>> 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<PackedScene> level) {
if(level.is_null() || !level.is_valid()) {
this->first_boot_level.unref();

View File

@ -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<PackedScene> level);