Merge pull request #20 from CegepSTH/SQC-18_Mecanique_de_combat

Sqc 18 mecanique de combat
This commit is contained in:
MarcEricMartel 2023-10-30 15:44:41 -04:00 committed by GitHub
commit 851d5f0c0b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 60 additions and 7 deletions

View File

@ -7,11 +7,19 @@ Bullet::Bullet(Vector3f pos, Vector3f dir, uint64_t tid): m_startpos(pos), m_cur
Bullet::~Bullet() {} Bullet::~Bullet() {}
bool Bullet::Update(World* world, float elapsedtime, int perframe) { bool Bullet::Update(World* world, float elapsedtime, int perframe, std::map<uint64_t, Player*> mapPlayer) {
int max = 100 / perframe; int max = 100 / perframe;
float damage = 0.057f;
for (int x = 0; x < max; ++x) { for (int x = 0; x < max; ++x) {
m_currentpos += m_velocity * elapsedtime; 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)) if (!world->ChunkAt(m_currentpos))
return true; return true;
else if (world->BlockAt(m_currentpos) != BTYPE_AIR) { 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; else if ((m_currentpos - m_startpos).Length() > VIEW_DISTANCE) return true;
} }
return false; return false;
} }

View File

@ -3,8 +3,12 @@
#include "define.h" #include "define.h"
#include "vector3.h" #include "vector3.h"
#include <map>
#include "player.h"
class World; class World;
class Player;
class Bullet { class Bullet {
public: public:
@ -12,7 +16,7 @@ public:
Bullet(Vector3f pos, Vector3f dir, uint64_t tid); Bullet(Vector3f pos, Vector3f dir, uint64_t tid);
~Bullet(); ~Bullet();
bool Update(World* world, float elapsedtime, int perframe); bool Update(World* world, float elapsedtime, int perframe, std::map<uint64_t, Player*> m_mapPlayer);
void Transpose(int& x, int& z); void Transpose(int& x, int& z);
Vector3f getPos() const; Vector3f getPos() const;
Vector3f getVel() const; Vector3f getVel() const;
@ -23,6 +27,8 @@ private:
m_currentpos, m_currentpos,
m_velocity; m_velocity;
uint64_t m_tid = 0; uint64_t m_tid = 0;
}; };
#endif // BULLET_H__ #endif // BULLET_H__

View File

@ -4,7 +4,7 @@
Player::Player(const Vector3f& position, float rotX, float rotY) : m_position(position), m_rotX(rotX), m_rotY(rotY) { 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_velocity = Vector3f(0, 0, 0);
m_airborne = true; m_airborne = true;
m_hp = 0.75f; //TODO: Remettre à 1.0f m_hp = 1.0f; //TODO: Remettre <20> 1.0f
m_username = "Zelda Bee-Bop56"; m_username = "Zelda Bee-Bop56";
} }
@ -167,7 +167,7 @@ Player::Sound Player::ApplyPhysics(Vector3f input, World* world, float elapsedTi
m_position += m_velocity; m_position += m_velocity;
static float bobbingtime = 0; // Gestion de la caméra static float bobbingtime = 0; // Gestion de la cam<EFBFBD>ra
static bool leftright = false; static bool leftright = false;
static bool isStep = false; static bool isStep = false;
if (bobbingtime <= 360.f) if (bobbingtime <= 360.f)
@ -208,6 +208,26 @@ void Player::Teleport(int& x, int& z) {
m_position.x -= x * CHUNK_SIZE_X; m_position.x -= x * CHUNK_SIZE_X;
m_position.z -= z * CHUNK_SIZE_Z; 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; } uint64_t Player::getId() const { return id; }

View File

@ -28,6 +28,10 @@ public:
float GetHP() const; float GetHP() const;
void Teleport(int& x, int& z); void Teleport(int& x, int& z);
bool AmIDead();
void InflictDamage(float hitPoints);
private:
uint64_t getId() const; uint64_t getId() const;
protected: protected:

View File

@ -420,6 +420,12 @@ void Engine::LoadResource() {
void Engine::UnloadResource() {} void Engine::UnloadResource() {}
void Engine::InstantDamage()
{
m_player.InflictDamage(0.10f);
m_damage = false;
}
void Engine::SystemNotification(std::string systemLog) { void Engine::SystemNotification(std::string systemLog) {
std::string message = ""; std::string message = "";
@ -1003,7 +1009,7 @@ void Engine::Render(float elapsedTime) {
for (int x = 0; x < MAX_BULLETS; ++x) { // Array de bullets en jeu. for (int x = 0; x < MAX_BULLETS; ++x) { // Array de bullets en jeu.
if (m_bullets[x]) { if (m_bullets[x]) {
for (int b = 0; b < BULLET_UPDATES_PER_FRAME; ++b) { 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(); m_bullets[x]->~Bullet();
if (m_whoosh[x]) if (m_whoosh[x])
m_whoosh[x]->drop(); m_whoosh[x]->drop();
@ -1031,7 +1037,10 @@ void Engine::Render(float elapsedTime) {
DrawHud(elapsedTime, bloc); DrawHud(elapsedTime, bloc);
DisplayPovGun(); DisplayPovGun();
ProcessNotificationQueue(); ProcessNotificationQueue();
if (m_damage)
{
InstantDamage();
}
static bool fell = false; static bool fell = false;
if (m_player.GetPosition().y < 1.7f && !fell) { 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); m_audio.Create3DAudioObj(m_scream, AUDIO_PATH "scream.wav", m_player.GetPOV(), m_player.GetVelocity(), false,1.f);
@ -1127,6 +1136,8 @@ void Engine::KeyPressEvent(unsigned char key) {
break; break;
case 8: // I - Ignorer case 8: // I - Ignorer
break; break;
case 9: // J - InstantDamage
m_damage = true;
case 15: // P - Ignorer case 15: // P - Ignorer
break; break;
case 17: // R - Ignorer case 17: // R - Ignorer

View File

@ -46,6 +46,7 @@ private:
bool LoadTexture(Texture& texture, const std::string& filename, bool useMipmaps = true, bool stopOnError = true); bool LoadTexture(Texture& texture, const std::string& filename, bool useMipmaps = true, bool stopOnError = true);
void InstantDamage();
void SystemNotification(std::string systemLog); void SystemNotification(std::string systemLog);
void KillNotification(Player killer, Player killed); void KillNotification(Player killer, Player killed);
void DisplayNotification(std::string message); void DisplayNotification(std::string message);
@ -86,7 +87,7 @@ private:
Bullet* m_bullets[MAX_BULLETS]; Bullet* m_bullets[MAX_BULLETS];
std::map<uint64_t, RemotePlayer*> m_players; std::map<uint64_t, Player*> m_players;
//Menu //Menu
enum class GameState: uint8_t { MAIN_MENU, OPTIONS, QUIT, NEWG, PLAY }; enum class GameState: uint8_t { MAIN_MENU, OPTIONS, QUIT, NEWG, PLAY };
@ -107,6 +108,8 @@ private:
int m_renderCount = 0; int m_renderCount = 0;
int m_countdown = COUNTDOWN; int m_countdown = COUNTDOWN;
bool m_damage = false;
bool m_wireframe = false; bool m_wireframe = false;
bool m_isSkybox = true; bool m_isSkybox = true;
bool m_block = false; bool m_block = false;