From cf155d9aab28a3ae86f772d3fd583933b3b9f7af Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Tue, 13 Feb 2024 21:04:35 +0100 Subject: [PATCH] Added multiple skills --- client/player/Player.gd | 6 ++-- client/player/animation/AnimationComponent.gd | 15 ++++++-- client/player/controller/PlayerController.gd | 7 ++-- client/player/skills/SkillsComponent.gd | 4 +-- client/project.godot | 34 ++++++++++++------- 5 files changed, 43 insertions(+), 23 deletions(-) diff --git a/client/player/Player.gd b/client/player/Player.gd index 92a5b95..6a6ad7f 100644 --- a/client/player/Player.gd +++ b/client/player/Player.gd @@ -1,7 +1,7 @@ class_name Player extends CharacterBody3D -signal attacked +signal skill_used(slot: int) signal dashed signal jumped signal name_changed(new_name: String) @@ -10,8 +10,8 @@ signal direction_changed var id: String var controller: Controller -func attack(): - attacked.emit() +func use_skill(slot: int): + skill_used.emit(slot) func dash(): dashed.emit() diff --git a/client/player/animation/AnimationComponent.gd b/client/player/animation/AnimationComponent.gd index 9bb4a6f..a946dd9 100644 --- a/client/player/animation/AnimationComponent.gd +++ b/client/player/animation/AnimationComponent.gd @@ -11,7 +11,7 @@ var skip: int func _ready(): var player := owner as Player player.dashed.connect(dash) - player.attacked.connect(attack) + player.skill_used.connect(use_skill) movement = player.find_child("Movement") animation_player = $AnimationPlayer @@ -24,6 +24,11 @@ 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) @@ -41,8 +46,12 @@ func play_movement(): func dash(): play_with_duration("human/roll", 1.0) -func attack(): - play_with_duration("human/slash", 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 diff --git a/client/player/controller/PlayerController.gd b/client/player/controller/PlayerController.gd index 55869f6..46ea6ba 100644 --- a/client/player/controller/PlayerController.gd +++ b/client/player/controller/PlayerController.gd @@ -29,6 +29,7 @@ func _unhandled_input(event): if event.is_action_pressed("dash"): player.dash() - - if event.is_action_pressed("attack"): - player.attack() + + for i in range(4): + if event.is_action_pressed("skill_%d" % (i + 1)): + player.use_skill(i) diff --git a/client/player/skills/SkillsComponent.gd b/client/player/skills/SkillsComponent.gd index 1880644..8fd7594 100644 --- a/client/player/skills/SkillsComponent.gd +++ b/client/player/skills/SkillsComponent.gd @@ -7,9 +7,9 @@ var area: Area3D func _ready(): player = owner area = %MeleeArea - player.attacked.connect(attack) + player.skill_used.connect(use_skill) -func attack(): +func use_skill(_slot: int): await get_tree().create_timer(0.7).timeout area.monitoring = true await get_tree().create_timer(0.1).timeout diff --git a/client/project.godot b/client/project.godot index f3661bc..ba0af08 100644 --- a/client/project.godot +++ b/client/project.godot @@ -79,18 +79,6 @@ dash={ "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194325,"key_label":0,"unicode":0,"echo":false,"script":null) ] } -attack={ -"deadzone": 0.5, -"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":1,"canceled":false,"pressed":false,"double_click":false,"script":null) -, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":0,"pressure":0.0,"pressed":false,"script":null) -, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":81,"key_label":0,"unicode":113,"echo":false,"script":null) -] -} -aim={ -"deadzone": 0.5, -"events": [Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":9,"pressure":0.0,"pressed":false,"script":null) -] -} menu={ "deadzone": 0.5, "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194305,"key_label":0,"unicode":0,"echo":false,"script":null) @@ -132,6 +120,28 @@ zoom_out={ , Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194435,"key_label":0,"unicode":45,"echo":false,"script":null) ] } +skill_1={ +"deadzone": 0.5, +"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":1,"canceled":false,"pressed":false,"double_click":false,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":0,"pressure":0.0,"pressed":false,"script":null) +, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":81,"key_label":0,"unicode":113,"echo":false,"script":null) +] +} +skill_2={ +"deadzone": 0.5, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":69,"key_label":0,"unicode":101,"echo":false,"script":null) +] +} +skill_3={ +"deadzone": 0.5, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":82,"key_label":0,"unicode":114,"echo":false,"script":null) +] +} +skill_4={ +"deadzone": 0.5, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":84,"key_label":0,"unicode":116,"echo":false,"script":null) +] +} [layer_names]