Merge branch 'master' into SQC-15_paquets

This commit is contained in:
MarcEricMartel
2023-11-01 06:27:02 -04:00
6 changed files with 59 additions and 6 deletions

View File

@@ -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<uint64_t, Player*> 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;
}

View File

@@ -3,8 +3,12 @@
#include "define.h"
#include "vector3.h"
#include <map>
#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<uint64_t, Player*> 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__

View File

@@ -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 <20> 1.0f
m_hp = 1.0f; //TODO: Remettre <20> 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<61>ra
static float bobbingtime = 0; // Gestion de la cam<61>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; }

View File

@@ -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: