diff --git a/DungeonShooting_Godot/project.godot b/DungeonShooting_Godot/project.godot
index 93ab966..4470bd7 100644
--- a/DungeonShooting_Godot/project.godot
+++ b/DungeonShooting_Godot/project.godot
@@ -11,7 +11,7 @@
[application]
config/name="DungeonShooting"
-run/main_scene="res://scene/test/TestCommpont.tscn"
+run/main_scene="res://scene/Room.tscn"
config/icon="res://icon.png"
[autoload]
diff --git a/DungeonShooting_Godot/scene/test/TestCommpont.tscn b/DungeonShooting_Godot/scene/test/TestCommpont.tscn
index 7046b05..c9288d8 100644
--- a/DungeonShooting_Godot/scene/test/TestCommpont.tscn
+++ b/DungeonShooting_Godot/scene/test/TestCommpont.tscn
@@ -1,7 +1,6 @@
-[gd_scene load_steps=3 format=2]
+[gd_scene load_steps=2 format=2]
[ext_resource path="res://icon.png" type="Texture" id=1]
-[ext_resource path="res://src/test/TestPlayer.cs" type="Script" id=2]
[node name="Node2D" type="Node2D"]
@@ -9,4 +8,3 @@
position = Vector2( 200, 102 )
scale = Vector2( 0.3, 0.3 )
texture = ExtResource( 1 )
-script = ExtResource( 2 )
diff --git a/DungeonShooting_Godot/src/framework/ActivityObject.cs b/DungeonShooting_Godot/src/framework/ActivityObject.cs
new file mode 100644
index 0000000..b65f714
--- /dev/null
+++ b/DungeonShooting_Godot/src/framework/ActivityObject.cs
@@ -0,0 +1,38 @@
+
+using Godot;
+
+///
+/// 房间内活动物体基类
+///
+public abstract class ActivityObject : ActivityObject where T : KinematicBody2D
+{
+ public ActivityObject()
+ {
+ ComponentControl = CreateComponentControl();
+ }
+
+ ///
+ /// 组件管理器
+ ///
+ public ComponentControl ComponentControl { get; }
+
+ public abstract ComponentControl CreateComponentControl();
+}
+
+///
+/// 房间内活动物体基类
+///
+public abstract class ActivityObject : KinematicBody2D
+{
+ ///
+ /// 返回是否能与其他ActivityObject互动
+ ///
+ /// 触发者
+ public abstract CheckInteractiveResult CheckInteractive(ActivityObject master) where TU : KinematicBody2D;
+
+ ///
+ /// 与其它ActivityObject互动时调用
+ ///
+ /// 触发者
+ public abstract void Interactive(ActivityObject master) where TU : KinematicBody2D;
+}
\ No newline at end of file
diff --git a/DungeonShooting_Godot/src/framework/Component.cs b/DungeonShooting_Godot/src/framework/Component.cs
index 1725b03..acace94 100644
--- a/DungeonShooting_Godot/src/framework/Component.cs
+++ b/DungeonShooting_Godot/src/framework/Component.cs
@@ -4,38 +4,93 @@
///
/// 组件基类
///
-public abstract class Component : IComponent where TG : Node2D
+public abstract class Component : Component where TG : KinematicBody2D
{
- public GameObject GameObject { get; private set; }
+ public ComponentControl ComponentControl { get; private set; }
public Vector2 Position
{
- get => GameObject.Position;
- set => GameObject.Position = value;
+ get => ComponentControl.Position;
+ set => ComponentControl.Position = value;
}
public Vector2 GlobalPosition
{
- get => GameObject.GlobalPosition;
- set => GameObject.GlobalPosition = value;
+ get => ComponentControl.GlobalPosition;
+ set => ComponentControl.GlobalPosition = value;
}
public bool Visible
{
- get => GameObject.Visible;
- set => GameObject.Visible = value;
+ get => ComponentControl.Visible;
+ set => ComponentControl.Visible = value;
}
public bool Enable { get; set; } = true;
public bool IsDestroyed { get; private set; }
+ ///
+ /// 当组件销毁
+ ///
+ public override void Destroy()
+ {
+ if (IsDestroyed)
+ {
+ return;
+ }
+
+ IsDestroyed = true;
+ if (ComponentControl != null)
+ {
+ ComponentControl.RemoveComponent(this);
+ }
+
+ OnDestroy();
+ }
+
+ internal void SetGameObject(ComponentControl componentControl)
+ {
+ ComponentControl = componentControl;
+ }
+}
+
+///
+/// 组件基类
+///
+public abstract class Component : IProcess, IDestroy
+{
+ ///
+ /// 该组件所绑定的GameObject的坐标
+ ///
+ Vector2 Position { get; set; }
+
+ ///
+ /// 该组件所绑定的GameObject的全局坐标
+ ///
+ Vector2 GlobalPosition { get; set; }
+
+ ///
+ /// 该组件所绑定的GameObject的显示状态
+ ///
+ bool Visible { get; set; }
+
+ ///
+ /// 是否启用该组件, 如果停用, 则不会调用 Process 和 PhysicsProcess
+ ///
+ bool Enable { get; set; }
+
+ public bool IsDestroyed { get; }
+
private bool _isReady = false;
+ ///
+ /// 第一次调用 Process 或 PhysicsProcess 之前调用
+ ///
public virtual void Ready()
{
}
-
+
public virtual void Process(float delta)
{
}
@@ -48,29 +103,21 @@
{
}
+ ///
+ /// 当该组件挂载到GameObject上时调用
+ ///
public virtual void OnMount()
{
}
+ ///
+ /// 当该组件被取消挂载时调用
+ ///
public virtual void OnUnMount()
{
}
-
- public void Destroy()
- {
- if (IsDestroyed)
- {
- return;
- }
-
- IsDestroyed = true;
- if (GameObject != null)
- {
- GameObject.RemoveComponent(this);
- }
-
- OnDestroy();
- }
+
+ public abstract void Destroy();
internal void _TriggerProcess(float delta)
{
@@ -79,8 +126,10 @@
_isReady = true;
Ready();
}
+
Process(delta);
}
+
internal void _TriggerPhysicsProcess(float delta)
{
if (!_isReady)
@@ -88,10 +137,7 @@
_isReady = true;
Ready();
}
+
PhysicsProcess(delta);
}
- internal void SetGameObject(GameObject gameObject)
- {
- GameObject = gameObject;
- }
-}
+}
\ No newline at end of file
diff --git a/DungeonShooting_Godot/src/framework/ComponentControl.cs b/DungeonShooting_Godot/src/framework/ComponentControl.cs
new file mode 100644
index 0000000..e3c548c
--- /dev/null
+++ b/DungeonShooting_Godot/src/framework/ComponentControl.cs
@@ -0,0 +1,131 @@
+using System.Collections.Generic;
+using Godot;
+
+public class ComponentControl : Node, IDestroy where T : KinematicBody2D
+{
+ public float Altitude { get; set; }
+
+ public Vector2 Position
+ {
+ get => Node.Position;
+ set => Node.Position = value;
+ }
+
+ public Vector2 GlobalPosition
+ {
+ get => Node.GlobalPosition;
+ set => Node.GlobalPosition = value;
+ }
+
+ public bool Visible
+ {
+ get => Node.Visible;
+ set => Node.Visible = value;
+ }
+
+ public bool IsDestroyed { get; private set; }
+
+ public T Node { get; private set; }
+
+ private List> _components = new List>();
+
+ public ComponentControl(T node)
+ {
+ Name = "ComponentControl";
+ Node = node;
+ node.AddChild(this);
+ }
+
+ public void AddComponent(NodeComponent nodeComponent) where TN : Node
+ {
+ if (!_components.Contains(nodeComponent))
+ {
+ _components.Add(nodeComponent);
+ nodeComponent.SetGameObject(this);
+ var parent = nodeComponent.Node.GetParent();
+ if (parent == null)
+ {
+ Node.AddChild(nodeComponent.Node);
+ }
+ else if (parent != Node)
+ {
+ parent.RemoveChild(nodeComponent.Node);
+ Node.AddChild(nodeComponent.Node);
+ }
+ nodeComponent.OnMount();
+ }
+ }
+
+ public void RemoveComponent(NodeComponent nodeComponent) where TN : Node
+ {
+ if (_components.Remove(nodeComponent))
+ {
+ nodeComponent.SetGameObject(null);
+ Node.RemoveChild(nodeComponent.Node);
+ nodeComponent.OnUnMount();
+ }
+ }
+
+ public void AddComponent(Component component)
+ {
+ if (!_components.Contains(component))
+ {
+ _components.Add(component);
+ component.SetGameObject(this);
+ component.OnMount();
+ }
+ }
+
+ public void RemoveComponent(Component component)
+ {
+ if (_components.Remove(component))
+ {
+ component.SetGameObject(null);
+ component.OnUnMount();
+ }
+ }
+
+ public override void _Process(float delta)
+ {
+ var arr = _components.ToArray();
+ for (int i = 0; i < arr.Length; i++)
+ {
+ if (IsDestroyed) return;
+ var temp = arr[i];
+ if (temp != null && temp.ComponentControl == this && temp.Enable)
+ {
+ temp._TriggerProcess(delta);
+ }
+ }
+ }
+
+ public override void _PhysicsProcess(float delta)
+ {
+ var arr = _components.ToArray();
+ for (int i = 0; i < arr.Length; i++)
+ {
+ if (IsDestroyed) return;
+ var temp = arr[i];
+ if (temp != null && temp.ComponentControl == this && temp.Enable)
+ {
+ temp._TriggerPhysicsProcess(delta);
+ }
+ }
+ }
+
+ public void Destroy()
+ {
+ if (IsDestroyed)
+ {
+ return;
+ }
+
+ IsDestroyed = true;
+ Node.QueueFree();
+ var arr = _components.ToArray();
+ for (int i = 0; i < arr.Length; i++)
+ {
+ arr[i].Destroy();
+ }
+ }
+}
\ No newline at end of file
diff --git a/DungeonShooting_Godot/src/framework/GameObject.cs b/DungeonShooting_Godot/src/framework/GameObject.cs
deleted file mode 100644
index aae59ed..0000000
--- a/DungeonShooting_Godot/src/framework/GameObject.cs
+++ /dev/null
@@ -1,122 +0,0 @@
-using System.Collections.Generic;
-using Godot;
-
-public class GameObject : Node, IDestroy where T : Node2D
-{
- public float Altitude { get; set; }
-
- public Vector2 Position
- {
- get => Node.Position;
- set => Node.Position = value;
- }
-
- public Vector2 GlobalPosition
- {
- get => Node.GlobalPosition;
- set => Node.GlobalPosition = value;
- }
-
- public bool Visible
- {
- get => Node.Visible;
- set => Node.Visible = value;
- }
-
- public bool IsDestroyed { get; private set; }
-
- public T Node { get; private set; }
-
- private List> _components = new List>();
-
- public GameObject(T node)
- {
- Name = "ComponentControl";
- Node = node;
- node.AddChild(this);
- }
-
- public void AddComponent(NodeComponent nodeComponent) where TN : Node
- {
- if (!_components.Contains(nodeComponent))
- {
- _components.Add(nodeComponent);
- nodeComponent.SetGameObject(this);
- Node.AddChild(nodeComponent.Node);
- nodeComponent.OnMount();
- }
- }
-
- public void RemoveComponent(NodeComponent nodeComponent) where TN : Node
- {
- if (_components.Remove(nodeComponent))
- {
- nodeComponent.SetGameObject(null);
- Node.RemoveChild(nodeComponent.Node);
- nodeComponent.OnUnMount();
- }
- }
-
- public void AddComponent(Component component)
- {
- if (!_components.Contains(component))
- {
- _components.Add(component);
- component.SetGameObject(this);
- component.OnMount();
- }
- }
-
- public void RemoveComponent(Component component)
- {
- if (_components.Remove(component))
- {
- component.SetGameObject(null);
- component.OnUnMount();
- }
- }
-
- public override void _Process(float delta)
- {
- var arr = _components.ToArray();
- for (int i = 0; i < arr.Length; i++)
- {
- if (IsDestroyed) return;
- var temp = arr[i];
- if (temp != null && temp.GameObject == this && temp.Enable)
- {
- temp._TriggerProcess(delta);
- }
- }
- }
-
- public override void _PhysicsProcess(float delta)
- {
- var arr = _components.ToArray();
- for (int i = 0; i < arr.Length; i++)
- {
- if (IsDestroyed) return;
- var temp = arr[i];
- if (temp != null && temp.GameObject == this && temp.Enable)
- {
- temp._TriggerPhysicsProcess(delta);
- }
- }
- }
-
- public void Destroy()
- {
- if (IsDestroyed)
- {
- return;
- }
-
- IsDestroyed = true;
- Node.QueueFree();
- var arr = _components.ToArray();
- for (int i = 0; i < arr.Length; i++)
- {
- arr[i].Destroy();
- }
- }
-}
\ No newline at end of file
diff --git a/DungeonShooting_Godot/src/framework/IComponent.cs b/DungeonShooting_Godot/src/framework/IComponent.cs
deleted file mode 100644
index 74b5083..0000000
--- a/DungeonShooting_Godot/src/framework/IComponent.cs
+++ /dev/null
@@ -1,48 +0,0 @@
-
-using Godot;
-
-///
-/// 组件接口
-///
-public interface IComponent : IProcess, IDestroy where TN : Node2D
-{
- ///
- /// 该组件绑定的GameObject对象
- ///
- GameObject GameObject { get; }
-
- ///
- /// 该组件所绑定的GameObject的坐标
- ///
- Vector2 Position { get; set; }
-
- ///
- /// 该组件所绑定的GameObject的全局坐标
- ///
- Vector2 GlobalPosition { get; set; }
-
- ///
- /// 该组件所绑定的GameObject的显示状态
- ///
- bool Visible { get; set; }
-
- ///
- /// 是否启用该组件, 如果停用, 则不会调用 Process 和 PhysicsProcess
- ///
- bool Enable { get; set; }
-
- ///
- /// 第一次调用 Process 或 PhysicsProcess 之前调用
- ///
- void Ready();
-
- ///
- /// 当该组件挂载到GameObject上时调用
- ///
- void OnMount();
-
- ///
- /// 当该组件被取消挂载时调用
- ///
- void OnUnMount();
-}
\ No newline at end of file
diff --git a/DungeonShooting_Godot/src/framework/NodeComponent.cs b/DungeonShooting_Godot/src/framework/NodeComponent.cs
index 732d379..4ae2121 100644
--- a/DungeonShooting_Godot/src/framework/NodeComponent.cs
+++ b/DungeonShooting_Godot/src/framework/NodeComponent.cs
@@ -1,6 +1,6 @@
using Godot;
-public abstract class NodeComponent : Component where TN : Node where TG : Node2D
+public abstract class NodeComponent : Component where TN : Node where TG : KinematicBody2D
{
public TN Node { get; }
diff --git a/DungeonShooting_Godot/src/game/common/NodeExtend.cs b/DungeonShooting_Godot/src/game/common/NodeExtend.cs
index c1083a9..9f1242b 100644
--- a/DungeonShooting_Godot/src/game/common/NodeExtend.cs
+++ b/DungeonShooting_Godot/src/game/common/NodeExtend.cs
@@ -89,16 +89,16 @@
///
- /// 尝试将一个node2d节点转换成一个 IProp 类
+ /// 尝试将一个node2d节点转换成一个 ActivityObject 类
///
- public static IProp AsProp(this Node2D node2d)
+ public static ActivityObject AsActivityObject(this Node2D node2d)
{
- if (node2d is IProp p)
+ if (node2d is ActivityObject p)
{
return p;
}
var parent = node2d.GetParent();
- if (parent != null && parent is IProp p2)
+ if (parent != null && parent is ActivityObject p2)
{
return p2;
}
diff --git a/DungeonShooting_Godot/src/game/props/CheckInteractiveResult.cs b/DungeonShooting_Godot/src/game/props/CheckInteractiveResult.cs
index 07053f5..eb8676b 100644
--- a/DungeonShooting_Godot/src/game/props/CheckInteractiveResult.cs
+++ b/DungeonShooting_Godot/src/game/props/CheckInteractiveResult.cs
@@ -7,7 +7,7 @@
///
/// 互动物体
///
- public IProp Target;
+ public ActivityObject Target;
///
/// 是否可以互动
///
@@ -21,7 +21,7 @@
///
public string ShowIcon;
- public CheckInteractiveResult(IProp target)
+ public CheckInteractiveResult(ActivityObject target)
{
Target = target;
}
diff --git a/DungeonShooting_Godot/src/game/props/IProp.cs b/DungeonShooting_Godot/src/game/props/IProp.cs
deleted file mode 100644
index f17b5f4..0000000
--- a/DungeonShooting_Godot/src/game/props/IProp.cs
+++ /dev/null
@@ -1,24 +0,0 @@
-using Godot;
-
-///
-/// 道具接口
-///
-public interface IProp
-{
- ///
- /// 获取道具所在的坐标
- ///
- Vector2 GetItemPosition();
-
- ///
- /// 返回是否能互动
- ///
- /// 触发者
- CheckInteractiveResult CheckInteractive(Role master);
-
- ///
- /// 与角色互动时调用
- ///
- /// 触发者
- void Interactive(Role master);
-}
\ No newline at end of file
diff --git a/DungeonShooting_Godot/src/game/props/weapon/Weapon.cs b/DungeonShooting_Godot/src/game/props/weapon/Weapon.cs
index 25c1b6f..0812079 100644
--- a/DungeonShooting_Godot/src/game/props/weapon/Weapon.cs
+++ b/DungeonShooting_Godot/src/game/props/weapon/Weapon.cs
@@ -4,7 +4,7 @@
///
/// 武器的基类
///
-public abstract class Weapon : Node2D, IProp
+public abstract class Weapon : ActivityObject
{
///
@@ -213,6 +213,11 @@
///
protected abstract void OnConceal();
+ public override ComponentControl CreateComponentControl()
+ {
+ return new ComponentControl(this);
+ }
+
public override void _Process(float delta)
{
if (Master == null) //这把武器被扔在地上
@@ -266,7 +271,7 @@
if (downTimer > 0) //第一帧松开扳机
{
downTimer = 0;
- UpTriggern();
+ UpTrigger();
}
upTimer += delta;
}
@@ -294,7 +299,7 @@
if (continuousCount > 0 && delayedTime <= 0 && attackTimer <= 0)
{
//开火
- TriggernFire();
+ TriggerFire();
}
if (!attackFlag && attackTimer <= 0)
@@ -394,7 +399,7 @@
}
if (delayedTime <= 0 && attackTimer <= 0)
{
- TriggernFire();
+ TriggerFire();
}
attackFlag = true;
}
@@ -414,7 +419,7 @@
///
/// 刚松开扳机
///
- private void UpTriggern()
+ private void UpTrigger()
{
continuousShootFlag = false;
if (delayedTime > 0)
@@ -427,7 +432,7 @@
///
/// 触发开火
///
- private void TriggernFire()
+ private void TriggerFire()
{
continuousCount = continuousCount > 0 ? continuousCount - 1 : 0;
@@ -574,103 +579,114 @@
}
}
- public CheckInteractiveResult CheckInteractive(Role master)
+ public override CheckInteractiveResult CheckInteractive(ActivityObject master)
{
var result = new CheckInteractiveResult(this);
- if (Master == null)
+
+ if (master is Role roleMaster) //碰到角色
{
- var masterWeapon = master.Holster.ActiveWeapon;
- //查找是否有同类型武器
- var index = master.Holster.FindWeapon(Id);
- if (index != -1) //如果有这个武器
+ if (Master == null)
{
- if (CurrAmmo + ResidueAmmo != 0) //子弹不为空
+ var masterWeapon = roleMaster.Holster.ActiveWeapon;
+ //查找是否有同类型武器
+ var index = roleMaster.Holster.FindWeapon(Id);
+ if (index != -1) //如果有这个武器
{
- var targetWeapon = master.Holster.GetWeapon(index);
- if (!targetWeapon.IsFullAmmo()) //背包里面的武器子弹未满
+ if (CurrAmmo + ResidueAmmo != 0) //子弹不为空
{
- //可以互动拾起弹药
+ var targetWeapon = roleMaster.Holster.GetWeapon(index);
+ if (!targetWeapon.IsFullAmmo()) //背包里面的武器子弹未满
+ {
+ //可以互动拾起弹药
+ result.CanInteractive = true;
+ result.Message = Attribute.Name;
+ result.ShowIcon = "res://resource/sprite/ui/icon/icon_bullet.png";
+ return result;
+ }
+ }
+ }
+ else //没有武器
+ {
+ if (roleMaster.Holster.CanPickupWeapon(this)) //能拾起武器
+ {
+ //可以互动, 拾起武器
result.CanInteractive = true;
result.Message = Attribute.Name;
- result.ShowIcon = "res://resource/sprite/ui/icon/icon_bullet.png";
+ result.ShowIcon = "res://resource/sprite/ui/icon/icon_pickup.png";
+ return result;
+ }
+ else if (masterWeapon != null && masterWeapon.Attribute.WeightType == Attribute.WeightType) //替换武器
+ {
+ //可以互动, 切换武器
+ result.CanInteractive = true;
+ result.Message = Attribute.Name;
+ result.ShowIcon = "res://resource/sprite/ui/icon/icon_replace.png";
return result;
}
}
}
- else //没有武器
- {
- if (master.Holster.CanPickupWeapon(this)) //能拾起武器
- {
- //可以互动, 拾起武器
- result.CanInteractive = true;
- result.Message = Attribute.Name;
- result.ShowIcon = "res://resource/sprite/ui/icon/icon_pickup.png";
- return result;
- }
- else if (masterWeapon != null && masterWeapon.Attribute.WeightType == Attribute.WeightType) //替换武器
- {
- //可以互动, 切换武器
- result.CanInteractive = true;
- result.Message = Attribute.Name;
- result.ShowIcon = "res://resource/sprite/ui/icon/icon_replace.png";
- return result;
- }
- }
}
+
return result;
}
- public void Interactive(Role master)
+ public override void Interactive(ActivityObject master)
{
- //查找是否有同类型武器
- var index = master.Holster.FindWeapon(Id);
- if (index != -1) //如果有这个武器
+ if (master is Role roleMaster) //与role碰撞
{
- if (CurrAmmo + ResidueAmmo == 0) //没有子弹了
+ //查找是否有同类型武器
+ var index = roleMaster.Holster.FindWeapon(Id);
+ if (index != -1) //如果有这个武器
{
- return;
- }
- var weapon = master.Holster.GetWeapon(index);
- //子弹上限
- var maxCount = Attribute.MaxAmmoCapacity;
- //是否捡到子弹
- var flag = false;
- if (ResidueAmmo > 0 && weapon.CurrAmmo + weapon.ResidueAmmo < maxCount)
- {
- var count = weapon.PickUpAmmo(ResidueAmmo);
- if (count != ResidueAmmo)
+ if (CurrAmmo + ResidueAmmo == 0) //没有子弹了
{
- ResidueAmmo = count;
- flag = true;
+ return;
+ }
+
+ var weapon = roleMaster.Holster.GetWeapon(index);
+ //子弹上限
+ var maxCount = Attribute.MaxAmmoCapacity;
+ //是否捡到子弹
+ var flag = false;
+ if (ResidueAmmo > 0 && weapon.CurrAmmo + weapon.ResidueAmmo < maxCount)
+ {
+ var count = weapon.PickUpAmmo(ResidueAmmo);
+ if (count != ResidueAmmo)
+ {
+ ResidueAmmo = count;
+ flag = true;
+ }
+ }
+
+ if (CurrAmmo > 0 && weapon.CurrAmmo + weapon.ResidueAmmo < maxCount)
+ {
+ var count = weapon.PickUpAmmo(CurrAmmo);
+ if (count != CurrAmmo)
+ {
+ CurrAmmo = count;
+ flag = true;
+ }
+ }
+
+ //播放互动效果
+ if (flag)
+ {
+ this.StartThrow(new Vector2(20, 20), GlobalPosition, 0, 0,
+ MathUtils.RandRangeInt(-20, 20), MathUtils.RandRangeInt(20, 50),
+ MathUtils.RandRangeInt(-180, 180), WeaponSprite);
}
}
- if (CurrAmmo > 0 && weapon.CurrAmmo + weapon.ResidueAmmo < maxCount)
+ else //没有武器
{
- var count = weapon.PickUpAmmo(CurrAmmo);
- if (count != CurrAmmo)
+ if (roleMaster.Holster.PickupWeapon(this) == -1)
{
- CurrAmmo = count;
- flag = true;
- }
- }
- //播放互动效果
- if (flag)
- {
- this.StartThrow(new Vector2(20, 20), GlobalPosition, 0, 0,
- MathUtils.RandRangeInt(-20, 20), MathUtils.RandRangeInt(20, 50),
- MathUtils.RandRangeInt(-180, 180), WeaponSprite);
- }
- }
- else //没有武器
- {
- if (master.Holster.PickupWeapon(this) == -1)
- {
- var slot = master.Holster.SlotList[master.Holster.ActiveIndex];
- if (slot.Type == Attribute.WeightType)
- {
- var weapon = master.Holster.RmoveWeapon(master.Holster.ActiveIndex);
- weapon.StartThrowWeapon(master);
- master.PickUpWeapon(this);
+ var slot = roleMaster.Holster.SlotList[roleMaster.Holster.ActiveIndex];
+ if (slot.Type == Attribute.WeightType)
+ {
+ var weapon = roleMaster.Holster.RmoveWeapon(roleMaster.Holster.ActiveIndex);
+ weapon.StartThrowWeapon(roleMaster);
+ roleMaster.PickUpWeapon(this);
+ }
}
}
}
diff --git a/DungeonShooting_Godot/src/game/role/FaceDirection.cs b/DungeonShooting_Godot/src/game/role/FaceDirection.cs
new file mode 100644
index 0000000..b6f34a7
--- /dev/null
+++ b/DungeonShooting_Godot/src/game/role/FaceDirection.cs
@@ -0,0 +1,8 @@
+///
+/// 脸的朝向
+///
+public enum FaceDirection
+{
+ Left,
+ Right,
+}
\ No newline at end of file
diff --git a/DungeonShooting_Godot/src/game/role/Player.cs b/DungeonShooting_Godot/src/game/role/Player.cs
index efe2d5c..9402cbf 100644
--- a/DungeonShooting_Godot/src/game/role/Player.cs
+++ b/DungeonShooting_Godot/src/game/role/Player.cs
@@ -97,7 +97,7 @@
}
else if (Input.IsActionJustPressed("interactive")) //互动物体
{
- var item = TriggerTnteractive();
+ var item = TriggerInteractive();
if (item is Weapon)
{
RefreshGunTexture();
@@ -154,7 +154,7 @@
if (InteractiveItem is Weapon gun)
{
//显示互动提示
- RoomUI.Current.InteractiveTipBar.ShowBar(result.Target.GetItemPosition(), result.ShowIcon, result.Message);
+ RoomUI.Current.InteractiveTipBar.ShowBar(result.Target.GlobalPosition, result.ShowIcon, result.Message);
}
}
}
diff --git a/DungeonShooting_Godot/src/game/role/Role.cs b/DungeonShooting_Godot/src/game/role/Role.cs
index 362981b..d5e6583 100644
--- a/DungeonShooting_Godot/src/game/role/Role.cs
+++ b/DungeonShooting_Godot/src/game/role/Role.cs
@@ -2,18 +2,9 @@
using Godot;
///
-/// 脸的朝向
-///
-public enum FaceDirection
-{
- Left,
- Right,
-}
-
-///
/// 角色基类
///
-public abstract class Role : KinematicBody2D
+public abstract class Role : ActivityObject
{
///
/// 重写的纹理
@@ -88,17 +79,18 @@
}
}
private int _maxHp = 0;
-
+
+ //初始缩放
private Vector2 StartScele;
//所有角色碰撞的道具
- private readonly List InteractiveItemList = new List();
+ private readonly List InteractiveItemList = new List();
private CheckInteractiveResult TempResultData;
///
/// 可以互动的道具
///
- protected IProp InteractiveItem { get; private set; }
+ protected ActivityObject InteractiveItem { get; private set; }
///
/// 当血量改变时调用
@@ -115,6 +107,21 @@
/// 检测是否可互动时的返回值
protected abstract void ChangeInteractiveItem(CheckInteractiveResult result);
+ public override ComponentControl CreateComponentControl()
+ {
+ return new ComponentControl(this);
+ }
+
+ public override CheckInteractiveResult CheckInteractive(ActivityObject master)
+ {
+ return null;
+ }
+
+ public override void Interactive(ActivityObject master)
+ {
+
+ }
+
public override void _Ready()
{
StartScele = Scale;
@@ -218,7 +225,7 @@
///
/// 返回是否存在可互动的物体
///
- public bool HasTnteractive()
+ public bool HasInteractive()
{
return InteractiveItem != null;
}
@@ -226,9 +233,9 @@
///
/// 触发与碰撞的物体互动, 并返回与其互动的物体
///
- public IProp TriggerTnteractive()
+ public ActivityObject TriggerInteractive()
{
- if (HasTnteractive())
+ if (HasInteractive())
{
var item = InteractiveItem;
item.Interactive(this);
@@ -303,12 +310,12 @@
///
private void _OnPropsEnter(Area2D other)
{
- IProp prop = other.AsProp();
- if (prop != null) //道具类型
+ ActivityObject propObject = other.AsActivityObject();
+ if (propObject != null) //道具类型
{
- if (!InteractiveItemList.Contains(prop))
+ if (!InteractiveItemList.Contains(propObject))
{
- InteractiveItemList.Add(prop);
+ InteractiveItemList.Add(propObject);
}
}
}
@@ -319,14 +326,14 @@
///
private void _OnPropsExit(Area2D other)
{
- IProp prop = other.AsProp();
- if (prop != null) //道具类型
+ ActivityObject propObject = other.AsActivityObject();
+ if (propObject != null) //道具类型
{
- if (InteractiveItemList.Contains(prop))
+ if (InteractiveItemList.Contains(propObject))
{
- InteractiveItemList.Remove(prop);
+ InteractiveItemList.Remove(propObject);
}
- if (InteractiveItem == prop)
+ if (InteractiveItem == propObject)
{
InteractiveItem = null;
ChangeInteractiveItem(null);
diff --git a/DungeonShooting_Godot/src/test/TestAttackComponent.cs b/DungeonShooting_Godot/src/test/TestAttackComponent.cs
deleted file mode 100644
index a13eb59..0000000
--- a/DungeonShooting_Godot/src/test/TestAttackComponent.cs
+++ /dev/null
@@ -1,13 +0,0 @@
-
-using Godot;
-
-public class TestAttackComponent : Component
-{
- public override void Process(float delta)
- {
- if (Input.IsActionPressed("fire"))
- {
- GD.Print("点击了开火");
- }
- }
-}
\ No newline at end of file
diff --git a/DungeonShooting_Godot/src/test/TestMoveNodeComponent.cs b/DungeonShooting_Godot/src/test/TestMoveNodeComponent.cs
deleted file mode 100644
index 46c53df..0000000
--- a/DungeonShooting_Godot/src/test/TestMoveNodeComponent.cs
+++ /dev/null
@@ -1,29 +0,0 @@
-
-using Godot;
-
-public class TestMoveNodeComponent : NodeComponent
-{
- public TestMoveNodeComponent(KinematicBody2D inst) : base(inst)
- {
-
- }
-
- public override void Process(float delta)
- {
-
- }
-
- public override void PhysicsProcess(float delta)
- {
- var axis = Input.GetAxis("move_left", "move_right");
- if (axis != 0f)
- {
- Position += new Vector2(axis * 10 * delta, 0);
- }
- }
-
- public override void OnDestroy()
- {
-
- }
-}
\ No newline at end of file
diff --git a/DungeonShooting_Godot/src/test/TestPlayer.cs b/DungeonShooting_Godot/src/test/TestPlayer.cs
deleted file mode 100644
index 4ff89e3..0000000
--- a/DungeonShooting_Godot/src/test/TestPlayer.cs
+++ /dev/null
@@ -1,14 +0,0 @@
-using Godot;
-
-public class TestPlayer : Sprite
-{
- public GameObject GameObject { get; private set; }
-
- public override void _Ready()
- {
- GameObject = new GameObject(this);
- var move = new TestMoveNodeComponent(ResourceManager.Load("res://prefab/test/MoveComponent.tscn").Instance());
- GameObject.AddComponent(move);
- GameObject.AddComponent(new TestAttackComponent());
- }
-}
\ No newline at end of file