Added health bars

This commit is contained in:
2024-02-13 00:22:27 +01:00
parent ba978049a5
commit 6727be5cd0
23 changed files with 154 additions and 41 deletions

View File

@ -0,0 +1,55 @@
class_name AnimationComponent
extends Node
const RESET = "human/RESET"
var animation_player: AnimationPlayer
var movement: MovementComponent
var next_animation: StringName = RESET
var skip: int
func _ready():
var player := owner as Player
player.dashed.connect(dash)
player.attacked.connect(attack)
movement = player.find_child("Movement")
animation_player = $AnimationPlayer
func _process(_delta):
if skip == 0:
play_movement()
if animation_player.current_animation == next_animation:
return
animation_player.play(next_animation)
func play_movement():
if !movement:
play(RESET)
return
if movement.body.velocity.y > 0:
play("human/jump")
elif movement.body.velocity.y < 0:
play("human/fall")
elif movement.direction != Vector3.ZERO:
play("human/run-fast")
else:
play("human/idle")
func dash():
play_with_duration("human/roll", 1.0)
func attack():
play_with_duration("human/slash", 1.0)
func play(action_name: StringName):
next_animation = action_name
func play_with_duration(action_name: StringName, duration: float):
next_animation = action_name
skip += 1
await get_tree().create_timer(duration).timeout
skip -= 1

View File

@ -0,0 +1,9 @@
[gd_scene load_steps=2 format=3 uid="uid://bivxnxwi863o0"]
[ext_resource type="Script" path="res://player/animation/AnimationComponent.gd" id="1_lenw3"]
[node name="Animation" type="Node"]
script = ExtResource("1_lenw3")
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
playback_default_blend_time = 0.2