commit
793da52871
@ -7,8 +7,9 @@ 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) {
|
bool Bullet::Update(World* world, float elapsedtime, int perframe) {
|
||||||
for (int x = 0; x < 1000; ++x) {
|
int max = 100 / perframe;
|
||||||
|
for (int x = 0; x < max; ++x) {
|
||||||
m_currentpos += m_velocity * elapsedtime;
|
m_currentpos += m_velocity * elapsedtime;
|
||||||
|
|
||||||
if (!world->ChunkAt(m_currentpos))
|
if (!world->ChunkAt(m_currentpos))
|
||||||
@ -30,10 +31,14 @@ void Bullet::Transpose(int& x, int& z) {
|
|||||||
m_startpos.z -= z * CHUNK_SIZE_Z;
|
m_startpos.z -= z * CHUNK_SIZE_Z;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3f Bullet::getPos() {
|
Vector3f Bullet::getPos() const {
|
||||||
return m_currentpos;
|
return m_currentpos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Vector3f Bullet::getVel() const {
|
||||||
|
return m_velocity;
|
||||||
|
}
|
||||||
|
|
||||||
uint64_t Bullet::getTeamID(){
|
uint64_t Bullet::getTeamID(){
|
||||||
return m_tid;
|
return m_tid;
|
||||||
}
|
}
|
||||||
|
@ -12,9 +12,10 @@ 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);
|
bool Update(World* world, float elapsedtime, int perframe);
|
||||||
void Transpose(int& x, int& z);
|
void Transpose(int& x, int& z);
|
||||||
Vector3f getPos();
|
Vector3f getPos() const;
|
||||||
|
Vector3f getVel() const;
|
||||||
uint64_t getTeamID();
|
uint64_t getTeamID();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -2,17 +2,17 @@
|
|||||||
|
|
||||||
Audio::Audio() {
|
Audio::Audio() {
|
||||||
m_engine = irrklang::createIrrKlangDevice();
|
m_engine = irrklang::createIrrKlangDevice();
|
||||||
m_engine->setDopplerEffectParameters(1);
|
m_engine->setDopplerEffectParameters(10);
|
||||||
m_engine->setRolloffFactor(1);
|
m_engine->setRolloffFactor(2);
|
||||||
m_engine->setDefault3DSoundMinDistance(1);
|
m_engine->setDefault3DSoundMinDistance(.1);
|
||||||
m_engine->setDefault3DSoundMaxDistance(1000);
|
m_engine->setDefault3DSoundMaxDistance(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
Audio::Audio(const char * music) {
|
Audio::Audio(const char * music) {
|
||||||
m_engine = irrklang::createIrrKlangDevice();
|
m_engine = irrklang::createIrrKlangDevice();
|
||||||
m_engine->setDopplerEffectParameters(1);
|
m_engine->setDopplerEffectParameters(1);
|
||||||
m_engine->setRolloffFactor(1);
|
m_engine->setRolloffFactor(2);
|
||||||
m_engine->setDefault3DSoundMinDistance(1);
|
m_engine->setDefault3DSoundMinDistance(.1);
|
||||||
m_engine->setDefault3DSoundMaxDistance(1000);
|
m_engine->setDefault3DSoundMaxDistance(1000);
|
||||||
m_music = m_engine->play2D(music, false, true, true, irrklang::ESM_STREAMING);
|
m_music = m_engine->play2D(music, false, true, true, irrklang::ESM_STREAMING);
|
||||||
}
|
}
|
||||||
@ -28,10 +28,11 @@ void Audio::Update3DAudio(Vector3f pos, Vector3f dir, Vector3f vel) {
|
|||||||
irrklang::vec3df(vel.x, vel.y, vel.z));
|
irrklang::vec3df(vel.x, vel.y, vel.z));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Audio::Create3DAudioObj(irrklang::ISound* sound, const char* name, Vector3f pos, Vector3f vel, float volume = 1) {
|
irrklang::ISound* Audio::Create3DAudioObj(irrklang::ISound* sound, const char* name, Vector3f pos, Vector3f vel, bool is_looped = false, float volume = 1) {
|
||||||
sound = m_engine->play3D(name, irrklang::vec3df(pos.x, pos.y, pos.z), false, false, true, irrklang::ESM_NO_STREAMING, true);
|
sound = m_engine->play3D(name, irrklang::vec3df(pos.x, pos.y, pos.z), is_looped, false, true, is_looped? irrklang::ESM_STREAMING: irrklang::ESM_NO_STREAMING, true);
|
||||||
sound->setVelocity(irrklang::vec3df(vel.x, vel.y, vel.z));
|
sound->setVelocity(irrklang::vec3df(vel.x, vel.y, vel.z));
|
||||||
sound->setVolume(volume);
|
sound->setVolume(volume);
|
||||||
|
return sound;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Audio::Render3DAudioObj(irrklang::ISound* sound, Vector3f& pos, Vector3f& vel, float volume = 1) {
|
void Audio::Render3DAudioObj(irrklang::ISound* sound, Vector3f& pos, Vector3f& vel, float volume = 1) {
|
||||||
|
@ -14,17 +14,17 @@
|
|||||||
|
|
||||||
class Audio {
|
class Audio {
|
||||||
private:
|
private:
|
||||||
irrklang::ISoundEngine* m_engine;
|
|
||||||
irrklang::ISound* m_music;
|
irrklang::ISound* m_music;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Audio();
|
Audio();
|
||||||
Audio(const char* music);
|
Audio(const char* music);
|
||||||
~Audio();
|
~Audio();
|
||||||
|
irrklang::ISoundEngine* m_engine;
|
||||||
|
|
||||||
void Update3DAudio(Vector3f pos, Vector3f dir, Vector3f speed);
|
void Update3DAudio(Vector3f pos, Vector3f dir, Vector3f speed);
|
||||||
|
|
||||||
void Create3DAudioObj(irrklang::ISound* sound, const char* name, Vector3f pos, Vector3f vel, float volume);
|
irrklang::ISound* Create3DAudioObj(irrklang::ISound* sound, const char* name, Vector3f pos, Vector3f vel, bool is_looped, float volume);
|
||||||
|
|
||||||
void Render3DAudioObj(irrklang::ISound* sound, Vector3f& pos, Vector3f& vel, float volume);
|
void Render3DAudioObj(irrklang::ISound* sound, Vector3f& pos, Vector3f& vel, float volume);
|
||||||
|
|
||||||
|
@ -24,9 +24,12 @@
|
|||||||
#define SRV_ADDR "127.0.0.1"
|
#define SRV_ADDR "127.0.0.1"
|
||||||
#define COUNTDOWN 300
|
#define COUNTDOWN 300
|
||||||
|
|
||||||
|
#define BULLET_UPDATES_PER_FRAME 20
|
||||||
|
|
||||||
#define BASE_WIDTH 640
|
#define BASE_WIDTH 640
|
||||||
#define BASE_HEIGHT 480
|
#define BASE_HEIGHT 480
|
||||||
|
|
||||||
|
|
||||||
#define TEXTURE_PATH "./media/textures/"
|
#define TEXTURE_PATH "./media/textures/"
|
||||||
#define SHADER_PATH "./media/shaders/"
|
#define SHADER_PATH "./media/shaders/"
|
||||||
#define AUDIO_PATH "./media/audio/"
|
#define AUDIO_PATH "./media/audio/"
|
||||||
|
@ -256,8 +256,10 @@ void Engine::Init() {
|
|||||||
//m_audio.ToggleMusicState();
|
//m_audio.ToggleMusicState();
|
||||||
|
|
||||||
// Array pour les balles.
|
// Array pour les balles.
|
||||||
for (int x = 0; x < MAX_BULLETS; ++x)
|
for (int x = 0; x < MAX_BULLETS; ++x) {
|
||||||
m_bullets[x] = nullptr;
|
m_bullets[x] = nullptr;
|
||||||
|
m_whoosh[x] = nullptr; // = m_audio.m_engine.m_audio.m_engine->addSoundSourceFromFile(AUDIO_PATH "noise.ogg", irrklang::ESM_AUTO_DETECT, false);
|
||||||
|
}
|
||||||
|
|
||||||
uint64_t seed = SEED;
|
uint64_t seed = SEED;
|
||||||
std::string playname = "La Chienne <20> Jacques";
|
std::string playname = "La Chienne <20> Jacques";
|
||||||
@ -279,6 +281,8 @@ void Engine::Init() {
|
|||||||
// Init Chunks
|
// Init Chunks
|
||||||
m_world.GetChunks().Reset(nullptr);
|
m_world.GetChunks().Reset(nullptr);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Gestion de souris.
|
// Gestion de souris.
|
||||||
CenterMouse();
|
CenterMouse();
|
||||||
HideCursor();
|
HideCursor();
|
||||||
@ -717,24 +721,27 @@ void Engine::Render(float elapsedTime) {
|
|||||||
m_bullets[0]->~Bullet();
|
m_bullets[0]->~Bullet();
|
||||||
m_bullets[0] = new Bullet(m_player.GetPOV() + m_player.GetDirection(), m_player.GetDirection());
|
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);
|
|
||||||
if (m_flash) { // Coupe le rendering et affiche un frame blanc, pour simuler un flash.
|
|
||||||
glClearColor(.8f, .8f, .8f, 1.f);
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
|
||||||
glClearColor(0.f, 0.f, 0.f, 1.f);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (m_mouseR)
|
else if (m_mouseR)
|
||||||
m_world.ChangeBlockAtCursor(BTYPE_AIR, m_player.GetPosition(), m_player.GetDirection(), m_block);
|
m_world.ChangeBlockAtCursor(BTYPE_AIR, m_player.GetPosition(), m_player.GetDirection(), m_block);
|
||||||
|
|
||||||
for (int x = 0; x < MAX_BULLETS; ++x) // Array de bullets en jeu.
|
for (int x = 0; x < MAX_BULLETS; ++x) { // Array de bullets en jeu.
|
||||||
if (m_bullets[x])
|
if (m_bullets[x]) {
|
||||||
if (m_bullets[x]->Update(&m_world, elapsedTime)) {
|
for (int b = 0; b < BULLET_UPDATES_PER_FRAME; ++b)
|
||||||
|
if (m_bullets[x]->Update(&m_world, elapsedTime, BULLET_UPDATES_PER_FRAME)) {
|
||||||
m_bullets[x]->~Bullet();
|
m_bullets[x]->~Bullet();
|
||||||
|
if (m_whoosh[x])
|
||||||
|
m_whoosh[x]->drop();
|
||||||
m_bullets[x] = nullptr;
|
m_bullets[x] = nullptr;
|
||||||
|
m_whoosh[x] = nullptr;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if (!m_whoosh[x]) {
|
||||||
|
m_whoosh[x] = m_audio.Create3DAudioObj(m_whoosh[x], AUDIO_PATH "noise.wav", m_bullets[x]->getPos(), m_bullets[x]->getVel(), true, (m_bullets[x]->getPos() - m_player.GetPosition()).Length());
|
||||||
|
}
|
||||||
|
else m_audio.Render3DAudioObj(m_whoosh[x], m_bullets[x]->getPos(), m_bullets[x]->getVel(), 5 - (m_bullets[x]->getPos() - m_player.GetPosition()).Length());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m_wrenderer.RenderWorld(&m_world, m_renderCount, m_player.GetPosition(), m_player.GetDirection(), all, m_shader01, m_textureAtlas);
|
m_wrenderer.RenderWorld(&m_world, m_renderCount, m_player.GetPosition(), m_player.GetDirection(), all, m_shader01, m_textureAtlas);
|
||||||
@ -755,6 +762,7 @@ void Engine::Render(float elapsedTime) {
|
|||||||
m_player = Player(Vector3f(.5f, CHUNK_SIZE_Y + 1.8f, .5f)); // Respawn si le bonho- joueur tombe en bas du monde.
|
m_player = Player(Vector3f(.5f, CHUNK_SIZE_Y + 1.8f, .5f)); // Respawn si le bonho- joueur tombe en bas du monde.
|
||||||
fell = false;
|
fell = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (m_gamestate == GameState::MAIN_MENU || m_gamestate == GameState::OPTIONS)
|
else if (m_gamestate == GameState::MAIN_MENU || m_gamestate == GameState::OPTIONS)
|
||||||
{
|
{
|
||||||
@ -818,6 +826,8 @@ void Engine::KeyPressEvent(unsigned char key) {
|
|||||||
break;
|
break;
|
||||||
case 8: // I - Ignorer
|
case 8: // I - Ignorer
|
||||||
break;
|
break;
|
||||||
|
case 15: // P - Ignorer
|
||||||
|
break;
|
||||||
case 17: // R - Ignorer
|
case 17: // R - Ignorer
|
||||||
break;
|
break;
|
||||||
case 19: // T - Ignorer
|
case 19: // T - Ignorer
|
||||||
@ -867,6 +877,17 @@ void Engine::KeyReleaseEvent(unsigned char key) {
|
|||||||
case 12: // M - Toggle music
|
case 12: // M - Toggle music
|
||||||
m_audio.ToggleMusicState();
|
m_audio.ToggleMusicState();
|
||||||
break;
|
break;
|
||||||
|
case 15:
|
||||||
|
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.GetPOV() - Vector3f(1.f, 0.f, 1.f), Vector3f(1.f,0.f,1.f));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if (x == MAX_BULLETS - 1) { // S'il y a pas d'espace dans l'array, prendre la place de la premi<6D>re balle de l'array.
|
||||||
|
m_bullets[0]->~Bullet();
|
||||||
|
m_bullets[0] = new Bullet(m_player.GetPOV() - Vector3f(1.f, 0.f, 1.f), Vector3f(1.f, 0.f, 1.f));
|
||||||
|
}
|
||||||
|
break;
|
||||||
case 17: // R - Toggle skybox
|
case 17: // R - Toggle skybox
|
||||||
m_isSkybox = !m_isSkybox;
|
m_isSkybox = !m_isSkybox;
|
||||||
break;
|
break;
|
||||||
|
@ -71,8 +71,9 @@ private:
|
|||||||
Skybox m_skybox;
|
Skybox m_skybox;
|
||||||
Audio m_audio = Audio(AUDIO_PATH "start.wav");
|
Audio m_audio = Audio(AUDIO_PATH "start.wav");
|
||||||
|
|
||||||
irrklang::ISound* m_powpow;
|
irrklang::ISound* m_powpow,
|
||||||
irrklang::ISound* m_scream;
|
* m_scream;
|
||||||
|
irrklang::ISound *m_whoosh[MAX_BULLETS];
|
||||||
|
|
||||||
Player m_player = Player(Vector3f(.5f, CHUNK_SIZE_Y + 1.8f, .5f));
|
Player m_player = Player(Vector3f(.5f, CHUNK_SIZE_Y + 1.8f, .5f));
|
||||||
|
|
||||||
|
BIN
SQCSim2021/media/audio/noise.wav
Normal file
BIN
SQCSim2021/media/audio/noise.wav
Normal file
Binary file not shown.
@ -211,3 +211,4 @@ void WorldRenderer::UpdateWorld(World* origin, const Vector3f& player, BlockInfo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user