From b943a268ae6f835b3425350f3c0d117d0e623b47 Mon Sep 17 00:00:00 2001 From: Jonathan Trottier Date: Mon, 23 Oct 2023 15:43:55 -0400 Subject: [PATCH 1/5] barre de vie --- SQCSim-common/player.cpp | 18 +++++++++++++++++- SQCSim-common/player.h | 3 +++ SQCSim2021/engine.cpp | 12 +++++++++++- SQCSim2021/engine.h | 3 +++ 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/SQCSim-common/player.cpp b/SQCSim-common/player.cpp index 9fe810c..c963849 100644 --- a/SQCSim-common/player.cpp +++ b/SQCSim-common/player.cpp @@ -4,7 +4,7 @@ Player::Player(const Vector3f& position, float rotX, float rotY) : m_position(position), m_rotX(rotX), m_rotY(rotY) { m_velocity = Vector3f(0, 0, 0); m_airborne = true; - m_hp = 0.75f; //TODO: Remettre à 1.0f + m_hp = 1.0f; //TODO: Remettre à 1.0f m_username = "Zelda Bee-Bop56"; } @@ -206,3 +206,19 @@ void Player::Teleport(int& x, int& z) { m_position.x -= x * CHUNK_SIZE_X; m_position.z -= z * CHUNK_SIZE_Z; } + +void Player::InflictDamage(Player playerHit, float hitPoints) +{ + + playerHit.m_hp -= hitPoints; + + + if (playerHit.GetHP() <= 0) + { // Quand l'autre joueur est mort. + + + + } + + +} diff --git a/SQCSim-common/player.h b/SQCSim-common/player.h index e439fa2..79e0008 100644 --- a/SQCSim-common/player.h +++ b/SQCSim-common/player.h @@ -26,6 +26,9 @@ public: float GetHP() const; void Teleport(int& x, int& z); + + void InflictDamage(Player playerHit, float hitPoints); + private: Vector3f m_position; Vector3f m_velocity; diff --git a/SQCSim2021/engine.cpp b/SQCSim2021/engine.cpp index f44eb96..f427a29 100644 --- a/SQCSim2021/engine.cpp +++ b/SQCSim2021/engine.cpp @@ -131,6 +131,12 @@ void Engine::LoadResource() { void Engine::UnloadResource() {} +void Engine::InstantDamage() +{ + m_player.InflictDamage(m_player, 0.10f); + m_damage = false; +} + void Engine::SystemNotification(std::string systemLog) { std::string message = ""; @@ -536,7 +542,8 @@ void Engine::Render(float elapsedTime) { m_wrenderer.UpdateWorld(&m_world, m_player.GetPosition(), m_blockinfo); if (m_isSkybox) m_skybox.Render(skybox); - + if (m_damage) + InstantDamage(); ProcessNotificationQueue(); DrawHud(elapsedTime, bloc); @@ -604,6 +611,9 @@ void Engine::KeyPressEvent(unsigned char key) { break; case 8: // I - Ignorer break; + case 9: // J - InstantDamage + m_damage = true; + break; case 17: // R - Ignorer break; case 19: // T - Ignorer diff --git a/SQCSim2021/engine.h b/SQCSim2021/engine.h index fa3a088..e6584eb 100644 --- a/SQCSim2021/engine.h +++ b/SQCSim2021/engine.h @@ -43,6 +43,7 @@ private: bool LoadTexture(Texture& texture, const std::string& filename, bool useMipmaps = true, bool stopOnError = true); + void InstantDamage(); void SystemNotification(std::string systemLog); void KillNotification(Player killer, Player killed); void DisplayNotification(std::string message); @@ -83,6 +84,8 @@ private: int m_renderCount = 0; int m_countdown = COUNTDOWN; + bool m_damage = false; + bool m_wireframe = false; bool m_isSkybox = true; bool m_block = false; From 6e75bec25cd6ca8a1e73f7cd509827933c212823 Mon Sep 17 00:00:00 2001 From: Jonathan Trottier Date: Mon, 30 Oct 2023 14:36:44 -0400 Subject: [PATCH 2/5] degats dans bullet --- SQCSim-common/bullet.cpp | 22 ++++++++++++++++++++-- SQCSim-common/bullet.h | 7 ++++++- SQCSim-common/player.cpp | 13 +++++++++---- SQCSim-common/player.h | 4 ++-- SQCSim2021/engine.cpp | 7 +++++-- 5 files changed, 42 insertions(+), 11 deletions(-) diff --git a/SQCSim-common/bullet.cpp b/SQCSim-common/bullet.cpp index 873879d..b4ccd09 100644 --- a/SQCSim-common/bullet.cpp +++ b/SQCSim-common/bullet.cpp @@ -7,11 +7,29 @@ Bullet::Bullet(Vector3f pos, Vector3f dir, uint64_t tid): m_startpos(pos), m_cur Bullet::~Bullet() {} -bool Bullet::Update(World* world, float elapsedtime, int perframe) { +bool Bullet::Update(World* world, float elapsedtime, int perframe, std::map mapPlayer) { int max = 100 / perframe; + float damage = 0.57f; for (int x = 0; x < max; ++x) { m_currentpos += m_velocity * elapsedtime; + + std::map::iterator it = mapPlayer.begin(); + + while (it != mapPlayer.end()) + { + + Player* player = it->second; + Vector3f playerPos = player->GetPosition(); + if (playerPos == m_currentpos) + { + player->InflictDamage(damage); + return true; + } + it++; + } + + if (!world->ChunkAt(m_currentpos)) return true; else if (world->BlockAt(m_currentpos) != BTYPE_AIR) { @@ -20,7 +38,7 @@ bool Bullet::Update(World* world, float elapsedtime, int perframe) { } else if ((m_currentpos - m_startpos).Length() > VIEW_DISTANCE) return true; } - + return false; } diff --git a/SQCSim-common/bullet.h b/SQCSim-common/bullet.h index 1b5e227..a035290 100644 --- a/SQCSim-common/bullet.h +++ b/SQCSim-common/bullet.h @@ -3,8 +3,11 @@ #include "define.h" #include "vector3.h" +#include +#include "player.h" class World; +class Player; class Bullet { public: @@ -12,7 +15,7 @@ public: Bullet(Vector3f pos, Vector3f dir, uint64_t tid); ~Bullet(); - bool Update(World* world, float elapsedtime, int perframe); + bool Update(World* world, float elapsedtime, int perframe, std::map m_mapPlayer); void Transpose(int& x, int& z); Vector3f getPos() const; Vector3f getVel() const; @@ -23,6 +26,8 @@ private: m_currentpos, m_velocity; uint64_t m_tid = 0; + + }; #endif // BULLET_H__ diff --git a/SQCSim-common/player.cpp b/SQCSim-common/player.cpp index c963849..15e935d 100644 --- a/SQCSim-common/player.cpp +++ b/SQCSim-common/player.cpp @@ -206,15 +206,20 @@ void Player::Teleport(int& x, int& z) { m_position.x -= x * CHUNK_SIZE_X; m_position.z -= z * CHUNK_SIZE_Z; } +bool Player::AmIDead() +{ + return m_hp <= 0; +} -void Player::InflictDamage(Player playerHit, float hitPoints) + +void Player::InflictDamage(float hitPoints) { - playerHit.m_hp -= hitPoints; + m_hp -= hitPoints; - if (playerHit.GetHP() <= 0) - { // Quand l'autre joueur est mort. + if (AmIDead()) + { // Quand le joueur est mort. diff --git a/SQCSim-common/player.h b/SQCSim-common/player.h index 79e0008..59d7776 100644 --- a/SQCSim-common/player.h +++ b/SQCSim-common/player.h @@ -26,8 +26,8 @@ public: float GetHP() const; void Teleport(int& x, int& z); - - void InflictDamage(Player playerHit, float hitPoints); + bool AmIDead(); + void InflictDamage(float hitPoints); private: Vector3f m_position; diff --git a/SQCSim2021/engine.cpp b/SQCSim2021/engine.cpp index e668998..2d741e7 100644 --- a/SQCSim2021/engine.cpp +++ b/SQCSim2021/engine.cpp @@ -391,7 +391,7 @@ void Engine::UnloadResource() {} void Engine::InstantDamage() { - m_player.InflictDamage(m_player, 0.10f); + m_player.InflictDamage(0.10f); m_damage = false; } @@ -991,7 +991,10 @@ void Engine::Render(float elapsedTime) { DrawHud(elapsedTime, bloc); DisplayPovGun(); ProcessNotificationQueue(); - + if (m_damage) + { + InstantDamage(); + } static bool fell = false; if (m_player.GetPosition().y < 1.7f && !fell) { m_audio.Create3DAudioObj(m_scream, AUDIO_PATH "scream.wav", m_player.GetPOV(), m_player.GetVelocity(), false,1.f); From 602bb844281b362ae00e58aae8e98ffdbc57cfe1 Mon Sep 17 00:00:00 2001 From: Jonathan Trottier Date: Mon, 30 Oct 2023 14:56:04 -0400 Subject: [PATCH 3/5] fonctionnel --- SQCSim-common/bullet.h | 1 + SQCSim-common/player.cpp | 4 ++-- SQCSim2021/engine.cpp | 2 +- SQCSim2021/engine.h | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/SQCSim-common/bullet.h b/SQCSim-common/bullet.h index a035290..cc04737 100644 --- a/SQCSim-common/bullet.h +++ b/SQCSim-common/bullet.h @@ -6,6 +6,7 @@ #include #include "player.h" + class World; class Player; diff --git a/SQCSim-common/player.cpp b/SQCSim-common/player.cpp index 5c92653..790507f 100644 --- a/SQCSim-common/player.cpp +++ b/SQCSim-common/player.cpp @@ -219,14 +219,14 @@ void Player::InflictDamage(float hitPoints) m_hp -= hitPoints; - + if (AmIDead()) { // Quand le joueur est mort. } - +} uint64_t Player::getId() const { return id; } diff --git a/SQCSim2021/engine.cpp b/SQCSim2021/engine.cpp index f2ce768..5c2f9f3 100644 --- a/SQCSim2021/engine.cpp +++ b/SQCSim2021/engine.cpp @@ -1009,7 +1009,7 @@ void Engine::Render(float elapsedTime) { for (int x = 0; x < MAX_BULLETS; ++x) { // Array de bullets en jeu. if (m_bullets[x]) { for (int b = 0; b < BULLET_UPDATES_PER_FRAME; ++b) { - if (m_bullets[x]->Update(&m_world, elapsedTime, BULLET_UPDATES_PER_FRAME)) { + if (m_bullets[x]->Update(&m_world, elapsedTime, BULLET_UPDATES_PER_FRAME, m_players)) { m_bullets[x]->~Bullet(); if (m_whoosh[x]) m_whoosh[x]->drop(); diff --git a/SQCSim2021/engine.h b/SQCSim2021/engine.h index 888d696..928a102 100644 --- a/SQCSim2021/engine.h +++ b/SQCSim2021/engine.h @@ -87,7 +87,7 @@ private: Bullet* m_bullets[MAX_BULLETS]; - std::map m_players; + std::map m_players; //Menu enum class GameState: uint8_t { MAIN_MENU, OPTIONS, QUIT, NEWG, PLAY }; From 9b0c4dc594836eb567d0f355d07b801e46c90771 Mon Sep 17 00:00:00 2001 From: Jonathan Trottier Date: Mon, 30 Oct 2023 14:58:17 -0400 Subject: [PATCH 4/5] modif des degats --- SQCSim-common/bullet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SQCSim-common/bullet.cpp b/SQCSim-common/bullet.cpp index b4ccd09..d59d635 100644 --- a/SQCSim-common/bullet.cpp +++ b/SQCSim-common/bullet.cpp @@ -9,7 +9,7 @@ Bullet::~Bullet() {} bool Bullet::Update(World* world, float elapsedtime, int perframe, std::map mapPlayer) { int max = 100 / perframe; - float damage = 0.57f; + float damage = 0.057f; for (int x = 0; x < max; ++x) { m_currentpos += m_velocity * elapsedtime; From 2a4a5e13cc9430eb9485bbfcd86af67385a63485 Mon Sep 17 00:00:00 2001 From: MarcEricMartel Date: Mon, 30 Oct 2023 15:42:02 -0400 Subject: [PATCH 5/5] Correction pour pr20 --- SQCSim-common/bullet.cpp | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/SQCSim-common/bullet.cpp b/SQCSim-common/bullet.cpp index d59d635..09dde11 100644 --- a/SQCSim-common/bullet.cpp +++ b/SQCSim-common/bullet.cpp @@ -13,22 +13,12 @@ bool Bullet::Update(World* world, float elapsedtime, int perframe, std::map::iterator it = mapPlayer.begin(); - - while (it != mapPlayer.end()) - { - - Player* player = it->second; - Vector3f playerPos = player->GetPosition(); - if (playerPos == m_currentpos) - { + for (auto& [key, player] : mapPlayer) { + if ((m_currentpos - player->GetPosition()).Length() < .4f) { player->InflictDamage(damage); return true; } - it++; } - if (!world->ChunkAt(m_currentpos)) return true;