This patch fix issues the jetpack had with the new way characters are moving. This patch also makes jetpack working over the network and improves the way how jetpack works. You can now for example release the left and right arrow key without stop flying upwards. --- src/character/character.cpp | 16 ++++++ src/character/character.h | 2 + src/weapon/jetpack.cpp | 116 +++++++++++-------------------------------- src/weapon/jetpack.h | 10 +--- 4 files changed, 51 insertions(+), 93 deletions(-)
diff --git a/src/character/character.cpp b/src/character/character.cpp index fb695a9..5ccd9f6 100644 --- a/src/character/character.cpp +++ b/src/character/character.cpp @@ -1034,6 +1034,14 @@ void Character::StopMovingRight(bool slowly) ActiveTeam().crosshair.Show(); } +bool Character::IsMovingRight(bool slowly) +{ + if (slowly) + return move_right_slowly_pressed; + else + return move_right_pressed; +} + void Character::HandleKeyPressed_MoveRight(bool slowly) { Action *a = new Action(Action::ACTION_CHARACTER_START_MOVING_RIGHT); @@ -1076,6 +1084,14 @@ void Character::StopMovingLeft(bool slowly) ActiveTeam().crosshair.Show(); } +bool Character::IsMovingLeft(bool slowly) +{ + if (slowly) + return move_left_slowly_pressed; + else + return move_left_pressed; +} + void Character::HandleKeyPressed_MoveLeft(bool slowly) { Action *a = new Action(Action::ACTION_CHARACTER_START_MOVING_LEFT); diff --git a/src/character/character.h b/src/character/character.h index 950de4e..372a32d 100644 --- a/src/character/character.h +++ b/src/character/character.h @@ -191,8 +191,10 @@ public: void StartMovingLeft(bool slowly); void StopMovingLeft(bool slowly); + bool IsMovingLeft(bool slowly); void StartMovingRight(bool slowly); void StopMovingRight(bool slowly); + bool IsMovingRight(bool slowly); // Jumps void Jump(double strength, double angle); diff --git a/src/weapon/jetpack.cpp b/src/weapon/jetpack.cpp index 3f092cd..5327a04 100644 --- a/src/weapon/jetpack.cpp +++ b/src/weapon/jetpack.cpp @@ -50,7 +50,6 @@ JetPack::JetPack() : Weapon(WEAPON_JETPACK, "jetpack", use_unit_on_first_shoot = false; - m_x_force = 0.0; m_y_force = 0.0; m_flying = false; } @@ -66,13 +65,26 @@ void JetPack::Refresh() { if (IsInUse()) { - if (!ActiveTeam().IsLocal()) { - return; + Point2d F; + F.x = 0; + F.y = m_y_force; + if (!ActiveCharacter().IsImmobile()) { + if (ActiveCharacter().IsMovingLeft(false) && !ActiveCharacter().IsMovingRight(false)) { + F.x = - JETPACK_FORCE; + if (ActiveCharacter().GetDirection() == DIRECTION_RIGHT) + ActiveCharacter().SetDirection(DIRECTION_LEFT); + } + if (ActiveCharacter().IsMovingRight(false) && !ActiveCharacter().IsMovingLeft(false)) { + F.x = JETPACK_FORCE; + if (ActiveCharacter().GetDirection() == DIRECTION_LEFT) + ActiveCharacter().SetDirection(DIRECTION_RIGHT); + } } - Point2d F; - F.x = m_x_force ; - F.y = m_y_force ; + if (F.IsNull() && m_flying) + StopFlying(); + else if (!F.IsNull() && m_flying) + StartFlying(); ActiveCharacter().SetExternForceXY(F); @@ -104,16 +116,11 @@ void JetPack::p_Select() { ActiveCharacter().SetClothe("jetpack"); - if (!ActiveTeam().IsLocal() && !ActiveTeam().IsLocalAI()) { - m_unit_visibility = NEVER_VISIBLE; // do not show ammo units accross the network - } else { - m_unit_visibility = VISIBLE_ONLY_WHEN_ACTIVE; - } + m_unit_visibility = VISIBLE_ONLY_WHEN_ACTIVE; } void JetPack::p_Deselect() { - m_x_force = 0; m_y_force = 0; ActiveCharacter().SetExternForce(0,0); StopFlying(); @@ -133,7 +140,7 @@ void JetPack::StartFlying() return; ActiveCharacter().SetMovement("jetpack-fire"); - if ( (m_x_force == 0) && (m_y_force == 0)) + if ((m_y_force == 0)) { m_last_fuel_down = Time::GetInstance()->Read(); flying_sound.Play(ActiveTeam().GetSoundProfile(),"weapon/jetpack", -1); @@ -157,8 +164,6 @@ void JetPack::StopFlying() return; ActiveCharacter().SetMovement("jetpack-nofire"); - m_x_force = 0.0; - m_y_force = 0.0; flying_sound.Stop(); m_flying = false; } @@ -169,91 +174,30 @@ void JetPack::GoUp() m_y_force = -(ActiveCharacter().GetMass() * GameMode::GetInstance()->gravity + JETPACK_FORCE); } -void JetPack::GoLeft() +void JetPack::StartMovingUp() { - StartFlying(); - m_x_force = - JETPACK_FORCE ; - if(ActiveCharacter().GetDirection() == DIRECTION_RIGHT) - ActiveCharacter().SetDirection(DIRECTION_LEFT); + GoUp(); } -void JetPack::GoRight() +void JetPack::StopMovingUp() { - StartFlying(); - m_x_force = JETPACK_FORCE ; - if(ActiveCharacter().GetDirection() == DIRECTION_LEFT) - ActiveCharacter().SetDirection(DIRECTION_RIGHT); + m_y_force = 0.0; } void JetPack::HandleKeyPressed_Up(bool slowly) { - if (!IsInUse()) { - ActiveCharacter().HandleKeyPressed_Up(slowly); - return; - } + ActiveCharacter().HandleKeyPressed_Up(slowly); - GoUp(); + if (IsInUse()) + StartMovingUpForAllPlayers(); } void JetPack::HandleKeyReleased_Up(bool slowly) { - if (!IsInUse()) { - ActiveCharacter().HandleKeyReleased_Up(slowly); - return; - } - - StopFlying(); -} - -void JetPack::HandleKeyPressed_MoveLeft(bool slowly) -{ - if (!IsInUse()) { - ActiveCharacter().HandleKeyPressed_MoveLeft(slowly); - return; - } + ActiveCharacter().HandleKeyReleased_Up(slowly); - if (!ActiveCharacter().FootsInVacuum()) { - StopFlying(); - ActiveCharacter().HandleKeyPressed_MoveLeft(slowly); - } else if (IsInUse()) { - GoLeft(); - } -} - -void JetPack::HandleKeyReleased_MoveLeft(bool slowly) -{ - if (!IsInUse()) { - ActiveCharacter().HandleKeyReleased_MoveLeft(slowly); - return; - } - - StopFlying(); -} - -void JetPack::HandleKeyPressed_MoveRight(bool slowly) -{ - if (!IsInUse()) { - ActiveCharacter().HandleKeyPressed_MoveRight(slowly); - return; - } - - if (!ActiveCharacter().FootsInVacuum()) { - // the character is landing! - StopFlying(); - ActiveCharacter().HandleKeyPressed_MoveRight(slowly); - } else if (IsInUse()) { - GoRight(); - } -} - -void JetPack::HandleKeyReleased_MoveRight(bool slowly) -{ - if (!IsInUse()) { - ActiveCharacter().HandleKeyReleased_MoveRight(slowly); - return; - } - - StopFlying(); + if (IsInUse()) + StopMovingUpForAllPlayers(); } void JetPack::HandleKeyPressed_Shoot() diff --git a/src/weapon/jetpack.h b/src/weapon/jetpack.h index cf1c4d5..bb4e848 100644 --- a/src/weapon/jetpack.h +++ b/src/weapon/jetpack.h @@ -27,7 +27,6 @@ class JetPack : public Weapon { private: - double m_x_force; double m_y_force; bool m_flying; @@ -42,12 +41,11 @@ class JetPack : public Weapon void Reset(); virtual void ActionStopUse(); + void StartMovingUp(); + void StopMovingUp(); + virtual void HandleKeyPressed_Up(bool slowly); virtual void HandleKeyReleased_Up(bool slowly); - virtual void HandleKeyPressed_MoveLeft(bool slowly); - virtual void HandleKeyReleased_MoveLeft(bool slowly); - virtual void HandleKeyPressed_MoveRight(bool slowly); - virtual void HandleKeyReleased_MoveRight(bool slowly); virtual void HandleKeyPressed_Shoot(); void UpdateTranslationStrings(); @@ -61,8 +59,6 @@ class JetPack : public Weapon private: void GoUp(); - void GoLeft(); - void GoRight(); void StartFlying(); void StopFlying(); }; -- 1.6.0.4 _______________________________________________ Wormux-dev mailing list Wormux-dev@gna.org https://mail.gna.org/listinfo/wormux-dev