fix: player attack logic; add sfx to the player attack;
This commit is contained in:
@@ -6,6 +6,7 @@ class_name Player
|
||||
@export var push_strength: int = 50
|
||||
@export var move_acceleration: float = 50
|
||||
var is_attacking: bool = false
|
||||
var can_interact: bool = false
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
@@ -26,7 +27,7 @@ func _physics_process(delta: float) -> void:
|
||||
push_blocks()
|
||||
update_scrolls()
|
||||
move_and_slide()
|
||||
if Input.is_action_just_pressed("Interact"):
|
||||
if Input.is_action_just_pressed("Interact") and not can_interact:
|
||||
attack()
|
||||
|
||||
func move_player():
|
||||
@@ -62,11 +63,13 @@ func update_scrolls():
|
||||
|
||||
func _on_area_2d_body_entered(body: Node2D) -> void:
|
||||
if body.is_in_group("interactable"):
|
||||
can_interact = true
|
||||
body.can_interact = true
|
||||
|
||||
|
||||
func _on_area_2d_body_exited(body: Node2D) -> void:
|
||||
if body.is_in_group("interactable"):
|
||||
can_interact = false
|
||||
body.can_interact = false
|
||||
|
||||
|
||||
@@ -105,6 +108,7 @@ func _on_sword_area_2d_body_entered(body: Node2D) -> void:
|
||||
body.queue_free()
|
||||
|
||||
func attack():
|
||||
$Sword/SwordSFX.play()
|
||||
if not $Sword/SwordTimer.is_stopped():
|
||||
return
|
||||
var player_animation: String = $AnimatedSprite2D.animation
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
[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"]
|
||||
[ext_resource type="AudioStream" uid="uid://bso7qwqwgjpme" path="res://Ninja Adventure - Asset Pack/Sounds/Game/Sword2.wav" id="8_jlvik"]
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_eksi1"]
|
||||
atlas = ExtResource("2_dd0ac")
|
||||
@@ -500,6 +501,10 @@ debug_color = Color(0.6497558, 0.52038795, 0, 0.41960785)
|
||||
wait_time = 0.3
|
||||
one_shot = true
|
||||
|
||||
[node name="SwordSFX" type="AudioStreamPlayer" parent="Sword" unique_id=913634626]
|
||||
stream = ExtResource("8_jlvik")
|
||||
volume_db = -5.0
|
||||
|
||||
[node name="AnimationPlayer" type="AnimationPlayer" parent="." unique_id=1687360666]
|
||||
libraries/ = SubResource("AnimationLibrary_jlvik")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user