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] 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);