diff --git a/src/tunnels_game_mode.cpp b/src/tunnels_game_mode.cpp index ff01d14..a222e3a 100644 --- a/src/tunnels_game_mode.cpp +++ b/src/tunnels_game_mode.cpp @@ -1,6 +1,24 @@ #include "tunnels_game_mode.hpp" +#include "godot_cpp/variant/utility_functions.hpp" +#include "utils/game_root.hpp" +#include "utils/godot_macros.h" +#include namespace godot { void TunnelsGameMode::_bind_methods() { +#define CLASSNAME TunnelsGameMode + GDFUNCTION_ARGS(on_player_spawned, "player"); +} + +void TunnelsGameMode::_begin() { + GameRoot::get_singleton()->connect("player_spawned", Callable(this, "on_player_spawned")); +} + +void TunnelsGameMode::on_player_spawned(Node *player) { + this->player = Object::cast_to(player); +} + +TunnelsPlayer *TunnelsGameMode::get_player_instance() const { + return this->player; } } diff --git a/src/tunnels_game_mode.hpp b/src/tunnels_game_mode.hpp index c54ce3b..937942e 100644 --- a/src/tunnels_game_mode.hpp +++ b/src/tunnels_game_mode.hpp @@ -1,6 +1,8 @@ #ifndef TUNNELS_GAME_MODE_HPP #define TUNNELS_GAME_MODE_HPP +#include "tunnels_game_state.hpp" +#include "tunnels_player.hpp" #include "utils/game_mode.hpp" namespace godot { @@ -8,6 +10,13 @@ class TunnelsGameMode : public GameMode { GDCLASS(TunnelsGameMode, GameMode) static void _bind_methods(); public: + virtual void _begin() override; + + void on_player_spawned(Node *player); + + TunnelsPlayer *get_player_instance() const; +private: + TunnelsPlayer *player{nullptr}; }; }