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() {}
|
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.57f;
|
||||||
for (int x = 0; x < max; ++x) {
|
for (int x = 0; x < max; ++x) {
|
||||||
m_currentpos += m_velocity * elapsedtime;
|
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))
|
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) {
|
||||||
|
@ -3,8 +3,11 @@
|
|||||||
|
|
||||||
#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 +15,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 +26,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__
|
||||||
|
@ -206,15 +206,20 @@ 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(Player playerHit, float hitPoints)
|
|
||||||
|
void Player::InflictDamage(float hitPoints)
|
||||||
{
|
{
|
||||||
|
|
||||||
playerHit.m_hp -= hitPoints;
|
m_hp -= hitPoints;
|
||||||
|
|
||||||
|
|
||||||
if (playerHit.GetHP() <= 0)
|
if (AmIDead())
|
||||||
{ // Quand l'autre joueur est mort.
|
{ // Quand le joueur est mort.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -26,8 +26,8 @@ public:
|
|||||||
float GetHP() const;
|
float GetHP() const;
|
||||||
void Teleport(int& x, int& z);
|
void Teleport(int& x, int& z);
|
||||||
|
|
||||||
|
bool AmIDead();
|
||||||
void InflictDamage(Player playerHit, float hitPoints);
|
void InflictDamage(float hitPoints);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Vector3f m_position;
|
Vector3f m_position;
|
||||||
|
@ -391,7 +391,7 @@ void Engine::UnloadResource() {}
|
|||||||
|
|
||||||
void Engine::InstantDamage()
|
void Engine::InstantDamage()
|
||||||
{
|
{
|
||||||
m_player.InflictDamage(m_player, 0.10f);
|
m_player.InflictDamage(0.10f);
|
||||||
m_damage = false;
|
m_damage = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -991,7 +991,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);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user