SQCSimulator2023/SQCSim-common/bullet.cpp
Jonathan Trottier 9b0c4dc594 modif des degats
2023-10-30 14:58:17 -04:00

63 lines
1.4 KiB
C++

#include "bullet.h"
#include "world.h"
Bullet::Bullet(Vector3f pos, Vector3f dir) : m_startpos(pos), m_currentpos(pos), m_velocity(dir) {}
Bullet::Bullet(Vector3f pos, Vector3f dir, uint64_t tid): m_startpos(pos), m_currentpos(pos), m_velocity(dir), m_tid(tid) {}
Bullet::~Bullet() {}
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;
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) {
world->ChangeBlockAtPosition(BTYPE_AIR, m_currentpos);
return true;
}
else if ((m_currentpos - m_startpos).Length() > VIEW_DISTANCE) return true;
}
return false;
}
void Bullet::Transpose(int& x, int& z) {
m_currentpos.x -= x * CHUNK_SIZE_X;
m_currentpos.z -= z * CHUNK_SIZE_Z;
m_startpos.x -= x * CHUNK_SIZE_X;
m_startpos.z -= z * CHUNK_SIZE_Z;
}
Vector3f Bullet::getPos() const {
return m_currentpos;
}
Vector3f Bullet::getVel() const {
return m_velocity;
}
uint64_t Bullet::getTeamID(){
return m_tid;
}