feat: add animation player node; add animation for the animation player node with the sword;
This commit is contained in:
+29
-8
@@ -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,6 +17,7 @@ func _ready() -> void:
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _physics_process(delta: float) -> void:
|
||||
if not is_attacking:
|
||||
move_player()
|
||||
push_blocks()
|
||||
update_scrolls()
|
||||
@@ -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")
|
||||
|
||||
+159
-6
@@ -2,7 +2,7 @@
|
||||
|
||||
[ext_resource type="Script" uid="uid://duilaa5lwqeup" path="res://Scenes/Player/player.gd" id="1_a3d8c"]
|
||||
[ext_resource type="Texture2D" uid="uid://cjbvc07lh4x1b" path="res://Ninja Adventure - Asset Pack/Actor/Characters/KnightGold/SeparateAnim/Walk.png" id="2_a3d8c"]
|
||||
[ext_resource type="Texture2D" uid="uid://0k8vid4d4k6n" path="res://Ninja Adventure - Asset Pack/Actor/Characters/NinjaBlue/SeparateAnim/Attack.png" id="2_dd0ac"]
|
||||
[ext_resource type="Texture2D" uid="uid://cpuphg0fwkemr" path="res://Ninja Adventure - Asset Pack/Actor/Characters/KnightGold/SeparateAnim/Attack.png" id="2_dd0ac"]
|
||||
[ext_resource type="Texture2D" uid="uid://6dmy1j0t5mqy" path="res://Ninja Adventure - Asset Pack/Items/Scroll/ScrollEmpty.png" id="3_xpcdj"]
|
||||
[ext_resource type="Texture2D" uid="uid://ff3wjwfsais6" path="res://Ninja Adventure - Asset Pack/Ui/LifeReceptacle/heart_2.png" id="4_mtuoh"]
|
||||
[ext_resource type="Texture2D" uid="uid://38ldil8moinv" path="res://Ninja Adventure - Asset Pack/Items/Weapons/Sword2/SpriteInHand.png" id="5_htcer"]
|
||||
@@ -17,7 +17,7 @@ region = Rect2(32, 0, 16, 16)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_rqdc0"]
|
||||
atlas = ExtResource("2_dd0ac")
|
||||
region = Rect2(32, 0, 16, 16)
|
||||
region = Rect2(48, 0, 16, 16)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_qr1w5"]
|
||||
atlas = ExtResource("2_dd0ac")
|
||||
@@ -257,6 +257,152 @@ animations = [{
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_3rdvi"]
|
||||
size = Vector2(10, 13)
|
||||
|
||||
[sub_resource type="Animation" id="Animation_gk6dx"]
|
||||
length = 0.001
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath("Sword:rotation")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0),
|
||||
"transitions": PackedFloat32Array(1),
|
||||
"update": 0,
|
||||
"values": [1.5707964]
|
||||
}
|
||||
tracks/1/type = "value"
|
||||
tracks/1/imported = false
|
||||
tracks/1/enabled = true
|
||||
tracks/1/path = NodePath("Sword:position")
|
||||
tracks/1/interp = 1
|
||||
tracks/1/loop_wrap = true
|
||||
tracks/1/keys = {
|
||||
"times": PackedFloat32Array(0),
|
||||
"transitions": PackedFloat32Array(1),
|
||||
"update": 0,
|
||||
"values": [Vector2(-3, -13)]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id="Animation_jhyir"]
|
||||
resource_name = "attack_bottom"
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath("Sword:position")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0),
|
||||
"transitions": PackedFloat32Array(1),
|
||||
"update": 0,
|
||||
"values": [Vector2(0, 13)]
|
||||
}
|
||||
tracks/1/type = "value"
|
||||
tracks/1/imported = false
|
||||
tracks/1/enabled = true
|
||||
tracks/1/path = NodePath("Sword:rotation")
|
||||
tracks/1/interp = 1
|
||||
tracks/1/loop_wrap = true
|
||||
tracks/1/keys = {
|
||||
"times": PackedFloat32Array(0),
|
||||
"transitions": PackedFloat32Array(1),
|
||||
"update": 0,
|
||||
"values": [0.0]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id="Animation_jlvik"]
|
||||
resource_name = "attack_left"
|
||||
length = 0.19999999999999998
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath("Sword:rotation")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0),
|
||||
"transitions": PackedFloat32Array(1),
|
||||
"update": 0,
|
||||
"values": [1.5707964]
|
||||
}
|
||||
tracks/1/type = "value"
|
||||
tracks/1/imported = false
|
||||
tracks/1/enabled = true
|
||||
tracks/1/path = NodePath("Sword:position")
|
||||
tracks/1/interp = 1
|
||||
tracks/1/loop_wrap = true
|
||||
tracks/1/keys = {
|
||||
"times": PackedFloat32Array(0),
|
||||
"transitions": PackedFloat32Array(1),
|
||||
"update": 0,
|
||||
"values": [Vector2(-13, 4)]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id="Animation_dd0ac"]
|
||||
resource_name = "attack_right"
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath("Sword:position")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0),
|
||||
"transitions": PackedFloat32Array(1),
|
||||
"update": 0,
|
||||
"values": [Vector2(13, 4)]
|
||||
}
|
||||
tracks/1/type = "value"
|
||||
tracks/1/imported = false
|
||||
tracks/1/enabled = true
|
||||
tracks/1/path = NodePath("Sword:rotation")
|
||||
tracks/1/interp = 1
|
||||
tracks/1/loop_wrap = true
|
||||
tracks/1/keys = {
|
||||
"times": PackedFloat32Array(0),
|
||||
"transitions": PackedFloat32Array(1),
|
||||
"update": 0,
|
||||
"values": [4.712389]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id="Animation_0u5uq"]
|
||||
resource_name = "attack_up"
|
||||
length = 0.19999999999999998
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath("Sword:position")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0),
|
||||
"transitions": PackedFloat32Array(1),
|
||||
"update": 0,
|
||||
"values": [Vector2(-3, -13)]
|
||||
}
|
||||
tracks/1/type = "value"
|
||||
tracks/1/imported = false
|
||||
tracks/1/enabled = true
|
||||
tracks/1/path = NodePath("Sword:rotation")
|
||||
tracks/1/interp = 1
|
||||
tracks/1/loop_wrap = true
|
||||
tracks/1/keys = {
|
||||
"times": PackedFloat32Array(0.2),
|
||||
"transitions": PackedFloat32Array(1),
|
||||
"update": 0,
|
||||
"values": [3.1415927]
|
||||
}
|
||||
|
||||
[sub_resource type="AnimationLibrary" id="AnimationLibrary_jlvik"]
|
||||
_data = {
|
||||
&"RESET": SubResource("Animation_gk6dx"),
|
||||
&"attack_bottom": SubResource("Animation_jhyir"),
|
||||
&"attack_left": SubResource("Animation_jlvik"),
|
||||
&"attack_right": SubResource("Animation_dd0ac"),
|
||||
&"attack_up": SubResource("Animation_0u5uq")
|
||||
}
|
||||
|
||||
[node name="CharacterBody2D" type="CharacterBody2D" unique_id=1991398375]
|
||||
collision_mask = 7
|
||||
motion_mode = 1
|
||||
@@ -264,13 +410,16 @@ script = ExtResource("1_a3d8c")
|
||||
|
||||
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="." unique_id=721334358]
|
||||
sprite_frames = SubResource("SpriteFrames_bqpwv")
|
||||
animation = &"attack_down"
|
||||
animation = &"attack_left"
|
||||
autoplay = "move_down"
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=129222135]
|
||||
visible = false
|
||||
position = Vector2(0, 3)
|
||||
shape = SubResource("CapsuleShape2D_bqpwv")
|
||||
|
||||
[node name="HitBoxArea2D" type="Area2D" parent="." unique_id=1052547818]
|
||||
visible = false
|
||||
collision_layer = 2
|
||||
collision_mask = 16
|
||||
|
||||
@@ -316,13 +465,13 @@ unique_name_in_owner = true
|
||||
position = Vector2(114, 88)
|
||||
scale = Vector2(4.7812505, 4.7812505)
|
||||
sprite_frames = SubResource("SpriteFrames_chgu2")
|
||||
animation = &"0_hp"
|
||||
animation = &"3_hp"
|
||||
|
||||
[node name="Sword" type="Sprite2D" parent="." unique_id=984511662]
|
||||
visible = false
|
||||
show_behind_parent = true
|
||||
position = Vector2(0, -12)
|
||||
rotation = 3.1415927
|
||||
position = Vector2(-3, -13)
|
||||
rotation = 1.5707964
|
||||
texture = ExtResource("5_htcer")
|
||||
|
||||
[node name="SwordArea2D" type="Area2D" parent="Sword" unique_id=479479356]
|
||||
@@ -331,6 +480,7 @@ collision_mask = 16
|
||||
monitoring = false
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Sword/SwordArea2D" unique_id=1964142758]
|
||||
visible = false
|
||||
position = Vector2(-4.927303e-07, 0.5)
|
||||
shape = SubResource("RectangleShape2D_3rdvi")
|
||||
debug_color = Color(0.6497558, 0.52038795, 0, 0.41960785)
|
||||
@@ -339,6 +489,9 @@ debug_color = Color(0.6497558, 0.52038795, 0, 0.41960785)
|
||||
wait_time = 0.3
|
||||
one_shot = true
|
||||
|
||||
[node name="AnimationPlayer" type="AnimationPlayer" parent="." unique_id=1687360666]
|
||||
libraries/ = SubResource("AnimationLibrary_jlvik")
|
||||
|
||||
[connection signal="body_entered" from="HitBoxArea2D" to="." method="_on_hit_box_area_2d_body_entered"]
|
||||
[connection signal="body_entered" from="InteractArea2D" to="." method="_on_area_2d_body_entered"]
|
||||
[connection signal="body_exited" from="InteractArea2D" to="." method="_on_area_2d_body_exited"]
|
||||
|
||||
Reference in New Issue
Block a user