diff --git a/DungeonShooting_Godot/src/CollisionComponent.cs b/DungeonShooting_Godot/src/CollisionComponent.cs
new file mode 100644
index 0000000..14140e5
--- /dev/null
+++ b/DungeonShooting_Godot/src/CollisionComponent.cs
@@ -0,0 +1,30 @@
+using Godot;
+using System;
+
+public class CollisionComponent
+{
+ public IObject Target { get; }
+
+ public Area2D AreaNode { get; }
+
+ public bool Disabled
+ {
+ get
+ {
+ return CollisionShape2DNode.Disabled;
+ }
+ set
+ {
+ CollisionShape2DNode.Disabled = value;
+ }
+ }
+
+ public CollisionShape2D CollisionShape2DNode { get; }
+
+ public CollisionComponent(IObject inst, Area2D area, CollisionShape2D collisionShape)
+ {
+ Target = inst;
+ AreaNode = area;
+ CollisionShape2DNode = collisionShape;
+ }
+}
\ No newline at end of file
diff --git a/DungeonShooting_Godot/src/IObject.cs b/DungeonShooting_Godot/src/IObject.cs
new file mode 100644
index 0000000..4afba80
--- /dev/null
+++ b/DungeonShooting_Godot/src/IObject.cs
@@ -0,0 +1,20 @@
+using Godot;
+using System;
+
+///
+/// 房间内所有物体都必须实现该接口
+///
+public interface IObject
+{
+ float GlobalHeight { get; set; }
+
+ Vector2 GlobalPosition { get; set; }
+
+ CollisionComponent Collision { get; }
+
+ void OnOtherEnter(IObject other);
+
+ void OnOtherExit(IObject other);
+
+ void Destroy();
+}
\ No newline at end of file
diff --git a/DungeonShooting_Godot/src/common/NodeExtend.cs b/DungeonShooting_Godot/src/common/NodeExtend.cs
index 6b0d817..c1083a9 100644
--- a/DungeonShooting_Godot/src/common/NodeExtend.cs
+++ b/DungeonShooting_Godot/src/common/NodeExtend.cs
@@ -1,6 +1,9 @@
using Godot;
using System;
+///
+/// 该类为 node 节点通用扩展函数类
+///
public static class NodeExtend
{
@@ -40,11 +43,18 @@
return inst;
}
+ ///
+ /// 将一个节点扔到地上, 并设置显示的阴影, 函数返回根据该节点创建的 ThrowNode 节点
+ ///
+ /// 显示的阴影sprite
public static ThrowNode PutDown(this Node2D node, Sprite shadowTarget)
{
return StartThrow(node, Vector2.Zero, node.Position, 0, 0, 0, 0, 0, shadowTarget);
}
+ ///
+ /// 拾起一个 node 节点, 返回是否拾起成功
+ ///
public static bool Pickup(this Node2D node)
{
ThrowNode parent = node.GetParentOrNull();
@@ -56,6 +66,10 @@
return false;
}
+ ///
+ /// 触发扔掉武器操作
+ ///
+ /// 触发扔掉该武器的的角色
public static ThrowWeapon StartThrowWeapon(this Weapon weapon, Role master)
{
if (master.Face == FaceDirection.Left)
@@ -73,6 +87,10 @@
return weapon.StartThrow(new Vector2(20, 20), startPos, startHeight, direction, xf, yf, rotate, weapon.WeaponSprite);
}
+
+ ///
+ /// 尝试将一个node2d节点转换成一个 IProp 类
+ ///
public static IProp AsProp(this Node2D node2d)
{
if (node2d is IProp p)
diff --git a/DungeonShooting_Godot/src/weapon/Weapon.cs b/DungeonShooting_Godot/src/weapon/Weapon.cs
index 2cde361..25c1b6f 100644
--- a/DungeonShooting_Godot/src/weapon/Weapon.cs
+++ b/DungeonShooting_Godot/src/weapon/Weapon.cs
@@ -140,12 +140,26 @@
var body = tempNode.GetChild(0);
tempNode.RemoveChild(body);
AddChild(body);
- }
- ///
- /// 初始化基础数据完成时调用
- ///
- protected abstract void Init();
+ WeaponSprite = GetNode("WeaponBody/WeaponSprite");
+ FirePoint = GetNode("WeaponBody/FirePoint");
+ OriginPoint = GetNode("WeaponBody/OriginPoint");
+ ShellPoint = GetNode("WeaponBody/ShellPoint");
+ AnimationPlayer = GetNode("WeaponBody/AnimationPlayer");
+ CollisionShape2D = GetNode("WeaponBody/Collision");
+
+ //更新图片
+ WeaponSprite.Texture = ResourceLoader.Load(Attribute.Sprite);
+ WeaponSprite.Position = Attribute.CenterPosition;
+ //开火位置
+ FirePoint.Position = new Vector2(Attribute.FirePosition.x, -Attribute.FirePosition.y);
+ OriginPoint.Position = new Vector2(0, -Attribute.FirePosition.y);
+
+ //弹药量
+ CurrAmmo = Attribute.AmmoCapacity;
+ //剩余弹药量
+ ResidueAmmo = Attribute.MaxAmmoCapacity - Attribute.AmmoCapacity;
+ }
///
/// 当按下扳机时调用
@@ -199,30 +213,6 @@
///
protected abstract void OnConceal();
- public override void _Ready()
- {
- WeaponSprite = GetNode("WeaponBody/WeaponSprite");
- FirePoint = GetNode("WeaponBody/FirePoint");
- OriginPoint = GetNode("WeaponBody/OriginPoint");
- ShellPoint = GetNode("WeaponBody/ShellPoint");
- AnimationPlayer = GetNode("WeaponBody/AnimationPlayer");
- CollisionShape2D = GetNode("WeaponBody/Collision");
-
- //更新图片
- WeaponSprite.Texture = ResourceLoader.Load(Attribute.Sprite);
- WeaponSprite.Position = Attribute.CenterPosition;
- //开火位置
- FirePoint.Position = new Vector2(Attribute.FirePosition.x, -Attribute.FirePosition.y);
- OriginPoint.Position = new Vector2(0, -Attribute.FirePosition.y);
-
- //弹药量
- CurrAmmo = Attribute.AmmoCapacity;
- //剩余弹药量
- ResidueAmmo = Attribute.MaxAmmoCapacity - Attribute.AmmoCapacity;
-
- Init();
- }
-
public override void _Process(float delta)
{
if (Master == null) //这把武器被扔在地上
diff --git a/DungeonShooting_Godot/src/weapon/WeaponManager.cs b/DungeonShooting_Godot/src/weapon/WeaponManager.cs
index 9137249..d5e8bf1 100644
--- a/DungeonShooting_Godot/src/weapon/WeaponManager.cs
+++ b/DungeonShooting_Godot/src/weapon/WeaponManager.cs
@@ -13,7 +13,7 @@
///
/// 从一个指定的程序集中扫描并注册武器对象
///
- /// 查询集
+ /// 数据集
public static void RegisterWeaponFromAssembly(Assembly assembly)
{
var types = assembly.GetTypes();
diff --git a/DungeonShooting_Godot/src/weapon/gun/Gun.cs b/DungeonShooting_Godot/src/weapon/gun/Gun.cs
index 2acfbb7..ca9ce7e 100644
--- a/DungeonShooting_Godot/src/weapon/gun/Gun.cs
+++ b/DungeonShooting_Godot/src/weapon/gun/Gun.cs
@@ -97,11 +97,6 @@
ShellPack = ResourceManager.Load("res://prefab/weapon/shell/ShellCase.tscn");
}
- protected override void Init()
- {
-
- }
-
protected override void OnFire()
{
//创建一个弹壳
diff --git a/DungeonShooting_Godot/src/weapon/gun/Shotgun.cs b/DungeonShooting_Godot/src/weapon/gun/Shotgun.cs
index f66b5f2..66cff82 100644
--- a/DungeonShooting_Godot/src/weapon/gun/Shotgun.cs
+++ b/DungeonShooting_Godot/src/weapon/gun/Shotgun.cs
@@ -59,11 +59,6 @@
ShellPack = ResourceManager.Load("res://prefab/weapon/shell/ShellCase.tscn");
}
- protected override void Init()
- {
-
- }
-
protected override void OnFire()
{
//创建一个弹壳