degats dans bullet
This commit is contained in:
parent
ada9330588
commit
6e75bec25c
@ -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<uint64_t, Player*> mapPlayer) {
|
||||
int max = 100 / perframe;
|
||||
float damage = 0.57f;
|
||||
for (int x = 0; x < max; ++x) {
|
||||
m_currentpos += m_velocity * elapsedtime;
|
||||
|
||||
|
||||
std::map<uint64_t, Player*>::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;
|
||||
}
|
||||
|
||||
|
@ -3,8 +3,11 @@
|
||||
|
||||
#include "define.h"
|
||||
#include "vector3.h"
|
||||
#include <map>
|
||||
#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<uint64_t, Player*> 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__
|
||||
|
@ -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.
|
||||
|
||||
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user