feat: implemented game over through gamemode

This commit is contained in:
Sara 2024-05-21 12:59:42 +02:00
parent b06fdfb1cf
commit 1cfa06e5d1
3 changed files with 25 additions and 0 deletions

View file

@ -1,5 +1,8 @@
#include "rally_rush_game_mode.hpp"
#include "godot_cpp/classes/resource_loader.hpp"
#include "utils/game_root.hpp"
#include "utils/godot_macros.h"
#include "utils/level.hpp"
namespace godot {
void RallyRushGameMode::_bind_methods() {
@ -18,4 +21,18 @@ void RallyRushGameMode::notify_key_found() {
if(num_keys_found == 3)
this->emit_signal("all_keys_found");
}
void RallyRushGameMode::notify_player_death() {
GameRoot3D *root = GameRoot3D::get_singleton();
HashMap<StringName, Level3D*> levels = root->get_levels();
for(KeyValue<StringName, Level3D*> &kvp : levels)
if(kvp.value->is_inside_tree())
kvp.value->queue_free();
root->get_levels().clear();
root->load_level(ResourceLoader::get_singleton()->load("res://game_end_screen.tscn"));
root->reset_game_mode();
}
void RallyRushGameMode::notify_player_escaped() {
}
}

View file

@ -10,6 +10,8 @@ class RallyRushGameMode : public GameMode {
public:
int get_num_found_keys();
void notify_key_found();
void notify_player_death();
void notify_player_escaped();
private:
int num_keys_found{0};
};

View file

@ -1,9 +1,12 @@
#include "register_types.h"
#include "car_physics.hpp"
#include "car_player.hpp"
#include "end_screen.hpp"
#include "game_ui.hpp"
#include "key_pickup.hpp"
#include "menu_ui.hpp"
#include "rally_rush_game_mode.hpp"
#include "turret.hpp"
#include "utils/game_mode.hpp"
#include "utils/game_root.hpp"
#include "utils/game_state.hpp"
@ -34,6 +37,9 @@ void initialize_gdextension_types(ModuleInitializationLevel p_level)
ClassDB::register_class<RallyRushGameMode>();
ClassDB::register_class<KeyPickup>();
ClassDB::register_class<GameUI>();
ClassDB::register_class<MenuUI>();
ClassDB::register_class<EndScreen>();
ClassDB::register_class<Turret>();
}
extern "C"