Added skill system

This commit is contained in:
2024-02-13 23:12:32 +01:00
parent cf155d9aab
commit d87d4c9e3f
15 changed files with 117 additions and 43 deletions

View File

@ -1,17 +1,19 @@
class_name Player
extends CharacterBody3D
signal skill_used(slot: int)
signal skill_used(skill: Skill)
signal dashed
signal jumped
signal name_changed(new_name: String)
signal direction_changed
@export var skills: Array[Skill]
var id: String
var controller: Controller
func use_skill(slot: int):
skill_used.emit(slot)
skill_used.emit(skills[slot])
func dash():
dashed.emit()

View File

@ -3,6 +3,8 @@
[ext_resource type="Script" path="res://player/Player.gd" id="1_8gebs"]
[ext_resource type="PackedScene" uid="uid://c8j7t4yg7anb0" path="res://assets/female/Female.blend" id="2_8nah6"]
[ext_resource type="PackedScene" uid="uid://2bbycjulf00g" path="res://player/health/HealthComponent.tscn" id="2_np5ag"]
[ext_resource type="Resource" uid="uid://yaq8ui3f6fwa" path="res://skill/slash/slash.tres" id="2_x58e1"]
[ext_resource type="Resource" uid="uid://ba1filjaldakv" path="res://skill/spin/spin.tres" id="3_l76ly"]
[ext_resource type="PackedScene" uid="uid://cgqbkj8wbcatv" path="res://assets/hair/PonyTail.blend" id="3_umw6q"]
[ext_resource type="FontFile" uid="uid://b7mov13kwi8u8" path="res://assets/font/ubuntu_nf_regular.ttf" id="4_76ehj"]
[ext_resource type="Skin" uid="uid://bbqyiue1vj37f" path="res://assets/hoodie/Hoodie_Skin.tres" id="4_b1tg1"]
@ -14,19 +16,16 @@
[ext_resource type="PackedScene" uid="uid://bivxnxwi863o0" path="res://player/animation/AnimationComponent.tscn" id="10_bcaeg"]
[ext_resource type="AnimationLibrary" uid="uid://d4n0puibh4hyt" path="res://assets/animations/human.blend" id="11_d0e6r"]
[ext_resource type="PackedScene" uid="uid://b8xf4ltqyorjv" path="res://player/skills/SkillsComponent.tscn" id="14_6idcf"]
[ext_resource type="Script" path="res://player/skills/MeleeArea.gd" id="14_g0mpw"]
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_2f50n"]
radius = 0.3
height = 1.6
[sub_resource type="CylinderShape3D" id="CylinderShape3D_4r7eu"]
radius = 1.5
[node name="Player" type="CharacterBody3D" groups=["player"]]
collision_layer = 512
collision_mask = 769
script = ExtResource("1_8gebs")
skills = Array[Resource("res://skill/Skill.gd")]([ExtResource("2_x58e1"), ExtResource("3_l76ly"), null, null])
[node name="Model" type="Node3D" parent="."]
@ -104,19 +103,5 @@ libraries = {
[node name="Skills" parent="." instance=ExtResource("14_6idcf")]
[node name="MeleeArea" type="Area3D" parent="."]
unique_name_in_owner = true
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1.8)
collision_layer = 0
collision_mask = 256
monitoring = false
monitorable = false
script = ExtResource("14_g0mpw")
[node name="CylinderShape" type="CollisionShape3D" parent="MeleeArea"]
shape = SubResource("CylinderShape3D_4r7eu")
[connection signal="body_entered" from="MeleeArea" to="MeleeArea" method="on_body_entered"]
[editable path="Model/Female"]
[editable path="Animation"]

View File

@ -11,7 +11,6 @@ var skip: int
func _ready():
var player := owner as Player
player.dashed.connect(dash)
player.skill_used.connect(use_skill)
movement = player.find_child("Movement")
animation_player = $AnimationPlayer
@ -24,11 +23,6 @@ func _process(_delta):
animation_player.play(next_animation)
if animation_player.current_animation == "human/spin":
animation_player.speed_scale = 2.0
else:
animation_player.speed_scale = 1.0
func play_movement():
if !movement:
play(RESET)
@ -46,19 +40,14 @@ func play_movement():
func dash():
play_with_duration("human/roll", 1.0)
func use_skill(slot: int):
match slot:
0:
play_with_duration("human/spin", 0.9)
1:
play_with_duration("human/slash", 1.0)
func play(action_name: StringName):
next_animation = action_name
func play_with_duration(action_name: StringName, duration: float):
func play_with_duration(action_name: StringName, duration: float, speed: float = 1.0):
next_animation = action_name
skip += 1
animation_player.speed_scale = speed
await get_tree().create_timer(duration).timeout
animation_player.speed_scale = 1.0
skip -= 1

View File

@ -1,7 +0,0 @@
extends Area3D
func on_body_entered(body: Node3D):
var health := body.get_node_or_null("Health") as HealthComponent
if health:
health.take_damage(DamageInstance.new(50))

View File

@ -2,15 +2,14 @@ class_name SkillsComponent
extends Node
var player: Player
var area: Area3D
func _ready():
player = owner
area = %MeleeArea
player.skill_used.connect(use_skill)
func use_skill(_slot: int):
await get_tree().create_timer(0.7).timeout
area.monitoring = true
await get_tree().create_timer(0.1).timeout
area.monitoring = false
func use_skill(skill: Skill):
if !skill:
return
var scene := skill.scene.instantiate()
player.add_child(scene)