feat: 1. 添加武器击退功能,player 使用weapon_behavior/melee_behavior(hitbox 会调用 setup 初始化) 的 hitbox 击中 enemy_slow,enemy_slow拿到hitbox的knockback_power,以及hitbox指向enemy的方向,然后朝着该方向,使用power击退:调用enemy.gd 的 apply_knockback,然后_process中会对position修改,同时开启定时器,定时器结束的时候,使用 reset_knockback 重置
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
extends WeaponBehavior
|
||||
class_name MeleeBehavior
|
||||
|
||||
@export var hitbox: HitboxComponent
|
||||
|
||||
func execute_attack() -> void:
|
||||
weapon.is_attacking = true
|
||||
|
||||
var tween := create_tween()
|
||||
|
||||
var recoil_pos := Vector2(weapon.atk_start_pos.x - weapon.data.stats.recoil, weapon.atk_start_pos.y)
|
||||
tween.tween_property(weapon.sprite_2d, "position", recoil_pos, weapon.data.stats.recoil_duration)
|
||||
|
||||
hitbox.enable()
|
||||
hitbox.setup(get_damage(), critical, weapon.data.stats.knockback, weapon.get_parent())
|
||||
|
||||
var attack_pos := Vector2(weapon.atk_start_pos.x + weapon.data.stats.max_range, weapon.atk_start_pos.y)
|
||||
tween.tween_property(weapon.sprite_2d, "position", attack_pos, weapon.data.stats.attack_duration)
|
||||
|
||||
tween.tween_property(weapon.sprite_2d, "position", weapon.atk_start_pos, weapon.data.stats.back_duration)
|
||||
|
||||
tween.finished.connect(func():
|
||||
hitbox.disable()
|
||||
weapon.is_attacking = false
|
||||
critical = false
|
||||
)
|
||||
@@ -0,0 +1 @@
|
||||
uid://bbqq80eq8fqwn
|
||||
@@ -0,0 +1,27 @@
|
||||
extends Node2D
|
||||
class_name WeaponBehavior
|
||||
|
||||
@export var weapon: Weapon
|
||||
|
||||
var critical := false
|
||||
|
||||
func execute_attack() -> void:
|
||||
pass
|
||||
|
||||
func get_damage() -> float:
|
||||
var damage := weapon.data.stats.damage + Global.player.stats.damage
|
||||
var crit_chance := weapon.data.stats.crit_chance
|
||||
if Global.get_chance_success(crit_chance):
|
||||
crit_chance = true
|
||||
damage = ceil(damage * weapon.data.stats.crit_damage)
|
||||
|
||||
return damage
|
||||
|
||||
# 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
|
||||
@@ -0,0 +1 @@
|
||||
uid://ww04x180xsa3
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://dcc7rsdy4j8v6" path="res://scenes/weapons/weapon_base.tscn" id="1_soyvn"]
|
||||
[ext_resource type="PackedScene" uid="uid://c0fyx8gj5uexl" path="res://scenes/components/hitbox_component.tscn" id="2_gq287"]
|
||||
[ext_resource type="Script" uid="uid://bbqq80eq8fqwn" path="res://scenes/weapons/melee/melee_behavior.gd" id="3_sv013"]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_gq287"]
|
||||
size = Vector2(52, 42)
|
||||
@@ -22,3 +23,8 @@ monitorable = false
|
||||
z_index = 1
|
||||
shape = SubResource("RectangleShape2D_gq287")
|
||||
debug_color = Color(0.9556908, 0.042769283, 0.5218647, 0.41960785)
|
||||
|
||||
[node name="WeaponBehavior" parent="." index="3" unique_id=1507497844 node_paths=PackedStringArray("hitbox", "weapon")]
|
||||
script = ExtResource("3_sv013")
|
||||
hitbox = NodePath("../Sprite2D/HitboxComponent")
|
||||
weapon = NodePath("..")
|
||||
|
||||
Reference in New Issue
Block a user