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