initial implementation of sword attack

This commit is contained in:
2021-12-04 02:28:48 -06:00
parent 7e39fdf2bc
commit f18924dd3d
10 changed files with 203 additions and 89 deletions

View File

@@ -56,7 +56,7 @@ func _on_Hitbox_body_entered(body: Node) -> void:
if health_index != 0:
health_index -= 1
#hud.update_health(HEALTH_SLICES[health_index])
hud.update_health(HEALTH_SLICES[health_index])
return
@@ -73,4 +73,8 @@ func _input(event: InputEvent) -> void:
if img.save_png('user://Screenshot_%d%d%d_%d.png' % [time.year, time.month, time.day, time_msecs]) != OK:
print('ERROR: Failed saving screenshot.')
if event.is_action_pressed("player_attack"):
$SwordAnimation/SwordAttack.play("swing")
return

View File

@@ -1,16 +1,17 @@
[gd_scene load_steps=20 format=2]
[gd_scene load_steps=21 format=2]
[ext_resource path="res://Player/Player.gd" type="Script" id=1]
[ext_resource path="res://Sprites/Player/Player.png" type="Texture" id=2]
[ext_resource path="res://Sprites/Player/Player_Down.png" type="Texture" id=3]
[ext_resource path="res://Sprites/Player/Player_Up.png" type="Texture" id=4]
[ext_resource path="res://Player/Inventory.tscn" type="PackedScene" id=5]
[ext_resource path="res://Player/Sword.tscn" type="PackedScene" id=7]
[sub_resource type="SpriteFrames" id=1]
animations = [ {
"frames": [ ExtResource( 2 ) ],
"frames": [ ExtResource( 3 ) ],
"loop": false,
"name": "look_right",
"name": "look_down",
"speed": 5.0
}, {
"frames": [ ExtResource( 4 ) ],
@@ -23,9 +24,9 @@ animations = [ {
"name": "look_left",
"speed": 5.0
}, {
"frames": [ ExtResource( 3 ) ],
"frames": [ ExtResource( 2 ) ],
"loop": false,
"name": "look_down",
"name": "look_right",
"speed": 5.0
} ]
@@ -220,5 +221,8 @@ parameters/Idle/blend_position = Vector2( 0.0760697, 0 )
[node name="Inventory" parent="." instance=ExtResource( 5 )]
[node name="SwordAnimation" parent="." instance=ExtResource( 7 )]
position = Vector2( 8, -6 )
[connection signal="body_entered" from="Hitbox" to="." method="_on_Hitbox_body_entered"]
[connection signal="update_currency" from="Inventory" to="." method="_on_Inventory_update_currency"]

26
Player/Sword.gd Normal file
View File

@@ -0,0 +1,26 @@
extends Node2D
# Declare member variables here. Examples:
# var a: int = 2
# var b: String = "text"
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta: float) -> void:
# pass
func _on_SwordAttack_animation_started(anim_name: String) -> void:
$Sword.visible = true
return
func _on_SwordAttack_animation_finished(anim_name: String) -> void:
$Sword.visible = false
return

76
Player/Sword.tscn Normal file
View File

@@ -0,0 +1,76 @@
[gd_scene load_steps=5 format=2]
[ext_resource path="res://Sprites/Items/Sword.png" type="Texture" id=1]
[ext_resource path="res://Player/Sword.gd" type="Script" id=2]
[sub_resource type="Animation" id=4]
length = 0.001
tracks/0/type = "value"
tracks/0/path = NodePath("Sword:rotation_degrees")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"times": PoolRealArray( 0 ),
"transitions": PoolRealArray( 1 ),
"update": 0,
"values": [ 45.0 ]
}
tracks/1/type = "value"
tracks/1/path = NodePath("Sword:position")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/keys = {
"times": PoolRealArray( 0 ),
"transitions": PoolRealArray( 1 ),
"update": 0,
"values": [ Vector2( 8, -7 ) ]
}
[sub_resource type="Animation" id=5]
resource_name = "swing"
length = 0.3
tracks/0/type = "value"
tracks/0/path = NodePath("Sword:position")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"times": PoolRealArray( 0, 0.1, 0.3 ),
"transitions": PoolRealArray( 1, 1, 1 ),
"update": 0,
"values": [ Vector2( 0, 0 ), Vector2( 2, 7 ), Vector2( 2, 7 ) ]
}
tracks/1/type = "value"
tracks/1/path = NodePath("Sword:rotation_degrees")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/keys = {
"times": PoolRealArray( 0, 0.1, 0.3 ),
"transitions": PoolRealArray( 1, 1, 1 ),
"update": 0,
"values": [ 45.0, 180.0, 180.0 ]
}
[node name="SwordAnimation" type="Node2D"]
script = ExtResource( 2 )
[node name="Sword" type="Sprite" parent="."]
visible = false
position = Vector2( 8, -7 )
rotation = 0.785398
scale = Vector2( 0.5, 0.5 )
texture = ExtResource( 1 )
[node name="SwordAttack" type="AnimationPlayer" parent="."]
anims/RESET = SubResource( 4 )
anims/swing = SubResource( 5 )
[connection signal="animation_finished" from="SwordAttack" to="." method="_on_SwordAttack_animation_finished"]
[connection signal="animation_started" from="SwordAttack" to="." method="_on_SwordAttack_animation_started"]