initial implementation of sword attack
This commit is contained in:
@@ -4,7 +4,6 @@ const SPEED: int = 60
|
||||
|
||||
var player: KinematicBody2D = null
|
||||
var velocity: Vector2 = Vector2.ZERO
|
||||
var last_x = 0.0
|
||||
|
||||
|
||||
func _physics_process(_delta: float) -> void:
|
||||
@@ -17,9 +16,6 @@ func _physics_process(_delta: float) -> void:
|
||||
$AnimatedSprite1.scale.x = -0.563
|
||||
else:
|
||||
$AnimatedSprite1.scale.x = 0.563
|
||||
|
||||
if velocity.x != 0:
|
||||
last_x = velocity.x
|
||||
|
||||
velocity = move_and_slide(velocity)
|
||||
return
|
||||
|
@@ -7,36 +7,6 @@
|
||||
[ext_resource path="res://Sprites/Enemies/hell-hound-jump.png" type="Texture" id=5]
|
||||
[ext_resource path="res://Sprites/Enemies/hell-hound-run.png" type="Texture" id=6]
|
||||
|
||||
[sub_resource type="AtlasTexture" id=3]
|
||||
flags = 4
|
||||
atlas = ExtResource( 5 )
|
||||
region = Rect2( 0, 0, 65, 48 )
|
||||
|
||||
[sub_resource type="AtlasTexture" id=4]
|
||||
flags = 4
|
||||
atlas = ExtResource( 5 )
|
||||
region = Rect2( 65, 0, 65, 48 )
|
||||
|
||||
[sub_resource type="AtlasTexture" id=5]
|
||||
flags = 4
|
||||
atlas = ExtResource( 5 )
|
||||
region = Rect2( 130, 0, 65, 48 )
|
||||
|
||||
[sub_resource type="AtlasTexture" id=6]
|
||||
flags = 4
|
||||
atlas = ExtResource( 5 )
|
||||
region = Rect2( 195, 0, 65, 48 )
|
||||
|
||||
[sub_resource type="AtlasTexture" id=7]
|
||||
flags = 4
|
||||
atlas = ExtResource( 5 )
|
||||
region = Rect2( 260, 0, 65, 48 )
|
||||
|
||||
[sub_resource type="AtlasTexture" id=8]
|
||||
flags = 4
|
||||
atlas = ExtResource( 5 )
|
||||
region = Rect2( 325, 0, 65, 48 )
|
||||
|
||||
[sub_resource type="AtlasTexture" id=9]
|
||||
flags = 4
|
||||
atlas = ExtResource( 3 )
|
||||
@@ -67,6 +37,36 @@ flags = 4
|
||||
atlas = ExtResource( 3 )
|
||||
region = Rect2( 320, 0, 64, 32 )
|
||||
|
||||
[sub_resource type="AtlasTexture" id=3]
|
||||
flags = 4
|
||||
atlas = ExtResource( 5 )
|
||||
region = Rect2( 0, 0, 65, 48 )
|
||||
|
||||
[sub_resource type="AtlasTexture" id=4]
|
||||
flags = 4
|
||||
atlas = ExtResource( 5 )
|
||||
region = Rect2( 65, 0, 65, 48 )
|
||||
|
||||
[sub_resource type="AtlasTexture" id=5]
|
||||
flags = 4
|
||||
atlas = ExtResource( 5 )
|
||||
region = Rect2( 130, 0, 65, 48 )
|
||||
|
||||
[sub_resource type="AtlasTexture" id=6]
|
||||
flags = 4
|
||||
atlas = ExtResource( 5 )
|
||||
region = Rect2( 195, 0, 65, 48 )
|
||||
|
||||
[sub_resource type="AtlasTexture" id=7]
|
||||
flags = 4
|
||||
atlas = ExtResource( 5 )
|
||||
region = Rect2( 260, 0, 65, 48 )
|
||||
|
||||
[sub_resource type="AtlasTexture" id=8]
|
||||
flags = 4
|
||||
atlas = ExtResource( 5 )
|
||||
region = Rect2( 325, 0, 65, 48 )
|
||||
|
||||
[sub_resource type="AtlasTexture" id=15]
|
||||
flags = 4
|
||||
atlas = ExtResource( 6 )
|
||||
@@ -94,16 +94,16 @@ region = Rect2( 268, 0, 67, 32 )
|
||||
|
||||
[sub_resource type="SpriteFrames" id=20]
|
||||
animations = [ {
|
||||
"frames": [ SubResource( 3 ), SubResource( 4 ), SubResource( 5 ), SubResource( 6 ), SubResource( 7 ), SubResource( 8 ) ],
|
||||
"loop": true,
|
||||
"name": "Jump",
|
||||
"speed": 8.0
|
||||
}, {
|
||||
"frames": [ SubResource( 9 ), SubResource( 10 ), SubResource( 11 ), SubResource( 12 ), SubResource( 13 ), SubResource( 14 ) ],
|
||||
"loop": true,
|
||||
"name": "Idle",
|
||||
"speed": 3.0
|
||||
}, {
|
||||
"frames": [ SubResource( 3 ), SubResource( 4 ), SubResource( 5 ), SubResource( 6 ), SubResource( 7 ), SubResource( 8 ) ],
|
||||
"loop": true,
|
||||
"name": "Jump",
|
||||
"speed": 8.0
|
||||
}, {
|
||||
"frames": [ SubResource( 15 ), SubResource( 16 ), SubResource( 17 ), SubResource( 18 ), SubResource( 19 ) ],
|
||||
"loop": true,
|
||||
"name": "Running",
|
||||
@@ -126,6 +126,7 @@ position = Vector2( 1, -3 )
|
||||
scale = Vector2( 0.5625, 0.5625 )
|
||||
frames = SubResource( 20 )
|
||||
animation = "Idle"
|
||||
frame = 1
|
||||
playing = true
|
||||
|
||||
[node name="Hitbox" type="CollisionShape2D" parent="."]
|
||||
@@ -141,6 +142,7 @@ monitorable = false
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Player Detector"]
|
||||
visible = false
|
||||
scale = Vector2( 1.5, 1.5 )
|
||||
shape = SubResource( 2 )
|
||||
|
||||
[node name="Player Attack" type="Area2D" parent="."]
|
||||
|
80
GUI/HUD.gd
80
GUI/HUD.gd
@@ -4,72 +4,72 @@ signal add_currency(amount)
|
||||
|
||||
|
||||
func _on_Add_Currency_pressed() -> void:
|
||||
emit_signal('add_currency', 1)
|
||||
return
|
||||
emit_signal('add_currency', 1)
|
||||
return
|
||||
|
||||
|
||||
func update_currency(amount: int) -> void:
|
||||
$Currency.set_text(String(amount))
|
||||
return
|
||||
$Currency.set_text(String(amount))
|
||||
return
|
||||
|
||||
|
||||
func update_health(value: int) -> void:
|
||||
$'Health Bar'.value = value
|
||||
return
|
||||
$'Health Bar'.value = value
|
||||
return
|
||||
|
||||
|
||||
func _on_weapon_slot_pressed() -> void:
|
||||
$'Weapon Selection'.set_visible(not $'Weapon Selection'.visible)
|
||||
return
|
||||
$'Weapon Selection'.set_visible(not $'Weapon Selection'.visible)
|
||||
return
|
||||
|
||||
|
||||
func _on_select_bow_pressed() -> void:
|
||||
$'Weapon Selection/Bow'.set_visible(false)
|
||||
$'Equipped Weapon/Weapon'.set_normal_texture(
|
||||
$'Weapon Selection/Bow/Weapon'.get_normal_texture())
|
||||
$'Weapon Selection/Bow'.set_visible(false)
|
||||
$'Equipped Weapon/Weapon'.set_normal_texture(
|
||||
$'Weapon Selection/Bow/Weapon'.get_normal_texture())
|
||||
|
||||
$'Weapon Selection/Javelin'.set_visible(true)
|
||||
$'Weapon Selection/Staff'.set_visible(true)
|
||||
$'Weapon Selection/Sword'.set_visible(true)
|
||||
$'Weapon Selection/Javelin'.set_visible(true)
|
||||
$'Weapon Selection/Staff'.set_visible(true)
|
||||
$'Weapon Selection/Sword'.set_visible(true)
|
||||
|
||||
$'Weapon Selection'.set_visible(false)
|
||||
return
|
||||
$'Weapon Selection'.set_visible(false)
|
||||
return
|
||||
|
||||
|
||||
func _on_select_javelin_pressed() -> void:
|
||||
$'Weapon Selection/Javelin'.set_visible(false)
|
||||
$'Equipped Weapon/Weapon'.set_normal_texture(
|
||||
$'Weapon Selection/Javelin/Weapon'.get_normal_texture())
|
||||
$'Weapon Selection/Javelin'.set_visible(false)
|
||||
$'Equipped Weapon/Weapon'.set_normal_texture(
|
||||
$'Weapon Selection/Javelin/Weapon'.get_normal_texture())
|
||||
|
||||
$'Weapon Selection/Bow'.set_visible(true)
|
||||
$'Weapon Selection/Staff'.set_visible(true)
|
||||
$'Weapon Selection/Sword'.set_visible(true)
|
||||
$'Weapon Selection/Bow'.set_visible(true)
|
||||
$'Weapon Selection/Staff'.set_visible(true)
|
||||
$'Weapon Selection/Sword'.set_visible(true)
|
||||
|
||||
$'Weapon Selection'.set_visible(false)
|
||||
return
|
||||
$'Weapon Selection'.set_visible(false)
|
||||
return
|
||||
|
||||
|
||||
func _on_select_staff_pressed() -> void:
|
||||
$'Weapon Selection/Staff'.set_visible(false)
|
||||
$'Equipped Weapon/Weapon'.set_normal_texture(
|
||||
$'Weapon Selection/Staff/Weapon'.get_normal_texture())
|
||||
$'Weapon Selection/Staff'.set_visible(false)
|
||||
$'Equipped Weapon/Weapon'.set_normal_texture(
|
||||
$'Weapon Selection/Staff/Weapon'.get_normal_texture())
|
||||
|
||||
$'Weapon Selection/Bow'.set_visible(true)
|
||||
$'Weapon Selection/Javelin'.set_visible(true)
|
||||
$'Weapon Selection/Sword'.set_visible(true)
|
||||
$'Weapon Selection/Bow'.set_visible(true)
|
||||
$'Weapon Selection/Javelin'.set_visible(true)
|
||||
$'Weapon Selection/Sword'.set_visible(true)
|
||||
|
||||
$'Weapon Selection'.set_visible(false)
|
||||
return
|
||||
$'Weapon Selection'.set_visible(false)
|
||||
return
|
||||
|
||||
|
||||
func _on_select_sword_pressed() -> void:
|
||||
$'Weapon Selection/Sword'.set_visible(false)
|
||||
$'Equipped Weapon/Weapon'.set_normal_texture(
|
||||
$'Weapon Selection/Sword/Weapon'.get_normal_texture())
|
||||
$'Weapon Selection/Sword'.set_visible(false)
|
||||
$'Equipped Weapon/Weapon'.set_normal_texture(
|
||||
$'Weapon Selection/Sword/Weapon'.get_normal_texture())
|
||||
|
||||
$'Weapon Selection/Bow'.set_visible(true)
|
||||
$'Weapon Selection/Javelin'.set_visible(true)
|
||||
$'Weapon Selection/Staff'.set_visible(true)
|
||||
$'Weapon Selection/Bow'.set_visible(true)
|
||||
$'Weapon Selection/Javelin'.set_visible(true)
|
||||
$'Weapon Selection/Staff'.set_visible(true)
|
||||
|
||||
$'Weapon Selection'.set_visible(false)
|
||||
return
|
||||
$'Weapon Selection'.set_visible(false)
|
||||
return
|
||||
|
@@ -1,5 +1,6 @@
|
||||
extends Node2D
|
||||
|
||||
func _ready() -> void:
|
||||
$YSort/Player.position = get_viewport_rect().size / 2
|
||||
#$YSort/Player.position = get_viewport_rect().size / 2
|
||||
$YSort/Player.load_hud($HUD)
|
||||
return
|
||||
|
@@ -101,21 +101,21 @@ tile_data = PoolIntArray( -524290, 0, 5, -524289, 0, 196610, -589824, 0, 196610,
|
||||
[node name="Fire3" type="AnimatedSprite" parent="."]
|
||||
position = Vector2( -607.628, -210.601 )
|
||||
frames = SubResource( 1 )
|
||||
frame = 12
|
||||
frame = 10
|
||||
playing = true
|
||||
offset = Vector2( 679.819, 333.222 )
|
||||
|
||||
[node name="Fire2" type="AnimatedSprite" parent="."]
|
||||
position = Vector2( -543.25, -212.563 )
|
||||
frames = SubResource( 1 )
|
||||
frame = 1
|
||||
frame = 13
|
||||
playing = true
|
||||
offset = Vector2( 679.819, 333.222 )
|
||||
|
||||
[node name="Fire1" type="AnimatedSprite" parent="."]
|
||||
position = Vector2( -479.806, -214.167 )
|
||||
frames = SubResource( 1 )
|
||||
frame = 8
|
||||
frame = 6
|
||||
playing = true
|
||||
offset = Vector2( 679.819, 333.222 )
|
||||
|
||||
|
@@ -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
|
||||
|
||||
|
@@ -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
26
Player/Sword.gd
Normal 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
76
Player/Sword.tscn
Normal 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"]
|
@@ -54,6 +54,11 @@ screenshot={
|
||||
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777245,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
player_attack={
|
||||
"deadzone": 0.5,
|
||||
"events": [ Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"button_mask":0,"position":Vector2( 0, 0 ),"global_position":Vector2( 0, 0 ),"factor":1.0,"button_index":1,"pressed":false,"doubleclick":false,"script":null)
|
||||
]
|
||||
}
|
||||
|
||||
[physics]
|
||||
|
||||
|
Reference in New Issue
Block a user