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.

116 lines
3.6KB

  1. extends Node2D
  2. const ANIM_RATE_DEFAULT = 3.5
  3. const ANIM_RATE_AGGRESSIVE = 6.0
  4. const ANIM_RATE_CONTENT = 1.0
  5. const EXCITEMENT_MIN_SPEED = 150
  6. const EXCITEMENT_MAX_SPEED = 350
  7. # Mood = r: <aggression>, g: <neediness>, b: <contentment>
  8. # <aggression> Affects how strong a players push is and how strong the player's collision with the world will be.
  9. # <neediness> Affects how quickly and strongly the player will follow the mouse
  10. # <contentment> Affects how slowly mood color is shifted back to neutral and widens comfort distance
  11. var _mood = Color.black
  12. onready var _spr = get_parent().get_node("Sprite")
  13. onready var _body_radius = get_parent().get_node("CollisionShape2D").shape.radius
  14. func adjust_mood(r, g, b):
  15. _mood.r = clamp(_mood.r + r, 0.0, 1.0)
  16. _mood.g = clamp(_mood.g + g, 0.0, 1.0)
  17. _mood.b = clamp(_mood.b + b, 0.0, 1.0)
  18. _spr.material.set_shader_param("cell_color", _mood);
  19. if is_aggressive():
  20. _spr.material.set_shader_param("cell_energy", ANIM_RATE_AGGRESSIVE)
  21. elif is_content():
  22. _spr.material.set_shader_param("cell_energy", ANIM_RATE_CONTENT)
  23. else:
  24. _spr.material.set_shader_param("cell_energy", ANIM_RATE_DEFAULT)
  25. func adjust_mood_from_color(c):
  26. if c.r != c.g or c.r != c.b: # Only adjust mood if not all values are the same.
  27. # Even if not all the same, there must be a single dominant color for mood to be adjusted.
  28. if c.r > c.g and c.r > c.b:
  29. adjust_mood(0.25, 0.0, 0.0)
  30. if c.g > c.r and c.g > c.b:
  31. adjust_mood(0.0, 0.25, 0.0)
  32. if c.b > c.r and c.b > c.g:
  33. adjust_mood(0.0, 0.0, 0.25)
  34. func is_aggressive():
  35. return _mood.r > _mood.g and _mood.r > _mood.b
  36. func is_needie():
  37. return _mood.g > _mood.r and _mood.g > _mood.b
  38. func is_content():
  39. return _mood.b > _mood.r and _mood.b > _mood.g
  40. func is_neutral():
  41. return not is_aggressive() and not is_needie() and not is_content()
  42. func get_aggression():
  43. return _mood.r
  44. func get_need():
  45. return _mood.g
  46. func get_contentment():
  47. return _mood.b
  48. func get_comfort_distance():
  49. return get_parent().get_node("CollisionShape2D").shape.radius * 2.1
  50. func get_mood_color():
  51. return _mood
  52. func _agg_shift(in_air, speed):
  53. var v = -0.1 # By default, aggression is always lowering
  54. if in_air and speed >= EXCITEMENT_MIN_SPEED and speed <= EXCITEMENT_MAX_SPEED:
  55. v = 0.1 # If in the air, going at an "exciting" speed, aggression rises!
  56. elif is_aggressive():
  57. v = -0.05 # Otherwise, if we're dominantly aggressive, slow aggression cooldown.
  58. if speed > 1.0 and _mood.r * 0.5 > _mood.b and _mood.r * 0.5 > _mood.g:
  59. v = 0.0 # But, if we're moving and our aggression is more than twice the other emotions, don't cooldown at all.
  60. return v
  61. func _need_shift(in_air, distance):
  62. var v = -0.1
  63. if in_air:
  64. # Decrease neediness faster while in air, as "player" is giving attension (in the air) or
  65. # otherwise excited!!
  66. v = -0.25
  67. else:
  68. var cdist = get_comfort_distance()
  69. if distance > cdist:
  70. v = 0.1
  71. if distance > cdist * 8.0:
  72. v = 0.25
  73. return v
  74. func _con_shift(in_air, speed, distance):
  75. var v = -0.1
  76. if in_air and speed < EXCITEMENT_MIN_SPEED:
  77. v = 0.1
  78. if is_aggressive(): # Assuming aggression hasn't taken over...
  79. v = 0.05 # Levitating in the air is nice!
  80. else:
  81. var cdist = get_comfort_distance()
  82. if distance <= cdist:
  83. v = 0.1 # It's nice when the player is nearby
  84. if is_needie():
  85. v = 0.05 # My neediness is slowing my contentment.
  86. elif is_aggressive():
  87. v = -0.25 # If aggressive, reduce contentment a lot.
  88. return v
  89. func shift_mood(delta, in_air, speed, distance):
  90. adjust_mood(
  91. _agg_shift(in_air, speed) * delta,
  92. _need_shift(in_air, distance) * delta,
  93. _con_shift(in_air, speed, distance) * delta
  94. )