fireworks.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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/fireworks.hpp"
  17. #include "audio/sound_manager.hpp"
  18. #include "math/random.hpp"
  19. #include "object/camera.hpp"
  20. #include "object/particles.hpp"
  21. #include "supertux/sector.hpp"
  22. #include "video/drawing_context.hpp"
  23. #include "video/video_system.hpp"
  24. #include "video/viewport.hpp"
  25. Fireworks::Fireworks() :
  26. timer()
  27. {
  28. timer.start(.2f);
  29. SoundManager::current()->preload("sounds/fireworks.wav");
  30. }
  31. void
  32. Fireworks::update(float )
  33. {
  34. if (timer.check()) {
  35. Vector pos = Sector::get().get_camera().get_translation();
  36. pos += Vector(graphicsRandom.randf(static_cast<float>(SCREEN_WIDTH)),
  37. graphicsRandom.randf(static_cast<float>(SCREEN_HEIGHT) / 2.0f));
  38. float red = graphicsRandom.randf(1.0f);
  39. float green = graphicsRandom.randf(1.0f);
  40. Sector::get().add<Particles>(
  41. pos, 0, 360, 140.0f, 140.0f,
  42. Vector(0, 0), 45, Color(red, green, 0.0f), 3, 1.3f,
  43. LAYER_FOREGROUND1+1);
  44. SoundManager::current()->play("sounds/fireworks.wav");
  45. timer.start(graphicsRandom.randf(1.0f, 1.5f));
  46. }
  47. }
  48. void
  49. Fireworks::draw(DrawingContext& )
  50. {
  51. }
  52. /* EOF */