feat: add animation player node; add animation for the animation player node with the sword;
This commit is contained in:
+30
-9
@@ -4,6 +4,7 @@ class_name Player
|
||||
@export var move_speed: float = 100
|
||||
@export var hp: int = 10
|
||||
@export var push_strength: int = 50
|
||||
var is_attacking: bool = false
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
@@ -16,7 +17,8 @@ func _ready() -> void:
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _physics_process(delta: float) -> void:
|
||||
move_player()
|
||||
if not is_attacking:
|
||||
move_player()
|
||||
push_blocks()
|
||||
update_scrolls()
|
||||
move_and_slide()
|
||||
@@ -78,18 +80,37 @@ func _on_sword_area_2d_body_entered(body: Node2D) -> void:
|
||||
body.queue_free()
|
||||
|
||||
func attack():
|
||||
if velocity.x > 0:
|
||||
$Sword.position = Vector2(0, 0.5)
|
||||
elif velocity.x < 0:
|
||||
$Sword.position = Vector2(-5, 2)
|
||||
elif velocity.y > 0:
|
||||
$Sword.position = Vector2(0, 8)
|
||||
elif velocity.y < 0:
|
||||
$Sword.position = Vector2(0, -4)
|
||||
var player_animation: String = $AnimatedSprite2D.animation
|
||||
if player_animation == "move_right":
|
||||
$AnimatedSprite2D.play("attack_right")
|
||||
$AnimationPlayer.play("attack_right")
|
||||
if player_animation == "move_left":
|
||||
$AnimatedSprite2D.play("attack_left")
|
||||
$AnimationPlayer.play("attack_left")
|
||||
if player_animation == "move_up":
|
||||
$AnimatedSprite2D.play("attack_up")
|
||||
$AnimationPlayer.play("attack_up")
|
||||
if player_animation == "move_down":
|
||||
$AnimatedSprite2D.play("attack_down")
|
||||
$AnimationPlayer.play("attack_bottom")
|
||||
|
||||
is_attacking = true
|
||||
velocity = Vector2(0,0 )
|
||||
|
||||
$Sword.visible = true
|
||||
$Sword/SwordArea2D.monitoring = true
|
||||
$Sword/SwordTimer.start()
|
||||
|
||||
func _on_sword_timer_timeout() -> void:
|
||||
is_attacking = false
|
||||
$Sword.visible = false
|
||||
$Sword/SwordArea2D.monitoring = false
|
||||
var player_animation: String = $AnimatedSprite2D.animation
|
||||
if player_animation == "attack_right":
|
||||
$AnimatedSprite2D.play("move_right")
|
||||
if player_animation == "attack_left":
|
||||
$AnimatedSprite2D.play("move_left")
|
||||
if player_animation == "attack_up":
|
||||
$AnimatedSprite2D.play("move_up")
|
||||
if player_animation == "attack_down":
|
||||
$AnimatedSprite2D.play("move_down")
|
||||
|
||||
Reference in New Issue
Block a user