This commit is contained in:
MarcEricMartel 2023-12-09 15:54:06 -05:00
parent 461a8aa11b
commit 46298f8256
3 changed files with 28 additions and 16 deletions

View File

@ -202,8 +202,8 @@ void Server::Run() {
m_conns.erase(key); m_conns.erase(key);
continue; continue;
} }
int x = (rand() % (CHUNK_SIZE_X * WORLD_SIZE_X - 1) - (CHUNK_SIZE_X * WORLD_SIZE_X / 2)) / 4, int x = (rand() % (CHUNK_SIZE_X * WORLD_SIZE_X - 1) - (CHUNK_SIZE_X * WORLD_SIZE_X / 2)) / 8,
y = (rand() % (CHUNK_SIZE_Y * WORLD_SIZE_Y - 1) - (CHUNK_SIZE_Y * WORLD_SIZE_Y / 2)) / 4; y = (rand() % (CHUNK_SIZE_Y * WORLD_SIZE_Y - 1) - (CHUNK_SIZE_Y * WORLD_SIZE_Y / 2)) / 8;
conn->player = new Player(Vector3f(x + .5f, CHUNK_SIZE_Y + 1.8f, y + .5f)); conn->player = new Player(Vector3f(x + .5f, CHUNK_SIZE_Y + 1.8f, y + .5f));
conn->player->m_username = conn->GetName(); conn->player->m_username = conn->GetName();
m_players[key] = conn->player; m_players[key] = conn->player;

View File

@ -29,9 +29,6 @@ Engine::~Engine() {
} }
void Engine::Init() { void Engine::Init() {
uint64_t seed = SEED;
if (m_istarted) if (m_istarted)
return; return;
else m_istarted = true; else m_istarted = true;
@ -39,7 +36,7 @@ void Engine::Init() {
// Objet de skybox avec sa propre texture et son propre shader! // Objet de skybox avec sa propre texture et son propre shader!
m_skybox.Init(0.2f); m_skybox.Init(0.2f);
// Objet de musique! // Objet de musique!
//m_audio.ToggleMusicState(); m_audio.ToggleMusicState();
// Array pour les balles. // Array pour les balles.
for (int x = 0; x < MAX_BULLETS; ++x) { for (int x = 0; x < MAX_BULLETS; ++x) {
@ -47,7 +44,8 @@ void Engine::Init() {
m_whoosh[x] = nullptr; m_whoosh[x] = nullptr;
} }
m_world.SetSeed(seed); m_world.GetChunks().Reset(nullptr);
m_world.SetSeed(SEED);
m_startTime = std::chrono::high_resolution_clock::now(); m_startTime = std::chrono::high_resolution_clock::now();
} }
@ -609,7 +607,8 @@ int Engine::GetOptionsChoice() {
return m_selectedOption; return m_selectedOption;
} }
void Engine::StartMultiplayerGame() { bool Engine::StartMultiplayerGame() {
bool ok = true;
if (!m_conn.Init()) { if (!m_conn.Init()) {
if (!m_conn.Connect(m_serverAddr.c_str(), m_username)) { if (!m_conn.Connect(m_serverAddr.c_str(), m_username)) {
// setup jeu en reseau. // setup jeu en reseau.
@ -620,12 +619,20 @@ void Engine::StartMultiplayerGame() {
for (auto& [key, player] : m_conn.m_players) for (auto& [key, player] : m_conn.m_players)
m_players[key] = new RemotePlayer(player); m_players[key] = new RemotePlayer(player);
//seed = m_conn.getSeed(); //m_world.SetSeed(m_conn.getSeed());
m_world.SetSeed(9370707);
m_networkgame = true; m_networkgame = true;
} }
else std::cout << "Erreur de connexion." << std::endl; else {
std::cout << "Erreur de connexion." << std::endl;
ok = false;
}
} }
else std::cout << "Erreur de creation de socket." << std::endl; else {
std::cout << "Erreur de creation de socket." << std::endl;
ok = false;
}
return ok;
} }
void Engine::DisplayInfo(float elapsedTime, BlockType bloc) { void Engine::DisplayInfo(float elapsedTime, BlockType bloc) {
@ -1228,8 +1235,14 @@ void Engine::Render(float elapsedTime) {
if (m_gamestate == GameState::LOBBY) { if (m_gamestate == GameState::LOBBY) {
DisplayLobbyMenu(elapsedTime); DisplayLobbyMenu(elapsedTime);
if (m_multiReady) { if (m_multiReady) {
StartMultiplayerGame(); if (StartMultiplayerGame()) {
std::cout << "Starting multiplayer game reached" << std::endl; std::cout << "Starting multiplayer game reached" << std::endl;
m_gamestate = GameState::PLAY;
}
else {
std::cout << "Cannot reach server." << std::endl;
m_gamestate = GameState::MAIN_MENU;
}
} }
return; return;
} }
@ -2018,7 +2031,6 @@ void Engine::HandlePlayerInput(float elapsedTime) {
m_currentInputString = ""; m_currentInputString = "";
m_settingServer = false; m_settingServer = false;
m_multiReady = true; m_multiReady = true;
m_gamestate = GameState::PLAY;
} }
} }
m_keyEnter = false; m_keyEnter = false;

View File

@ -46,7 +46,7 @@ private:
int GetFps(float elapsedTime) const; int GetFps(float elapsedTime) const;
int GetCountdown(float elapsedTime); int GetCountdown(float elapsedTime);
int GetOptionsChoice(); int GetOptionsChoice();
void StartMultiplayerGame(); bool StartMultiplayerGame();
bool LoadTexture(Texture& texture, const std::string& filename, bool useMipmaps = true, bool stopOnError = true); bool LoadTexture(Texture& texture, const std::string& filename, bool useMipmaps = true, bool stopOnError = true);
@ -104,7 +104,7 @@ private:
BlockInfo* m_blockinfo[BTYPE_LAST]; BlockInfo* m_blockinfo[BTYPE_LAST];
BoostInfo* m_boostinfo[BTYPE_BOOST_LAST]; BoostInfo* m_boostinfo[BTYPE_BOOST_LAST];
GameState m_gamestate = GameState::PLAY; GameState m_gamestate = GameState::SPLASH;
Shader m_shader01; Shader m_shader01;