extends KinematicBody2D const ACCELERATION = 1000 var hud: CanvasLayer = null const HEALTH_SLICES: Array = [0, 20, 35, 50, 65, 80, 100] var health_index: int = 6 const MAX_SPEED = 120 const FRICTION = 1000 var velocity: Vector2 = Vector2.ZERO func _physics_process(delta) -> void: var input_vector: Vector2 = Vector2.ZERO input_vector.x = Input.get_action_strength('player_right') - Input.get_action_strength('player_left') input_vector.y = Input.get_action_strength('player_down') - Input.get_action_strength('player_up') input_vector = input_vector.normalized() if input_vector != Vector2.ZERO: $AnimationTree.set('parameters/Idle/blend_position', input_vector) velocity = velocity.move_toward(input_vector * MAX_SPEED, ACCELERATION * delta) else: velocity = velocity.move_toward(Vector2.ZERO, FRICTION * delta) velocity = move_and_slide(velocity) return func load_hud(node: CanvasLayer) -> void: hud = node #if hud.connect('add_currency', self, 'add_currency') != OK: #print('ERROR: HUD "add_currency" signal already connected.') hud.update_health(HEALTH_SLICES[health_index]) hud.update_currency($Inventory.get_currency()) return