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
+23
View File
@@ -0,0 +1,23 @@
extends Node2D
class_name Projectile
@export var hitbox: HitboxComponent
var velocity: Vector2
func _process(delta: float) -> void:
position += velocity * delta
func set_projectile(velocity: Vector2, damage: float, critical: bool, knockback: float, unit: Node2D) -> void:
self.velocity = velocity
rotation = velocity.angle()
if hitbox:
hitbox.setup(damage, critical, knockback, unit)
func _on_visible_on_screen_notifier_2d_screen_exited() -> void:
queue_free()
func _on_hitbox_component_on_hit_hurtbox(hurtbox: HurtboxComponent) -> void:
queue_free()
+1
View File
@@ -0,0 +1 @@
uid://bmye8ydta5x0x
+9
View File
@@ -0,0 +1,9 @@
[gd_scene format=3 uid="uid://dgxgta5rdunaj"]
[ext_resource type="PackedScene" uid="uid://cponp20ht0gf6" path="res://scenes/projectiles/projectile_pistol.tscn" id="1_kgo5h"]
[ext_resource type="Texture2D" uid="uid://3c2kwaw7powj" path="res://assets/sprites/Projectiles/Projectile_3.png" id="2_4n0tj"]
[node name="ProjectileLaser" unique_id=109874266 instance=ExtResource("1_kgo5h")]
[node name="Sprite2D" parent="." index="0" unique_id=575255969]
texture = ExtResource("2_4n0tj")
+28
View File
@@ -0,0 +1,28 @@
[gd_scene format=3 uid="uid://cponp20ht0gf6"]
[ext_resource type="Texture2D" uid="uid://45dwbyxmy4wd" path="res://assets/sprites/Projectiles/Projectile_2.png" id="1_4u32m"]
[ext_resource type="Script" uid="uid://bmye8ydta5x0x" path="res://scenes/projectiles/projectile.gd" id="1_71gtn"]
[ext_resource type="PackedScene" uid="uid://c0fyx8gj5uexl" path="res://scenes/components/hitbox_component.tscn" id="1_u4710"]
[sub_resource type="CircleShape2D" id="CircleShape2D_4u32m"]
radius = 13.0
[node name="ProjectilePistol" type="Node2D" unique_id=109874266 node_paths=PackedStringArray("hitbox")]
script = ExtResource("1_71gtn")
hitbox = NodePath("HitboxComponent")
[node name="Sprite2D" type="Sprite2D" parent="." unique_id=575255969]
scale = Vector2(0.5, 0.5)
texture = ExtResource("1_4u32m")
[node name="HitboxComponent" parent="." unique_id=151235566 instance=ExtResource("1_u4710")]
collision_layer = 16
collision_mask = 8
[node name="CollisionShape2D" type="CollisionShape2D" parent="HitboxComponent" unique_id=1598992093]
shape = SubResource("CircleShape2D_4u32m")
[node name="VisibleOnScreenNotifier2D" type="VisibleOnScreenNotifier2D" parent="." unique_id=1911021715]
[connection signal="on_hit_hurtbox" from="HitboxComponent" to="." method="_on_hitbox_component_on_hit_hurtbox"]
[connection signal="screen_exited" from="VisibleOnScreenNotifier2D" to="." method="_on_visible_on_screen_notifier_2d_screen_exited"]
@@ -0,0 +1,9 @@
[gd_scene format=3 uid="uid://bvdn35euxceps"]
[ext_resource type="PackedScene" uid="uid://cponp20ht0gf6" path="res://scenes/projectiles/projectile_pistol.tscn" id="1_yd76t"]
[ext_resource type="Texture2D" uid="uid://d3m2aqwl8u1qx" path="res://assets/sprites/Projectiles/Projectile_4.png" id="2_5bfio"]
[node name="ProjectileRevolver" unique_id=109874266 instance=ExtResource("1_yd76t")]
[node name="Sprite2D" parent="." index="0" unique_id=575255969]
texture = ExtResource("2_5bfio")
@@ -0,0 +1,9 @@
[gd_scene format=3 uid="uid://5mv5jtkql7pm"]
[ext_resource type="PackedScene" uid="uid://cponp20ht0gf6" path="res://scenes/projectiles/projectile_pistol.tscn" id="1_lmmiu"]
[ext_resource type="Texture2D" uid="uid://cmr4xxqrthts7" path="res://assets/sprites/Projectiles/Projectile_1.png" id="2_gh7rf"]
[node name="ProjectileShotgun" unique_id=109874266 instance=ExtResource("1_lmmiu")]
[node name="Sprite2D" parent="." index="0" unique_id=575255969]
texture = ExtResource("2_gh7rf")
+9
View File
@@ -0,0 +1,9 @@
[gd_scene format=3 uid="uid://7doitq0bldjw"]
[ext_resource type="PackedScene" uid="uid://cponp20ht0gf6" path="res://scenes/projectiles/projectile_pistol.tscn" id="1_s2juw"]
[ext_resource type="Texture2D" uid="uid://bf4yrlp8dofx1" path="res://assets/sprites/Projectiles/Projectile_5.png" id="2_7qwbs"]
[node name="ProjectileSMG" unique_id=109874266 instance=ExtResource("1_s2juw")]
[node name="Sprite2D" parent="." index="0" unique_id=575255969]
texture = ExtResource("2_7qwbs")
+2 -1
View File
@@ -23,7 +23,8 @@ func _ready() -> void:
dash_timer.wait_time = dash_duration
dash_cooldown_timer.wait_time = dash_cooldown
add_weapon(preload("uid://murcuuks1j8l"))
#add_weapon(preload("uid://murcuuks1j8l"))
add_weapon(preload("uid://bxlu2qkyn4xqf"))
+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)