Push tin toé
This commit is contained in:
parent
bc5c28a373
commit
63d8a62429
@ -39,6 +39,7 @@
|
||||
enum GameState {
|
||||
MAIN_MENU,
|
||||
SPLASH,
|
||||
LOBBY,
|
||||
OPTIONS,
|
||||
QUIT,
|
||||
PLAY,
|
||||
|
@ -70,61 +70,12 @@ void Engine::Init() {
|
||||
m_whoosh[x] = nullptr;
|
||||
}
|
||||
|
||||
char* ch = new char[2];
|
||||
|
||||
std::cout << "Jouer en ligne? [o/N] ";
|
||||
std::cin.getline(ch, 2);
|
||||
std::cout << std::endl;
|
||||
|
||||
if (*ch == 'o' || *ch == 'O') {
|
||||
char* input = new char[32];
|
||||
std::string playname, srvname;
|
||||
|
||||
while (playname.size() < 1) {
|
||||
std::cout << "Veuillez entrer un nom de joueur: ";
|
||||
std::cin.getline(input, 32);
|
||||
std::cout << std::endl;
|
||||
playname = input;
|
||||
if (playname.size() < 1 || playname.size() > 32)
|
||||
std::puts("Nom invalide.");
|
||||
}
|
||||
while (srvname.size() < 1) {
|
||||
std::cout << "Veuillez entrer une adresse de serveur: ";
|
||||
std::cin.getline(input, 32);
|
||||
std::cout << std::endl;
|
||||
srvname = input;
|
||||
if (srvname.size() < 1 || srvname.size() > 32)
|
||||
std::puts("Adresse serveur invalide.");
|
||||
}
|
||||
delete[] input;
|
||||
|
||||
if (!m_conn.Init()) {
|
||||
if (!m_conn.Connect(srvname.c_str(), playname)) {
|
||||
// setup jeu en reseau.
|
||||
std::cout << "ID recu du serveur: " << std::to_string(m_conn.getId()) << "!" << std::endl;
|
||||
std::cout << "Seed recu du serveur: " << std::to_string(m_conn.getSeed()) << "!" << std::endl;
|
||||
m_player = Player(m_conn.getOrigin().position);
|
||||
|
||||
for (auto& [key, player] : m_conn.m_players)
|
||||
m_players[key] = new RemotePlayer(player);
|
||||
|
||||
seed = m_conn.getSeed();
|
||||
m_networkgame = true;
|
||||
}
|
||||
else std::cout << "Erreur de connexion." << std::endl;
|
||||
}
|
||||
else std::cout << "Erreur de creation de socket." << std::endl;
|
||||
}
|
||||
delete[] ch;
|
||||
|
||||
m_world.SetSeed(seed);
|
||||
|
||||
// Init Chunks
|
||||
m_world.GetChunks().Reset(nullptr);
|
||||
|
||||
m_startTime = std::chrono::high_resolution_clock::now();
|
||||
|
||||
m_remotePlayer.SetPosition(Vector3f(.5, CHUNK_SIZE_Y + 10., .5));
|
||||
}
|
||||
|
||||
void Engine::DeInit() {}
|
||||
@ -136,8 +87,9 @@ void Engine::LoadResource() {
|
||||
LoadTexture(m_textureGun, TEXTURE_PATH "gun01.png", false);
|
||||
LoadTexture(m_texturePovGun, TEXTURE_PATH "GUN.png", false);
|
||||
|
||||
LoadTexture(m_textureLobbyMenu, TEXTURE_PATH "menus/backgrounds/bgLobby.png", false);
|
||||
LoadTexture(m_textureMainMenu, TEXTURE_PATH "menus/backgrounds/bgMainMenu.png", false);
|
||||
LoadTexture(m_texturePauseMenu, TEXTURE_PATH "menus/backgrounds/bgPause.png", false);
|
||||
//LoadTexture(m_texturePauseMenu, TEXTURE_PATH "menus/backgrounds/bgPause.png", false);
|
||||
LoadTexture(m_textureOptionsMenu, TEXTURE_PATH "menus/backgrounds/bgOptions.png", false);
|
||||
LoadTexture(m_textureSplashScreen, TEXTURE_PATH "menus/backgrounds/bgSplash.png", false);
|
||||
|
||||
@ -550,14 +502,10 @@ void Engine::DisplayPovGun() {
|
||||
glLoadIdentity();
|
||||
glTranslated(xTranslation, 0, 0);
|
||||
glBegin(GL_QUADS);
|
||||
glTexCoord2f(0, 0);
|
||||
glVertex2i(0, 0);
|
||||
glTexCoord2f(1, 0);
|
||||
glVertex2i(quadWidth, 0);
|
||||
glTexCoord2f(1, 1);
|
||||
glVertex2i(quadWidth, quadHeight);
|
||||
glTexCoord2f(0, 1);
|
||||
glVertex2i(0, quadHeight);
|
||||
glTexCoord2f(0, 0); glVertex2i(0, 0);
|
||||
glTexCoord2f(1, 0); glVertex2i(quadWidth, 0);
|
||||
glTexCoord2f(1, 1); glVertex2i(quadWidth, quadHeight);
|
||||
glTexCoord2f(0, 1); glVertex2i(0, quadHeight);
|
||||
glEnd();
|
||||
|
||||
// Reset du blend function
|
||||
@ -624,6 +572,60 @@ int Engine::GetOptionsChoice() {
|
||||
return m_selectedOption;
|
||||
}
|
||||
|
||||
void Engine::StartMultiplayerGame() {
|
||||
char* ch = new char[2];
|
||||
|
||||
//std::cout << "Jouer en ligne? [o/N] ";
|
||||
//std::cin.getline(ch, 2);
|
||||
//std::cout << std::endl;
|
||||
|
||||
char* input = new char[32];
|
||||
std::string playname, srvname;
|
||||
|
||||
/*if (*ch == 'o' || *ch == 'O') {
|
||||
char* input = new char[32];
|
||||
std::string playname, srvname;
|
||||
|
||||
while (playname.size() < 1) {
|
||||
std::cout << "Veuillez entrer un nom de joueur: ";
|
||||
std::cin.getline(input, 32);
|
||||
std::cout << std::endl;
|
||||
playname = input;
|
||||
if (playname.size() < 1 || playname.size() > 32)
|
||||
std::puts("Nom invalide.");
|
||||
}
|
||||
while (srvname.size() < 1) {
|
||||
std::cout << "Veuillez entrer une adresse de serveur: ";
|
||||
std::cin.getline(input, 32);
|
||||
std::cout << std::endl;
|
||||
srvname = input;
|
||||
if (srvname.size() < 1 || srvname.size() > 32)
|
||||
std::puts("Adresse serveur invalide.");
|
||||
}
|
||||
delete[] input;
|
||||
|
||||
|
||||
}
|
||||
delete[] ch;*/
|
||||
|
||||
if (!m_conn.Init()) {
|
||||
if (!m_conn.Connect(srvname.c_str(), playname)) {
|
||||
// setup jeu en reseau.
|
||||
std::cout << "ID recu du serveur: " << std::to_string(m_conn.getId()) << "!" << std::endl;
|
||||
std::cout << "Seed recu du serveur: " << std::to_string(m_conn.getSeed()) << "!" << std::endl;
|
||||
m_player = Player(m_conn.getOrigin().position);
|
||||
|
||||
for (auto& [key, player] : m_conn.m_players)
|
||||
m_players[key] = new RemotePlayer(player);
|
||||
|
||||
//seed = m_conn.getSeed();
|
||||
m_networkgame = true;
|
||||
}
|
||||
else std::cout << "Erreur de connexion." << std::endl;
|
||||
}
|
||||
else std::cout << "Erreur de creation de socket." << std::endl;
|
||||
}
|
||||
|
||||
void Engine::DisplayInfo(float elapsedTime, BlockType bloc) {
|
||||
m_textureFont.Bind();
|
||||
std::ostringstream ss;
|
||||
@ -709,15 +711,60 @@ void Engine::DisplaySplashScreen() {
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
void Engine::DisplayPauseMenu() {
|
||||
void Engine::DisplayLobbyMenu() {
|
||||
GLint viewport[4];
|
||||
glGetIntegerv(GL_VIEWPORT, viewport);
|
||||
|
||||
m_texturePauseMenu.Bind();
|
||||
glDisable(GL_STENCIL_TEST);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glBlendEquation(GL_FUNC_ADD);
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPushMatrix();
|
||||
|
||||
glLoadIdentity();
|
||||
glOrtho(0, Width(), 0, Height(), -1, 1);
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPushMatrix();
|
||||
|
||||
m_textureLobbyMenu.Bind();
|
||||
glBegin(GL_QUADS);
|
||||
glTexCoord2f(0, 0); glVertex2i(0, 0);
|
||||
glTexCoord2f(1, 0); glVertex2i(Width(), 0);
|
||||
glTexCoord2f(1, 1); glVertex2i(Width(), Height());
|
||||
glTexCoord2f(0, 1); glVertex2i(0, Height());
|
||||
glEnd();
|
||||
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
|
||||
|
||||
m_textureFont.Bind();
|
||||
std::ostringstream ss;
|
||||
|
||||
|
||||
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
glBegin(GL_QUADS);
|
||||
glTexCoord2f(0, 0); glVertex2i(Width() * 0.6, Height() * 0.425);
|
||||
glTexCoord2f(1, 0); glVertex2i(Width() * 0.95, Height() * 0.425);
|
||||
glTexCoord2f(1, 1); glVertex2i(Width() * 0.95, Height() * 0.475);
|
||||
glTexCoord2f(0, 1); glVertex2i(Width() * 0.6, Height() * 0.475);
|
||||
glEnd();
|
||||
|
||||
glViewport(viewport[0], viewport[1], viewport[2], viewport[3]);
|
||||
|
||||
glEnable(GL_STENCIL_TEST);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPopMatrix();
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
void Engine::DisplayMainMenu() {
|
||||
@ -1155,8 +1202,8 @@ void Engine::Render(float elapsedTime) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_gamestate == GameState::PAUSE) {
|
||||
DisplayPauseMenu();
|
||||
if (m_gamestate == GameState::LOBBY) {
|
||||
DisplayLobbyMenu();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1697,7 +1744,8 @@ void Engine::MousePressEvent(const MOUSE_BUTTON& button, int x, int y) {
|
||||
}
|
||||
else if (x > leftButton && x < rightButton && y > bottomSecond && y < topSecond) {
|
||||
if (m_selectedPlayOptions) {
|
||||
m_gamestate = GameState::PLAY;
|
||||
m_gamestate = GameState::LOBBY;
|
||||
StartMultiplayerGame();
|
||||
}
|
||||
else {
|
||||
m_gamestate = GameState::OPTIONS;
|
||||
|
@ -45,6 +45,7 @@ private:
|
||||
int GetFps(float elapsedTime) const;
|
||||
int GetCountdown(float elapsedTime);
|
||||
int GetOptionsChoice();
|
||||
void StartMultiplayerGame();
|
||||
|
||||
bool LoadTexture(Texture& texture, const std::string& filename, bool useMipmaps = true, bool stopOnError = true);
|
||||
|
||||
@ -61,7 +62,7 @@ private:
|
||||
void DisplayInfo(float elapsedTime, BlockType bloc);
|
||||
|
||||
void DisplaySplashScreen();
|
||||
void DisplayPauseMenu();
|
||||
void DisplayLobbyMenu();
|
||||
|
||||
void DisplayMainMenu();
|
||||
void DrawButtonBackgrounds(float centerX, float centerY, int iterations);
|
||||
@ -122,6 +123,7 @@ private:
|
||||
Texture m_texturePovGun;
|
||||
Texture m_textureSkybox;
|
||||
|
||||
Texture m_textureLobbyMenu;
|
||||
Texture m_textureMainMenu;
|
||||
Texture m_textureOptionsMenu;
|
||||
Texture m_texturePauseMenu;
|
||||
|
BIN
SQCSim2021/media/textures/menus/backgrounds/bgLobby.png
Normal file
BIN
SQCSim2021/media/textures/menus/backgrounds/bgLobby.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 505 KiB |
1893
enc_temp_folder/b3c3cb753ef72fdaf31cb22525389b8/engine.cpp
Normal file
1893
enc_temp_folder/b3c3cb753ef72fdaf31cb22525389b8/engine.cpp
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user