coin_explode.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // CoinExplode - several coins are hurled through the air
  2. // Copyright (C) 2013 LMH <lmh.0013@gmail.com>
  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/coin_explode.hpp"
  17. #include "math/random.hpp"
  18. #include "object/coin.hpp"
  19. #include "supertux/sector.hpp"
  20. #include <list>
  21. CoinExplode::CoinExplode(const Vector& pos, bool count_stats, const std::string& sprite) :
  22. m_sprite(sprite),
  23. position(pos),
  24. m_count_stats(count_stats)
  25. {
  26. }
  27. void
  28. CoinExplode::update(float )
  29. {
  30. float mag = 100.0f; // Magnitude at which coins are thrown.
  31. float rand = 30.0f; // Max variation to be subtracted from the magnitude.
  32. // Each coin in the explosion has a different velocity.
  33. static std::list<Vector> coin_velocities = {
  34. { 2.5, -4.5 }, { 2, -5 },
  35. { 1.5, -5.5 }, { 1, -6 }, { 0.5, -6.5 },
  36. { -2.5, -4.5 }, { -2, -5 },
  37. { -1.5, -5.5 }, { -1, -6 }, { -0.5, -6.5 }
  38. };
  39. for(const auto& vector: coin_velocities)
  40. {
  41. auto velocity = vector * (mag - gameRandom.randf(rand));
  42. Sector::get().add<HeavyCoin>(position, velocity, m_count_stats, m_sprite);
  43. }
  44. remove_me();
  45. }
  46. void
  47. CoinExplode::draw(DrawingContext &)
  48. {
  49. }
  50. /* EOF */