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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. tool
  2. extends Node2D
  3. const PUSH_VEC_DEFAULT = Vector2(0.0, -1.0)
  4. export var pulse_color:Color = Color(1.0, 1.0, 1.0, 1.0) setget _set_color
  5. export(float, 0, 400) var push_force = 128
  6. export(float, 0, 1.0) var push_frequency = 0.2
  7. export(float, -180.0, 180) var push_angle = 0 setget _set_angle
  8. var _bodies = []
  9. var _delay = 1.1
  10. func _set_angle(a):
  11. push_angle = a
  12. $Body.rotation_degrees = push_angle
  13. func _set_color(c):
  14. pulse_color = c
  15. for i in range(6):
  16. get_node("Body/PulseArrow" + String(i + 1)).set_color(pulse_color)
  17. $Body/Particles.process_material.color = c
  18. func _dominant_color(c):
  19. if c.r > c.g and c.r > c.b:
  20. return "r"
  21. elif c.g > c.r and c.g > c.b:
  22. return "g"
  23. elif c.b > c.r and c.b > c.g:
  24. return "b"
  25. return "n"
  26. func _ready():
  27. set_process(true)
  28. for i in range(6):
  29. get_node("Body/PulseArrow" + String(i + 1)).set_color(pulse_color)
  30. func _rim_match(body):
  31. if body.has_method("get_rim_color"):
  32. var rdc = _dominant_color(body.get_rim_color())
  33. var dc = _dominant_color(pulse_color)
  34. print ("RIM: ", rdc, " | Push: ", dc)
  35. if (rdc == dc):
  36. return true
  37. return false
  38. func _process(delta):
  39. if _bodies.size() > 0 and _delay >= push_frequency:
  40. _delay = 0.0
  41. var v = PUSH_VEC_DEFAULT.rotated(deg2rad(push_angle))
  42. for i in range(_bodies.size()):
  43. if _rim_match(_bodies[i]):
  44. _bodies[i].apply_central_impulse(v * push_force)
  45. else:
  46. _delay = min(1.1, _delay + delta)
  47. func _has_body(body):
  48. for i in range(_bodies.size()):
  49. if _bodies[i] == body:
  50. return i
  51. return -1
  52. func _on_Area2D_body_entered(body):
  53. if body.is_in_group("Player") and _has_body(body) < 0:
  54. _bodies.append(body)
  55. func _on_Area2D_body_exited(body):
  56. var id = _has_body(body)
  57. if (id >= 0):
  58. _bodies.remove(id)