particle_zone.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. // SuperTux - Particle spawn zone
  2. // Copyright (C) 2020 A. Semphris <semphris@protonmail.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/particle_zone.hpp"
  17. #include "editor/editor.hpp"
  18. #include "supertux/resources.hpp"
  19. #include "util/reader_mapping.hpp"
  20. #include "video/drawing_context.hpp"
  21. ParticleZone::ParticleZone(const ReaderMapping& reader) :
  22. MovingObject(reader),
  23. m_enabled(),
  24. m_particle_name()
  25. {
  26. parse_type(reader);
  27. float w,h;
  28. reader.get("x", m_col.m_bbox.get_left(), 0.0f);
  29. reader.get("y", m_col.m_bbox.get_top(), 0.0f);
  30. reader.get("width", w, 32.0f);
  31. reader.get("height", h, 32.0f);
  32. m_col.m_bbox.set_size(w, h);
  33. reader.get("enabled", m_enabled, true);
  34. reader.get("particle-name", m_particle_name, "");
  35. set_group(COLGROUP_TOUCHABLE);
  36. }
  37. ObjectSettings
  38. ParticleZone::get_settings()
  39. {
  40. ObjectSettings result = MovingObject::get_settings();
  41. result.add_bool(_("Enabled"), &m_enabled, "enabled", true);
  42. result.add_text(_("Particle Name"), &m_particle_name, "particle-name");
  43. result.reorder({"width", "height", "name", "x", "y"});
  44. return result;
  45. }
  46. GameObjectTypes
  47. ParticleZone::get_types() const
  48. {
  49. return {
  50. { "spawn", _("Spawn") },
  51. { "life", _("Life zone") },
  52. { "life-clear", _("Life zone (clear)") },
  53. { "killer", _("Kill particles") },
  54. { "destroyer", _("Clear particles") }
  55. };
  56. }
  57. void
  58. ParticleZone::update(float dt_sec)
  59. {
  60. // This object doesn't manage creating particles :)
  61. // See `src/object/custom_particle_system.*pp` for that
  62. }
  63. void
  64. ParticleZone::draw(DrawingContext& context)
  65. {
  66. if (Editor::is_active()) {
  67. Color c;
  68. switch(m_type) {
  69. case ParticleZoneType::Spawn:
  70. c = Color(0.5f, 0.5f, 1.0f, 0.6f);
  71. break;
  72. case ParticleZoneType::Life:
  73. c = Color(0.5f, 1.0f, 0.5f, 0.6f);
  74. break;
  75. case ParticleZoneType::LifeClear:
  76. c = Color(1.0f, 1.0f, 0.5f, 0.6f);
  77. break;
  78. case ParticleZoneType::Killer:
  79. c = Color(1.0f, 0.75f, 0.5f, 0.6f);
  80. break;
  81. case ParticleZoneType::Destroyer:
  82. c = Color(1.0f, 0.5f, 0.5f, 0.6f);
  83. break;
  84. }
  85. context.color().draw_filled_rect(m_col.m_bbox, c,
  86. 0.0f, LAYER_OBJECTS);
  87. context.color().draw_text(Resources::small_font,
  88. m_particle_name,
  89. m_col.m_bbox.p1(),
  90. FontAlignment::ALIGN_LEFT,
  91. LAYER_OBJECTS,
  92. Color::WHITE);
  93. }
  94. }
  95. HitResponse
  96. ParticleZone::collision(MovingObject& other, const CollisionHit& hit)
  97. {
  98. return ABORT_MOVE;
  99. }
  100. /* EOF */