feat: added get_players and redefined how spawnpoints are stored
parent
a9e33a3781
commit
7bdb5e70eb
|
@ -147,7 +147,8 @@ void GameRoot3D::register_spawn_point(SpawnPoint3D *spawn_point) {
|
||||||
UtilityFunctions::push_error("Duplicate attempt to register spawnpoint '", spawn_point->get_path(), "'");
|
UtilityFunctions::push_error("Duplicate attempt to register spawnpoint '", spawn_point->get_path(), "'");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this->spawn_points.insert(spawn_point);
|
if(!this->spawn_points.has(spawn_point))
|
||||||
|
this->spawn_points.push_back(spawn_point);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameRoot3D::unregister_spawn_point(SpawnPoint3D *spawn_point) {
|
void GameRoot3D::unregister_spawn_point(SpawnPoint3D *spawn_point) {
|
||||||
|
@ -160,7 +161,7 @@ void GameRoot3D::unregister_spawn_point(SpawnPoint3D *spawn_point) {
|
||||||
|
|
||||||
void GameRoot3D::place_player_at_spawnpoint(IPlayer *player) {
|
void GameRoot3D::place_player_at_spawnpoint(IPlayer *player) {
|
||||||
if(this->spawn_points.is_empty()) return;
|
if(this->spawn_points.is_empty()) return;
|
||||||
SpawnPoint3D *spawn_point = *this->spawn_points.begin();
|
SpawnPoint3D *spawn_point = this->spawn_points[rng.randi() % this->spawn_points.size()];
|
||||||
player->spawn_at_position(spawn_point->get_global_transform());
|
player->spawn_at_position(spawn_point->get_global_transform());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -226,6 +227,18 @@ HashMap<StringName, Level3D *> &GameRoot3D::get_levels() {
|
||||||
return this->levels;
|
return this->levels;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IPlayer *GameRoot3D::get_player(uint32_t id) {
|
||||||
|
return this->players[id].second;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector<IPlayer*> GameRoot3D::get_players() {
|
||||||
|
Vector<IPlayer*> players{};
|
||||||
|
for(KeyValue<uint32_t, Pair<PlayerInput*, IPlayer*>> pair : this->players) {
|
||||||
|
players.push_back(pair.value.second);
|
||||||
|
}
|
||||||
|
return players;
|
||||||
|
}
|
||||||
|
|
||||||
void GameRoot3D::grab_singleton() {
|
void GameRoot3D::grab_singleton() {
|
||||||
if(GameRoot3D::has_singleton()) {
|
if(GameRoot3D::has_singleton()) {
|
||||||
this->set_process_mode(PROCESS_MODE_DISABLED);
|
this->set_process_mode(PROCESS_MODE_DISABLED);
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#define GAME_ROOT_HPP
|
#define GAME_ROOT_HPP
|
||||||
|
|
||||||
#include "game_mode.hpp"
|
#include "game_mode.hpp"
|
||||||
|
#include "godot_cpp/classes/random_number_generator.hpp"
|
||||||
#include "level.hpp"
|
#include "level.hpp"
|
||||||
#include <godot_cpp/classes/node.hpp>
|
#include <godot_cpp/classes/node.hpp>
|
||||||
#include <godot_cpp/classes/packed_scene.hpp>
|
#include <godot_cpp/classes/packed_scene.hpp>
|
||||||
|
@ -68,6 +69,8 @@ public:
|
||||||
void set_first_boot_level(Ref<PackedScene> level);
|
void set_first_boot_level(Ref<PackedScene> level);
|
||||||
Ref<PackedScene> get_first_boot_level() const;
|
Ref<PackedScene> get_first_boot_level() const;
|
||||||
HashMap<StringName, Level3D *> &get_levels();
|
HashMap<StringName, Level3D *> &get_levels();
|
||||||
|
IPlayer *get_player(uint32_t id);
|
||||||
|
Vector<IPlayer*> get_players();
|
||||||
protected:
|
protected:
|
||||||
// attempt to make 'this' the current singleton instance
|
// attempt to make 'this' the current singleton instance
|
||||||
void grab_singleton();
|
void grab_singleton();
|
||||||
|
@ -85,8 +88,9 @@ protected:
|
||||||
HashMap<uint32_t, Pair<PlayerInput*, IPlayer*>> players{};
|
HashMap<uint32_t, Pair<PlayerInput*, IPlayer*>> players{};
|
||||||
Ref<GameMode> game_mode{};
|
Ref<GameMode> game_mode{};
|
||||||
private:
|
private:
|
||||||
|
RandomNumberGenerator rng{};
|
||||||
HashMap<StringName, Level3D*> levels{};
|
HashMap<StringName, Level3D*> levels{};
|
||||||
HashSet<SpawnPoint3D*> spawn_points{};
|
Vector<SpawnPoint3D*> spawn_points{};
|
||||||
|
|
||||||
Ref<PackedScene> first_boot_level{};
|
Ref<PackedScene> first_boot_level{};
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue