feat: add user's attack animation to the player's node;
This commit is contained in:
@@ -20,6 +20,8 @@ func _physics_process(delta: float) -> void:
|
||||
push_blocks()
|
||||
update_scrolls()
|
||||
move_and_slide()
|
||||
if Input.is_action_just_pressed("Interact"):
|
||||
attack()
|
||||
|
||||
func move_player():
|
||||
var move_vector: Vector2 = Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down")
|
||||
@@ -71,3 +73,23 @@ func _on_hit_box_area_2d_body_entered(body: Node2D) -> void:
|
||||
func die():
|
||||
get_tree().call_deferred("reload_current_scene")
|
||||
SceneManager.player_hp = 3
|
||||
|
||||
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)
|
||||
$Sword.visible = true
|
||||
$Sword/SwordArea2D.monitoring = true
|
||||
$Sword/SwordTimer.start()
|
||||
|
||||
func _on_sword_timer_timeout() -> void:
|
||||
$Sword.visible = false
|
||||
$Sword/SwordArea2D.monitoring = false
|
||||
|
||||
@@ -2,8 +2,26 @@
|
||||
|
||||
[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://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"]
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_eksi1"]
|
||||
atlas = ExtResource("2_dd0ac")
|
||||
region = Rect2(0, 0, 16, 16)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_jincj"]
|
||||
atlas = ExtResource("2_dd0ac")
|
||||
region = Rect2(32, 0, 16, 16)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_rqdc0"]
|
||||
atlas = ExtResource("2_dd0ac")
|
||||
region = Rect2(32, 0, 16, 16)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_qr1w5"]
|
||||
atlas = ExtResource("2_dd0ac")
|
||||
region = Rect2(16, 0, 16, 16)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_a3d8c"]
|
||||
atlas = ExtResource("2_a3d8c")
|
||||
@@ -73,6 +91,38 @@ region = Rect2(16, 48, 16, 16)
|
||||
animations = [{
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_eksi1")
|
||||
}],
|
||||
"loop": 1,
|
||||
"name": &"attack_down",
|
||||
"speed": 5.0
|
||||
}, {
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_jincj")
|
||||
}],
|
||||
"loop": 1,
|
||||
"name": &"attack_left",
|
||||
"speed": 5.0
|
||||
}, {
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_rqdc0")
|
||||
}],
|
||||
"loop": 1,
|
||||
"name": &"attack_right",
|
||||
"speed": 5.0
|
||||
}, {
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_qr1w5")
|
||||
}],
|
||||
"loop": 1,
|
||||
"name": &"attack_up",
|
||||
"speed": 5.0
|
||||
}, {
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_a3d8c")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
@@ -204,6 +254,9 @@ animations = [{
|
||||
"speed": 5.0
|
||||
}]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_3rdvi"]
|
||||
size = Vector2(10, 13)
|
||||
|
||||
[node name="CharacterBody2D" type="CharacterBody2D" unique_id=1991398375]
|
||||
collision_mask = 7
|
||||
motion_mode = 1
|
||||
@@ -211,7 +264,7 @@ script = ExtResource("1_a3d8c")
|
||||
|
||||
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="." unique_id=721334358]
|
||||
sprite_frames = SubResource("SpriteFrames_bqpwv")
|
||||
animation = &"move_down"
|
||||
animation = &"attack_down"
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=129222135]
|
||||
position = Vector2(0, 3)
|
||||
@@ -265,6 +318,29 @@ scale = Vector2(4.7812505, 4.7812505)
|
||||
sprite_frames = SubResource("SpriteFrames_chgu2")
|
||||
animation = &"0_hp"
|
||||
|
||||
[node name="Sword" type="Sprite2D" parent="." unique_id=984511662]
|
||||
visible = false
|
||||
show_behind_parent = true
|
||||
position = Vector2(0, -12)
|
||||
rotation = 3.1415927
|
||||
texture = ExtResource("5_htcer")
|
||||
|
||||
[node name="SwordArea2D" type="Area2D" parent="Sword" unique_id=479479356]
|
||||
collision_layer = 2
|
||||
collision_mask = 16
|
||||
monitoring = false
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Sword/SwordArea2D" unique_id=1964142758]
|
||||
position = Vector2(-4.927303e-07, 0.5)
|
||||
shape = SubResource("RectangleShape2D_3rdvi")
|
||||
debug_color = Color(0.6497558, 0.52038795, 0, 0.41960785)
|
||||
|
||||
[node name="SwordTimer" type="Timer" parent="Sword" unique_id=639462034]
|
||||
wait_time = 0.3
|
||||
one_shot = true
|
||||
|
||||
[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"]
|
||||
[connection signal="body_entered" from="Sword/SwordArea2D" to="." method="_on_sword_area_2d_body_entered"]
|
||||
[connection signal="timeout" from="Sword/SwordTimer" to="." method="_on_sword_timer_timeout"]
|
||||
|
||||
Reference in New Issue
Block a user