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 1/3] 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 = ""; }; From 2364fb9c1f718acc0407dc5cb96887194064f3bc Mon Sep 17 00:00:00 2001 From: Frederic Leger <57264593+freeedleger@users.noreply.github.com> Date: Fri, 15 Dec 2023 23:02:20 -0500 Subject: [PATCH 2/3] booster quasi fonctionnel affichage seulement visible a travers un autre booster. ne se ramasse pas encore. --- SQCSim-common/SQCSim-common.vcxproj | 2 + SQCSim-common/SQCSim-common.vcxproj.filters | 6 + SQCSim-common/booster.cpp | 38 ++++ {SQCSim2021 => SQCSim-common}/booster.h | 9 +- SQCSim-common/define.h | 2 +- SQCSim-common/player.cpp | 3 +- SQCSim-common/player.h | 2 +- SQCSim2021/SQCSim2021.vcxproj | 2 - SQCSim2021/SQCSim2021.vcxproj.filters | 6 - SQCSim2021/booster.cpp | 81 -------- SQCSim2021/define.h | 2 +- SQCSim2021/engine.cpp | 36 ++-- SQCSim2021/engine.h | 194 +++++++++++++++----- SQCSim2021/renderer.cpp | 92 +++++++--- SQCSim2021/renderer.h | 2 +- 15 files changed, 285 insertions(+), 192 deletions(-) create mode 100644 SQCSim-common/booster.cpp rename {SQCSim2021 => SQCSim-common}/booster.h (53%) delete mode 100644 SQCSim2021/booster.cpp diff --git a/SQCSim-common/SQCSim-common.vcxproj b/SQCSim-common/SQCSim-common.vcxproj index c618082..c762f1d 100644 --- a/SQCSim-common/SQCSim-common.vcxproj +++ b/SQCSim-common/SQCSim-common.vcxproj @@ -131,6 +131,7 @@ + @@ -147,6 +148,7 @@ + diff --git a/SQCSim-common/SQCSim-common.vcxproj.filters b/SQCSim-common/SQCSim-common.vcxproj.filters index 45814cf..22804b4 100644 --- a/SQCSim-common/SQCSim-common.vcxproj.filters +++ b/SQCSim-common/SQCSim-common.vcxproj.filters @@ -54,6 +54,9 @@ Fichiers d%27en-tête + + Fichiers d%27en-tête + Fichiers d%27en-tête @@ -83,6 +86,9 @@ Fichiers sources + + Fichiers sources + Fichiers sources diff --git a/SQCSim-common/booster.cpp b/SQCSim-common/booster.cpp new file mode 100644 index 0000000..677a28d --- /dev/null +++ b/SQCSim-common/booster.cpp @@ -0,0 +1,38 @@ +#include "booster.h" + +Booster::Booster() +{ +} + +Booster::Booster(Vector3f tpos, BOOST_TYPE ttype) +{ + pos = tpos; + type = ttype; + available = true; +} + +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; +} + diff --git a/SQCSim2021/booster.h b/SQCSim-common/booster.h similarity index 53% rename from SQCSim2021/booster.h rename to SQCSim-common/booster.h index 3ab5de4..6bfbed5 100644 --- a/SQCSim2021/booster.h +++ b/SQCSim-common/booster.h @@ -1,18 +1,13 @@ #ifndef BOOSTER_H__ #define BOOSTER_H__ #include "define.h" -#include "textureatlas.h" -#include "shader.h" -#include "../SQCSim-common/vector3.h" -#include "../SQCSim-common/transformation.h" -#include "../SQCSim-common/player.h" - +#include "vector3.h" class Booster { public: + Booster(); Booster(Vector3f tpos, BOOST_TYPE ttype); ~Booster(); - void RenderBillboard(TextureAtlas& textureAtlas, Shader& shader, Transformation tran, Player player); Vector3f GetPosition(); BOOST_TYPE GetType(); bool GetAvailability(); diff --git a/SQCSim-common/define.h b/SQCSim-common/define.h index a4f1b90..4685cc4 100644 --- a/SQCSim-common/define.h +++ b/SQCSim-common/define.h @@ -31,7 +31,7 @@ #define TEXTURE_SIZE 512 #define MAX_BULLETS 512 -#define NB_BOOST 1 +#define NB_BOOST 2 #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 4845908..b22a5d2 100644 --- a/SQCSim-common/player.cpp +++ b/SQCSim-common/player.cpp @@ -216,7 +216,8 @@ void Player::TakeBooster(Booster booster_table[]) { 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) + Vector3f pos = booster_table[i].GetPosition(); + if (abs((m_position.x + m_position.y + m_position.z) - (pos.x + pos.y +pos.z)) <= 0.5f && booster_table[i].GetAvailability() == true) { GetBooster(booster_table[i].GetType()); booster_table[i].SetAvailability(false); diff --git a/SQCSim-common/player.h b/SQCSim-common/player.h index 015aea3..1b395c2 100644 --- a/SQCSim-common/player.h +++ b/SQCSim-common/player.h @@ -4,7 +4,7 @@ #include #include "transformation.h" #include "vector3.h" -#include "../SQCSim2021/booster.h" +#include "booster.h" #include "define.h" diff --git a/SQCSim2021/SQCSim2021.vcxproj b/SQCSim2021/SQCSim2021.vcxproj index 7d14bc6..b472f23 100644 --- a/SQCSim2021/SQCSim2021.vcxproj +++ b/SQCSim2021/SQCSim2021.vcxproj @@ -20,7 +20,6 @@ - @@ -38,7 +37,6 @@ - diff --git a/SQCSim2021/SQCSim2021.vcxproj.filters b/SQCSim2021/SQCSim2021.vcxproj.filters index 417ba37..ac1e31c 100644 --- a/SQCSim2021/SQCSim2021.vcxproj.filters +++ b/SQCSim2021/SQCSim2021.vcxproj.filters @@ -53,9 +53,6 @@ Fichiers d%27en-tête - - Fichiers d%27en-tête - Fichiers d%27en-tête @@ -103,9 +100,6 @@ Fichiers sources - - Fichiers sources - Fichiers sources diff --git a/SQCSim2021/booster.cpp b/SQCSim2021/booster.cpp deleted file mode 100644 index eff683f..0000000 --- a/SQCSim2021/booster.cpp +++ /dev/null @@ -1,81 +0,0 @@ -#include "booster.h" - -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) -{ - float width = 1.0f; - float height = 1.7f; - - Matrix4 mat4 = tran.GetMatrix(); - - 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); - - float u, v, w, h; - - shader.Use(); - textureAtlas.Bind(); - 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(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(); -} diff --git a/SQCSim2021/define.h b/SQCSim2021/define.h index fc5e6f1..ca3c4f7 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 e32b150..3cc3dbc 100644 --- a/SQCSim2021/engine.cpp +++ b/SQCSim2021/engine.cpp @@ -78,7 +78,6 @@ void Engine::LoadResource() { std::cerr << " ERREUR GLEW : " << glewGetErrorString(glewErr) << std::endl; abort(); } - LoadTexture(m_skybox.GetTexture(), TEXTURE_PATH "skybox.png", true); LoadTexture(m_textureCrosshair, TEXTURE_PATH "cross.bmp", true); LoadTexture(m_textureFont, TEXTURE_PATH "font.bmp", true); @@ -124,15 +123,15 @@ void Engine::LoadResource() { LoadTexture(m_textureMenuQuit, TEXTURE_PATH "menus/buttons/main/mainQuit.png", false); LoadTexture(m_textureMenuSingle, TEXTURE_PATH "menus/buttons/main/mainSingle.png", false); - TextureAtlas::TextureIndex texDirtIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "metal2.png"); - TextureAtlas::TextureIndex texIceIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "metal3.png"); - TextureAtlas::TextureIndex texGrassIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "grass.png"); - TextureAtlas::TextureIndex texMetalIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "dirt.png"); - TextureAtlas::TextureIndex texGreenGrassIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "greengrass.png"); - TextureAtlas::TextureIndex texBoostHeal = m_textureAtlas.AddTexture(BOOSTER_TEXTURE_PATH "BoosterVert.png"); - TextureAtlas::TextureIndex texBoostDmg = m_textureAtlas.AddTexture(BOOSTER_TEXTURE_PATH "BoosterRouge.png"); - TextureAtlas::TextureIndex texBoostSpd = m_textureAtlas.AddTexture(BOOSTER_TEXTURE_PATH "BoosterBleu.png"); - TextureAtlas::TextureIndex texBoostInv = m_textureAtlas.AddTexture(BOOSTER_TEXTURE_PATH "BoosterJaune.png"); + TextureAtlas::TextureIndex texDirtIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "metal2.png"); //0 + TextureAtlas::TextureIndex texIceIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "metal3.png"); //1 + TextureAtlas::TextureIndex texGrassIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "grass.png"); //2 + TextureAtlas::TextureIndex texMetalIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "dirt.png"); //3 + TextureAtlas::TextureIndex texGreenGrassIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "greengrass.png"); //4 + TextureAtlas::TextureIndex texBoostHeal = m_textureAtlas.AddTexture(BOOSTER_TEXTURE_PATH "BoosterVert.png"); //5 + TextureAtlas::TextureIndex texBoostDmg = m_textureAtlas.AddTexture(BOOSTER_TEXTURE_PATH "BoosterRouge.png"); //6 + TextureAtlas::TextureIndex texBoostSpd = m_textureAtlas.AddTexture(BOOSTER_TEXTURE_PATH "BoosterBleu.png"); //7 + TextureAtlas::TextureIndex texBoostInv = m_textureAtlas.AddTexture(BOOSTER_TEXTURE_PATH "BoosterJaune.png"); //8 //AJOUTER LES TEXTURES DANS L'ORDRE DE L'ÉNUM @@ -1326,6 +1325,8 @@ void Engine::Render(float elapsedTime) { static float pollTime = 0; static float bulletTime = 0; static BlockType bloc = 1; + booster_table[0] = Booster({ 215, 15, 195 }, BTYPE_SPEED); + booster_table[1] = Booster({ 213, 15, 195 }, BTYPE_HEAL); if (elapsedTime > 0.1f) return; @@ -1424,17 +1425,14 @@ 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); - m_remotePlayer.Render(m_animeAtlas, m_shader01, all, elapsedTime); - booster_table[0].RenderBillboard(m_textureAtlas, m_shader01, all, m_player); + glDisable(GL_CULL_FACE); + for (Booster booster : booster_table) { + glClear(GL_STENCIL_BUFFER_BIT); + m_renderer.RenderBooster(m_textureAtlas, m_shader01, all, m_player, booster); + } + glEnable(GL_CULL_FACE); if (m_isSkybox) m_renderer.RenderWorld(&m_world, m_renderCount, m_player.GetPosition(), m_player.GetDirection(), all, m_shader01, m_textureAtlas); diff --git a/SQCSim2021/engine.h b/SQCSim2021/engine.h index 8e27ef9..c276348 100644 --- a/SQCSim2021/engine.h +++ b/SQCSim2021/engine.h @@ -5,6 +5,7 @@ #include #include #include +#include #include "../SQCSim-common/array2d.h" #include "../SQCSim-common/blockinfo.h" #include "../SQCSim-common/boostinfo.h" @@ -13,6 +14,7 @@ #include "../SQCSim-common/world.h" #include "../SQCSim-common/transformation.h" #include "../SQCSim-common/player.h" +#include "../SQCSim-common/booster.h" #include "define.h" #include "openglcontext.h" #include "texture.h" @@ -23,16 +25,15 @@ #include "connector.h" #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(); @@ -41,96 +42,159 @@ public: virtual void KeyPressEvent(unsigned char key); virtual void KeyReleaseEvent(unsigned char key); virtual void MouseMoveEvent(int x, int y); - virtual void MousePressEvent(const MOUSE_BUTTON &button, int x, int y); - virtual void MouseReleaseEvent(const MOUSE_BUTTON &button, int x, int y); + virtual void MousePressEvent(const MOUSE_BUTTON& button, int x, int y); + virtual void MouseReleaseEvent(const MOUSE_BUTTON& button, int x, int y); 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 DisplayInfo(float elapsedTime, BlockType bloc); - void DisplaySingleOrMultiplayerMenu(); 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 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); - Connector m_conn; - Shader m_shader01; + World m_world = World(); + Player m_player = Player(Vector3f(.5f, CHUNK_SIZE_Y + 1.8f, .5f)); + + Renderer m_renderer = Renderer(); + + Booster booster_table[NB_BOOST]; 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); - World m_world = World(); - Renderer m_renderer = Renderer(); - Booster* booster_table; + TextureAtlas::TextureIndex texBoostHeal; 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; - TextureAtlas::TextureIndex texBoostHeal; + Texture m_textureLobbyMenu; + Texture m_textureMainMenu; + Texture m_textureOptionsMenu; + Texture m_texturePauseMenu; + Texture m_textureSplashScreen; - Skybox m_skybox; - Audio m_audio = Audio(AUDIO_PATH "start.wav"); + Texture m_textureHd; + Texture m_textureFhd; + Texture m_textureQhd; + Texture m_textureUhd; - irrklang::ISound* m_powpow, - * m_scream; - irrklang::ISound *m_whoosh[MAX_BULLETS]; + Texture m_textureLobbyServer; + Texture m_textureLobbyIdentify; + Texture m_textureCheck; + Texture m_textureChecked; - Player m_player = Player(Vector3f(.5f, CHUNK_SIZE_Y + 1.8f, .5f)); - - Bullet* m_bullets[MAX_BULLETS]; + Texture m_texturePauseResume; + Texture m_texturePauseMainMenu; - std::unordered_map m_players; - netprot::Buffer m_buf, m_bufout; - std::chrono::high_resolution_clock::time_point m_startTime; + 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; - //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; + Texture m_textureMenuBack; + Texture m_textureMenuMulti; + Texture m_textureMenuOptions; + Texture m_textureMenuPlay; + Texture m_textureMenuQuit; + Texture m_textureMenuSingle; + Texture m_textureMenuTitle; + 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; @@ -143,7 +207,26 @@ 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; @@ -153,20 +236,31 @@ private: 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; - netprot::PlayerInfo m_pinfo; - RemotePlayer m_remotePlayer = RemotePlayer(netprot::PlayerInfo(),Vector3f(5.5f, CHUNK_SIZE_Y + 1.8f, 5.5f)); + + 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; std::string m_messageNotification = ""; }; -#endif // ENGINE_H__ +#endif // ENGINE_H__ \ No newline at end of file diff --git a/SQCSim2021/renderer.cpp b/SQCSim2021/renderer.cpp index 3e5fc97..31440a6 100644 --- a/SQCSim2021/renderer.cpp +++ b/SQCSim2021/renderer.cpp @@ -120,7 +120,7 @@ void Renderer::RenderWorld(World* origin, int& rendercount, const Vector3f& play glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); unsigned int sx, sy, cx, cy; - origin->GetScope(sx,sy); + origin->GetScope(sx, sy); for (int index = 0; index < rendercount; ++index) { int chx = (renderManifest[index].x - sx) * CHUNK_SIZE_X, chy = (renderManifest[index].z - sy) * CHUNK_SIZE_Z; @@ -129,9 +129,9 @@ void Renderer::RenderWorld(World* origin, int& rendercount, const Vector3f& play glLoadMatrixf(world.GetMatrix().GetInternalValues()); float blcolor = renderManifest[index].y / (VIEW_DISTANCE / 50.f); glBlendColor(blcolor, blcolor, blcolor, 1.f); - origin->ChunkAt(chx, 1, chy)->GetPosition(cx,cy); + origin->ChunkAt(chx, 1, chy)->GetPosition(cx, cy); if (m_meshes.Get(cx - sx, cy - sy)) - m_meshes.Get(cx - sx, cy -sy)->Render(); + m_meshes.Get(cx - sx, cy - sy)->Render(); world.ApplyTranslation(-chx, 0, -chy); } shader.Disable(); @@ -147,7 +147,7 @@ void Renderer::UpdateMesh(World* origin, const Vector3f& player, BlockInfo* bloc int threads = 0; std::future updateThList[THREADS_UPDATE_CHUNKS]; - unsigned int mx = 0 , my = 0, sx, sy; + unsigned int mx = 0, my = 0, sx, sy; origin->GetScope(sx, sy); @@ -244,27 +244,75 @@ void Renderer::UpdateMesh(World* origin, const Vector3f& player, BlockInfo* bloc } } -void Renderer::RenderBillboard(const Vector3f pos, TextureAtlas textureAtlas, TextureAtlas::TextureIndex idx, Shader& shader, Transformation tran) +void Renderer::RenderBooster(TextureAtlas& textureAtlas, Shader& shader, Transformation tran, Player player, Booster booster) { - //float x = pos.x; - //float y = pos.y; - //float z = pos.z; - //float width = 1.0f; - //float height = 1.0f; + if (booster.GetAvailability() == true) + { + float width = 1.f; + float height = 1.f; - //float u, v, w, h; - //shader.Use(); - //textureAtlas.Bind(); - //textureAtlas.TextureIndexToCoord(idx, u, v, w, h); + Vector3f DiffCam = booster.GetPosition() - player.GetPosition(); + Vector3f UpCam = Vector3f(0.f, 1.f, 0.f); - //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); - //glEnd(); - //shader.Disable(); + Vector3f CrossA = DiffCam.Cross(UpCam); + Vector3f CrossB = DiffCam.Cross(CrossA); + + CrossA.Normalize(); + CrossB.Normalize(); + + Vector3f playerPosition = booster.GetPosition() + Vector3f(0.f, -.75f, 0.f); + + Vector3f v2 = (playerPosition + CrossA * 0.5 * width + CrossB * 0.5 * height); + Vector3f v1 = (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); + + int index; + BOOST_TYPE type = booster.GetType(); + + switch (type) + { + case BTYPE_HEAL: + index = 5; + break; + case BTYPE_DAMAGE: + index = 6; + break; + case BTYPE_SPEED: + index = 7; + break; + case BTYPE_INVINCIBLE: + index = 8; + break; + default: + index = 1; + break; + } + float u, v, w, h; + + shader.Use(); + textureAtlas.Bind(); + textureAtlas.TextureIndexToCoord(index, 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(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(); + } } diff --git a/SQCSim2021/renderer.h b/SQCSim2021/renderer.h index 5a13709..12df11c 100644 --- a/SQCSim2021/renderer.h +++ b/SQCSim2021/renderer.h @@ -29,7 +29,7 @@ public: void UpdateMesh(World* origin, const Vector3f& player, BlockInfo* blockinfo[BTYPE_LAST]); - void RenderBillboard(const Vector3f pos, TextureAtlas textureAtlas, TextureAtlas::TextureIndex idx, Shader& shader, Transformation tran); + void RenderBooster(TextureAtlas& textureAtlas, Shader& shader, Transformation tran, Player player, Booster booster); void RenderWorld(World* origin, int& rendercount, const Vector3f& player_pos, const Vector3f& player_dir, Transformation world, Shader& shader, TextureAtlas& atlas) const; void RenderPlayer(Player* player, Transformation tran) const; From f2c5f8b636f5d5eac0582407ea7374cf0e6cb306 Mon Sep 17 00:00:00 2001 From: Frederic Leger <57264593+freeedleger@users.noreply.github.com> Date: Sat, 16 Dec 2023 14:38:01 -0500 Subject: [PATCH 3/3] booster fonctionnel manque la distribution booster sur la map --- SQCSim-common/define.h | 2 +- SQCSim-common/player.cpp | 22 +++++++++++----------- SQCSim-common/player.h | 10 +++++----- SQCSim2021/engine.cpp | 5 ++--- 4 files changed, 19 insertions(+), 20 deletions(-) diff --git a/SQCSim-common/define.h b/SQCSim-common/define.h index 4685cc4..6524ff1 100644 --- a/SQCSim-common/define.h +++ b/SQCSim-common/define.h @@ -35,7 +35,7 @@ #define TIME_SPEED_BOOST 10 //secondes #define TIME_DAMAGE_BOOST 10 //secondes #define TIME_INVINCIBLE_BOOST 4 //secondes -#define STRENGTH_SPEED_BOOST 10 //Pourcentage +#define STRENGTH_SPEED_BOOST 1000 //Pourcentage #define BULLET_TIME .1 typedef uint8_t BlockType; diff --git a/SQCSim-common/player.cpp b/SQCSim-common/player.cpp index b22a5d2..f5f9a60 100644 --- a/SQCSim-common/player.cpp +++ b/SQCSim-common/player.cpp @@ -198,7 +198,7 @@ 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); + TakeBooster(booster_table, elapsedTime); RemoveBooster(elapsedTime); return snd; } @@ -212,20 +212,22 @@ void Player::ApplyTransformation(Transformation& transformation, bool rel, bool if (rel) transformation.ApplyTranslation(-GetPOV()); } -void Player::TakeBooster(Booster booster_table[]) +void Player::TakeBooster(Booster booster_table[], float elapsedtime) { + Vector3f playerpos = GetPosition(); for (int i = 0; i < sizeof(booster_table); i++) { Vector3f pos = booster_table[i].GetPosition(); - if (abs((m_position.x + m_position.y + m_position.z) - (pos.x + pos.y +pos.z)) <= 0.5f && booster_table[i].GetAvailability() == true) + if (abs(playerpos.x - pos.x) <= 0.5f && abs(playerpos.y - pos.y) <= 1.0f && abs(playerpos.z - pos.z) <= 0.5f && booster_table[i].GetAvailability() == true) { - GetBooster(booster_table[i].GetType()); + GetBooster(booster_table[i].GetType(), elapsedtime); booster_table[i].SetAvailability(false); + break; } } } -void Player::GetBooster(BOOST_TYPE boosttype) +void Player::GetBooster(BOOST_TYPE boosttype, float elapsedtime) { if (boosttype == BTYPE_SPEED) { @@ -234,7 +236,7 @@ void Player::GetBooster(BOOST_TYPE boosttype) } if (boosttype == BTYPE_HEAL) { - m_hp = 100; + m_hp = 1.0f; } if (boosttype == BTYPE_DAMAGE) { @@ -252,19 +254,17 @@ void Player::RemoveBooster(float elapsedtime) if (boostspeed) { timeboostspeed += elapsedtime; - if (timeboostspeed >= TIME_SPEED_BOOST) + if (timeboostspeed >= TIME_SPEED_BOOST && boostspeed == true) boostspeed = false; } if (boostdamage) { - timeboostdamage += elapsedtime; - if (timeboostdamage >= TIME_DAMAGE_BOOST) + if (timeboostdamage >= TIME_DAMAGE_BOOST && boostdamage == true) boostdamage = false; } if (boostinvincible) { - timeboostinvincible += elapsedtime; - if (timeboostinvincible >= TIME_INVINCIBLE_BOOST) + if (timeboostinvincible >= TIME_INVINCIBLE_BOOST && boostinvincible == true) boostinvincible = false; } } diff --git a/SQCSim-common/player.h b/SQCSim-common/player.h index 1b395c2..6db788f 100644 --- a/SQCSim-common/player.h +++ b/SQCSim-common/player.h @@ -22,8 +22,8 @@ public: 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, Booster booster_table[]); - void TakeBooster(Booster booster_table[]); - void GetBooster(BOOST_TYPE boosttype); + void TakeBooster(Booster booster_table[], float elapsedTime); + void GetBooster(BOOST_TYPE boosttype, float elapsedTime); void RemoveBooster(float elapsedtime); void ApplyTransformation(Transformation& transformation, bool rel = true, bool rot = true) const; @@ -72,9 +72,9 @@ protected: float m_hp; bool m_airborne; - bool boostspeed; - bool boostdamage; - bool boostinvincible; + bool boostspeed = false; + bool boostdamage = false; + bool boostinvincible = false; Vector3f InterpolatePosition(const Vector3f& vec1, const Vector3f& vec2, const Timestamp& tim1, const Timestamp& tim2, const Timestamp& now); }; diff --git a/SQCSim2021/engine.cpp b/SQCSim2021/engine.cpp index 3cc3dbc..2fea399 100644 --- a/SQCSim2021/engine.cpp +++ b/SQCSim2021/engine.cpp @@ -1304,6 +1304,8 @@ void Engine::Render(float elapsedTime) { } if (m_gamestate == GameState::PAUSE) { + booster_table[0] = Booster({ 215, 15, 195 }, BTYPE_SPEED); + booster_table[1] = Booster({ 213, 15, 195 }, BTYPE_HEAL); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); @@ -1325,8 +1327,6 @@ void Engine::Render(float elapsedTime) { static float pollTime = 0; static float bulletTime = 0; static BlockType bloc = 1; - booster_table[0] = Booster({ 215, 15, 195 }, BTYPE_SPEED); - booster_table[1] = Booster({ 213, 15, 195 }, BTYPE_HEAL); if (elapsedTime > 0.1f) return; @@ -1429,7 +1429,6 @@ void Engine::Render(float elapsedTime) { m_renderer.UpdateMesh(&m_world, m_player.GetPosition(), m_blockinfo); glDisable(GL_CULL_FACE); for (Booster booster : booster_table) { - glClear(GL_STENCIL_BUFFER_BIT); m_renderer.RenderBooster(m_textureAtlas, m_shader01, all, m_player, booster); } glEnable(GL_CULL_FACE);