diff --git a/SQCSim-common/bullet.cpp b/SQCSim-common/bullet.cpp index d5e7f91..09dde11 100644 --- a/SQCSim-common/bullet.cpp +++ b/SQCSim-common/bullet.cpp @@ -7,11 +7,19 @@ 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.057f; for (int x = 0; x < max; ++x) { m_currentpos += m_velocity * elapsedtime; + for (auto& [key, player] : mapPlayer) { + if ((m_currentpos - player->GetPosition()).Length() < .4f) { + player->InflictDamage(damage); + return true; + } + } + if (!world->ChunkAt(m_currentpos)) return true; else if (world->BlockAt(m_currentpos) != BTYPE_AIR) { @@ -20,6 +28,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..cc04737 100644 --- a/SQCSim-common/bullet.h +++ b/SQCSim-common/bullet.h @@ -3,8 +3,12 @@ #include "define.h" #include "vector3.h" +#include +#include "player.h" + class World; +class Player; class Bullet { public: @@ -12,7 +16,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 +27,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 57c2259..790507f 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"; } @@ -167,7 +167,7 @@ Player::Sound Player::ApplyPhysics(Vector3f input, World* world, float elapsedTi m_position += m_velocity; - static float bobbingtime = 0; // Gestion de la caméra + static float bobbingtime = 0; // Gestion de la cam�ra static bool leftright = false; static bool isStep = false; if (bobbingtime <= 360.f) @@ -208,6 +208,26 @@ 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(float hitPoints) +{ + + m_hp -= hitPoints; + + + if (AmIDead()) + { // Quand le joueur est mort. + + + + } +} + uint64_t Player::getId() const { return id; } diff --git a/SQCSim-common/player.h b/SQCSim-common/player.h index 757528b..eedbf74 100644 --- a/SQCSim-common/player.h +++ b/SQCSim-common/player.h @@ -28,6 +28,10 @@ public: float GetHP() const; void Teleport(int& x, int& z); + bool AmIDead(); + void InflictDamage(float hitPoints); + +private: uint64_t getId() const; protected: diff --git a/SQCSim2021/engine.cpp b/SQCSim2021/engine.cpp index 4710e3e..0995fe0 100644 --- a/SQCSim2021/engine.cpp +++ b/SQCSim2021/engine.cpp @@ -421,6 +421,12 @@ void Engine::LoadResource() { void Engine::UnloadResource() {} +void Engine::InstantDamage() +{ + m_player.InflictDamage(0.10f); + m_damage = false; +} + void Engine::SystemNotification(std::string systemLog) { std::string message = ""; @@ -1032,7 +1038,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); @@ -1128,6 +1137,8 @@ void Engine::KeyPressEvent(unsigned char key) { break; case 8: // I - Ignorer break; + case 9: // J - InstantDamage + m_damage = true; case 15: // P - Ignorer break; case 17: // R - Ignorer diff --git a/SQCSim2021/engine.h b/SQCSim2021/engine.h index d0e20fe..928a102 100644 --- a/SQCSim2021/engine.h +++ b/SQCSim2021/engine.h @@ -46,6 +46,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); @@ -86,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 }; @@ -107,6 +108,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;