added choising spaceship type for multiplayer and some fix in respawn

This commit is contained in:
Vlad committed 2026-02-25 19:17:42 +06:00
1 parent 5216965496
commit 74c2f786a1
6 files changed
+196 -39

No files matched your search

+25 -1
View File
@@ -24,6 +24,7 @@
#endif
#include "network/LocalClient.h"
#include "network/ClientState.h"
namespace ZL
@@ -122,7 +123,11 @@ namespace ZL
spaceGameStarted = 1;
};
menuManager.onMultiplayerPressed = [this]() {
menuManager.onMultiplayerPressed = [this](const std::string& nickname, int shipType) {
Environment::shipState.nickname = nickname;
Environment::shipState.shipType = shipType;
networkClient = std::make_unique<LocalClient>();
#ifdef NETWORK
#ifdef EMSCRIPTEN
networkClient = std::make_unique<WebSocketClientEmscripten>();
@@ -131,7 +136,26 @@ namespace ZL
networkClient = std::make_unique<WebSocketClient>(taskManager.getIOContext());
networkClient->Connect("localhost", 8081);
#endif
#else
networkClient->Connect("", 0);
#endif
#ifndef NETWORK
auto localClient = dynamic_cast<ZL::LocalClient*>(networkClient.get());
if (localClient) {
ZL::ClientState st = Environment::shipState;
st.id = localClient->GetClientId();
localClient->setLocalPlayerState(st);
}
#endif
if (networkClient) {
std::string joinMsg = std::string("JOIN:") + nickname + ":" + std::to_string(shipType);
networkClient->Send(joinMsg);
std::cerr << "Sent JOIN: " << joinMsg << std::endl;
}
lastTickCount = 0;
spaceGameStarted = 1;
};