degats dans bullet

This commit is contained in:
Jonathan Trottier
2023-10-30 14:36:44 -04:00
parent ada9330588
commit 6e75bec25c
5 changed files with 42 additions and 11 deletions

View File

@@ -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;
}