feat: 1. 添加武器基础脚本
2. 添加武器基本resources 3. 武器碰撞 RangeArea 进入和退出检测 4. 添加 Hitbox 进行武器碰撞敌人区域(只是添加了,功能还没实现) 5. 武器冷却时间 weapon_base / CooldownTimer
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
[gd_scene format=3 uid="uid://d1igydtpm3sq8"]
|
||||
|
||||
[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"]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_gq287"]
|
||||
size = Vector2(52, 42)
|
||||
|
||||
[node name="WeaponPunch" unique_id=63743776 instance=ExtResource("1_soyvn")]
|
||||
|
||||
[node name="Sprite2D" parent="." index="0" unique_id=1011668514]
|
||||
position = Vector2(21, 1)
|
||||
|
||||
[node name="HitboxComponent" parent="Sprite2D" index="0" unique_id=151235566 instance=ExtResource("2_gq287")]
|
||||
scale = Vector2(2, 2)
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Sprite2D/HitboxComponent" index="0" unique_id=1064980236]
|
||||
z_index = 1
|
||||
shape = SubResource("RectangleShape2D_gq287")
|
||||
debug_color = Color(0.9556908, 0.042769283, 0.5218647, 0.41960785)
|
||||
@@ -0,0 +1,36 @@
|
||||
extends Node2D
|
||||
class_name Weapon
|
||||
|
||||
|
||||
@onready var sprite_2d: Sprite2D = $Sprite2D
|
||||
@onready var collision: CollisionShape2D = %CollisionShape2D
|
||||
@onready var cooldown_timer: Timer = $CooldownTimer
|
||||
|
||||
var data: ItemWeapon
|
||||
var is_attacking := false
|
||||
var atk_start_pos: Vector2
|
||||
var targets: Array[Enemy]
|
||||
var closest_target: Enemy
|
||||
var weapon_spread: float
|
||||
|
||||
func _ready() -> void:
|
||||
atk_start_pos = sprite_2d.position
|
||||
|
||||
|
||||
func setup_weapon(data: ItemWeapon) -> void:
|
||||
self.data = data
|
||||
collision.shape.radius = data.stats.max_range
|
||||
|
||||
|
||||
func can_use_weapon() -> bool:
|
||||
return cooldown_timer.is_stopped() and closest_target
|
||||
|
||||
|
||||
func _on_range_area_area_entered(area: Area2D) -> void:
|
||||
targets.push_back(area)
|
||||
|
||||
|
||||
func _on_range_area_area_exited(area: Area2D) -> void:
|
||||
targets.erase(area)
|
||||
if targets.size() == 0:
|
||||
closest_target = null
|
||||
@@ -0,0 +1 @@
|
||||
uid://d2fxp4oky50qs
|
||||
@@ -0,0 +1,29 @@
|
||||
[gd_scene format=3 uid="uid://dcc7rsdy4j8v6"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://d2fxp4oky50qs" path="res://scenes/weapons/weapon.gd" id="1_v4xn6"]
|
||||
[ext_resource type="Texture2D" uid="uid://l5hst1cf27oo" path="res://assets/sprites/Weapons/Melee/Weapon_Punch.png" id="2_uvw4m"]
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_vffjk"]
|
||||
radius = 150.0
|
||||
|
||||
[node name="WeaponBase" type="Node2D" unique_id=63743776]
|
||||
script = ExtResource("1_v4xn6")
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="." unique_id=1011668514]
|
||||
scale = Vector2(0.5, 0.5)
|
||||
texture = ExtResource("2_uvw4m")
|
||||
|
||||
[node name="RangeArea" type="Area2D" parent="." unique_id=877203105]
|
||||
collision_mask = 2
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="RangeArea" unique_id=902525969]
|
||||
unique_name_in_owner = true
|
||||
shape = SubResource("CircleShape2D_vffjk")
|
||||
|
||||
[node name="CooldownTimer" type="Timer" parent="." unique_id=1814049304]
|
||||
one_shot = true
|
||||
|
||||
[node name="WeaponBehavior" type="Node2D" parent="." unique_id=1507497844]
|
||||
|
||||
[connection signal="area_entered" from="RangeArea" to="." method="_on_range_area_area_entered"]
|
||||
[connection signal="area_exited" from="RangeArea" to="." method="_on_range_area_area_exited"]
|
||||
Reference in New Issue
Block a user