From 2e43a1b24a7e61e5584d44ae6ddb6a7831b5e5f5 Mon Sep 17 00:00:00 2001 From: wardje Date: Wed, 28 Mar 2012 13:19:21 +0000 Subject: [PATCH] Fix #532 - Only allow nitro use when pressing accelerate. git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@11043 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- src/karts/controller/player_controller.cpp | 14 ++++++++++++-- src/karts/controller/player_controller.hpp | 1 + 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/karts/controller/player_controller.cpp b/src/karts/controller/player_controller.cpp index bed2defa1..de2bd28fc 100644 --- a/src/karts/controller/player_controller.cpp +++ b/src/karts/controller/player_controller.cpp @@ -85,6 +85,7 @@ void PlayerController::reset() m_steer_val = 0; m_prev_brake = 0; m_prev_accel = 0; + m_prev_nitro = false; m_penalty_time = 0; } // reset @@ -100,6 +101,7 @@ void PlayerController::resetInputState() m_steer_val = 0; m_prev_brake = 0; m_prev_accel = 0; + m_prev_nitro = false; m_controls->m_accel = 0.0f; m_controls->m_brake = false; m_controls->m_skid = false; @@ -109,7 +111,7 @@ void PlayerController::resetInputState() m_controls->m_rescue = false; m_controls->m_steer = 0.0f; -} // resetKeyState +} // resetInputState // ---------------------------------------------------------------------------- /** This function interprets a kart action and value, and set the corresponding @@ -150,11 +152,13 @@ void PlayerController::action(PlayerAction action, int value) { m_controls->m_accel = value/32768.0f; m_controls->m_brake = false; + m_controls->m_nitro = m_prev_nitro; } else { m_controls->m_accel = 0.0f; m_controls->m_brake = m_prev_brake; + m_controls->m_nitro = false; } break; case PA_BRAKE: @@ -164,15 +168,21 @@ void PlayerController::action(PlayerAction action, int value) { m_controls->m_brake = true; m_controls->m_accel = 0.0f; + m_controls->m_nitro = false; } else { m_controls->m_brake = false; m_controls->m_accel = m_prev_accel/32768.0f; + // Nitro still depends on whether we're accelerating + m_controls->m_nitro = (m_prev_nitro && m_prev_accel); } break; case PA_NITRO: - m_controls->m_nitro = (value!=0); + // This basically keeps track whether the button still is being pressed + m_prev_nitro = (value != 0); + // Enable nitro only when also accelerating + m_controls->m_nitro = ((value!=0) && m_controls->m_accel); break; case PA_RESCUE: m_controls->m_rescue = (value!=0); diff --git a/src/karts/controller/player_controller.hpp b/src/karts/controller/player_controller.hpp index d29408ae7..fe03e03a0 100644 --- a/src/karts/controller/player_controller.hpp +++ b/src/karts/controller/player_controller.hpp @@ -39,6 +39,7 @@ private: int m_steer_val, m_steer_val_l, m_steer_val_r; int m_prev_accel; bool m_prev_brake; + bool m_prev_nitro; float m_penalty_time;