From 570bef266c635c706022502b5dd6b0136047b1d5 Mon Sep 17 00:00:00 2001 From: Frederic Leger <57264593+freeedleger@users.noreply.github.com> Date: Fri, 15 Dec 2023 15:40:13 -0500 Subject: [PATCH] merge conflict --- SQCSim-common/define.h | 1 + SQCSim-common/player.cpp | 32 ++++--- SQCSim-common/player.h | 9 +- SQCSim2021/booster.cpp | 97 ++++++++++++++------- SQCSim2021/booster.h | 13 ++- SQCSim2021/define.h | 2 +- SQCSim2021/engine.cpp | 17 +++- SQCSim2021/engine.h | 179 ++++++++++----------------------------- 8 files changed, 169 insertions(+), 181 deletions(-) diff --git a/SQCSim-common/define.h b/SQCSim-common/define.h index 685bf5d..a4f1b90 100644 --- a/SQCSim-common/define.h +++ b/SQCSim-common/define.h @@ -31,6 +31,7 @@ #define TEXTURE_SIZE 512 #define MAX_BULLETS 512 +#define NB_BOOST 1 #define TIME_SPEED_BOOST 10 //secondes #define TIME_DAMAGE_BOOST 10 //secondes #define TIME_INVINCIBLE_BOOST 4 //secondes diff --git a/SQCSim-common/player.cpp b/SQCSim-common/player.cpp index a0ed584..4845908 100644 --- a/SQCSim-common/player.cpp +++ b/SQCSim-common/player.cpp @@ -68,8 +68,8 @@ Vector3f Player::GetInput(bool front, bool back, bool left, bool right, bool jum delta.x *= .6f; delta.z *= .6f; - if ((jump || shoot ) && !m_airborne) { - delta.y += jump? .32f: shoot? .1f : 0.f; + if ((jump || shoot) && !m_airborne) { + delta.y += jump ? .32f : shoot ? .1f : 0.f; m_airborne = true; } if (boostspeed) @@ -84,7 +84,7 @@ Vector3f Player::GetInput(bool front, bool back, bool left, bool right, bool jum return delta; } -Player::Sound Player::ApplyPhysics(Vector3f input, World* world, float elapsedTime) { +Player::Sound Player::ApplyPhysics(Vector3f input, World* world, float elapsedTime, Booster booster_table[]) { Player::Sound snd = Player::Sound::NOSOUND; static float timing = 0.f; /* Gestion de collisions */ @@ -198,37 +198,49 @@ Player::Sound Player::ApplyPhysics(Vector3f input, World* world, float elapsedTi else isStep = false; m_POV = m_position.y; m_POV += m_airborne ? 0 : (sin(bobbingtime) - 0.5f) * (abs(m_velocity.x) + abs(m_velocity.z)) * .2f; + TakeBooster(booster_table); RemoveBooster(elapsedTime); return snd; } void Player::ApplyTransformation(Transformation& transformation, bool rel, bool rot) const { + transformation.ApplyRotation(-m_rotX, 1, 0, 0); transformation.ApplyRotation(-m_rotY, 0, 1, 0); if (rel) transformation.ApplyTranslation(-GetPOV()); - - } -void Player::GetBooster(Booster boosttype) +void Player::TakeBooster(Booster booster_table[]) { - if (boosttype == SPEED) + for (int i = 0; i < sizeof(booster_table); i++) + { + if (abs((m_position.x + m_position.y + m_position.z) - (booster_table[i].GetPosition().x + booster_table[i].GetPosition().y + booster_table[i].GetPosition().z)) <= 0.5f && booster_table[i].GetAvailability() == true) + { + GetBooster(booster_table[i].GetType()); + booster_table[i].SetAvailability(false); + } + } +} + +void Player::GetBooster(BOOST_TYPE boosttype) +{ + if (boosttype == BTYPE_SPEED) { boostspeed = true; timeboostspeed = 0; } - if (boosttype == HEAL) + if (boosttype == BTYPE_HEAL) { m_hp = 100; } - if (boosttype == DAMAGE) + if (boosttype == BTYPE_DAMAGE) { boostdamage = true; timeboostdamage = 0; } - if (boosttype == INVINCIBLE) + if (boosttype == BTYPE_INVINCIBLE) { boostinvincible = true; boostinvincible = 0; diff --git a/SQCSim-common/player.h b/SQCSim-common/player.h index 8a91cb5..015aea3 100644 --- a/SQCSim-common/player.h +++ b/SQCSim-common/player.h @@ -4,6 +4,8 @@ #include #include "transformation.h" #include "vector3.h" +#include "../SQCSim2021/booster.h" +#include "define.h" class World; @@ -11,7 +13,7 @@ class World; class Player { public: enum Sound { NOSOUND, STEP, FALL }; - enum Booster { SPEED, HEAL, DAMAGE, INVINCIBLE }; + //enum BoosterType { SPEED, HEAL, DAMAGE, INVINCIBLE }; Player(const Vector3f& position, float rotX = 0, float rotY = 0); ~Player(); @@ -19,8 +21,9 @@ public: void TurnLeftRight(float value, float sensitivity); void TurnTopBottom(float value, float sensitivity); Vector3f GetInput(bool front, bool back, bool left, bool right, bool jump, bool dash, float elapsedTime); - Sound ApplyPhysics(Vector3f input, World* world, float elapsedTime); - void GetBooster(Booster boosttype); + Sound ApplyPhysics(Vector3f input, World* world, float elapsedTime, Booster booster_table[]); + void TakeBooster(Booster booster_table[]); + void GetBooster(BOOST_TYPE boosttype); void RemoveBooster(float elapsedtime); void ApplyTransformation(Transformation& transformation, bool rel = true, bool rot = true) const; diff --git a/SQCSim2021/booster.cpp b/SQCSim2021/booster.cpp index 4e7417f..eff683f 100644 --- a/SQCSim2021/booster.cpp +++ b/SQCSim2021/booster.cpp @@ -1,46 +1,81 @@ #include "booster.h" -void Booster::RenderBillboard(const Vector3f pos, TextureAtlas& textureAtlas, Shader& shader, Transformation tran) +Booster::Booster(Vector3f tpos, BOOST_TYPE ttype) +{ + pos = tpos; + type = ttype; +} + +Booster::~Booster() +{ + +} + +Vector3f Booster::GetPosition() +{ + return pos; +} + +BOOST_TYPE Booster::GetType() +{ + return type; +} + +bool Booster::GetAvailability() +{ + return available; +} + +void Booster::SetAvailability(bool value) +{ + available = value; +} + +void Booster::RenderBillboard(TextureAtlas& textureAtlas, Shader& shader, Transformation tran, Player player) { - // - //Vector3f playerToQuad = m_player.GetPosition() - m_position; - //playerToQuad.Normalize(); - //Vector3f targetPosition = m_player.GetPosition() + playerToQuad * 10.0f; - //Matrix4f rotationMatrix; - //rotationMatrix.SetLookAt(m_position, targetPosition, Vector3f(0, 1, 0)); - //glMultMatrixf(rotationMatrix.GetInternalValues()); - float x = pos.x; - float y = pos.y; - float z = pos.z; float width = 1.0f; - float height = 1.0f; - //Pt override les collisions.. a ce point la je sais pas quoi faire + float height = 1.7f; - //Matrix4 mat4 = tran.GetMatrix(); - //mat4 VP = pMatrix * vMatrix; - //Vector3f CameraRight = Vector3f(mat4.Get11(), mat4.Get21(), mat4.Get31()); - //Vector3f CameraUp = Vector3f(mat4.Get12(), mat4.Get22(), mat4.Get32()); + Matrix4 mat4 = tran.GetMatrix(); - //Vector3f v1 = (m_position + CameraRight * 0.5 * width + CameraUp * -0.5 * width); - //Vector3f v2 = (m_position + CameraRight * 0.5 * width + CameraUp * 0.5 * width); - //Vector3f v4 = (m_position + CameraRight * -0.5 * width + CameraUp * -0.5 * width); - //Vector3f v3 = (m_position + CameraRight * -0.5 * width + CameraUp * 0.5 * width); + Vector3f DiffCam = GetPosition() - player.GetPosition(); + Vector3f UpCam = Vector3f(mat4.Get12(), mat4.Get22(), mat4.Get32()); + + Vector3f CrossA = DiffCam.Cross(UpCam); + Vector3f CrossB = DiffCam.Cross(CrossA); + CrossA.Normalize(); + CrossB.Normalize(); + + Vector3f playerPosition = GetPosition() + Vector3f(0.f, 0.f, 0.f); + + + Vector3f v1 = (playerPosition + CrossA * 0.5 * width + CrossB * 0.5 * height); + Vector3f v2 = (playerPosition - CrossA * 0.5 * width + CrossB * 0.5 * height); + Vector3f v3 = (playerPosition + CrossA * 0.5 * width - CrossB * 0.5 * height); + Vector3f v4 = (playerPosition - CrossA * 0.5 * width - CrossB * 0.5 * height); - //tran.ApplyTranslation(m_position); float u, v, w, h; - //glDisable(GL_DEPTH_TEST); + shader.Use(); textureAtlas.Bind(); - textureAtlas.TextureIndexToCoord(8, u, v, w, h); - //glLoadIdentity(); + textureAtlas.TextureIndexToCoord(0, u, v, w, h); + + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glBlendEquation(GL_FUNC_ADD); + glLoadMatrixf(tran.GetMatrix().GetInternalValues()); glBegin(GL_QUADS); - glTexCoord2f(u, v); glVertex3f(x - width / 2., y - height, z); //glVertex3f(v4.x, v4.y, v4.z);//glVertex3f(0, 50, 0); - glTexCoord2f(u + w, v); glVertex3f(x + width / 2., y - height, z); //glVertex3f(v3.x, v3.y, v3.z); //glVertex3f(50,50, 0); - glTexCoord2f(u + w, v + h); glVertex3f(x + width / 2., y, z); //glVertex3f(v2.x, v2.y, v2.z); //glVertex3f(50, 0, 0); - glTexCoord2f(u, v + h); glVertex3f(x - width / 2., y, z); //glVertex3f(v1.x, v1.y, v1.z);// glVertex3f(0, 0, 0); + glTexCoord2f(u, v); glVertex3f(v1.x, v1.y, v1.z); + glTexCoord2f(u + w, v); glVertex3f(v2.x, v2.y, v2.z); + glTexCoord2f(u + w, v + h); glVertex3f(v3.x, v3.y, v3.z); + glTexCoord2f(u, v + h); glVertex3f(v4.x, v4.y, v4.z); + glEnd(); + + glBlendFunc(GL_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR); + glBlendEquation(GL_FUNC_SUBTRACT); + glDisable(GL_BLEND); + shader.Disable(); - //tran.ApplyTranslation(-m_position); - //glEnable(GL_DEPTH_TEST); } diff --git a/SQCSim2021/booster.h b/SQCSim2021/booster.h index e06f2b4..3ab5de4 100644 --- a/SQCSim2021/booster.h +++ b/SQCSim2021/booster.h @@ -5,10 +5,21 @@ #include "shader.h" #include "../SQCSim-common/vector3.h" #include "../SQCSim-common/transformation.h" +#include "../SQCSim-common/player.h" class Booster { public: - void RenderBillboard(const Vector3f pos, TextureAtlas& textureAtlas, Shader& shader, Transformation tran); + Booster(Vector3f tpos, BOOST_TYPE ttype); + ~Booster(); + void RenderBillboard(TextureAtlas& textureAtlas, Shader& shader, Transformation tran, Player player); + Vector3f GetPosition(); + BOOST_TYPE GetType(); + bool GetAvailability(); + void SetAvailability(bool value); +private: + Vector3f pos; + BOOST_TYPE type; + bool available; }; #endif diff --git a/SQCSim2021/define.h b/SQCSim2021/define.h index ca3c4f7..fc5e6f1 100644 --- a/SQCSim2021/define.h +++ b/SQCSim2021/define.h @@ -3,13 +3,13 @@ //#define SFML_STATIC true +#include "../SQCSim-common/define.h" #include #include #include #include #include #include -#include "../SQCSim-common/define.h" #ifdef _WIN32 #include diff --git a/SQCSim2021/engine.cpp b/SQCSim2021/engine.cpp index b00e88e..e32b150 100644 --- a/SQCSim2021/engine.cpp +++ b/SQCSim2021/engine.cpp @@ -1346,7 +1346,7 @@ void Engine::Render(float elapsedTime) { static bool leftright = false; if (pollTime >= .005f) { - Player::Sound snd = m_player.ApplyPhysics(m_player.GetInput(m_keyW, m_keyS, m_keyA, m_keyD, m_keySpace, (bloc == BTYPE_LAST && bulletTime <= 0.f && m_mouseL), elapsedTime), &m_world, elapsedTime); + Player::Sound snd = m_player.ApplyPhysics(m_player.GetInput(m_keyW, m_keyS, m_keyA, m_keyD, m_keySpace, (bloc == BTYPE_LAST && bulletTime <= 0.f && m_mouseL), elapsedTime), &m_world, elapsedTime, booster_table); switch (snd) { case Player::Sound::STEP: if (leftright) @@ -1425,9 +1425,22 @@ void Engine::Render(float elapsedTime) { } } + gameTime += elapsedTime * 10; + + Vector3f dance = Vector3f(sin(gameTime), 0, cos(-gameTime)); + dance.Normalize(); + booster_table[0] = Booster({ 195, 16, 195 }, BTYPE_SPEED); + m_remotePlayer.ApplyPhysics(dance, &m_world, elapsedTime, booster_table); m_world.Update(m_bullets, m_player.GetPosition(), m_blockinfo); m_renderer.UpdateMesh(&m_world, m_player.GetPosition(), m_blockinfo); - glDisable(GL_BLEND); + m_remotePlayer.Render(m_animeAtlas, m_shader01, all, elapsedTime); + booster_table[0].RenderBillboard(m_textureAtlas, m_shader01, all, m_player); + + if (m_isSkybox) m_renderer.RenderWorld(&m_world, m_renderCount, m_player.GetPosition(), m_player.GetDirection(), all, m_shader01, m_textureAtlas); + + //glClear(GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); + //m_remotePlayer.Render(m_textureAtlas, m_shader01, all, elapsedTime); + m_renderer.RenderWorld(&m_world, m_renderCount, m_player.GetPosition(), m_player.GetDirection(), all, m_shader01, m_textureAtlas); glEnable(GL_BLEND); diff --git a/SQCSim2021/engine.h b/SQCSim2021/engine.h index 1a1303a..8e27ef9 100644 --- a/SQCSim2021/engine.h +++ b/SQCSim2021/engine.h @@ -5,7 +5,6 @@ #include #include #include -#include #include "../SQCSim-common/array2d.h" #include "../SQCSim-common/blockinfo.h" #include "../SQCSim-common/boostinfo.h" @@ -25,12 +24,15 @@ #include "renderer.h" #include "remoteplayer.h" #include "booster.h" -#include "settings.h" + class Engine : public OpenglContext { public: Engine(); virtual ~Engine(); + virtual void DrawMenu(); + virtual void DrawPause(); + virtual void DrawSplachScreen(); virtual void Init(); virtual void DeInit(); virtual void LoadResource(); @@ -45,150 +47,90 @@ public: private: int GetFps(float elapsedTime) const; int GetCountdown(float elapsedTime); - int GetOptionsChoice(); - bool StartMultiplayerGame(); bool LoadTexture(Texture& texture, const std::string& filename, bool useMipmaps = true, bool stopOnError = true); - void ChangeResolution(Resolution resolution); void InstantDamage(); void SystemNotification(std::string systemLog); void KillNotification(Player killer, Player killed); - void DisplayNotification(std::string message); + void ProcessNotificationQueue(); void DisplayCrosshair(); void DisplayPovGun(); void DisplayCurrentItem(); void DisplayHud(int timer); - void DrawHud(float elapsedTime, BlockType bloc); void DisplayInfo(float elapsedTime, BlockType bloc); - - void DisplaySplashScreen(); - - void DisplayMainMenu(); - void DrawButtonBackgrounds(float centerX, float centerY, int iterations); - void DrawMainMenuButtons(float centerX, float centerY); - void DrawSingleMultiButtons(float centerX, float centerY); - - void DisplayLobbyMenu(float elapsedTime); - void SetPlayerUsername(float elapsedTime); - void SetServerAddress(float elapsedTime); - - void DisplayPauseMenu(float elapsedTime); - - void DisplayOptionsMenu(); - void DisplayAudioMenu(float centerX, float centerY); - void DisplayGraphicsMenu(float centerX, float centerY); - void DisplayGameplayMenu(float centerX, float centerY); - void DrawSliderBackground(float centerX, float centerY, float minVal, float maxVal, float bottomSideValue, float topSideValue); - void DisplayBarPercentValue(float centerX, float centerY, float posX, float posY, float minVal, float maxVal, float value); - void DrawSlider(float centerX, float centerY, float value, float minVal, float maxVal, float bottomSideValue, float topSideValue); - + void DisplaySingleOrMultiplayerMenu(); + void DrawHud(float elapsedTime, BlockType bloc); void PrintText(float x, float y, const std::string& t, float charSizeMultiplier = 1.0f); - void ProcessNotificationQueue(); - char SimulateKeyboard(unsigned char key); - void HandlePlayerInput(float elapsedTime); - Audio m_audio = Audio(AUDIO_PATH "music01.wav", AUDIO_PATH "menumusic01.wav"); - irrklang::ISound* m_powpow, * m_scream; - irrklang::ISound* m_whoosh[MAX_BULLETS]; - Bullet* m_bullets[MAX_BULLETS]; + - //Menu - Vector3f m_otherplayerpos = Vector3f(999, 999, 999); - World m_world = World(); - Player m_player = Player(Vector3f(.5f, CHUNK_SIZE_Y + 1.8f, .5f)); - - Renderer m_renderer = Renderer(); - - Booster m_booster = Booster(); + Connector m_conn; + Shader m_shader01; BlockInfo* m_blockinfo[BTYPE_LAST]; BoostInfo* m_boostinfo[BTYPE_BOOST_LAST]; - - GameState m_gamestate = GameState::SPLASH; - - Shader m_shader01; - - Skybox m_skybox; - TextureAtlas m_textureAtlas = TextureAtlas(BTYPE_LAST); TextureAtlas m_animeAtlas = TextureAtlas(TYPE_LAST + POS_LAST); - TextureAtlas::TextureIndex texBoostHeal; + World m_world = World(); + Renderer m_renderer = Renderer(); + Booster* booster_table; Texture m_textureCrosshair; Texture m_textureFont; Texture m_textureGun; Texture m_texturePovGun; Texture m_textureSkybox; + Texture m_textureSoloMultiMenu; + Texture m_textureSoloText; + Texture m_textureMultiText; + Texture m_textureTitle; - Texture m_textureLobbyMenu; - Texture m_textureMainMenu; - Texture m_textureOptionsMenu; - Texture m_texturePauseMenu; - Texture m_textureSplashScreen; + TextureAtlas::TextureIndex texBoostHeal; - Texture m_textureHd; - Texture m_textureFhd; - Texture m_textureQhd; - Texture m_textureUhd; + Skybox m_skybox; + Audio m_audio = Audio(AUDIO_PATH "start.wav"); - Texture m_textureLobbyServer; - Texture m_textureLobbyIdentify; - Texture m_textureCheck; - Texture m_textureChecked; + irrklang::ISound* m_powpow, + * m_scream; + irrklang::ISound *m_whoosh[MAX_BULLETS]; - Texture m_texturePauseResume; - Texture m_texturePauseMainMenu; + Player m_player = Player(Vector3f(.5f, CHUNK_SIZE_Y + 1.8f, .5f)); + + Bullet* m_bullets[MAX_BULLETS]; - Texture m_textureOptAudio; - Texture m_textureOptBack; - Texture m_textureOptGameplay; - Texture m_textureOptGraphics; - Texture m_textureOptMain; - Texture m_textureOptMusic; - Texture m_textureOptOptions; - Texture m_textureOptResolution; - Texture m_textureOptSensitivity; - Texture m_textureOptSfx; + std::unordered_map m_players; + netprot::Buffer m_buf, m_bufout; + std::chrono::high_resolution_clock::time_point m_startTime; - Texture m_textureMenuBack; - Texture m_textureMenuMulti; - Texture m_textureMenuOptions; - Texture m_textureMenuPlay; - Texture m_textureMenuQuit; - Texture m_textureMenuSingle; - Texture m_textureMenuTitle; + //Menu + enum class GameState: uint8_t { MAIN_MENU, OPTIONS, QUIT, NEWG, PLAY, PAUSE }; + GameState m_gamestate = GameState::MAIN_MENU; + Texture MenuTitleTexture; + Texture MenuBGTexture; + Texture MenuStartTexture; + Texture MenuQuitTexture; + Texture MenuOptionsTexture; + Texture PauseBGTexture; + Texture SplachScreenTexture; - Settings m_options = Settings(m_audio); - Resolution m_resolution = HD; - - float m_splashTime = 2.0f; float m_scale; float m_time = 0; + float m_time_SplashScreen = 0; float m_titleX = 0; float m_titleY = 0; + float m_Width = 0; + float m_Height = 0; int m_renderCount = 0; int m_countdown = COUNTDOWN; int m_nbReductionChunk = 4; int m_timerReductionChunk = 30; - float m_mainvolume; - float m_musicvolume; - float m_sfxvolume; - float m_sensitivity; - - int m_selectedOption = 0; - - bool m_selectedOptAudioMainBar = false; - bool m_selectedOptAudioMusicBar = false; - bool m_selectedOptAudioSfxBar = false; - bool m_selectedGameplaySensitivityBar = false; - bool m_damage = false; bool m_wireframe = false; @@ -201,58 +143,29 @@ private: bool m_resetcountdown = false; bool m_soloMultiChoiceMade = false; bool m_stopcountdown = false; - - bool m_selectedPlayOptions = false; - bool m_selectedOptions = false; - bool m_selectedQuit = false; - - std::string m_currentInputString; - std::string m_username; - std::string m_serverAddr; - - char m_inputChar = 0; - bool m_invalidChar = false; - bool m_charChanged = false; - bool m_settingUsername = false; - bool m_settingServer = false; - bool m_selectedSinglePlayer = false; - bool m_selectedMultiPlayer = false; - bool m_singleReady = false; - bool m_multiReady = false; - bool m_key1 = false; bool m_key2 = false; + bool m_keyK = false; bool m_keyL = false; bool m_keyW = false; bool m_keyA = false; bool m_keyS = false; bool m_keyD = false; - bool m_keyEnter = false; bool m_keySpace = false; - bool m_keyShift = false; - bool m_keyBackspace = false; - bool m_mouseL = false; bool m_mouseR = false; bool m_mouseC = false; bool m_mouseWU = false; bool m_mouseWD = false; - + //Pour trouver ou est la souris float m_mousemx = 0; float m_mousemy = 0; bool m_networkgame = false; - - Connector m_conn; - std::deque m_chunkmod_manifest; - std::chrono::high_resolution_clock::time_point m_startTime; - std::unordered_map m_players; - netprot::Buffer m_buf, m_bufout; - netprot::ChunkMod* m_chunkmod = nullptr; - - std::unordered_map m_syncs; + netprot::PlayerInfo m_pinfo; + RemotePlayer m_remotePlayer = RemotePlayer(netprot::PlayerInfo(),Vector3f(5.5f, CHUNK_SIZE_Y + 1.8f, 5.5f)); std::string m_messageNotification = ""; };