AlterationLabel.gd 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. extends Label
  2. #
  3. var timeLeft : float = 3.0
  4. var fadingTime : float = 1.0
  5. var velocity : Vector2 = Vector2.ZERO
  6. var criticalHit : bool = false
  7. var HSVA : Vector4 = Vector4.ZERO
  8. var floorPosition : float = 0.0
  9. var bounce : bool = false
  10. const gravityRedux : float = 180.0
  11. const maxVelocityAngle : float = 36
  12. const minVelocitySpeed : float = 24.0
  13. const maxVelocitySpeed : float = 60.0
  14. const overheadOffset : int = -10
  15. #
  16. func SetPosition(startPos : Vector2, floorPos : Vector2):
  17. position = startPos
  18. floorPosition = floorPos.y
  19. func SetValue(dealer : Entity, value : int, alteration : ActorCommons.Alteration):
  20. velocity.x = randf_range(-maxVelocityAngle, maxVelocityAngle)
  21. velocity.y = randf_range(minVelocitySpeed, maxVelocitySpeed)
  22. var hue : float = 0.0
  23. match alteration:
  24. ActorCommons.Alteration.CRIT:
  25. criticalHit = true
  26. bounce = true
  27. set_text(str(value))
  28. ActorCommons.Alteration.DODGE:
  29. hue = ActorCommons.DodgeAttackColor
  30. bounce = true
  31. set_text("dodge")
  32. ActorCommons.Alteration.HIT:
  33. bounce = true
  34. if dealer == Launcher.Player:
  35. hue = ActorCommons.LocalAttackColor
  36. elif dealer.type == ActorCommons.Type.PLAYER:
  37. hue = ActorCommons.PlayerAttackColor
  38. else:
  39. hue = ActorCommons.MonsterAttackColor
  40. set_text(str(value))
  41. ActorCommons.Alteration.MISS:
  42. bounce = true
  43. hue = ActorCommons.MissAttackColor
  44. set_text("miss")
  45. ActorCommons.Alteration.HEAL:
  46. bounce = true
  47. hue = ActorCommons.HealColor
  48. set_text(str(value))
  49. ActorCommons.Alteration.EXP:
  50. velocity = Vector2(0.0, 12)
  51. floorPosition = -100000.0
  52. hue = ActorCommons.ExpColor
  53. set_text("%d xp" % value)
  54. ActorCommons.Alteration.GP:
  55. velocity = Vector2(0.0, 12)
  56. hue = ActorCommons.GPColor
  57. set_text("%d GP" % value)
  58. _:
  59. assert(false, "Alteration type not handled: " + str(alteration))
  60. HSVA = Vector4(hue, 0.8, 1.0, 1.0)
  61. add_theme_color_override("font_color", Color.from_hsv(HSVA.x, HSVA.y, HSVA.z, HSVA.w))
  62. add_theme_color_override("font_outline_color", Color.from_hsv(HSVA.x, HSVA.y, 0.0, HSVA.w))
  63. #
  64. func _process(delta):
  65. timeLeft -= delta
  66. if timeLeft <= 0.0:
  67. queue_free()
  68. return
  69. if timeLeft < fadingTime:
  70. modulate.a = timeLeft / fadingTime
  71. if velocity != Vector2.ZERO:
  72. var deltaVelocity : Vector2 = velocity * delta
  73. if bounce:
  74. if position.y - deltaVelocity.y >= floorPosition:
  75. velocity.y = -velocity.y
  76. velocity.y *= 0.66
  77. velocity.y -= gravityRedux * delta
  78. position -= deltaVelocity
  79. if criticalHit:
  80. HSVA.x = HSVA.x + delta * 2
  81. if HSVA.x > 1.0:
  82. HSVA.x = 0.0
  83. if HSVA.x > 0.3 and HSVA.x < 0.7:
  84. HSVA.x = 0.7
  85. add_theme_color_override("font_color", Color.from_hsv(HSVA.x, HSVA.y, HSVA.z, HSVA.w))
  86. add_theme_color_override("font_outline_color", Color.from_hsv(HSVA.x, HSVA.y, 0.2, HSVA.w))