Merge pull request #41 from CegepSTH/ConnexionVariablesMenuOptions

Connexion variables menu options
This commit is contained in:
MarcEricMartel 2023-12-15 07:02:09 -05:00 committed by GitHub
commit 77a982b1fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 334 additions and 108 deletions

View File

@ -4,14 +4,15 @@
Player::Player(const Vector3f& position, float rotX, float rotY) : m_position(position), m_rotX(rotX), m_rotY(rotY) {
m_velocity = Vector3f(0, 0, 0);
m_airborne = true;
m_hp = 1.0f; //TODO: Remettre <20> 1.0f
m_hp = 1.0f;
m_sensitivity = 0.5f;
m_username = "Zelda Bee-Bop56";
}
Player::~Player() {}
void Player::TurnLeftRight(float value) {
m_rotY += value;
void Player::TurnLeftRight(float value, float sensitivity) {
m_rotY += value * sensitivity;
if (m_rotY > 360) m_rotY = 0;
else if (m_rotY < -360) m_rotY = 0;
@ -25,8 +26,8 @@ void Player::TurnLeftRight(float value) {
m_direction.Normalize();
}
void Player::TurnTopBottom(float value) {
m_rotX += value;
void Player::TurnTopBottom(float value, float sensitivity) {
m_rotX += value * sensitivity;
if (m_rotX > 80) m_rotX = 80;
else if (m_rotX < -80) m_rotX = -80;
@ -78,7 +79,7 @@ Vector3f Player::GetInput(bool front, bool back, bool left, bool right, bool jum
}
if (shoot) // Recoil!
TurnTopBottom(-1);
TurnTopBottom(-1, 1.0f);
return delta;
}
@ -270,6 +271,18 @@ Vector3f Player::GetDirection() const { return m_direction; }
std::string Player::GetUsername() const { return m_username; }
void Player::SetUsername(std::string username) {
m_username = username;
}
float Player::GetSensitivity() const {
return m_sensitivity;
}
void Player::SetSensitivity(float sensitivity) {
m_sensitivity = sensitivity;
}
float Player::GetHP() const { return m_hp; }
void Player::Teleport(int& x, int& z) {

View File

@ -16,8 +16,8 @@ public:
Player(const Vector3f& position, float rotX = 0, float rotY = 0);
~Player();
void TurnLeftRight(float value);
void TurnTopBottom(float value);
void TurnLeftRight(float value, float sensitivity);
void TurnTopBottom(float value, float sensitivity);
Vector3f GetInput(bool front, bool back, bool left, bool right, bool jump, bool dash, float elapsedTime);
Sound ApplyPhysics(Vector3f input, World* world, float elapsedTime);
void GetBooster(Booster boosttype);
@ -32,6 +32,9 @@ public:
Vector3f GetVelocity() const;
Vector3f GetPOV() const;
std::string GetUsername() const;
void SetUsername(std::string username);
float GetSensitivity() const;
void SetSensitivity(float sensitivity);
float GetHP() const;
void Teleport(int& x, int& z);
@ -61,6 +64,7 @@ protected:
float timeboostspeed;
float timeboostdamage;
float timeboostinvincible;
float m_sensitivity;
float m_hp;
@ -69,8 +73,6 @@ protected:
bool boostdamage;
bool boostinvincible;
Vector3f InterpolatePosition(const Vector3f& vec1, const Vector3f& vec2, const Timestamp& tim1, const Timestamp& tim2, const Timestamp& now);
};
#endif //_PLAYER_H__

View File

@ -18,6 +18,9 @@ Audio::Audio(const char * music, const char* menumusic) {
m_menumusic = m_engine->play2D(menumusic, true, true, true, irrklang::ESM_STREAMING);
m_music->setVolume(.5);
m_menumusic->setVolume(.5);
m_mainvolume = 0.5f;
m_engine->setSoundVolume(m_mainvolume);
m_sfxvolume = 0.5f;
}
Audio::~Audio() {
@ -26,8 +29,11 @@ Audio::~Audio() {
if (m_engine) m_engine->drop();
}
void Audio::playSound(const char* sound) {
m_engine->play2D(sound);
void Audio::playSound(const char* name, float volume = 1.) {
irrklang::ISound* sfx = m_engine->play2D(name, false, true);
sfx->setVolume(volume);
sfx->setIsPaused(false);
m_sfxes.push_back(sfx);
}
void Audio::Update3DAudio(Vector3f pos, Vector3f dir, Vector3f vel) {
@ -37,9 +43,10 @@ void Audio::Update3DAudio(Vector3f pos, Vector3f dir, Vector3f vel) {
}
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 = m_engine->play3D(name, irrklang::vec3df(pos.x, pos.y, pos.z), is_looped, true, true, is_looped? irrklang::ESM_STREAMING: irrklang::ESM_NO_STREAMING, true);
sound->setVelocity(irrklang::vec3df(vel.x, vel.y, vel.z));
sound->setVolume(volume);
sound->setIsPaused(false);
return sound;
}
@ -53,6 +60,17 @@ void Audio::Render3DAudioObj(irrklang::ISound* sound, Vector3f& pos, Vector3f& v
// m_music = m_engine->play2D(music, false, false, false, irrklang::ESM_STREAMING);
//}
void Audio::CleanupSFX() {
while (!m_sfxes.empty()) {
irrklang::ISound* sfx = m_sfxes.back();
if (sfx->isFinished()) {
sfx->drop(); // drop() fait deja la job du delete sfx.
}
else break;
m_sfxes.pop_back();
}
}
void Audio::ToggleMusicState(GameState state) {
if (m_music_on) {
switch (state) {
@ -94,3 +112,24 @@ void Audio::PauseEngine() { m_engine->setAllSoundsPaused(); }
float Audio::GetMusicVolume() const {
return m_music->getVolume();
}
void Audio::SetMusicVolume(float volume) {
m_music->setVolume(volume);
m_menumusic->setVolume(volume);
}
float Audio::GetMainVolume() const {
return m_engine->getSoundVolume();
}
void Audio::SetMainVolume(float volume) {
m_engine->setSoundVolume(volume);
}
float Audio::GetSfxVolume() const {
return m_sfxvolume;
}
void Audio::SetSfxVolume(float volume) {
m_sfxvolume = volume;
}

View File

@ -16,7 +16,10 @@ class Audio {
private:
irrklang::ISound* m_music;
irrklang::ISound* m_menumusic;
float m_mainvolume;
float m_sfxvolume;
bool m_music_on = true;
std::vector<irrklang::ISound*> m_sfxes;
public:
Audio();
@ -26,22 +29,32 @@ public:
void Update3DAudio(Vector3f pos, Vector3f dir, Vector3f speed);
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 PlaySong(const char* music);
void CleanupSFX();
void ToggleMusicState(GameState state);
void playSound(const char* sound);
void playSound(const char* sound, float volume);
void SetMusic(bool ison, GameState state);
bool GetMusic();
void PauseEngine();
float GetMainVolume() const;
void SetMainVolume(float volume);
float GetMusicVolume() const;
void SetMusicVolume(float volume);
float GetSfxVolume() const;
void SetSfxVolume(float volume);
};
#endif // AUDIO_H__

View File

@ -25,8 +25,8 @@
#define BULLET_UPDATES_PER_FRAME 20
#define BASE_WIDTH 640
#define BASE_HEIGHT 480
#define BASE_WIDTH 1280
#define BASE_HEIGHT 720
#define ANIME_PATH_JUMP "./media/textures/AssetOtherPlayer/FinalPNGJumping/"
@ -58,7 +58,7 @@ enum Resolution {
HD = 0, // 1280x720 (High Definition)
FHD, // 1920x1080 (Full HD)
QHD, // 2560x1440 (Quad HD)
UHD // 3840x2160 (Ultra HD)
UHD, // 3840x2160 (Ultra HD)
};
#endif // DEFINE_H__

View File

@ -45,7 +45,6 @@ void Engine::Init() {
gluPerspective(45.0f, (float)Width() / (float)Height(), 0.1f, VIEW_DISTANCE);
glShadeModel(GL_SMOOTH);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glDisable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
@ -167,7 +166,6 @@ void Engine::LoadResource() {
TextureAtlas::TextureIndex StillQuarterBackRightShootFire = m_animeAtlas.AddTexture(ANIM_PATH_SSHOOT2 "BlueBackRightShootingRightShoot1.png"); ////23
TextureAtlas::TextureIndex StillBackShootFire = m_animeAtlas.AddTexture(ANIM_PATH_SSHOOT2 "BlueShootingBackRightShoot1.png"); ////24
//JUMP
TextureAtlas::TextureIndex JumpFront = m_animeAtlas.AddTexture(ANIME_PATH_JUMP "BlueFrontJumpRight.png"); ////25
TextureAtlas::TextureIndex JumpQuarterFrontLeft = m_animeAtlas.AddTexture(ANIME_PATH_JUMP "BlueLeftFrontJumpLeft.png"); ////26
@ -178,7 +176,6 @@ void Engine::LoadResource() {
TextureAtlas::TextureIndex JumpQuarterBackRight = m_animeAtlas.AddTexture(ANIME_PATH_JUMP "BlueRightBackJumpRight.png"); ////31
TextureAtlas::TextureIndex JumpBack = m_animeAtlas.AddTexture(ANIME_PATH_JUMP "BlueBackJumpRight.png"); ////32
//SHOOTINGJUMP SANS TIRER
TextureAtlas::TextureIndex JumpFrontShoot = m_animeAtlas.AddTexture(ANIM_PATH_JSHOOT1 "BlueFrontJumpRightShootingRight.png"); ////33
TextureAtlas::TextureIndex JumpQuarterFrontLeftShoot = m_animeAtlas.AddTexture(ANIM_PATH_JSHOOT1 "BlueFrontLeftJumpLeftShootingLeft.png"); ////34
@ -189,7 +186,6 @@ void Engine::LoadResource() {
TextureAtlas::TextureIndex JumpQuarterBackRightShoot = m_animeAtlas.AddTexture(ANIM_PATH_JSHOOT1 "BlueBackRightJumpRightShootingRight.png"); ////39
TextureAtlas::TextureIndex JumpBackShoot = m_animeAtlas.AddTexture(ANIM_PATH_JSHOOT1 "BlueBackJumpRightShootingRight.png"); ////40
//SHOOTINGJUMP TIRER
TextureAtlas::TextureIndex JumpFrontShootFire = m_animeAtlas.AddTexture(ANIM_PATH_JSHOOT2 "BlueFrontJumpRightShootingRightShoot1.png"); ////41
TextureAtlas::TextureIndex JumpQuarterFrontLeftShootFire = m_animeAtlas.AddTexture(ANIM_PATH_JSHOOT2 "BlueFrontLeftJumpLeftShootingLeftShoot1.png"); ////42
@ -200,8 +196,6 @@ void Engine::LoadResource() {
TextureAtlas::TextureIndex JumpQuarterBackRightShootFire = m_animeAtlas.AddTexture(ANIM_PATH_JSHOOT2 "BlueBackRightJumpRightShootingRightShoot1.png"); ////47
TextureAtlas::TextureIndex JumpBackShootFire = m_animeAtlas.AddTexture(ANIM_PATH_JSHOOT2 "BlueBackJumpRightShootingRightShoot1.png"); ////48
if (!m_animeAtlas.Generate(TEXTURE_SIZE, false)) {
std::cout << " Unable to generate texture atlas ..." << std::endl;
abort();
@ -244,12 +238,23 @@ void Engine::LoadResource() {
std::cout << " Failed to load shader " << std::endl;
exit(1);
}
// Settings
m_mainvolume = m_audio.GetMainVolume();
m_options.SetMainVolume(m_mainvolume);
m_musicvolume = m_audio.GetMusicVolume();
m_options.SetMusicVolume(m_musicvolume);
m_sfxvolume = m_audio.GetSfxVolume();
m_options.SetSfxVolume(m_sfxvolume);
m_sensitivity = m_player.GetSensitivity();
m_options.SetMouseSensitivity(m_sensitivity);
}
void Engine::UnloadResource() {}
void Engine::InstantDamage() {
m_player.InflictDamage(0.10f);
m_damage = false;
@ -720,6 +725,7 @@ void Engine::DisplayLobbyMenu(float elapsedTime) {
GLint viewport[4];
glGetIntegerv(GL_VIEWPORT, viewport);
glDisable(GL_STENCIL_TEST);
glDisable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
@ -731,6 +737,7 @@ void Engine::DisplayLobbyMenu(float elapsedTime) {
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
m_textureLobbyMenu.Bind();
glBegin(GL_QUADS);
glTexCoord2f(0, 0); glVertex2i(0, 0);
@ -739,7 +746,6 @@ void Engine::DisplayLobbyMenu(float elapsedTime) {
glTexCoord2f(0, 1); glVertex2i(0, Height());
glEnd();
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
if (m_settingUsername) {
SetPlayerUsername(elapsedTime);
@ -748,9 +754,20 @@ void Engine::DisplayLobbyMenu(float elapsedTime) {
SetServerAddress(elapsedTime);
}
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
m_textureOptBack.Bind();
glBegin(GL_QUADS);
glTexCoord2f(0, 0); glVertex2i(Width() * 0.675, Height() * 0.15);
glTexCoord2f(1, 0); glVertex2i(Width() * 0.9, Height() * 0.15);
glTexCoord2f(1, 1); glVertex2i(Width() * 0.9, Height() * 0.225);
glTexCoord2f(0, 1); glVertex2i(Width() * 0.675, Height() * 0.225);
glEnd();
glViewport(viewport[0], viewport[1], viewport[2], viewport[3]);
glEnable(GL_STENCIL_TEST);
glEnable(GL_DEPTH_TEST);
glDisable(GL_BLEND);
glMatrixMode(GL_PROJECTION);
glPopMatrix();
@ -759,6 +776,7 @@ void Engine::DisplayLobbyMenu(float elapsedTime) {
}
void Engine::SetPlayerUsername(float elapsedTime) {
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
m_textureLobbyIdentify.Bind();
glBegin(GL_QUADS);
glTexCoord2f(0, 0); glVertex2i(Width() * 0.6, Height() * 0.75);
@ -770,11 +788,10 @@ void Engine::SetPlayerUsername(float elapsedTime) {
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
HandlePlayerInput(elapsedTime);
glDisable(GL_BLEND);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
}
void Engine::SetServerAddress(float elapsedTime) {
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
m_textureLobbyServer.Bind();
glBegin(GL_QUADS);
glTexCoord2f(0, 0); glVertex2i(Width() * 0.6, Height() * 0.75);
@ -787,7 +804,6 @@ void Engine::SetServerAddress(float elapsedTime) {
HandlePlayerInput(elapsedTime);
glDisable(GL_BLEND);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
}
void Engine::DisplayPauseMenu(float elapsedTime) {
@ -1003,7 +1019,6 @@ void Engine::DisplayOptionsMenu() {
glPushMatrix();
m_textureOptionsMenu.Bind();
glLoadIdentity();
glBegin(GL_QUADS);
glTexCoord2f(0, 0); glVertex2i(0, 0);
glTexCoord2f(1, 0); glVertex2i(Width(), 0);
@ -1115,8 +1130,8 @@ void Engine::DisplayAudioMenu(float centerX, float centerY) {
float principalTop = centerY + Height() * 0.2f;
DrawSliderBackground(centerX, centerY, minBar, maxBar, principalBottom, principalTop);
DrawSlider(centerX, centerY, m_volPrincipal, minBar, maxBar, principalBottom, principalTop);
DisplayBarPercentValue(centerX, centerY, percentPosX, principalBottom, minBar, maxBar, m_volPrincipal);
DrawSlider(centerX, centerY, m_mainvolume, minBar, maxBar, principalBottom, principalTop);
DisplayBarPercentValue(centerX, centerY, percentPosX, principalBottom, minBar, maxBar, m_mainvolume);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
@ -1135,8 +1150,8 @@ void Engine::DisplayAudioMenu(float centerX, float centerY) {
float musiqueTop = centerY + Height() * 0.075f;
DrawSliderBackground(centerX, centerY, minBar, maxBar, musiqueBottom, musiqueTop);
DrawSlider(centerX, centerY, m_volMusique, minBar, maxBar, musiqueBottom, musiqueTop);
DisplayBarPercentValue(centerX, centerY, percentPosX, musiqueBottom, minBar, maxBar, m_volMusique);
DrawSlider(centerX, centerY, m_musicvolume, minBar, maxBar, musiqueBottom, musiqueTop);
DisplayBarPercentValue(centerX, centerY, percentPosX, musiqueBottom, minBar, maxBar, m_musicvolume);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
@ -1155,8 +1170,8 @@ void Engine::DisplayAudioMenu(float centerX, float centerY) {
float effectsTop = centerY - Height() * 0.05f;
DrawSliderBackground(centerX, centerY, minBar, maxBar, effectsBottom, effectsTop);
DrawSlider(centerX, centerY, m_volEffets, minBar, maxBar, effectsBottom, effectsTop);
DisplayBarPercentValue(centerX, centerY, percentPosX, effectsBottom, minBar, maxBar, m_volEffets);
DrawSlider(centerX, centerY, m_sfxvolume, minBar, maxBar, effectsBottom, effectsTop);
DisplayBarPercentValue(centerX, centerY, percentPosX, effectsBottom, minBar, maxBar, m_sfxvolume);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
}
@ -1174,10 +1189,10 @@ void Engine::DisplayGraphicsMenu(float centerX, float centerY) {
glColor4f(1.0f, 1.0f, 1.0f, 0.5f);
glBindTexture(GL_TEXTURE_2D, 0);
glBegin(GL_QUADS);
glTexCoord2f(0, 0); glVertex2i(centerX - Width() * 0.16, centerY + Height() * 0.165);
glTexCoord2f(1, 0); glVertex2i(centerX + Width() * 0.1, centerY + Height() * 0.165);
glTexCoord2f(1, 1); glVertex2i(centerX + Width() * 0.1, centerY - Height() * 0.04);
glTexCoord2f(0, 1); glVertex2i(centerX - Width() * 0.16, centerY - Height() * 0.04);
glTexCoord2f(0, 0); glVertex2i(Width() * 0.34, Height() * 0.46);
glTexCoord2f(1, 0); glVertex2i(Width() * 0.6, Height() * 0.46);
glTexCoord2f(1, 1); glVertex2i(Width() * 0.6, Height() * 0.67);
glTexCoord2f(0, 1); glVertex2i(Width() * 0.34, Height() * 0.67);
glEnd();
glColor4f(0.0f, 0.0f, 0.0f, 1.0f);
@ -1243,6 +1258,7 @@ void Engine::DisplayGraphicsMenu(float centerX, float centerY) {
void Engine::Render(float elapsedTime) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
m_audio.CleanupSFX();
if (m_gamestate == GameState::SPLASH) {
if (m_splashTime > 0.0f) {
@ -1280,6 +1296,11 @@ void Engine::Render(float elapsedTime) {
m_gamestate = GameState::MAIN_MENU;
}
}
else if (m_singleReady) {
m_gamestate = GameState::PLAY;
m_audio.ToggleMusicState(m_gamestate);
m_startTime = std::chrono::high_resolution_clock::now();
}
return;
}
@ -1331,11 +1352,11 @@ void Engine::Render(float elapsedTime) {
if (leftright)
vstep = Vector3f(m_player.GetPosition().x + m_player.GetDirection().z, m_player.GetPosition().y - 1.7f, m_player.GetPosition().z + m_player.GetDirection().x);
else vstep = Vector3f(m_player.GetPosition().x - m_player.GetDirection().z, m_player.GetPosition().y - 1.7f, m_player.GetPosition().z - m_player.GetDirection().x);
m_audio.Create3DAudioObj(step, AUDIO_PATH "step.wav", vstep, m_player.GetVelocity(), false, .8f);
m_audio.Create3DAudioObj(step, AUDIO_PATH "step.wav", vstep, m_player.GetVelocity(), false, m_sfxvolume);
leftright = !leftright;
break;
case Player::Sound::FALL:
m_audio.Create3DAudioObj(step, AUDIO_PATH "hit.wav", m_player.GetPosition(), m_player.GetVelocity(), false, 1.f);
m_audio.Create3DAudioObj(step, AUDIO_PATH "hit.wav", m_player.GetPosition(), m_player.GetVelocity(), false, m_sfxvolume);
break;
default: break;
}
@ -1364,7 +1385,7 @@ void Engine::Render(float elapsedTime) {
m_bullets[0] = new Bullet(m_player.GetPOV() + m_player.GetDirection(), m_player.GetDirection());
}
bulletTime = BULLET_TIME;
m_audio.Create3DAudioObj(m_powpow, AUDIO_PATH "pow.wav", m_player.GetPOV(), m_player.GetDirection() * 10, false, .5f);
m_audio.Create3DAudioObj(m_powpow, AUDIO_PATH "pow.wav", m_player.GetPOV(), m_player.GetDirection() * 10, false, m_sfxvolume);
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);
@ -1418,7 +1439,7 @@ void Engine::Render(float elapsedTime) {
}
static bool died = false;
if ((m_player.GetPosition().y < -1.7f || m_player.AmIDead()) && !died) {
m_audio.Create3DAudioObj(m_scream, AUDIO_PATH "scream.wav", m_player.GetPOV(), m_player.GetVelocity(), false, 1.f);
m_audio.Create3DAudioObj(m_scream, AUDIO_PATH "scream.wav", m_player.GetPOV(), m_player.GetVelocity(), false, m_sfxvolume);
died = true;
}
if (m_player.GetPosition().y < -21.f || died) {
@ -1539,7 +1560,7 @@ void Engine::Render(float elapsedTime) {
RemotePlayer* rt = static_cast<RemotePlayer*>(m_players[out.id]);
rt->Feed(out);
if (rt->AmIDead()) {
m_audio.Create3DAudioObj(m_scream, AUDIO_PATH "scream.wav", m_player.GetPOV(), m_player.GetVelocity(), false, 1.f);
m_audio.Create3DAudioObj(m_scream, AUDIO_PATH "scream.wav", m_player.GetPOV(), m_player.GetVelocity(), false, m_sfxvolume);
}
}
break;
@ -1569,7 +1590,7 @@ void Engine::Render(float elapsedTime) {
m_bullets[0] = bult;
break;
}
m_audio.Create3DAudioObj(m_powpow, AUDIO_PATH "pow.wav", bull.pos, bull.dir, false, 1.f);
m_audio.Create3DAudioObj(m_powpow, AUDIO_PATH "pow.wav", bull.pos, bull.dir, false, m_sfxvolume);
}
else SystemNotification("Bullet is kraput.");
break;
@ -1628,8 +1649,8 @@ void Engine::DisplayGameplayMenu(float centerX, float centerY) {
float sensibleTop = centerY + Height() * 0.2f;
DrawSliderBackground(centerX, centerY, minBar, maxBar, sensibleBottom, sensibleTop);
DrawSlider(centerX, centerY, m_volSensible, minBar, maxBar, sensibleBottom, sensibleTop);
DisplayBarPercentValue(centerX, centerY, percentPosX, sensibleBottom, minBar, maxBar, m_volSensible);
DrawSlider(centerX, centerY, m_sensitivity, minBar, maxBar, sensibleBottom, sensibleTop);
DisplayBarPercentValue(centerX, centerY, percentPosX, sensibleBottom, minBar, maxBar, m_sensitivity);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
}
@ -1649,14 +1670,22 @@ void Engine::DisplayBarPercentValue(float centerX, float centerY, float posX, fl
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
float percentage = (value / (maxVal - minVal)) * 100;
if (m_selectedOption == 0) {
if (value < 0.0f) {
value = 0.0f;
}
}
else {
if (value < 0.1f) {
value = 0.1f;
}
}
if (value > 1.0f) {
value = 1.0f;
}
if (percentage < 0.0f) {
percentage = 0.0f;
}
else if (percentage > 100.0f) {
percentage = 100.0f;
}
float percentage = value * 100;
m_textureFont.Bind();
std::ostringstream ss;
@ -1670,19 +1699,31 @@ void Engine::DisplayBarPercentValue(float centerX, float centerY, float posX, fl
}
void Engine::DrawSlider(float centerX, float centerY, float value, float minVal, float maxVal, float bottomSideValue, float topSideValue) {
if (value < 0.0f) {
value = 0.0f;
float barLength = maxVal - minVal;
if (m_selectedOption == 0) {
if (value < 0.0f) {
value = 0.0f;
}
}
else if (value > (maxVal - minVal)) {
value = (maxVal - minVal);
else {
if (value < 0.1f) {
value = 0.1f;
}
}
if (value >= 0.0f && value <= (maxVal - minVal)) {
if (value > 1.0f) {
value = 1.0f;
}
float scaledLength = minVal + value * barLength;
if (value >= 0.0f && value <= 1.0f) {
glColor4f(0.0f, 1.0f, 0.0f, 1.0f);
glBegin(GL_QUADS);
glTexCoord2f(0, 0); glVertex2i(minVal, bottomSideValue);
glTexCoord2f(1, 0); glVertex2i(minVal + value, bottomSideValue);
glTexCoord2f(1, 1); glVertex2i(minVal + value, topSideValue);
glTexCoord2f(1, 0); glVertex2i(scaledLength, bottomSideValue);
glTexCoord2f(1, 1); glVertex2i(scaledLength, topSideValue);
glTexCoord2f(0, 1); glVertex2i(minVal, topSideValue);
glEnd();
}
@ -2067,9 +2108,16 @@ void Engine::HandlePlayerInput(float elapsedTime) {
m_currentInputString.size() > 1 &&
m_currentInputString.size() < 26) {
m_username = m_currentInputString;
m_player.SetUsername(m_username);
m_currentInputString = "";
m_settingUsername = false;
m_settingServer = true;
if (m_selectedMultiPlayer) {
m_settingServer = true;
}
else if (m_selectedSinglePlayer) {
m_singleReady = true;
}
}
}
else if (m_settingServer) {
@ -2097,11 +2145,10 @@ void Engine::HandlePlayerInput(float elapsedTime) {
PrintText(Width() * 0.6f, Height() * 0.4f, ss.str(), 2.0f);
}
void Engine::MouseMoveEvent(int x, int y) {
if (m_gamestate == GameState::PLAY) {
m_player.TurnLeftRight(x - (Width() / 2));
m_player.TurnTopBottom(y - (Height() / 2));
m_player.TurnLeftRight(x - (Width() / 2), m_sensitivity);
m_player.TurnTopBottom(y - (Height() / 2), m_sensitivity);
// Centrer la souris seulement si elle n'est pas d<>j<EFBFBD> centr<74>e
// Il est n<>cessaire de faire la v<>rification pour <20>viter de tomber
@ -2119,18 +2166,24 @@ void Engine::MouseMoveEvent(int x, int y) {
float centerY = Height() * 0.5f;
float leftBar = centerX - Width() * 0.15f;
float rightBar = centerX + Width() * 0.3f;
float barLength = rightBar - leftBar;
float normalizedPosition = (x - leftBar) / barLength;
if (m_selectedOption == 0 && m_selectedOptAudioMainBar) {
m_volPrincipal = x - leftBar;
m_mainvolume = normalizedPosition;
m_audio.SetMainVolume(m_mainvolume);
}
else if (m_selectedOption == 0 && m_selectedOptAudioMusicBar) {
m_volMusique = x - leftBar;
m_musicvolume = normalizedPosition;
m_audio.SetMusicVolume(m_musicvolume);
}
else if (m_selectedOption == 0 && m_selectedOptAudioSfxBar) {
m_volEffets = x - leftBar;
m_sfxvolume = normalizedPosition;
m_audio.SetSfxVolume(m_sfxvolume);
}
else if (m_selectedOption == 2 && m_selectedGameplaySensitivityBar) {
m_volSensible = x - leftBar;
m_sensitivity = normalizedPosition;
}
}
}
@ -2176,19 +2229,23 @@ void Engine::MousePressEvent(const MOUSE_BUTTON& button, int x, int y) {
float bottomThird = centerY + Height() * 0.198f;
if (x > leftButton && x < rightButton && y > bottomFirst && y < topFirst) {
m_audio.playSound(AUDIO_PATH "snap.wav");
m_audio.playSound(AUDIO_PATH "snap.wav", m_sfxvolume);
if (m_selectedPlayOptions) {
m_gamestate = GameState::PLAY;
m_audio.ToggleMusicState(m_gamestate);
m_gamestate = GameState::LOBBY;
m_selectedSinglePlayer = true;
m_selectedMultiPlayer = false;
m_settingUsername = true;
}
else {
m_selectedPlayOptions = true;
}
}
else if (x > leftButton && x < rightButton && y > bottomSecond && y < topSecond) {
m_audio.playSound(AUDIO_PATH "snap.wav");
m_audio.playSound(AUDIO_PATH "snap.wav", m_sfxvolume);
if (m_selectedPlayOptions) {
m_gamestate = GameState::LOBBY;
m_selectedMultiPlayer = true;
m_selectedSinglePlayer = false;
m_settingUsername = true;
}
else {
@ -2196,7 +2253,7 @@ void Engine::MousePressEvent(const MOUSE_BUTTON& button, int x, int y) {
}
}
else if (x > leftButton && x < rightButton && y > bottomThird && y < topThird) {
m_audio.playSound(AUDIO_PATH "snap.wav");
m_audio.playSound(AUDIO_PATH "snap.wav", m_sfxvolume);
if (m_selectedPlayOptions) {
m_selectedPlayOptions = false;
}
@ -2227,25 +2284,26 @@ void Engine::MousePressEvent(const MOUSE_BUTTON& button, int x, int y) {
float bottomBack = centerY + Height() * 0.2f;
if (x > leftAudio && x < rightAudio && y > bottomAudio && y < topAudio) {
m_audio.playSound(AUDIO_PATH "snap.wav");
m_audio.playSound(AUDIO_PATH "snap.wav", m_sfxvolume);
m_selectedOption = 0; // Volume
}
else if (x > leftGraph && x < rightGraph && y > bottomGraph && y < topGraph) {
m_audio.playSound(AUDIO_PATH "snap.wav");
m_audio.playSound(AUDIO_PATH "snap.wav", m_sfxvolume);
m_selectedOption = 1; // Graphics
}
else if (x > leftGameplay && x < rightGameplay && y > bottomGameplay && y < topGameplay) {
m_audio.playSound(AUDIO_PATH "snap.wav");
m_audio.playSound(AUDIO_PATH "snap.wav", m_sfxvolume);
m_selectedOption = 2; // Gameplay
}
else if (x > leftBack && x < rightBack && y > bottomBack && y < topBack) {
m_audio.playSound(AUDIO_PATH "snap.wav");
m_audio.playSound(AUDIO_PATH "snap.wav", m_sfxvolume);
m_gamestate = GameState::MAIN_MENU;
}
// Audio
float leftBar = centerX - Width() * 0.15f;
float rightBar = centerX + Width() * 0.3f;
float barLength = rightBar - leftBar;
float topBarPrincipal = centerY - Height() * 0.165f;
float bottomBarPrincipal = centerY - Height() * 0.2f;
@ -2256,20 +2314,25 @@ void Engine::MousePressEvent(const MOUSE_BUTTON& button, int x, int y) {
float topBarEffets = centerY + Height() * 0.085f;
float bottomBarEffets = centerY + Height() * 0.05f;
float normalizedPosition = (x - leftBar) / barLength;
if (m_selectedOption == 0 && x > leftBar && x < rightBar && y > bottomBarPrincipal && y < topBarPrincipal) {
m_audio.playSound(AUDIO_PATH "snap.wav");
m_volPrincipal = x - leftBar;
m_selectedOptAudioMainBar = true;
m_mainvolume = normalizedPosition;
m_audio.SetMainVolume(m_mainvolume);
m_audio.playSound(AUDIO_PATH "snap.wav", m_sfxvolume);
}
else if (m_selectedOption == 0 && x > leftBar && x < rightBar && y > bottomBarMusique && y < topBarMusique) {
m_audio.playSound(AUDIO_PATH "snap.wav");
m_volMusique = x - leftBar;
m_selectedOptAudioMusicBar = true;
m_musicvolume = normalizedPosition;
m_audio.SetMusicVolume(m_musicvolume);
m_audio.playSound(AUDIO_PATH "snap.wav", m_sfxvolume);
}
else if (m_selectedOption == 0 && x > leftBar && x < rightBar && y > bottomBarEffets && y < topBarEffets) {
m_audio.playSound(AUDIO_PATH "snap.wav");
m_volEffets = x - leftBar;
m_selectedOptAudioSfxBar = true;
m_sfxvolume = normalizedPosition;
m_audio.SetSfxVolume(m_sfxvolume);
m_audio.playSound(AUDIO_PATH "snap.wav", m_sfxvolume);
}
// Resolution
@ -2288,28 +2351,38 @@ void Engine::MousePressEvent(const MOUSE_BUTTON& button, int x, int y) {
float topChkUHD = centerY + Height() * 0.025f;
float bottomChkUHD = centerY;
if (m_selectedOption == 1 && leftChk && x < rightChk && y > bottomChkHD && y < topChkHD) {
m_audio.playSound(AUDIO_PATH "snap.wav");
m_resolution = HD;
if (m_selectedOption == 1) {
if (x > leftChk && x < rightChk && y > bottomChkHD && y < topChkHD) {
m_audio.playSound(AUDIO_PATH "snap.wav", m_sfxvolume);
ChangeResolution(HD);
}
else if (x > leftChk && x < rightChk && y > bottomChkFHD && y < topChkFHD) {
m_audio.playSound(AUDIO_PATH "snap.wav", m_sfxvolume);
ChangeResolution(FHD);
}
else if (x > leftChk && x < rightChk && y > bottomChkQHD && y < topChkQHD) {
m_audio.playSound(AUDIO_PATH "snap.wav", m_sfxvolume);
ChangeResolution(QHD);
}
else if (x > leftChk && x < rightChk && y > bottomChkUHD && y < topChkUHD) {
m_audio.playSound(AUDIO_PATH "snap.wav", m_sfxvolume);
ChangeResolution(UHD);
}
}
else if (m_selectedOption == 1 && x > leftChk && x < rightChk && y > bottomChkFHD && y < topChkFHD) {
m_audio.playSound(AUDIO_PATH "snap.wav");
m_resolution = FHD;
if (normalizedPosition < 0.1f) {
normalizedPosition = 0.1f;
}
else if (m_selectedOption == 1 && x > leftChk && x < rightChk && y > bottomChkQHD && y < topChkQHD) {
m_audio.playSound(AUDIO_PATH "snap.wav");
m_resolution = QHD;
}
else if (m_selectedOption == 1 && x > leftChk && x < rightChk && y > bottomChkUHD && y < topChkUHD) {
m_audio.playSound(AUDIO_PATH "snap.wav");
m_resolution = UHD;
else if (normalizedPosition > 1.0f) {
normalizedPosition = 1.0f;
}
// Gameplay
if (m_selectedOption == 2 && x > leftBar && x < rightBar && y > bottomBarPrincipal && y < topBarPrincipal) {
m_audio.playSound(AUDIO_PATH "snap.wav");
m_volSensible = x - leftBar;
m_audio.playSound(AUDIO_PATH "snap.wav", m_sfxvolume);
m_selectedGameplaySensitivityBar = true;
m_sensitivity = normalizedPosition;
m_player.SetSensitivity(m_sensitivity);
}
}
else if (m_gamestate == GameState::PAUSE) {
@ -2324,22 +2397,77 @@ void Engine::MousePressEvent(const MOUSE_BUTTON& button, int x, int y) {
float bottomMainMenu = centerY - Height() * 0.4415f;
if (x > leftResume && x < rightResume && y > bottomResume && y < topResume) {
m_audio.playSound(AUDIO_PATH "snap.wav");
m_audio.playSound(AUDIO_PATH "snap.wav", m_sfxvolume);
m_gamestate = GameState::PLAY;
m_audio.ToggleMusicState(m_gamestate);
}
else if (x > leftMainMenu && x < rightMainMenu && y > bottomMainMenu && y < topMainMenu) {
m_audio.playSound(AUDIO_PATH "snap.wav");
m_audio.playSound(AUDIO_PATH "snap.wav", m_sfxvolume);
m_gamestate = GameState::MAIN_MENU;
m_selectedPlayOptions = false;
m_selectedSinglePlayer = false;
m_selectedMultiPlayer = false;
m_singleReady = false;
m_multiReady = false;
m_audio.ToggleMusicState(m_gamestate);
}
}
else if (m_gamestate == GameState::LOBBY) {
float leftBack = centerX + Width() * 0.178f;
float rightBack = centerX + Width() * 0.397f;
float topBack = centerY + Height() * 0.346f;
float bottomBack = centerY + Height() * 0.275f;
if (leftBack && x < rightBack && y > bottomBack && y < topBack) {
m_audio.playSound(AUDIO_PATH "snap.wav", m_sfxvolume);
m_gamestate = GameState::MAIN_MENU;
}
}
}
void Engine::MouseReleaseEvent(const MOUSE_BUTTON& button, int x, int y) {
float centerX = Width() * 0.5f;
float centerY = Height() * 0.5f;
float leftBar = centerX - Width() * 0.15f;
float rightBar = centerX + Width() * 0.3f;
float barLength = rightBar - leftBar;
float normalizedPosition = (x - leftBar) / barLength;
if (normalizedPosition > 1.0f) {
normalizedPosition = 1.0f;
}
switch (button) {
case MOUSE_BUTTON_LEFT:
if (m_selectedOption == 0) {
if (normalizedPosition < 0.0f) {
normalizedPosition = 0.0f;
}
if (m_selectedOptAudioMainBar) {
m_mainvolume = normalizedPosition;
m_audio.SetMainVolume(m_mainvolume);
}
else if (m_selectedOptAudioMusicBar) {
m_musicvolume = normalizedPosition;
m_audio.SetMusicVolume(m_musicvolume);
}
else if (m_selectedOptAudioSfxBar) {
m_sfxvolume = normalizedPosition;
m_audio.SetSfxVolume(m_sfxvolume);
}
}
else {
if (m_selectedGameplaySensitivityBar) {
if (normalizedPosition < 0.1f) {
normalizedPosition = 0.1f;
}
m_sensitivity = normalizedPosition;
m_player.SetSensitivity(m_sensitivity);
}
}
m_mouseL = false;
m_block = false;
m_selectedOptAudioMainBar = false;
@ -2377,4 +2505,29 @@ bool Engine::LoadTexture(Texture& texture, const std::string& filename, bool use
return true;
}
void Engine::ChangeResolution(Resolution resolution) {
DeInit();
switch (resolution) {
case HD:
OpenglContext::InitWindow(1280, 720);
m_resolution = HD;
break;
case FHD:
OpenglContext::InitWindow(1920, 1080);
m_resolution = FHD;
break;
case QHD:
OpenglContext::InitWindow(2560, 1440);
m_resolution = QHD;
break;
case UHD:
OpenglContext::InitWindow(3840, 2160);
m_resolution = UHD;
break;
}
Init();
}

View File

@ -49,6 +49,7 @@ private:
bool StartMultiplayerGame();
bool LoadTexture(Texture& texture, const std::string& filename, bool useMipmaps = true, bool stopOnError = true);
void ChangeResolution(Resolution resolution);
void InstantDamage();
void SystemNotification(std::string systemLog);
@ -176,10 +177,10 @@ private:
int m_nbReductionChunk = 4;
int m_timerReductionChunk = 30;
float m_volPrincipal = 0.0f;
float m_volMusique = 0.0f;
float m_volEffets = 0.0f;
float m_volSensible = 0.0f;
float m_mainvolume;
float m_musicvolume;
float m_sfxvolume;
float m_sensitivity;
int m_selectedOption = 0;
@ -208,12 +209,17 @@ private:
std::string m_currentInputString;
std::string m_username;
std::string m_serverAddr;
char m_inputChar = 0;
bool m_invalidChar = false;
bool m_charChanged = false;
bool m_settingUsername = false;
bool m_settingServer = false;
bool m_selectedSinglePlayer = false;
bool m_selectedMultiPlayer = false;
bool m_singleReady = false;
bool m_multiReady = false;
bool m_key1 = false;
bool m_key2 = false;

View File

@ -53,9 +53,9 @@ protected:
void ShowCrossCursor() const;
bool m_istarted = false;
void InitWindow(int width, int height);
private:
void InitWindow(int width, int height);
MOUSE_BUTTON ConvertMouseButton(sf::Mouse::Button button) const;
private:

View File

@ -9,7 +9,7 @@ Settings::Settings(Audio& audio)
m_fullscreen(false),
m_brightness(0.5f),
m_contrast(0.5f),
m_mouseSensitivity(0.5f) {
m_mouseSensitivity(0.0f) {
ApplyResolution(m_resolution);
}