Push mouse sensitivity
This commit is contained in:
parent
6c68114fbb
commit
6ba316aa2d
@ -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.1f;
|
||||
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,14 @@ Vector3f Player::GetDirection() const { return m_direction; }
|
||||
|
||||
std::string Player::GetUsername() const { return m_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) {
|
||||
|
@ -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,8 @@ public:
|
||||
Vector3f GetVelocity() const;
|
||||
Vector3f GetPOV() const;
|
||||
std::string GetUsername() const;
|
||||
float GetSensitivity() const;
|
||||
void SetSensitivity(float sensitivity);
|
||||
float GetHP() const;
|
||||
void Teleport(int& x, int& z);
|
||||
|
||||
@ -61,6 +63,7 @@ protected:
|
||||
float timeboostspeed;
|
||||
float timeboostdamage;
|
||||
float timeboostinvincible;
|
||||
float m_sensitivity;
|
||||
|
||||
float m_hp;
|
||||
|
||||
@ -69,8 +72,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__
|
||||
|
@ -229,6 +229,8 @@ void Engine::LoadResource() {
|
||||
m_boostinfo[BTYPE_INVINCIBLE] = new BoostInfo(BTYPE_INVINCIBLE, "Inv", u, v, s, 1);
|
||||
|
||||
m_animeAtlas.TextureIndexToCoord(0, u, v, s, s);
|
||||
m_sensitivity = m_player.GetSensitivity();
|
||||
m_options.SetMouseSensitivity(m_sensitivity);
|
||||
|
||||
std::cout << " Loading and compiling shaders ..." << std::endl;
|
||||
if (!m_shader01.Load(SHADER_PATH "shader01.vert", SHADER_PATH "shader01.frag", true)) {
|
||||
@ -1623,8 +1625,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);
|
||||
}
|
||||
@ -1644,7 +1646,14 @@ 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 (value < 0.1f) {
|
||||
value = 0.1f;
|
||||
}
|
||||
else if (value > 1.0f) {
|
||||
value = 1.0f;
|
||||
}
|
||||
|
||||
float percentage = value * 100;
|
||||
|
||||
if (percentage < 0.0f) {
|
||||
percentage = 0.0f;
|
||||
@ -1665,19 +1674,23 @@ 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 (value < 0.1f) {
|
||||
value = 0.1f;
|
||||
}
|
||||
else if (value > (maxVal - minVal)) {
|
||||
value = (maxVal - minVal);
|
||||
else if (value > 1.0f) {
|
||||
value = 1.0f;
|
||||
}
|
||||
|
||||
if (value >= 0.0f && value <= (maxVal - minVal)) {
|
||||
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();
|
||||
}
|
||||
@ -2095,11 +2108,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
|
||||
@ -2117,18 +2129,21 @@ 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_volPrincipal = normalizedPosition;
|
||||
}
|
||||
else if (m_selectedOption == 0 && m_selectedOptAudioMusicBar) {
|
||||
m_volMusique = x - leftBar;
|
||||
m_volMusique = normalizedPosition;
|
||||
}
|
||||
else if (m_selectedOption == 0 && m_selectedOptAudioSfxBar) {
|
||||
m_volEffets = x - leftBar;
|
||||
m_volEffets = normalizedPosition;
|
||||
}
|
||||
else if (m_selectedOption == 2 && m_selectedGameplaySensitivityBar) {
|
||||
m_volSensible = x - leftBar;
|
||||
m_sensitivity = normalizedPosition;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2237,6 +2252,7 @@ void Engine::MousePressEvent(const MOUSE_BUTTON& button, int x, int y) {
|
||||
// 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;
|
||||
@ -2247,6 +2263,8 @@ 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_volPrincipal = x - leftBar;
|
||||
m_selectedOptAudioMainBar = true;
|
||||
@ -2291,7 +2309,7 @@ void Engine::MousePressEvent(const MOUSE_BUTTON& button, int x, int y) {
|
||||
|
||||
// Gameplay
|
||||
if (m_selectedOption == 2 && x > leftBar && x < rightBar && y > bottomBarPrincipal && y < topBarPrincipal) {
|
||||
m_volSensible = x - leftBar;
|
||||
m_sensitivity = normalizedPosition;
|
||||
m_selectedGameplaySensitivityBar = true;
|
||||
}
|
||||
}
|
||||
|
@ -180,7 +180,7 @@ private:
|
||||
float m_volPrincipal = 0.0f;
|
||||
float m_volMusique = 0.0f;
|
||||
float m_volEffets = 0.0f;
|
||||
float m_volSensible = 0.0f;
|
||||
float m_sensitivity;
|
||||
|
||||
int m_selectedOption = 0;
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user