A game created for the Godot Wild Jam #21
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
1.6KB

  1. extends Node2D
  2. const PUSH_VEC_DEFAULT = Vector2(0.0, -1.0)
  3. export var pulse_color:Color = Color(1.0, 1.0, 1.0, 1.0)
  4. export(float, 0, 400) var push_force = 128
  5. export(float, 0, 1.0) var push_frequency = 0.2
  6. export(float, -180.0, 180) var push_angle = 0
  7. var _bodies = []
  8. var _delay = 1.1
  9. func _dominant_color():
  10. if pulse_color.r > pulse_color.g and pulse_color.r > pulse_color.b:
  11. return "r"
  12. elif pulse_color.g > pulse_color.r and pulse_color.g > pulse_color.b:
  13. return "g"
  14. elif pulse_color.b > pulse_color.r and pulse_color.b > pulse_color.g:
  15. return "b"
  16. return "n"
  17. func _ready():
  18. set_process(true)
  19. for i in range(6):
  20. get_node("PulseArrow" + String(i + 1)).set_color(pulse_color)
  21. func _mood_match(body):
  22. if body.has_method("get_mood"):
  23. var mood = body.get_mood()
  24. var dc = _dominant_color()
  25. if (dc == "r" and mood.is_aggressive()) or \
  26. (dc == "g" and mood.is_needie()) or \
  27. (dc == "b" and mood.is_content()):
  28. return true
  29. return false
  30. func _process(delta):
  31. if _bodies.size() > 0 and _delay >= push_frequency:
  32. _delay = 0.0
  33. var v = PUSH_VEC_DEFAULT.rotated(deg2rad(push_angle))
  34. for i in range(_bodies.size()):
  35. if _mood_match(_bodies[i]):
  36. _bodies[i].apply_central_impulse(v * push_force)
  37. else:
  38. _delay = min(1.1, _delay + delta)
  39. func _has_body(body):
  40. for i in range(_bodies.size()):
  41. if _bodies[i] == body:
  42. return i
  43. return -1
  44. func _on_Area2D_body_entered(body):
  45. if body.is_in_group("Player") and _has_body(body) < 0:
  46. _bodies.append(body)
  47. func _on_Area2D_body_exited(body):
  48. var id = _has_body(body)
  49. if (id >= 0):
  50. _bodies.remove(id)