particle_zone.cpp 3.2 KB

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