flower.cpp 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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/flower.hpp"
  17. #include "audio/sound_manager.hpp"
  18. #include "object/player.hpp"
  19. #include "sprite/sprite.hpp"
  20. #include "sprite/sprite_manager.hpp"
  21. #include "supertux/flip_level_transformer.hpp"
  22. Flower::Flower(BonusType _type, const std::string& custom_sprite) :
  23. type(_type),
  24. sprite(),
  25. flip(NO_FLIP),
  26. lightsprite(SpriteManager::current()->create("images/objects/lightmap_light/lightmap_light-small.sprite"))
  27. {
  28. m_col.m_bbox.set_size(32, 32);
  29. lightsprite->set_blend(Blend::ADD);
  30. if (type == FIRE_BONUS) {
  31. sprite = SpriteManager::current()->create(custom_sprite.empty() ? "images/powerups/fireflower/fireflower.sprite" : custom_sprite);
  32. SoundManager::current()->preload("sounds/fire-flower.wav");
  33. lightsprite->set_color(Color(0.3f, 0.0f, 0.0f));
  34. }
  35. else if (type == ICE_BONUS) {
  36. sprite = SpriteManager::current()->create(custom_sprite.empty() ? "images/powerups/iceflower/iceflower.sprite" : custom_sprite);
  37. SoundManager::current()->preload("sounds/fire-flower.wav");
  38. lightsprite->set_color(Color(0.0f, 0.1f, 0.2f));
  39. }
  40. else if (type == AIR_BONUS) {
  41. sprite = SpriteManager::current()->create(custom_sprite.empty() ? "images/powerups/airflower/airflower.sprite" : custom_sprite);
  42. SoundManager::current()->preload("sounds/fire-flower.wav");
  43. lightsprite->set_color(Color(0.15f, 0.0f, 0.15f));
  44. }
  45. else if (type == EARTH_BONUS) {
  46. sprite = SpriteManager::current()->create(custom_sprite.empty() ? "images/powerups/earthflower/earthflower.sprite" : custom_sprite);
  47. SoundManager::current()->preload("sounds/fire-flower.wav");
  48. lightsprite->set_color(Color(0.0f, 0.3f, 0.0f));
  49. } else {
  50. assert(false);
  51. }
  52. set_group(COLGROUP_TOUCHABLE);
  53. }
  54. void
  55. Flower::update(float )
  56. {
  57. }
  58. void
  59. Flower::draw(DrawingContext& context)
  60. {
  61. sprite->draw(context.color(), get_pos(), LAYER_OBJECTS, flip);
  62. lightsprite->draw(context.light(), m_col.m_bbox.get_middle(), 0);
  63. }
  64. HitResponse
  65. Flower::collision(GameObject& other, const CollisionHit& )
  66. {
  67. Player* player = dynamic_cast<Player*>(&other);
  68. if (!player)
  69. return ABORT_MOVE;
  70. if (!player->add_bonus(type, true))
  71. return FORCE_MOVE;
  72. SoundManager::current()->play("sounds/fire-flower.wav", get_pos());
  73. remove_me();
  74. return ABORT_MOVE;
  75. }
  76. void
  77. Flower::on_flip(float height)
  78. {
  79. MovingObject::on_flip(height);
  80. FlipLevelTransformer::transform_flip(flip);
  81. }
  82. /* EOF */