--- lib/wormux/include/WORMUX_action.h | 4 + src/character/character.cpp | 116 ++++++++++++++++++++++++++++++------ src/character/character.h | 21 +++++-- src/include/action_handler.cpp | 32 ++++++++++ 4 files changed, 149 insertions(+), 24 deletions(-)
diff --git a/lib/wormux/include/WORMUX_action.h b/lib/wormux/include/WORMUX_action.h index dd4471e..b6d1190 100644 --- a/lib/wormux/include/WORMUX_action.h +++ b/lib/wormux/include/WORMUX_action.h @@ -77,6 +77,10 @@ public: ACTION_CHARACTER_STOP_MOVING_LEFT, ACTION_CHARACTER_START_MOVING_RIGHT, ACTION_CHARACTER_STOP_MOVING_RIGHT, + ACTION_CHARACTER_START_INCREASING_FIRE_ANGLE, + ACTION_CHARACTER_STOP_INCREASING_FIRE_ANGLE, + ACTION_CHARACTER_START_DECREASING_FIRE_ANGLE, + ACTION_CHARACTER_STOP_DECREASING_FIRE_ANGLE, // ######################################################## // Using Weapon diff --git a/src/character/character.cpp b/src/character/character.cpp index dcdf599..174569d 100644 --- a/src/character/character.cpp +++ b/src/character/character.cpp @@ -135,6 +135,10 @@ Character::Character (Team& my_team, const std::string &name, Body *char_body) : move_left_slowly_pressed(false), move_right_pressed(false), move_right_slowly_pressed(false), + increase_fire_angle_pressed(false), + increase_fire_angle_slowly_pressed(false), + decrease_fire_angle_pressed(false), + decrease_fire_angle_slowly_pressed(false), previous_strength(0), body(NULL) { @@ -195,6 +199,10 @@ Character::Character (const Character& acharacter) : move_left_slowly_pressed(false), move_right_pressed(false), move_right_slowly_pressed(false), + increase_fire_angle_pressed(false), + increase_fire_angle_slowly_pressed(false), + decrease_fire_angle_pressed(false), + decrease_fire_angle_slowly_pressed(false), previous_strength(acharacter.previous_strength), body(NULL) { @@ -358,6 +366,10 @@ void Character::Die() move_left_slowly_pressed = false; move_right_pressed = false; move_right_slowly_pressed = false; + increase_fire_angle_pressed = false; + increase_fire_angle_slowly_pressed = false; + decrease_fire_angle_pressed = false; + decrease_fire_angle_slowly_pressed = false; if(death_explosion) ApplyExplosion(GetCenter(), GameMode::GetInstance()->death_explosion_cfg); @@ -537,6 +549,23 @@ void Character::Refresh() } else if (right && !left) { MoveRight(move_right_slowly_pressed); } + bool increase_angle = increase_fire_angle_pressed || increase_fire_angle_slowly_pressed; + bool decrease_angle = decrease_fire_angle_pressed || decrease_fire_angle_slowly_pressed; + if (increase_angle && !decrease_angle) { + UpdateLastMovingTime(); + CharacterCursor::GetInstance()->Hide(); + if (increase_fire_angle_slowly_pressed) + AddFiringAngle(DELTA_CROSSHAIR/10.0); + else + AddFiringAngle(DELTA_CROSSHAIR); + } else if (decrease_angle && ! increase_angle) { + UpdateLastMovingTime(); + CharacterCursor::GetInstance()->Hide(); + if (decrease_fire_angle_slowly_pressed) + AddFiringAngle(-DELTA_CROSSHAIR/10.0); + else + AddFiringAngle(-DELTA_CROSSHAIR); + } } if (IsGhost()) return; @@ -850,6 +879,10 @@ void Character::StopPlaying() move_left_slowly_pressed = false; move_right_pressed = false; move_right_slowly_pressed = false; + increase_fire_angle_pressed = false; + increase_fire_angle_slowly_pressed = false; + decrease_fire_angle_pressed = false; + decrease_fire_angle_slowly_pressed = false; } // Begining of turn or changed to this character @@ -1069,35 +1102,82 @@ void Character::HandleKeyReleased_MoveLeft(bool slowly) } // #################### UP -void Character::HandleKeyRefreshed_Up(bool slowly) +void Character::StartDecreasingFireAngle(bool slowly) { - HideGameInterface(); + if (slowly) + decrease_fire_angle_slowly_pressed = true; + else + decrease_fire_angle_pressed = true; +} + +void Character::StopDecreasingFireAngle(bool slowly) +{ + if (slowly) + decrease_fire_angle_slowly_pressed = false; + else + decrease_fire_angle_pressed = false; +} + +void Character::HandleKeyPressed_Up(bool slowly) +{ + Action a(Action::ACTION_CHARACTER_START_DECREASING_FIRE_ANGLE); + a.Push(slowly ? 1 : 0); + Network::GetInstance()->SendActionToAll(a); + + StartDecreasingFireAngle(slowly); + + HideGameInterface(); ActiveTeam().crosshair.Show(); +} - if (IsImmobile()) - { - UpdateLastMovingTime(); - CharacterCursor::GetInstance()->Hide(); - if (slowly) AddFiringAngle(-DELTA_CROSSHAIR/10.0); - else AddFiringAngle(-DELTA_CROSSHAIR); - } +void Character::HandleKeyReleased_Up(bool slowly) +{ + Action a(Action::ACTION_CHARACTER_STOP_DECREASING_FIRE_ANGLE); + a.Push(slowly ? 1 : 0); + Network::GetInstance()->SendActionToAll(a); + + StopDecreasingFireAngle(slowly); } // #################### DOWN -void Character::HandleKeyRefreshed_Down(bool slowly) + + +void Character::StartIncreasingFireAngle(bool slowly) { - HideGameInterface(); + if (slowly) + increase_fire_angle_slowly_pressed = true; + else + increase_fire_angle_pressed = true; +} + +void Character::StopIncreasingFireAngle(bool slowly) +{ + if (slowly) + increase_fire_angle_slowly_pressed = false; + else + increase_fire_angle_pressed = false; +} + +void Character::HandleKeyPressed_Down(bool slowly) +{ + Action a(Action::ACTION_CHARACTER_START_INCREASING_FIRE_ANGLE); + a.Push(slowly ? 1 : 0); + Network::GetInstance()->SendActionToAll(a); + + StartIncreasingFireAngle(slowly); + HideGameInterface(); ActiveTeam().crosshair.Show(); +} - if (IsImmobile()) - { - UpdateLastMovingTime(); - CharacterCursor::GetInstance()->Hide(); - if (slowly) AddFiringAngle(DELTA_CROSSHAIR/10.0); - else AddFiringAngle(DELTA_CROSSHAIR); - } +void Character::HandleKeyReleased_Down(bool slowly) +{ + Action a(Action::ACTION_CHARACTER_STOP_INCREASING_FIRE_ANGLE); + a.Push(slowly ? 1 : 0); + Network::GetInstance()->SendActionToAll(a); + + StopIncreasingFireAngle(slowly); } // #################### JUMP diff --git a/src/character/character.h b/src/character/character.h index 0fe5daa..98bddcf 100644 --- a/src/character/character.h +++ b/src/character/character.h @@ -87,6 +87,10 @@ private: bool move_left_slowly_pressed; bool move_right_pressed; bool move_right_slowly_pressed; + bool increase_fire_angle_pressed; + bool increase_fire_angle_slowly_pressed; + bool decrease_fire_angle_pressed; + bool decrease_fire_angle_slowly_pressed; public: // Previous strength @@ -167,6 +171,11 @@ public: double GetAbsFiringAngle() const { return firing_angle; }; void SetFiringAngle(double angle); + void StartIncreasingFireAngle(bool slowly); + void StopIncreasingFireAngle(bool slowly); + void StartDecreasingFireAngle(bool slowly); + void StopDecreasingFireAngle(bool slowly); + // Show hide the Character void Hide() { hidden = true; }; void Show() { hidden = false; }; @@ -236,13 +245,13 @@ public: void HandleKeyRefreshed_MoveLeft(bool /*slowly*/) {}; void HandleKeyReleased_MoveLeft(bool slowly); - void HandleKeyPressed_Up(bool slowly) { HandleKeyRefreshed_Up(slowly); }; - void HandleKeyRefreshed_Up(bool slowly); - void HandleKeyReleased_Up(bool /*slowly*/) const {}; + void HandleKeyPressed_Up(bool slowly); + void HandleKeyRefreshed_Up(bool /*slowly*/) {}; + void HandleKeyReleased_Up(bool slowly); - void HandleKeyPressed_Down(bool slowly) { HandleKeyRefreshed_Down(slowly); }; - void HandleKeyRefreshed_Down(bool slowly); - void HandleKeyReleased_Down(bool /*slowly*/) const {}; + void HandleKeyPressed_Down(bool slowly); + void HandleKeyRefreshed_Down(bool /*slowly*/) {}; + void HandleKeyReleased_Down(bool slowly); void HandleKeyPressed_Jump(); void HandleKeyRefreshed_Jump() const {}; diff --git a/src/include/action_handler.cpp b/src/include/action_handler.cpp index 7241d9e..588ab98 100644 --- a/src/include/action_handler.cpp +++ b/src/include/action_handler.cpp @@ -597,6 +597,34 @@ static void Action_Character_StopMovingRight(Action *a) ActiveCharacter().StopMovingRight(slowly); } +static void Action_Character_StartIncreasingFireAngle(Action *a) +{ + ASSERT(!Network::GetInstance()->IsTurnMaster()); + bool slowly = a->PopInt(); + ActiveCharacter().StartIncreasingFireAngle(slowly); +} + +static void Action_Character_StopIncreasingFireAngle(Action *a) +{ + ASSERT(!Network::GetInstance()->IsTurnMaster()); + bool slowly = a->PopInt(); + ActiveCharacter().StopIncreasingFireAngle(slowly); +} + +static void Action_Character_StartDecreasingFireAngle(Action *a) +{ + ASSERT(!Network::GetInstance()->IsTurnMaster()); + bool slowly = a->PopInt(); + ActiveCharacter().StartDecreasingFireAngle(slowly); +} + +static void Action_Character_StopDecreasingFireAngle(Action *a) +{ + ASSERT(!Network::GetInstance()->IsTurnMaster()); + bool slowly = a->PopInt(); + ActiveCharacter().StopDecreasingFireAngle(slowly); +} + static void Action_Weapon_Shoot (Action *a) { if (Game::GetInstance()->ReadState() != Game::PLAYING) @@ -951,6 +979,10 @@ void Action_Handler_Init() ActionHandler::GetInstance()->Register (Action::ACTION_CHARACTER_STOP_MOVING_LEFT, "CHARACTER_stop_moving_left", &Action_Character_StopMovingLeft); ActionHandler::GetInstance()->Register (Action::ACTION_CHARACTER_START_MOVING_RIGHT, "CHARACTER_start_moving_right", &Action_Character_StartMovingRight); ActionHandler::GetInstance()->Register (Action::ACTION_CHARACTER_STOP_MOVING_RIGHT, "CHARACTER_stop_moving_right", &Action_Character_StopMovingRight); + ActionHandler::GetInstance()->Register (Action::ACTION_CHARACTER_START_INCREASING_FIRE_ANGLE, "CHARACTER_start_increasing_fire_angle", &Action_Character_StartIncreasingFireAngle); + ActionHandler::GetInstance()->Register (Action::ACTION_CHARACTER_STOP_INCREASING_FIRE_ANGLE, "CHARACTER_stop_increasing_fire_angle", &Action_Character_StopIncreasingFireAngle); + ActionHandler::GetInstance()->Register (Action::ACTION_CHARACTER_START_DECREASING_FIRE_ANGLE, "CHARACTER_start_decreasing_fire_angle", &Action_Character_StartDecreasingFireAngle); + ActionHandler::GetInstance()->Register (Action::ACTION_CHARACTER_STOP_DECREASING_FIRE_ANGLE, "CHARACTER_stop_decreasing_fire_angle", &Action_Character_StopDecreasingFireAngle); // ######################################################## // Using Weapon -- 1.6.0.4 _______________________________________________ Wormux-dev mailing list Wormux-dev@gna.org https://mail.gna.org/listinfo/wormux-dev