feat: 添加手枪武器

This commit is contained in:
luke358
2026-05-19 21:07:44 +08:00
parent 4fa565e0e9
commit dc26a7cf60
27 changed files with 348 additions and 2 deletions
+5
View File
@@ -0,0 +1,5 @@
[gd_scene format=3 uid="uid://bpc7qmrh8hs0n"]
[ext_resource type="PackedScene" uid="uid://dcc7rsdy4j8v6" path="res://scenes/weapons/weapon_base.tscn" id="1_1b33f"]
[node name="WeaponAxe" unique_id=63743776 instance=ExtResource("1_1b33f")]
@@ -0,0 +1,5 @@
[gd_scene format=3 uid="uid://d2k5wxsuodxib"]
[ext_resource type="PackedScene" uid="uid://dcc7rsdy4j8v6" path="res://scenes/weapons/weapon_base.tscn" id="1_sj0xb"]
[node name="WeaponChainsaw" unique_id=63743776 instance=ExtResource("1_sj0xb")]
+5
View File
@@ -0,0 +1,5 @@
[gd_scene format=3 uid="uid://c40id7ntypee8"]
[ext_resource type="PackedScene" uid="uid://dcc7rsdy4j8v6" path="res://scenes/weapons/weapon_base.tscn" id="1_8xtns"]
[node name="WeaponMace" unique_id=63743776 instance=ExtResource("1_8xtns")]
+38
View File
@@ -0,0 +1,38 @@
extends WeaponBehavior
class_name RangeBehavior
@onready var muzzle: Marker2D = %Muzzle
func execute_attack() -> void:
weapon.is_attacking = true
create_projectile()
var tween := create_tween()
var attack_pos := Vector2(weapon.atk_start_pos.x - weapon.data.stats.recoil, weapon.atk_start_pos.y)
tween.tween_property(weapon.sprite_2d, "position", attack_pos, weapon.data.stats.recoil_duration)
tween.tween_property(weapon.sprite_2d, "position", weapon.atk_start_pos, weapon.data.stats.recoil_duration)
await tween.finished
weapon.is_attacking = false
critical = false
func create_projectile() -> void:
var instance := weapon.data.stats.projectile_scene.instantiate() as Projectile
get_tree().root.add_child(instance)
instance.global_position = muzzle.global_position
var velocity := Vector2.RIGHT.rotated(weapon.rotation) * weapon.data.stats.projectile_speed
instance.set_projectile(velocity, get_damage(), critical, weapon.data.stats.knockback, weapon.get_parent())
# 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://f71mwa3ckrj8
+19
View File
@@ -0,0 +1,19 @@
[gd_scene format=3 uid="uid://c6spr5c4dva2i"]
[ext_resource type="PackedScene" uid="uid://dcc7rsdy4j8v6" path="res://scenes/weapons/weapon_base.tscn" id="1_r5jol"]
[ext_resource type="Texture2D" uid="uid://xqoogkscdty6" path="res://assets/sprites/Weapons/Range/WeaponLaser.png" id="2_jsyfg"]
[ext_resource type="Script" uid="uid://f71mwa3ckrj8" path="res://scenes/weapons/range/range_behavior.gd" id="3_50c4r"]
[node name="WeaponLaser" unique_id=63743776 instance=ExtResource("1_r5jol")]
[node name="Sprite2D" parent="." index="0" unique_id=1011668514]
position = Vector2(16, -4)
texture = ExtResource("2_jsyfg")
[node name="Muzzle" type="Marker2D" parent="Sprite2D" index="0" unique_id=1914443055]
unique_name_in_owner = true
position = Vector2(78, -14)
[node name="WeaponBehavior" parent="." index="3" unique_id=1507497844 node_paths=PackedStringArray("weapon")]
script = ExtResource("3_50c4r")
weapon = NodePath("..")
+19
View File
@@ -0,0 +1,19 @@
[gd_scene format=3 uid="uid://jkxk68loxb55"]
[ext_resource type="PackedScene" uid="uid://dcc7rsdy4j8v6" path="res://scenes/weapons/weapon_base.tscn" id="1_g1grj"]
[ext_resource type="Texture2D" uid="uid://bbsd0o1wllf0p" path="res://assets/sprites/Weapons/Range/WeaponPistol.png" id="2_hqh7m"]
[ext_resource type="Script" uid="uid://f71mwa3ckrj8" path="res://scenes/weapons/range/range_behavior.gd" id="3_x7rn7"]
[node name="WeaponPistol" unique_id=63743776 instance=ExtResource("1_g1grj")]
[node name="Sprite2D" parent="." index="0" unique_id=1011668514]
position = Vector2(20, 0)
texture = ExtResource("2_hqh7m")
[node name="Muzzle" type="Marker2D" parent="Sprite2D" index="0" unique_id=2115750749]
unique_name_in_owner = true
position = Vector2(92, -28)
[node name="WeaponBehavior" parent="." index="3" unique_id=1507497844 node_paths=PackedStringArray("weapon")]
script = ExtResource("3_x7rn7")
weapon = NodePath("..")
+9
View File
@@ -26,6 +26,8 @@ func _process(delta: float) -> void:
rotate_to_target()
update_visuals()
if can_use_weapon():
use_weapon()
@@ -73,6 +75,13 @@ func get_idle_rotation() -> float:
else:
return PI
func update_visuals() -> void:
if abs(rotation) > PI / 2:
sprite_2d.scale.y = -0.5
else :
sprite_2d.scale.y = 0.5
func calculate_spread() -> void:
weapon_spread += randf_range(-1 + data.stats.accurary, 1- data.stats.accurary)