healing_beam.cpp 951 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #include "healing_beam.h"
  2. #include <cmath>
  3. namespace Game::Systems {
  4. HealingBeam::HealingBeam(const QVector3D &healer_pos,
  5. const QVector3D &target_pos, const QVector3D &color,
  6. float duration)
  7. : m_healer_pos(healer_pos), m_target_pos(target_pos), m_color(color),
  8. m_duration(duration) {
  9. float dist = (target_pos - healer_pos).length();
  10. m_beam_width = 0.1F + dist * 0.02F;
  11. }
  12. auto HealingBeam::get_arc_height() const -> float {
  13. float dist = (m_target_pos - m_healer_pos).length();
  14. return dist * 0.25F;
  15. }
  16. void HealingBeam::update(float delta_time) {
  17. if (!m_active) {
  18. return;
  19. }
  20. m_progress += delta_time / m_duration;
  21. if (m_progress >= 1.3F) {
  22. m_active = false;
  23. }
  24. float fade = 1.0F;
  25. if (m_progress > 1.0F) {
  26. fade = 1.0F - (m_progress - 1.0F) / 0.3F;
  27. }
  28. m_intensity = fade * (0.8F + 0.2F * std::sin(m_progress * 20.0F));
  29. }
  30. } // namespace Game::Systems