From 6d07285f430af00bdf061fe1d5c42fe046489a21 Mon Sep 17 00:00:00 2001 From: MarcEricMartel Date: Mon, 18 Dec 2023 14:50:18 -0500 Subject: [PATCH] Test pickup --- SQCSim-common/player.cpp | 6 ++++-- SQCSim-common/player.h | 2 +- SQCSim2021/engine.cpp | 17 +++++++++++++++-- SQCSim2021/engine.h | 1 + 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/SQCSim-common/player.cpp b/SQCSim-common/player.cpp index ac3e0f0..4f4a01f 100644 --- a/SQCSim-common/player.cpp +++ b/SQCSim-common/player.cpp @@ -196,19 +196,21 @@ void Player::ApplyTransformation(Transformation& transformation, bool rel, bool if (rel) transformation.ApplyTranslation(-GetPOV()); } -void Player::TakeBooster(std::unordered_map booster_table, float elapsedtime) +uint64_t Player::TakeBooster(std::unordered_map booster_table, float elapsedtime) { + uint64_t boostid = 0; Vector3f playerpos = GetPosition(); for (auto& [key, booster]: booster_table) { Vector3f pos = booster->GetPosition(); if (booster->GetAvailability() && abs(playerpos.x - pos.x) <= 0.5f && abs(playerpos.y - pos.y) <= 1.0f && abs(playerpos.z - pos.z) <= 0.5f) { - std::cout << "booster got" << std::endl; + boostid = booster->GetId(); GetBooster(booster->GetType(), elapsedtime); booster->SetAvailability(false); break; } } + return boostid; } void Player::GetBooster(BOOST_TYPE boosttype, float elapsedtime) diff --git a/SQCSim-common/player.h b/SQCSim-common/player.h index fdc3853..2754b35 100644 --- a/SQCSim-common/player.h +++ b/SQCSim-common/player.h @@ -23,7 +23,7 @@ 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, std::unordered_map booster_table); - void TakeBooster(std::unordered_map booster_table, float elapsedTime); + uint64_t TakeBooster(std::unordered_map 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; diff --git a/SQCSim2021/engine.cpp b/SQCSim2021/engine.cpp index f3d8076..d3bf98f 100644 --- a/SQCSim2021/engine.cpp +++ b/SQCSim2021/engine.cpp @@ -1343,7 +1343,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, m_boosters); + 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); switch (snd) { case Player::Sound::STEP: if (leftright) @@ -1361,6 +1361,9 @@ void Engine::Render(float elapsedTime) { // son vecteur de velocite (pour l'effet Doppler) pollTime = 0; } + uint64_t boostid = m_player.TakeBooster(m_boosters, elapsedTime); + + m_boost_manifest.insert(boostid); m_player.ApplyTransformation(all); @@ -1511,7 +1514,17 @@ void Engine::Render(float elapsedTime) { if (Deserialize(&pmod, pck, &bsize)) { if (m_boosters.count(pmod.id)) { Booster* boost = m_boosters.at(pmod.id); - std::cout << "Ramassé booster selon serveur " << (pmod.boost.damage ? "damage" : "") << (pmod.boost.hp ? "heal" : "") << (pmod.boost.invincible ? "invincible" : ""); + if (m_boost_manifest.count(boost->GetId())) { + std::string str = "Picked up "; + if (pmod.boost.damage) + str.append("Damage Booster"); + else if (pmod.boost.hp) + str.append("Healing"); + else if (pmod.boost.invincible) + str.append("Invincibility"); + else break; + SystemNotification(str); + } boost->SetAvailability(pmod.available); } else { diff --git a/SQCSim2021/engine.h b/SQCSim2021/engine.h index b00994e..5045143 100644 --- a/SQCSim2021/engine.h +++ b/SQCSim2021/engine.h @@ -259,6 +259,7 @@ private: netprot::Buffer m_buf, m_bufout; netprot::ChunkMod* m_chunkmod = nullptr; std::unordered_map m_boosters; + std::set m_boost_manifest; std::unordered_map m_syncs; std::string m_messageNotification = "";