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.

64 lines
1.2KB

  1. extends Node2D
  2. export var color:Color
  3. export var transition_rate = 0.75
  4. var _body = null
  5. var _triggered = false
  6. func _dominant_color():
  7. if color.r > color.g and color.r > color.b:
  8. return "r"
  9. if color.g > color.r and color.g > color.b:
  10. return "g"
  11. if color.b > color.r and color.b > color.g:
  12. return "b"
  13. return "n"
  14. func _ready():
  15. $LeftDoor.set_color(color)
  16. $LeftDoor.transition_rate = transition_rate
  17. $RightDoor.set_color(color)
  18. $RightDoor.transition_rate = transition_rate
  19. set_process(true)
  20. func _process(delta):
  21. if _body == null or _triggered:
  22. return
  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()) or \
  28. (dc == "n" and mood.is_neutral()):
  29. _triggered = true
  30. open()
  31. func open():
  32. $LeftDoor.open()
  33. $RightDoor.open()
  34. func close():
  35. $LeftDoor.close()
  36. $RightDoor.close()
  37. func stop():
  38. $LeftDoor.stop()
  39. $RightDoor.stop()
  40. func _on_Area2D_body_entered(body):
  41. if _body == null and body.is_in_group("Player"):
  42. _body = body
  43. _triggered = false
  44. func _on_Area2D_body_exited(body):
  45. if body == _body:
  46. _body = null
  47. _triggered = false
  48. close()