endsequence_walk.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // SuperTux - End Sequence: Tux walks right
  2. // Copyright (C) 2007 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.de>
  3. //
  4. // This program is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. #include "object/endsequence_walk.hpp"
  17. #include "object/player.hpp"
  18. #include "supertux/screen_manager.hpp"
  19. #include "supertux/sector.hpp"
  20. EndSequenceWalk::EndSequenceWalk() :
  21. EndSequence(),
  22. last_x_pos(),
  23. endsequence_timer()
  24. {
  25. }
  26. EndSequenceWalk::~EndSequenceWalk()
  27. {
  28. }
  29. void
  30. EndSequenceWalk::draw(DrawingContext& /*context*/)
  31. {
  32. }
  33. void
  34. EndSequenceWalk::starting()
  35. {
  36. EndSequence::starting();
  37. last_x_pos = -1;
  38. endsequence_timer.start(7.3f * ScreenManager::current()->get_speed());
  39. }
  40. void
  41. EndSequenceWalk::running(float dt_sec)
  42. {
  43. EndSequence::running(dt_sec);
  44. for (auto* player : Sector::get().get_players())
  45. {
  46. int dir = player->get_ending_direction();
  47. if (dir && !m_tux_is_stopped[player->get_id()]) {
  48. get_code_controller(player->get_id())->press(dir > 0 ? Control::RIGHT : Control::LEFT);
  49. if (int(last_x_pos) == int(player->get_pos().x)) {
  50. get_code_controller(player->get_id())->press(Control::JUMP);
  51. }
  52. last_x_pos = player->get_pos().x;
  53. }
  54. }
  55. if (endsequence_timer.check()) m_is_done = true;
  56. }
  57. void
  58. EndSequenceWalk::stopping()
  59. {
  60. EndSequence::stopping();
  61. }
  62. /* EOF */