feat: tunnels gamemode can now keep track of player characters

This commit is contained in:
Sara 2024-04-02 22:24:05 +02:00
parent 624989a7cd
commit 1095ee24f8
4 changed files with 28 additions and 4 deletions

View file

@ -1,8 +1,12 @@
#include "tunnels_game_mode.hpp"
#include "godot_cpp/variant/utility_functions.hpp"
#include "character_actor.hpp"
#include "utils/game_root.hpp"
#include "utils/godot_macros.h"
#include <godot_cpp/classes/node.hpp>
#include <godot_cpp/core/object.hpp>
#include <godot_cpp/variant/callable.hpp>
#include <godot_cpp/variant/callable_method_pointer.hpp>
#include <godot_cpp/variant/variant.hpp>
namespace godot {
void TunnelsGameMode::_bind_methods() {
@ -21,4 +25,15 @@ void TunnelsGameMode::on_player_spawned(Node *player) {
TunnelsPlayer *TunnelsGameMode::get_player_instance() const {
return this->player;
}
void TunnelsGameMode::register_player_character(CharacterActor *actor) {
if(!this->player_characters.has(actor)) {
this->player_characters.push_back(actor);
actor->connect("tree_exited", callable_mp(this, &TunnelsGameMode::on_character_destroyed).bind(actor));
}
}
void TunnelsGameMode::on_character_destroyed(CharacterActor *actor) {
this->player_characters.erase(actor);
}
}

View file

@ -1,9 +1,9 @@
#ifndef TUNNELS_GAME_MODE_HPP
#define TUNNELS_GAME_MODE_HPP
#include "tunnels_game_state.hpp"
#include "tunnels_player.hpp"
#include "utils/game_mode.hpp"
#include <godot_cpp/templates/vector.hpp>
namespace godot {
class TunnelsGameMode : public GameMode {
@ -15,8 +15,13 @@ public:
void on_player_spawned(Node *player);
TunnelsPlayer *get_player_instance() const;
void register_player_character(CharacterActor *actor);
void set_manual_character(CharacterActor *actor);
void on_character_destroyed(CharacterActor *actor);
private:
TunnelsPlayer *player{nullptr};
CharacterActor *manual_character{nullptr};
Vector<CharacterActor*> player_characters{};
};
}

View file

@ -22,13 +22,16 @@ void TunnelsPlayer::_bind_methods() {
GDPROPERTY_HINTED(camera_rotation_ramp, Variant::OBJECT, PROPERTY_HINT_RESOURCE_TYPE, "Curve");
}
void TunnelsPlayer::_ready() { GDGAMEONLY();
this->camera = this->get_viewport()->get_camera_3d();
void TunnelsPlayer::_enter_tree() { GDGAMEONLY();
this->initialize_character();
this->camera_rotation_ramp->bake();
this->reticle = this->get_node<Node3D>("Reticle");
}
void TunnelsPlayer::_ready() {
this->camera = this->get_viewport()->get_camera_3d();
}
void TunnelsPlayer::_exit_tree() { GDGAMEONLY();
GameRoot::get_singleton()->remove_player(this->get_player_id());
}

View file

@ -22,6 +22,7 @@ class TunnelsPlayer : public Node3D, public IPlayer {
};
public:
virtual void _enter_tree() override;
virtual void _ready() override;
virtual void _exit_tree() override;
virtual void _process(double delta_time) override;