diff --git a/prefab/role/Player.tscn b/prefab/role/Player.tscn
index 0389b0f..9089f4d 100644
--- a/prefab/role/Player.tscn
+++ b/prefab/role/Player.tscn
@@ -10,4 +10,4 @@
GunPrefab = ExtResource( 4 )
[node name="AnimatedSprite" parent="." index="0"]
-frame = 0
+frame = 1
diff --git a/prefab/shell/ShellCase.tscn b/prefab/shell/ShellCase.tscn
deleted file mode 100644
index 8741487..0000000
--- a/prefab/shell/ShellCase.tscn
+++ /dev/null
@@ -1,6 +0,0 @@
-[gd_scene load_steps=2 format=2]
-
-[ext_resource path="res://resource/sprite/shell/shellCase.png" type="Texture" id=1]
-
-[node name="ShellCase" type="Sprite"]
-texture = ExtResource( 1 )
diff --git a/prefab/weapon/Gun.tscn b/prefab/weapon/Gun.tscn
index 35e9f95..380fbda 100644
--- a/prefab/weapon/Gun.tscn
+++ b/prefab/weapon/Gun.tscn
@@ -3,7 +3,7 @@
[ext_resource path="res://src/weapon/gun/OrdinaryGun.cs" type="Script" id=1]
[ext_resource path="res://prefab/weapon/bullet/OrdinaryBullets.tscn" type="PackedScene" id=2]
[ext_resource path="res://resource/sprite/gun/gun1.png" type="Texture" id=3]
-[ext_resource path="res://prefab/shell/ShellCase.tscn" type="PackedScene" id=4]
+[ext_resource path="res://prefab/weapon/shell/ShellCase.tscn" type="PackedScene" id=4]
[sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 9.5, 3.5 )
diff --git a/prefab/weapon/shell/ShellCase.tscn b/prefab/weapon/shell/ShellCase.tscn
new file mode 100644
index 0000000..8741487
--- /dev/null
+++ b/prefab/weapon/shell/ShellCase.tscn
@@ -0,0 +1,6 @@
+[gd_scene load_steps=2 format=2]
+
+[ext_resource path="res://resource/sprite/shell/shellCase.png" type="Texture" id=1]
+
+[node name="ShellCase" type="Sprite"]
+texture = ExtResource( 1 )
diff --git a/src/effect/Cursor.cs b/src/effect/Cursor.cs
index 4450f54..06f6894 100644
--- a/src/effect/Cursor.cs
+++ b/src/effect/Cursor.cs
@@ -6,8 +6,6 @@
public class Cursor : Node2D
{
- public Gun TargetGun = null;
-
private Sprite lt;
private Sprite lb;
private Sprite rt;
@@ -23,13 +21,14 @@
public override void _Process(float delta)
{
- if (TargetGun != null)
+ var targetGun = RoomManager.Current?.Player?.Holster.ActiveGun;
+ if (targetGun != null)
{
- SetScope(TargetGun.CurrScatteringRange);
+ SetScope(targetGun.CurrScatteringRange, targetGun);
}
else
{
- SetScope(0);
+ SetScope(0, targetGun);
}
SetCursorPos();
}
@@ -37,14 +36,14 @@
///
/// 设置光标半径范围
///
- private void SetScope(float scope)
+ private void SetScope(float scope, Gun targetGun)
{
- if (TargetGun != null)
+ if (targetGun != null)
{
- var len = GlobalPosition.DistanceTo(TargetGun.GlobalPosition);
- if (TargetGun.Attribute != null)
+ var len = GlobalPosition.DistanceTo(targetGun.GlobalPosition);
+ if (targetGun.Attribute != null)
{
- len = Mathf.Max(0, len - TargetGun.Attribute.FirePosition.x);
+ len = Mathf.Max(0, len - targetGun.Attribute.FirePosition.x);
}
scope = len / GameConfig.ScatteringDistance * scope;
}
diff --git a/src/role/Player.cs b/src/role/Player.cs
index cc76373..367502e 100644
--- a/src/role/Player.cs
+++ b/src/role/Player.cs
@@ -18,45 +18,21 @@
[Export] public PackedScene GunPrefab;
+ public override void _EnterTree()
+ {
+ base._EnterTree();
+ RoomManager.Current.Player = this;
+ }
+
public override void _Ready()
{
base._Ready();
- //加载枪
- var gun = GunPrefab.Instance();
- MountPoint.AddChild(gun);
- var attr = new GunAttribute();
- attr.StartFiringSpeed = 480;
- attr.StartScatteringRange = 5;
- attr.FinalScatteringRange = 60;
- attr.ScatteringRangeAddValue = 2f;
- attr.ScatteringRangeBackSpeed = 40;
- //连发
- attr.ContinuousShoot = true;
- //扳机检测间隔
- attr.TriggerInterval = 0f;
- //连发数量
- attr.MinContinuousCount = 3;
- attr.MaxContinuousCount = 3;
- //开火前延时
- attr.DelayedTime = 0f;
- //攻击距离
- attr.MinDistance = 500;
- attr.MaxDistance = 600;
- //发射子弹数量
- attr.MinFireBulletCount = 1;
- attr.MaxFireBulletCount = 1;
- //抬起角度
- attr.UpliftAngle = 10;
- //枪身长度
- attr.FirePosition = new Vector2(16, 1.5f);
- attr.Sprite = "res://resource/sprite/gun/gun4.png";
- gun.Init(attr);
+ var gun = GunManager.GetGun1();
+ MountPoint.AddChild(gun);
gun.FireEvent += FireEvent_Func;
Holster.PickupGun(gun);
-
- RoomManager.Current.Cursor.TargetGun = gun;
}
public override void _Process(float delta)
diff --git a/src/room/RoomManager.cs b/src/room/RoomManager.cs
index a7433ac..6785fb8 100644
--- a/src/room/RoomManager.cs
+++ b/src/room/RoomManager.cs
@@ -16,6 +16,7 @@
public CanvasLayer UI;
public Cursor Cursor { get; private set; }
+ public Player Player { get; set; }
public YSort ItemRoot { get; private set; }
public override void _EnterTree()
diff --git a/src/weapon/gun/Gun.cs b/src/weapon/gun/Gun.cs
index e0af9e4..8cb5429 100644
--- a/src/weapon/gun/Gun.cs
+++ b/src/weapon/gun/Gun.cs
@@ -83,14 +83,6 @@
private float continuousCount = 0;
private bool continuousShootFlag = false;
- public override void _EnterTree()
- {
- GunSprite = GetNode("GunSprite");
- FirePoint = GetNode("FirePoint");
- OriginPoint = GetNode("OriginPoint");
- ShellPoint = GetNode("ShellPoint");
- }
-
public override void _Process(float delta)
{
if (triggerFlag)
@@ -164,6 +156,11 @@
throw new Exception("当前武器已经初始化过了!");
}
+ GunSprite = GetNode("GunSprite");
+ FirePoint = GetNode("FirePoint");
+ OriginPoint = GetNode("OriginPoint");
+ ShellPoint = GetNode("ShellPoint");
+
Attribute = attribute;
//更新图片
var texture = ResourceLoader.Load(attribute.Sprite);
diff --git a/src/weapon/gun/GunManager.cs b/src/weapon/gun/GunManager.cs
new file mode 100644
index 0000000..1000652
--- /dev/null
+++ b/src/weapon/gun/GunManager.cs
@@ -0,0 +1,67 @@
+using System.Collections.Generic;
+using Godot;
+
+public static class GunManager
+{
+
+ private static readonly Dictionary CacheGunPack = new Dictionary();
+
+ ///
+ /// 加载武器预制体,
+ /// 路径位于res://prefab/weapon/下
+ ///
+ /// 资源路径
+ public static Gun LoadGun(string path)
+ {
+ path = "res://prefab/weapon/" + path;
+ if (CacheGunPack.TryGetValue(path, out var pack))
+ {
+ return pack.Instance();
+ }
+ else
+ {
+ pack = ResourceLoader.Load(path);
+ if (pack != null)
+ {
+ CacheGunPack.Add(path, pack);
+ return pack.Instance();
+ }
+ }
+ return null;
+ }
+
+ public static Gun GetGun1()
+ {
+ //加载枪的 prefab
+ var gun = LoadGun("Gun.tscn");
+ //设置基础属性
+ var attr = new GunAttribute();
+ attr.StartFiringSpeed = 480;
+ attr.StartScatteringRange = 5;
+ attr.FinalScatteringRange = 60;
+ attr.ScatteringRangeAddValue = 2f;
+ attr.ScatteringRangeBackSpeed = 40;
+ //连发
+ attr.ContinuousShoot = true;
+ //扳机检测间隔
+ attr.TriggerInterval = 0f;
+ //连发数量
+ attr.MinContinuousCount = 3;
+ attr.MaxContinuousCount = 3;
+ //开火前延时
+ attr.DelayedTime = 0f;
+ //攻击距离
+ attr.MinDistance = 500;
+ attr.MaxDistance = 600;
+ //发射子弹数量
+ attr.MinFireBulletCount = 1;
+ attr.MaxFireBulletCount = 1;
+ //抬起角度
+ attr.UpliftAngle = 10;
+ //枪身长度
+ attr.FirePosition = new Vector2(16, 1.5f);
+ attr.Sprite = "res://resource/sprite/gun/gun4.png";
+ gun.Init(attr);
+ return gun;
+ }
+}