SQCSimulator2023/SQCSim-common/bullet.cpp

45 lines
1.1 KiB
C++
Raw Normal View History

2023-09-18 15:56:17 -04:00
#include "bullet.h"
#include "world.h"
2023-09-29 17:02:57 -04:00
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) {}
2023-09-18 15:56:17 -04:00
Bullet::~Bullet() {}
2023-10-16 12:02:37 -04:00
bool Bullet::Update(World* world, float elapsedtime, int perframe) {
int max = 100 / perframe;
for (int x = 0; x < max; ++x) {
2023-09-18 15:56:17 -04:00
m_currentpos += m_velocity * elapsedtime;
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;
}
2023-09-29 12:04:08 -04:00
2023-10-16 12:02:37 -04:00
Vector3f Bullet::getPos() const {
2023-09-29 12:04:08 -04:00
return m_currentpos;
}
2023-09-29 17:02:57 -04:00
2023-10-16 12:02:37 -04:00
Vector3f Bullet::getVel() const {
return m_velocity;
}
2023-09-29 17:02:57 -04:00
uint64_t Bullet::getTeamID(){
return m_tid;
}