player_controller.gd 770 B

1234567891011121314151617181920212223242526
  1. """
  2. The Player is a KinematicBody2D, in other words a physics-driven object.
  3. It can move, collide with the world...
  4. It HAS a state machine, but the body and the state machine are separate.
  5. """
  6. extends KinematicBody2D
  7. signal direction_changed(new_direction)
  8. var look_direction = Vector2(1, 0) setget set_look_direction
  9. func take_damage(attacker, amount, effect=null):
  10. if self.is_a_parent_of(attacker):
  11. return
  12. $States/Stagger.knockback_direction = (attacker.global_position - global_position).normalized()
  13. $Health.take_damage(amount, effect)
  14. func set_dead(value):
  15. set_process_input(not value)
  16. set_physics_process(not value)
  17. $CollisionPolygon2D.disabled = value
  18. func set_look_direction(value):
  19. look_direction = value
  20. emit_signal("direction_changed", value)