diff --git a/SQCSim-common/bullet.cpp b/SQCSim-common/bullet.cpp index 5c4e6c4..873879d 100644 --- a/SQCSim-common/bullet.cpp +++ b/SQCSim-common/bullet.cpp @@ -7,8 +7,9 @@ Bullet::Bullet(Vector3f pos, Vector3f dir, uint64_t tid): m_startpos(pos), m_cur Bullet::~Bullet() {} -bool Bullet::Update(World* world, float elapsedtime) { - for (int x = 0; x < 1000; ++x) { +bool Bullet::Update(World* world, float elapsedtime, int perframe) { + int max = 100 / perframe; + for (int x = 0; x < max; ++x) { m_currentpos += m_velocity * elapsedtime; if (!world->ChunkAt(m_currentpos)) @@ -30,10 +31,14 @@ void Bullet::Transpose(int& x, int& z) { m_startpos.z -= z * CHUNK_SIZE_Z; } -Vector3f Bullet::getPos() { +Vector3f Bullet::getPos() const { return m_currentpos; } +Vector3f Bullet::getVel() const { + return m_velocity; +} + uint64_t Bullet::getTeamID(){ return m_tid; } diff --git a/SQCSim-common/bullet.h b/SQCSim-common/bullet.h index e3ae989..1b5e227 100644 --- a/SQCSim-common/bullet.h +++ b/SQCSim-common/bullet.h @@ -12,9 +12,10 @@ public: Bullet(Vector3f pos, Vector3f dir, uint64_t tid); ~Bullet(); - bool Update(World* world, float elapsedtime); + bool Update(World* world, float elapsedtime, int perframe); void Transpose(int& x, int& z); - Vector3f getPos(); + Vector3f getPos() const; + Vector3f getVel() const; uint64_t getTeamID(); private: diff --git a/SQCSim2021/audio.cpp b/SQCSim2021/audio.cpp index b6a066b..e849c6f 100644 --- a/SQCSim2021/audio.cpp +++ b/SQCSim2021/audio.cpp @@ -2,17 +2,17 @@ Audio::Audio() { m_engine = irrklang::createIrrKlangDevice(); - m_engine->setDopplerEffectParameters(1); - m_engine->setRolloffFactor(1); - m_engine->setDefault3DSoundMinDistance(1); + m_engine->setDopplerEffectParameters(10); + m_engine->setRolloffFactor(2); + m_engine->setDefault3DSoundMinDistance(.1); m_engine->setDefault3DSoundMaxDistance(1000); } Audio::Audio(const char * music) { m_engine = irrklang::createIrrKlangDevice(); m_engine->setDopplerEffectParameters(1); - m_engine->setRolloffFactor(1); - m_engine->setDefault3DSoundMinDistance(1); + m_engine->setRolloffFactor(2); + m_engine->setDefault3DSoundMinDistance(.1); m_engine->setDefault3DSoundMaxDistance(1000); 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)); } -void Audio::Create3DAudioObj(irrklang::ISound* sound, const char* name, Vector3f pos, Vector3f vel, float volume = 1) { - sound = m_engine->play3D(name, irrklang::vec3df(pos.x, pos.y, pos.z), false, false, true, irrklang::ESM_NO_STREAMING, true); +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), 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->setVolume(volume); + return sound; } void Audio::Render3DAudioObj(irrklang::ISound* sound, Vector3f& pos, Vector3f& vel, float volume = 1) { diff --git a/SQCSim2021/audio.h b/SQCSim2021/audio.h index d4625cf..775f316 100644 --- a/SQCSim2021/audio.h +++ b/SQCSim2021/audio.h @@ -14,17 +14,17 @@ class Audio { private: - irrklang::ISoundEngine* m_engine; irrklang::ISound* m_music; public: Audio(); Audio(const char* music); ~Audio(); + irrklang::ISoundEngine* m_engine; 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); diff --git a/SQCSim2021/define.h b/SQCSim2021/define.h index 0ff1145..67c49c3 100644 --- a/SQCSim2021/define.h +++ b/SQCSim2021/define.h @@ -24,9 +24,12 @@ #define SRV_ADDR "127.0.0.1" #define COUNTDOWN 300 +#define BULLET_UPDATES_PER_FRAME 20 + #define BASE_WIDTH 640 #define BASE_HEIGHT 480 + #define TEXTURE_PATH "./media/textures/" #define SHADER_PATH "./media/shaders/" #define AUDIO_PATH "./media/audio/" diff --git a/SQCSim2021/engine.cpp b/SQCSim2021/engine.cpp index e7bff11..a5939e6 100644 --- a/SQCSim2021/engine.cpp +++ b/SQCSim2021/engine.cpp @@ -256,8 +256,10 @@ void Engine::Init() { //m_audio.ToggleMusicState(); // 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_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; std::string playname = "La Chienne � Jacques"; @@ -279,6 +281,8 @@ void Engine::Init() { // Init Chunks m_world.GetChunks().Reset(nullptr); + + // Gestion de souris. CenterMouse(); HideCursor(); @@ -717,25 +721,28 @@ void Engine::Render(float elapsedTime) { m_bullets[0]->~Bullet(); 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) - 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. - if (m_bullets[x]) - if (m_bullets[x]->Update(&m_world, elapsedTime)) { + } + else if (m_mouseR) + 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. + if (m_bullets[x]) { + 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(); + if (m_whoosh[x]) + m_whoosh[x]->drop(); 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_world.Update(m_bullets, m_player.GetPosition(), m_blockinfo); @@ -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. fell = false; } + } else if (m_gamestate == GameState::MAIN_MENU || m_gamestate == GameState::OPTIONS) { @@ -818,6 +826,8 @@ void Engine::KeyPressEvent(unsigned char key) { break; case 8: // I - Ignorer break; + case 15: // P - Ignorer + break; case 17: // R - Ignorer break; case 19: // T - Ignorer @@ -867,6 +877,17 @@ void Engine::KeyReleaseEvent(unsigned char key) { case 12: // M - Toggle music m_audio.ToggleMusicState(); 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�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 m_isSkybox = !m_isSkybox; break; diff --git a/SQCSim2021/engine.h b/SQCSim2021/engine.h index c66c202..57b4e2e 100644 --- a/SQCSim2021/engine.h +++ b/SQCSim2021/engine.h @@ -71,8 +71,9 @@ private: Skybox m_skybox; Audio m_audio = Audio(AUDIO_PATH "start.wav"); - irrklang::ISound* m_powpow; - irrklang::ISound* m_scream; + irrklang::ISound* m_powpow, + * m_scream; + irrklang::ISound *m_whoosh[MAX_BULLETS]; Player m_player = Player(Vector3f(.5f, CHUNK_SIZE_Y + 1.8f, .5f)); diff --git a/SQCSim2021/media/audio/noise.wav b/SQCSim2021/media/audio/noise.wav new file mode 100644 index 0000000..6c22f27 Binary files /dev/null and b/SQCSim2021/media/audio/noise.wav differ diff --git a/SQCSim2021/worldrenderer.cpp b/SQCSim2021/worldrenderer.cpp index dcf6d45..e4e0333 100644 --- a/SQCSim2021/worldrenderer.cpp +++ b/SQCSim2021/worldrenderer.cpp @@ -211,3 +211,4 @@ void WorldRenderer::UpdateWorld(World* origin, const Vector3f& player, BlockInfo } } } +