specialriser.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // SuperTux
  2. // Copyright (C) 2006 Matthias Braun <matze@braunis.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/specialriser.hpp"
  17. #include "supertux/sector.hpp"
  18. #include "video/drawing_context.hpp"
  19. SpecialRiser::SpecialRiser(const Vector& pos, std::unique_ptr<MovingObject> child, bool is_solid) :
  20. m_start_pos(pos),
  21. m_offset(0),
  22. m_child(std::move(child))
  23. {
  24. m_child->set_pos(pos - Vector(0,32));
  25. set_pos(m_start_pos);
  26. m_col.m_bbox.set_size(m_child->get_bbox().get_width(), 32);
  27. // Initial update of child object, in case it's required to be visible.
  28. // For example, badguys.
  29. m_child->update(0.f);
  30. if (is_solid)
  31. set_group(COLGROUP_STATIC);
  32. else
  33. set_group(COLGROUP_DISABLED);
  34. }
  35. void
  36. SpecialRiser::update(float dt_sec)
  37. {
  38. m_offset += 50 * dt_sec;
  39. set_pos(m_start_pos - Vector(0, m_offset));
  40. if (m_offset > 32) {
  41. Sector::get().add_object(std::move(m_child));
  42. remove_me();
  43. }
  44. }
  45. void
  46. SpecialRiser::draw(DrawingContext& context)
  47. {
  48. context.push_transform();
  49. context.set_translation(
  50. context.get_translation() + Vector(0, -32 + m_offset));
  51. m_child->draw(context);
  52. context.pop_transform();
  53. }
  54. /* EOF */