This commit is contained in:
Vladislav Khorev committed 2026-02-05 10:43:24 +03:00
commit c49c4626d0
7 files changed
+570 -172

No files matched your search

+79
View File
@@ -1039,11 +1039,16 @@ namespace ZL
if (!uiGameOverShown) {
if (uiManager.pushMenuFromFile("resources/config/game_over.json", this->renderer, CONST_ZIP_FILE)) {
uiManager.setButtonCallback("restartButton", [this](const std::string& name) {
std::string respawnMsg = "RESPAWN:" + std::to_string(networkClient->GetClientId());
networkClient->Send(respawnMsg);
this->shipAlive = true;
this->gameOver = false;
this->uiGameOverShown = false;
this->showExplosion = false;
this->explosionEmitter.setEmissionPoints(std::vector<Vector3f>());
this->deadRemotePlayers.clear();
Environment::shipState.position = Vector3f{ 0, 0, 45000.f };
Environment::shipState.velocity = 0.0f;
@@ -1434,6 +1439,80 @@ namespace ZL
}
}*/
}
// Обработка событий смерти, присланных сервером
auto deaths = networkClient->getPendingDeaths();
if (!deaths.empty()) {
int localId = networkClient->GetClientId();
std::cout << "Client: Received " << deaths.size() << " death events" << std::endl;
for (const auto& d : deaths) {
std::cout << "Client: Processing death - target=" << d.targetId
<< ", killer=" << d.killerId << ", pos=("
<< d.position.x() << ", " << d.position.y() << ", " << d.position.z() << ")" << std::endl;
showExplosion = true;
explosionEmitter.setUseWorldSpace(true);
explosionEmitter.setEmissionPoints(std::vector<Vector3f>{ d.position });
explosionEmitter.emit();
lastExplosionTime = SDL_GetTicks64();
std::cout << "Client: Explosion emitted at (" << d.position.x() << ", "
<< d.position.y() << ", " << d.position.z() << ")" << std::endl;
if (d.targetId == localId) {
std::cout << "Client: Local ship destroyed!" << std::endl;
shipAlive = false;
gameOver = true;
Environment::shipState.velocity = 0.0f;
if (!uiGameOverShown) {
if (uiManager.pushMenuFromFile("resources/config/game_over.json",
this->renderer, CONST_ZIP_FILE)) {
uiManager.setButtonCallback("restartButton", [this](const std::string& name) {
std::cout << "Client: Restart button clicked, sending RESPAWN" << std::endl;
std::string respawnMsg = "RESPAWN:" + std::to_string(networkClient->GetClientId());
networkClient->Send(respawnMsg);
this->shipAlive = true;
this->gameOver = false;
this->uiGameOverShown = false;
this->showExplosion = false;
this->explosionEmitter.setEmissionPoints(std::vector<Vector3f>());
this->deadRemotePlayers.clear();
Environment::shipState.position = Vector3f{ 0, 0, 45000.f };
Environment::shipState.velocity = 0.0f;
Environment::shipState.rotation = Eigen::Matrix3f::Identity();
Environment::inverseShipMatrix = Eigen::Matrix3f::Identity();
Environment::zoom = DEFAULT_ZOOM;
Environment::tapDownHold = false;
uiManager.popMenu();
std::cerr << "Game restarted\n";
});
uiManager.setButtonCallback("gameOverExitButton", [this](const std::string& name) {
Environment::exitGameLoop = true;
});
uiGameOverShown = true;
}
}
}
else {
deadRemotePlayers.insert(d.targetId);
std::cout << "Marked remote player " << d.targetId << " as dead" << std::endl;
}
}
}
auto respawns = networkClient->getPendingRespawns();
if (!respawns.empty()) {
for (const auto& respawnId : respawns) {
deadRemotePlayers.erase(respawnId);
std::cout << "Client: Remote player " << respawnId << " respawned, removed from dead list" << std::endl;
}
}
}
}