Cleanup de l'objet Bullet
This commit is contained in:
parent
954b976f27
commit
6bea176979
@ -1,10 +1,9 @@
|
||||
#include "bullet.h"
|
||||
#include "world.h"
|
||||
|
||||
Bullet::Bullet(Player& player) {
|
||||
m_startpos = m_currentpos = player.GetPOV() + player.GetDirection();
|
||||
m_velocity = player.GetDirection();
|
||||
}
|
||||
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() {}
|
||||
|
||||
@ -31,6 +30,10 @@ void Bullet::Transpose(int& x, int& z) {
|
||||
m_startpos.z -= z * CHUNK_SIZE_Z;
|
||||
}
|
||||
|
||||
Vector3f& Bullet::getPos() {
|
||||
Vector3f Bullet::getPos() {
|
||||
return m_currentpos;
|
||||
}
|
||||
|
||||
uint64_t Bullet::getTeamID(){
|
||||
return m_tid;
|
||||
}
|
||||
|
@ -1,23 +1,26 @@
|
||||
#ifndef BULLET_H__
|
||||
#define BULLET_H__
|
||||
|
||||
#include "player.h"
|
||||
#include "define.h"
|
||||
#include "vector3.h"
|
||||
|
||||
class World;
|
||||
|
||||
class Bullet {
|
||||
public:
|
||||
Bullet(Player& player);
|
||||
Bullet(Vector3f pos, Vector3f dir);
|
||||
Bullet(Vector3f pos, Vector3f dir, uint64_t tid);
|
||||
~Bullet();
|
||||
|
||||
bool Update(World* world, float elapsedtime);
|
||||
void Transpose(int& x, int& z);
|
||||
Vector3f& getPos();
|
||||
Vector3f getPos();
|
||||
uint64_t getTeamID();
|
||||
|
||||
private:
|
||||
Vector3f m_startpos;
|
||||
Vector3f m_currentpos;
|
||||
Vector3f m_velocity;
|
||||
Vector3f m_startpos,
|
||||
m_currentpos,
|
||||
m_velocity;
|
||||
uint64_t m_tid = 0;
|
||||
};
|
||||
|
||||
#endif // BULLET_H__
|
||||
|
@ -20,7 +20,6 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="audio.h" />
|
||||
<ClInclude Include="bullet.h" />
|
||||
<ClInclude Include="chunk.h" />
|
||||
<ClInclude Include="connector.h" />
|
||||
<ClInclude Include="define.h" />
|
||||
@ -38,7 +37,6 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="audio.cpp" />
|
||||
<ClCompile Include="bullet.cpp" />
|
||||
<ClCompile Include="chunk.cpp" />
|
||||
<ClCompile Include="connector.cpp" />
|
||||
<ClCompile Include="engine.cpp" />
|
||||
|
@ -56,9 +56,6 @@
|
||||
<ClInclude Include="tool.h">
|
||||
<Filter>Fichiers d%27en-tête</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="bullet.h">
|
||||
<Filter>Fichiers d%27en-tête</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="chunk.cpp">
|
||||
@ -106,8 +103,5 @@
|
||||
<ClCompile Include="tool.cpp">
|
||||
<Filter>Fichiers sources</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="bullet.cpp">
|
||||
<Filter>Fichiers sources</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
@ -1,32 +0,0 @@
|
||||
#include "bullet.h"
|
||||
#include "world.h"
|
||||
|
||||
Bullet::Bullet(Player& player) {
|
||||
m_startpos = m_currentpos = player.GetPOV() + player.GetDirection();
|
||||
m_velocity = player.GetDirection();
|
||||
}
|
||||
|
||||
Bullet::~Bullet() {}
|
||||
|
||||
bool Bullet::Update(World* world, Transformation& tran, float elapsedtime) {
|
||||
for (int x = 0; x < 1000; ++x) {
|
||||
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;
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
#ifndef BULLET_H__
|
||||
#define BULLET_H__
|
||||
|
||||
#include "audio.h"
|
||||
#include "player.h"
|
||||
#include "vertexbuffer.h"
|
||||
#include "texture.h"
|
||||
|
||||
class World;
|
||||
|
||||
class Bullet {
|
||||
public:
|
||||
Bullet(Player& player);
|
||||
~Bullet();
|
||||
|
||||
bool Update(World* world, Transformation& tran, float elapsedtime);
|
||||
void Transpose(int& x, int& z);
|
||||
|
||||
private:
|
||||
Vector3f m_startpos;
|
||||
Vector3f m_currentpos;
|
||||
Vector3f m_velocity;
|
||||
|
||||
};
|
||||
|
||||
#endif // BULLET_H__
|
||||
|
@ -374,12 +374,12 @@ void Engine::Render(float elapsedTime) {
|
||||
else if (bulletTime <= 0.f) {
|
||||
for (int x = 0; x < MAX_BULLETS; ++x) // Ajouter une balle dans l'array (aussi connu sous le nom de "faire pow pow").
|
||||
if (!m_bullets[x]) {
|
||||
m_bullets[x] = new Bullet(m_player);
|
||||
m_bullets[x] = new Bullet(m_player.GetPOV() + m_player.GetDirection(), m_player.GetDirection());
|
||||
break;
|
||||
}
|
||||
else if (x == MAX_BULLETS - 1) { // S'il y a pas d'espace dans l'array, prendre la place de la première balle de l'array.
|
||||
m_bullets[0]->~Bullet();
|
||||
m_bullets[0] = new Bullet(m_player);
|
||||
m_bullets[0] = new Bullet(m_player.GetPOV() + m_player.GetDirection(), m_player.GetDirection());
|
||||
}
|
||||
bulletTime = .1f;
|
||||
m_audio.Create3DAudioObj(m_powpow, AUDIO_PATH "windowsaccount.wav", m_player.GetPOV(), m_player.GetDirection() * 10, .5f);
|
||||
@ -396,7 +396,7 @@ void Engine::Render(float elapsedTime) {
|
||||
|
||||
for (int x = 0; x < MAX_BULLETS; ++x) // Array de bullets en jeu.
|
||||
if (m_bullets[x])
|
||||
if (m_bullets[x]->Update(&m_world, all, elapsedTime)) {
|
||||
if (m_bullets[x]->Update(&m_world, elapsedTime)) {
|
||||
m_bullets[x]->~Bullet();
|
||||
m_bullets[x] = nullptr;
|
||||
}
|
||||
|
@ -5,8 +5,8 @@
|
||||
#include <cmath>
|
||||
#include "../SQCSim-common/array2d.h"
|
||||
#include "../SQCSim-common/blockinfo.h"
|
||||
#include "../SQCSim-common/bullet.h"
|
||||
#include "define.h"
|
||||
#include "bullet.h"
|
||||
#include "openglcontext.h"
|
||||
#include "texture.h"
|
||||
#include "transformation.h"
|
||||
|
@ -7,7 +7,7 @@
|
||||
#include <thread>
|
||||
#include "../SQCSim-common/vector3.h"
|
||||
#include "../SQCSim-common/array2d.h"
|
||||
#include "bullet.h"
|
||||
#include "../SQCSim-common/bullet.h"
|
||||
#include "define.h"
|
||||
#include "player.h"
|
||||
#include "chunk.h"
|
||||
|
Loading…
Reference in New Issue
Block a user