diff --git a/DungeonShooting_Godot/prefab/effect/Hit.tscn b/DungeonShooting_Godot/prefab/effect/Hit.tscn index bbbbd32..1549fc4 100644 --- a/DungeonShooting_Godot/prefab/effect/Hit.tscn +++ b/DungeonShooting_Godot/prefab/effect/Hit.tscn @@ -7,7 +7,6 @@ [ext_resource path="res://resource/sprite/effect/hit/hit3.png" type="Texture" id=5] [ext_resource path="res://src/game/effect/Hit.cs" type="Script" id=6] - [sub_resource type="SpriteFrames" id=1] animations = [ { "frames": [ ExtResource( 4 ), ExtResource( 2 ), ExtResource( 1 ), ExtResource( 5 ), ExtResource( 3 ) ], @@ -17,6 +16,7 @@ } ] [node name="Hit" type="AnimatedSprite"] +z_index = 5 frames = SubResource( 1 ) animation = "Hit" offset = Vector2( 1, 11 ) diff --git a/DungeonShooting_Godot/prefab/role/Enemy.tscn b/DungeonShooting_Godot/prefab/role/Enemy.tscn new file mode 100644 index 0000000..38bee78 --- /dev/null +++ b/DungeonShooting_Godot/prefab/role/Enemy.tscn @@ -0,0 +1,9 @@ +[gd_scene load_steps=2 format=2] + +[ext_resource path="res://prefab/role/Role.tscn" type="PackedScene" id=1] + +[node name="Enemy" instance=ExtResource( 1 )] +CollisionLayer = 16 + +[node name="AnimatedSprite" parent="." index="2"] +frame = 1 diff --git a/DungeonShooting_Godot/prefab/role/Player.tscn b/DungeonShooting_Godot/prefab/role/Player.tscn index bf3afb0..25ff66f 100644 --- a/DungeonShooting_Godot/prefab/role/Player.tscn +++ b/DungeonShooting_Godot/prefab/role/Player.tscn @@ -16,4 +16,4 @@ material = SubResource( 1 ) [node name="AnimatedSprite" parent="." index="2"] -frame = 1 +frame = 3 diff --git a/DungeonShooting_Godot/prefab/role/Role.tscn b/DungeonShooting_Godot/prefab/role/Role.tscn index b9a1558..1565658 100644 --- a/DungeonShooting_Godot/prefab/role/Role.tscn +++ b/DungeonShooting_Godot/prefab/role/Role.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=20 format=2] +[gd_scene load_steps=21 format=2] [ext_resource path="res://resource/materlal/Shadow.tres" type="Material" id=1] [ext_resource path="res://addons/dungeonShooting_plugin/ActivityObjectTemplate.cs" type="Script" id=2] @@ -77,6 +77,9 @@ [sub_resource type="RectangleShape2D" id=29] extents = Vector2( 5, 7.5 ) +[sub_resource type="Animation" id=30] +resource_name = "hit" + [node name="Role" type="Node"] script = ExtResource( 2 ) CollisionMask = 1 @@ -92,6 +95,7 @@ position = Vector2( 0, -12 ) frames = SubResource( 6 ) animation = "idle" +frame = 2 playing = true [node name="Collision" type="CollisionShape2D" parent="."] @@ -119,3 +123,6 @@ [node name="MountPoint" type="Position2D" parent="."] position = Vector2( 2, -4 ) script = ExtResource( 4 ) + +[node name="AnimationPlayer" type="AnimationPlayer" parent="."] +anims/hit = SubResource( 30 ) diff --git a/DungeonShooting_Godot/prefab/weapon/bullet/OrdinaryBullets.tscn b/DungeonShooting_Godot/prefab/weapon/bullet/OrdinaryBullets.tscn index 77b0341..2071ef3 100644 --- a/DungeonShooting_Godot/prefab/weapon/bullet/OrdinaryBullets.tscn +++ b/DungeonShooting_Godot/prefab/weapon/bullet/OrdinaryBullets.tscn @@ -11,6 +11,7 @@ [node name="RayCast2D" type="RayCast2D" parent="."] enabled = true cast_to = Vector2( 18, 0 ) +collision_mask = 17 [node name="Bullet" type="Sprite" parent="."] position = Vector2( 0.5, 0 ) diff --git a/DungeonShooting_Godot/src/framework/ActivityObject.cs b/DungeonShooting_Godot/src/framework/ActivityObject.cs index e288578..8158fdd 100644 --- a/DungeonShooting_Godot/src/framework/ActivityObject.cs +++ b/DungeonShooting_Godot/src/framework/ActivityObject.cs @@ -138,7 +138,6 @@ public void GetCurrentTexture() { - } public Texture GetDefaultTexture() @@ -156,12 +155,11 @@ } /// <summary> - /// 与其它ActivityObject互动时调用 + /// 与其它ActivityObject互动时调用, 如果要检测是否能互动请 CheckInteractive() 函数, 如果直接调用该函数那么属于强制互动行为, 例如子弹碰到物体 /// </summary> /// <param name="master">触发者</param> public virtual void Interactive(ActivityObject master) { - } /// <summary> @@ -169,7 +167,6 @@ /// </summary> public virtual void OnThrowMaxHeight(float height) { - } /// <summary> @@ -177,7 +174,6 @@ /// </summary> public virtual void OnFirstFallToGround() { - } /// <summary> @@ -185,7 +181,6 @@ /// </summary> public virtual void OnFallToGround() { - } /// <summary> @@ -193,7 +188,6 @@ /// </summary> public virtual void OnThrowOver() { - } /// <summary> diff --git a/DungeonShooting_Godot/src/game/effect/Hit.cs b/DungeonShooting_Godot/src/game/effect/Hit.cs index 99b4b4d..80d3713 100644 --- a/DungeonShooting_Godot/src/game/effect/Hit.cs +++ b/DungeonShooting_Godot/src/game/effect/Hit.cs @@ -2,7 +2,6 @@ public class Hit : AnimatedSprite { - public override void _Ready() { Frame = 0; diff --git a/DungeonShooting_Godot/src/game/item/package/Holster.cs b/DungeonShooting_Godot/src/game/item/package/Holster.cs index f26c086..bd1f243 100644 --- a/DungeonShooting_Godot/src/game/item/package/Holster.cs +++ b/DungeonShooting_Godot/src/game/item/package/Holster.cs @@ -121,7 +121,7 @@ { weapon.Pickup(); item.Weapon = weapon; - weapon._PickUpWeapon(Master); + weapon.PickUpWeapon(Master); ExchangeByIndex(i); return i; } @@ -158,7 +158,7 @@ ActiveWeapon = null; } } - weapon._Remove(); + weapon.Remove(); return weapon; } @@ -245,7 +245,7 @@ ActiveWeapon.RotationDegrees = 60; ActiveWeapon.Scale = new Vector2(1, 1); } - ActiveWeapon._Conceal(); + ActiveWeapon.Conceal(); } } @@ -266,7 +266,7 @@ slot.Weapon.RotationDegrees = 0; ActiveWeapon = slot.Weapon; ActiveIndex = index; - ActiveWeapon._Active(); + ActiveWeapon.Active(); return true; } } diff --git a/DungeonShooting_Godot/src/game/item/weapon/Weapon.cs b/DungeonShooting_Godot/src/game/item/weapon/Weapon.cs index b973dbe..eeb710d 100644 --- a/DungeonShooting_Godot/src/game/item/weapon/Weapon.cs +++ b/DungeonShooting_Godot/src/game/item/weapon/Weapon.cs @@ -20,7 +20,7 @@ /// 属性数据 /// </summary> public WeaponAttribute Attribute { get; private set; } - + /// <summary> /// 动画播放器 /// </summary> @@ -41,6 +41,7 @@ /// 当前弹夹弹药剩余量 /// </summary> public int CurrAmmo { get; private set; } + /// <summary> /// 剩余弹药量 /// </summary> @@ -50,32 +51,39 @@ /// 武器管的开火点 /// </summary> public Position2D FirePoint { get; private set; } + /// <summary> /// 武器管的原点 /// </summary> public Position2D OriginPoint { get; private set; } + /// <summary> /// 弹壳抛出的点 /// </summary> public Position2D ShellPoint { get; private set; } + /// <summary> /// 碰撞器节点 /// </summary> /// <value></value> public CollisionShape2D CollisionShape2D { get; private set; } + /// <summary> /// 武器的当前散射半径 /// </summary> public float CurrScatteringRange { get; private set; } = 0; + /// <summary> /// 是否在换弹中 /// </summary> /// <value></value> public bool Reloading { get; private set; } = false; + /// <summary> /// 换弹计时器 /// </summary> public float ReloadTimer { get; private set; } = 0; + /// <summary> /// 换弹进度 (0 - 1) /// </summary> @@ -88,30 +96,41 @@ var num = 1f / Attribute.AmmoCapacity; return num * (Attribute.AmmoCapacity - CurrAmmo - 1) + num * (ReloadTimer / Attribute.ReloadTime); } + return ReloadTimer / Attribute.ReloadTime; } } //是否按下 private bool triggerFlag = false; + //扳机计时器 private float triggerTimer = 0; + //开火前延时时间 private float delayedTime = 0; + //开火间隙时间 private float fireInterval = 0; + //开火武器口角度 private float fireAngle = 0; + //攻击冷却计时 private float attackTimer = 0; + //攻击状态 private bool attackFlag = false; + //按下的时间 private float downTimer = 0; + //松开的时间 private float upTimer = 0; + //连发次数 private float continuousCount = 0; + //连发状态记录 private bool continuousShootFlag = false; @@ -120,7 +139,7 @@ /// </summary> /// <param name="id">武器唯一id</param> /// <param name="attribute">属性</param> - public Weapon(string id, WeaponAttribute attribute): base(attribute.WeaponPrefab) + public Weapon(string id, WeaponAttribute attribute) : base(attribute.WeaponPrefab) { Id = id; Attribute = attribute; @@ -210,7 +229,8 @@ triggerFlag = false; attackFlag = false; attackTimer = attackTimer > 0 ? attackTimer - delta : 0; - CurrScatteringRange = Mathf.Max(CurrScatteringRange - Attribute.ScatteringRangeBackSpeed * delta, Attribute.StartScatteringRange); + CurrScatteringRange = Mathf.Max(CurrScatteringRange - Attribute.ScatteringRangeBackSpeed * delta, + Attribute.StartScatteringRange); continuousCount = 0; delayedTime = 0; } @@ -222,7 +242,8 @@ triggerFlag = false; attackFlag = false; attackTimer = attackTimer > 0 ? attackTimer - delta : 0; - CurrScatteringRange = Mathf.Max(CurrScatteringRange - Attribute.ScatteringRangeBackSpeed * delta, Attribute.StartScatteringRange); + CurrScatteringRange = Mathf.Max(CurrScatteringRange - Attribute.ScatteringRangeBackSpeed * delta, + Attribute.StartScatteringRange); continuousCount = 0; delayedTime = 0; } @@ -246,6 +267,7 @@ upTimer = 0; DownTrigger(); } + downTimer += delta; } else @@ -255,6 +277,7 @@ downTimer = 0; UpTrigger(); } + upTimer += delta; } @@ -286,8 +309,10 @@ if (!attackFlag && attackTimer <= 0) { - CurrScatteringRange = Mathf.Max(CurrScatteringRange - Attribute.ScatteringRangeBackSpeed * delta, Attribute.StartScatteringRange); + CurrScatteringRange = Mathf.Max(CurrScatteringRange - Attribute.ScatteringRangeBackSpeed * delta, + Attribute.StartScatteringRange); } + triggerTimer = triggerTimer > 0 ? triggerTimer - delta : 0; triggerFlag = false; attackFlag = false; @@ -362,7 +387,7 @@ { fireFlag = false; //子弹不够 - _Reload(); + Reload(); } if (fireFlag) @@ -376,17 +401,21 @@ //连发数量 if (!Attribute.ContinuousShoot) { - continuousCount = MathUtils.RandRangeInt(Attribute.MinContinuousCount, Attribute.MaxContinuousCount); + continuousCount = + MathUtils.RandRangeInt(Attribute.MinContinuousCount, Attribute.MaxContinuousCount); } } + if (delayedTime <= 0 && attackTimer <= 0) { TriggerFire(); } + attackFlag = true; } } + triggerFlag = true; } @@ -408,6 +437,7 @@ { continuousCount = 0; } + OnUpTrigger(); } @@ -436,7 +466,7 @@ //先算武器口方向 var tempRotation = (float)GD.RandRange(-angle, angle); var tempAngle = Mathf.Rad2Deg(tempRotation); - + //开火时枪口角度 var fireRotation = Mathf.Deg2Rad(Master.MountPoint.RealAngle) + tempRotation; //创建子弹 @@ -494,7 +524,7 @@ /// <summary> /// 触发换弹 /// </summary> - public void _Reload() + public void Reload() { if (CurrAmmo < Attribute.AmmoCapacity && ResidueAmmo > 0 && !Reloading) { @@ -539,6 +569,7 @@ ResidueAmmo -= num; } } + if (ResidueAmmo == 0 || CurrAmmo == Attribute.AmmoCapacity) //换弹结束 { Reloading = false; @@ -563,6 +594,7 @@ CurrAmmo = ResidueAmmo; ResidueAmmo = 0; } + Reloading = false; ReloadTimer = 0; OnReloadFinish(); @@ -572,7 +604,7 @@ public override CheckInteractiveResult CheckInteractive(ActivityObject master) { var result = new CheckInteractiveResult(this); - + if (master is Role roleMaster) //碰到角色 { if (Master == null) @@ -616,13 +648,13 @@ } } } - + return result; } public override void Interactive(ActivityObject master) { - if (master is Role roleMaster) //与role碰撞 + if (master is Role roleMaster) //与role互动 { var holster = roleMaster.Holster; //查找是否有同类型武器 @@ -675,7 +707,7 @@ if (slot.Type == Attribute.WeightType) { var weapon = holster.RemoveWeapon(holster.ActiveIndex); - weapon.TriggerThrowWeapon(roleMaster); + weapon.ThrowWeapon(roleMaster); roleMaster.PickUpWeapon(this); } } @@ -690,21 +722,22 @@ { return Mathf.Deg2Rad(Master.MountPoint.RealAngle) + Rotation; } - + /// <summary> - /// 触发扔掉武器操作 + /// 触发扔掉武器抛出的效果, 并不会管武器是否在武器袋中 /// </summary> /// <param name="master">触发扔掉该武器的的角色</param> - public void TriggerThrowWeapon(Role master) + public virtual void ThrowWeapon(Role master) { //阴影偏移 ShadowOffset = new Vector2(0, 2); - + if (master.Face == FaceDirection.Left) { Scale *= new Vector2(1, -1); RotationDegrees = 180; } + var startHeight = 6; var direction = master.GlobalRotationDegrees + MathUtils.RandRangeInt(-20, 20); var xf = 30; @@ -712,7 +745,7 @@ var rotate = MathUtils.RandRangeInt(-180, 180); Throw(new Vector2(30, 15), master.MountPoint.GlobalPosition, startHeight, direction, xf, yf, rotate, true); } - + public override void OnThrowOver() { //启用碰撞 @@ -722,7 +755,7 @@ /// <summary> /// 触发拾起 /// </summary> - public void _PickUpWeapon(Role master) + public void PickUpWeapon(Role master) { Master = master; //握把位置 @@ -730,7 +763,7 @@ //停止动画 AnimationPlayer.Stop(); //清除泛白效果 - ShaderMaterial sm = (ShaderMaterial) AnimatedSprite.Material; + ShaderMaterial sm = (ShaderMaterial)AnimatedSprite.Material; sm.SetShaderParam("schedule", 0); ZIndex = 0; //禁用碰撞 @@ -741,7 +774,7 @@ /// <summary> /// 触发移除 /// </summary>a - public void _Remove() + public void Remove() { Master = null; AnimatedSprite.Position = Attribute.CenterPosition; @@ -752,7 +785,7 @@ /// <summary> /// 触发启用武器 /// </summary> - public void _Active() + public void Active() { ShadowOffset = new Vector2(0, Master.GlobalPosition.y - GlobalPosition.y); ShowShadowSprite(); @@ -762,7 +795,7 @@ /// <summary> /// 触发收起武器 /// </summary> - public void _Conceal() + public void Conceal() { HideShadowSprite(); OnConceal(); @@ -772,7 +805,8 @@ /// 实例化并返回子弹对象 /// </summary> /// <param name="bulletPack">子弹的预制体</param> - protected T CreateBullet<T>(PackedScene bulletPack, Vector2 globalPostion, float globalRotation, Node parent = null) where T : Node2D, IBullet + protected T CreateBullet<T>(PackedScene bulletPack, Vector2 globalPostion, float globalRotation, Node parent = null) + where T : Node2D, IBullet { return (T)CreateBullet(bulletPack, globalPostion, globalRotation, parent); } @@ -781,7 +815,8 @@ /// 实例化并返回子弹对象 /// </summary> /// <param name="bulletPack">子弹的预制体</param> - protected IBullet CreateBullet(PackedScene bulletPack, Vector2 globalPostion, float globalRotation, Node parent = null) + protected IBullet CreateBullet(PackedScene bulletPack, Vector2 globalPostion, float globalRotation, + Node parent = null) { // 实例化子弹 Node2D bullet = bulletPack.Instance<Node2D>(); @@ -797,6 +832,7 @@ { parent.AddChild(bullet); } + // 调用初始化 IBullet result = (IBullet)bullet; result.Init(TargetCamp, this, null); diff --git a/DungeonShooting_Godot/src/game/item/weapon/bullet/OrdinaryBullets.cs b/DungeonShooting_Godot/src/game/item/weapon/bullet/OrdinaryBullets.cs index 092fe89..aa19c76 100644 --- a/DungeonShooting_Godot/src/game/item/weapon/bullet/OrdinaryBullets.cs +++ b/DungeonShooting_Godot/src/game/item/weapon/bullet/OrdinaryBullets.cs @@ -74,6 +74,13 @@ { //var target = RayCast.GetCollider(); var pos = RayCast.GetCollisionPoint(); + var collider = RayCast.GetCollider(); + + if (collider is Role role) + { + role.Hit(1); + } + //播放受击动画 Node2D hit = Hit.Instance<Node2D>(); hit.RotationDegrees = MathUtils.RandRangeInt(0, 360); diff --git a/DungeonShooting_Godot/src/game/manager/ResourceManager.cs b/DungeonShooting_Godot/src/game/manager/ResourceManager.cs index 5421af6..33669b0 100644 --- a/DungeonShooting_Godot/src/game/manager/ResourceManager.cs +++ b/DungeonShooting_Godot/src/game/manager/ResourceManager.cs @@ -3,7 +3,6 @@ public static class ResourceManager { - /// <summary> /// 2D阴影的材质 /// </summary> diff --git a/DungeonShooting_Godot/src/game/manager/ResourcePath.cs b/DungeonShooting_Godot/src/game/manager/ResourcePath.cs new file mode 100644 index 0000000..a6be0ca --- /dev/null +++ b/DungeonShooting_Godot/src/game/manager/ResourcePath.cs @@ -0,0 +1,10 @@ + +/// <summary> +/// 该类后面会做自动自动生成 +/// </summary> +public class ResourcePath +{ + public const string prefab_role_Role_tscn = "res://prefab/role/Role.tscn"; + public const string prefab_role_Player_tscn = "res://prefab/role/Player.tscn"; + public const string prefab_role_Enemy_tscn = "res://prefab/role/Enemy.tscn"; +} \ No newline at end of file diff --git a/DungeonShooting_Godot/src/game/role/AnimatorNames.cs b/DungeonShooting_Godot/src/game/role/AnimatorNames.cs index 5645333..95aa0ad 100644 --- a/DungeonShooting_Godot/src/game/role/AnimatorNames.cs +++ b/DungeonShooting_Godot/src/game/role/AnimatorNames.cs @@ -1,4 +1,7 @@ +/// <summary> +/// 角色身上预制动画名称 +/// </summary> public static class AnimatorNames { public static readonly string Idle = "idle"; diff --git a/DungeonShooting_Godot/src/game/role/CampEnum.cs b/DungeonShooting_Godot/src/game/role/CampEnum.cs index afe6f3b..6954070 100644 --- a/DungeonShooting_Godot/src/game/role/CampEnum.cs +++ b/DungeonShooting_Godot/src/game/role/CampEnum.cs @@ -1,8 +1,10 @@ public enum CampEnum { - // 友军 - Friend, - // 敌人 - Enemy + // 阵营1, 玩家 + Camp1, + // 阵营2, 敌人 + Camp2, + // 阵营3, 中立单位 + Camp3 } \ No newline at end of file diff --git a/DungeonShooting_Godot/src/game/role/Enemy.cs b/DungeonShooting_Godot/src/game/role/Enemy.cs new file mode 100644 index 0000000..67c33f7 --- /dev/null +++ b/DungeonShooting_Godot/src/game/role/Enemy.cs @@ -0,0 +1,8 @@ + +public class Enemy : Role +{ + public Enemy() : base(ResourcePath.prefab_role_Enemy_tscn) + { + Camp = CampEnum.Camp2; + } +} diff --git a/DungeonShooting_Godot/src/game/role/MountRotation.cs b/DungeonShooting_Godot/src/game/role/MountRotation.cs index 73059c9..4738cd7 100644 --- a/DungeonShooting_Godot/src/game/role/MountRotation.cs +++ b/DungeonShooting_Godot/src/game/role/MountRotation.cs @@ -7,6 +7,11 @@ public class MountRotation : Position2D { /// <summary> + /// 吸附角度 + /// </summary> + private int _adsorption = 5; + + /// <summary> /// 所在的角色 /// </summary> public Role Master { get; set; } @@ -14,16 +19,7 @@ /// <summary> /// 当前节点真实的旋转角度 /// </summary> - public float RealAngle - { - get => _readAngle; - // set - // { - // - // } - } - - private float _readAngle = 0; + public float RealAngle { get; private set; } /// <summary> /// 设置看向的目标点 @@ -50,7 +46,7 @@ angle = Mathf.Clamp(angle, -100, 100); } - _readAngle = angle; + RealAngle = angle; if (Master.GlobalPosition.x >= target.x) { @@ -62,6 +58,6 @@ private float AdsorptionAngle(float angle) { - return ((int)angle / 5) * 5; + return ((int)angle / _adsorption) * _adsorption; } } \ 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 11a9943..c3998a2 100644 --- a/DungeonShooting_Godot/src/game/role/Player.cs +++ b/DungeonShooting_Godot/src/game/role/Player.cs @@ -48,8 +48,9 @@ [Export] public PackedScene GunPrefab; - public Player(): base("res://prefab/role/Player.tscn") + public Player(): base(ResourcePath.prefab_role_Player_tscn) { + Camp = CampEnum.Camp1; } public override void _Ready() @@ -68,9 +69,9 @@ RefreshGunTexture(); MaxHp = 50; - Hp = 40; + Hp = 50; MaxShield = 30; - Shield = 10; + Shield = 30; } public override void _Process(float delta) @@ -93,12 +94,12 @@ if (Input.IsActionJustPressed("exchange")) //切换武器 { - TriggerExchangeNext(); + ExchangeNext(); RefreshGunTexture(); } else if (Input.IsActionJustPressed("throw")) //扔掉武器 { - TriggerThrowWeapon(); + ThrowWeapon(); RefreshGunTexture(); } else if (Input.IsActionJustPressed("interactive")) //互动物体 @@ -111,11 +112,11 @@ } else if (Input.IsActionJustPressed("reload")) //换弹 { - TriggerReload(); + Reload(); } if (Input.IsActionPressed("fire")) //开火 { - TriggerAttack(); + Attack(); } //刷新显示的弹药剩余量 RefreshGunAmmunition(); diff --git a/DungeonShooting_Godot/src/game/role/Role.cs b/DungeonShooting_Godot/src/game/role/Role.cs index 0a20cdd..59321f9 100644 --- a/DungeonShooting_Godot/src/game/role/Role.cs +++ b/DungeonShooting_Godot/src/game/role/Role.cs @@ -7,6 +7,11 @@ public abstract class Role : ActivityObject { /// <summary> + /// 动画播放器 + /// </summary> + public AnimationPlayer AnimationPlayer { get; private set; } + + /// <summary> /// 重写的纹理 /// </summary> public Texture OverrideTexture { get; protected set; } @@ -29,7 +34,7 @@ /// <summary> /// 角色携带的枪套 /// </summary> - public Holster Holster { get; private set; } + public Holster Holster { get; } /// <summary> /// 武器挂载点 @@ -96,11 +101,24 @@ /// <summary> /// 当血量改变时调用 /// </summary> - protected abstract void OnChangeHp(int hp); + protected virtual void OnChangeHp(int hp) + { + } + /// <summary> /// 当最大血量改变时调用 /// </summary> - protected abstract void OnChangeMaxHp(int maxHp); + protected virtual void OnChangeMaxHp(int maxHp) + { + } + + /// <summary> + /// 当受伤时调用 + /// </summary> + /// <param name="damage">受到的伤害</param> + public virtual void OnHit(int damage) + { + } /// <summary> /// 当可互动的物体改变时调用, result 参数为 null 表示变为不可互动 @@ -108,34 +126,26 @@ /// <param name="result">检测是否可互动时的返回值</param> protected virtual void ChangeInteractiveItem(CheckInteractiveResult result) { - } - public override CheckInteractiveResult CheckInteractive(ActivityObject master) - { - return new CheckInteractiveResult(this); - } - - public override void Interactive(ActivityObject master) - { - - } - - public Role() : base("res://prefab/role/Role.tscn") + public Role() : this(ResourcePath.prefab_role_Role_tscn) { } public Role(string scenePath) : base(scenePath) { + Holster = new Holster(this); } public override void _Ready() { base._Ready(); + AnimationPlayer = GetNode<AnimationPlayer>("AnimationPlayer"); StartScele = Scale; MountPoint = GetNode<MountRotation>("MountPoint"); MountPoint.Master = this; BackMountPoint = GetNode<Position2D>("BackMountPoint"); + //即将弃用 if (OverrideTexture != null) { // 更改纹理 @@ -143,8 +153,6 @@ ChangeFrameTexture(AnimatorNames.Run, AnimatedSprite, OverrideTexture); ChangeFrameTexture(AnimatorNames.ReverseRun, AnimatedSprite, OverrideTexture); } - - Holster = new Holster(this); Face = FaceDirection.Right; //连接互动物体信号 @@ -196,12 +204,11 @@ } } - /// <summary> /// 拾起一个武器, 并且切换到这个武器 /// </summary> /// <param name="weapon">武器对象</param> - public void PickUpWeapon(Weapon weapon) + public virtual void PickUpWeapon(Weapon weapon) { if (Holster.PickupWeapon(weapon) != -1) { @@ -213,7 +220,7 @@ /// <summary> /// 切换到下一个武器 /// </summary> - public void TriggerExchangeNext() + public virtual void ExchangeNext() { Holster.ExchangeNext(); } @@ -221,7 +228,7 @@ /// <summary> /// 切换到上一个武器 /// </summary> - public void ExchangePrev() + public virtual void ExchangePrev() { Holster.ExchangePrev(); } @@ -229,13 +236,13 @@ /// <summary> /// 扔掉当前使用的武器, 切换到上一个武器 /// </summary> - public void TriggerThrowWeapon() + public virtual void ThrowWeapon() { var weapon = Holster.RemoveWeapon(Holster.ActiveIndex); //播放抛出效果 if (weapon != null) { - weapon.TriggerThrowWeapon(this); + weapon.ThrowWeapon(this); } } @@ -264,18 +271,18 @@ /// <summary> /// 触发换弹 /// </summary> - public void TriggerReload() + public virtual void Reload() { if (Holster.ActiveWeapon != null) { - Holster.ActiveWeapon._Reload(); + Holster.ActiveWeapon.Reload(); } } /// <summary> /// 触发攻击 /// </summary> - public void TriggerAttack() + public virtual void Attack() { if (Holster.ActiveWeapon != null) { @@ -284,6 +291,17 @@ } /// <summary> + /// 受到伤害 + /// </summary> + /// <param name="damage">伤害的量</param> + public virtual void Hit(int damage) + { + Hp -= damage; + GD.Print("打到敌人了!"); + OnHit(damage); + } + + /// <summary> /// 设置脸的朝向 /// </summary> private void SetFace(FaceDirection face) diff --git a/DungeonShooting_Godot/src/game/room/RoomManager.cs b/DungeonShooting_Godot/src/game/room/RoomManager.cs index 6d432fa..c6092bb 100644 --- a/DungeonShooting_Godot/src/game/room/RoomManager.cs +++ b/DungeonShooting_Godot/src/game/room/RoomManager.cs @@ -25,8 +25,10 @@ Player = new Player(); Player.Position = new Vector2(100, 100); Player.Name = "Player"; - //SortRoot.AddChild(player); Player.PutDown(); + + var enemy1 = new Enemy(); + enemy1.PutDown(new Vector2(150, 150)); } public override void _Ready() diff --git a/DungeonShooting_Godot/src/game/ui/ReloadBar.cs b/DungeonShooting_Godot/src/game/ui/ReloadBar.cs index 3cd608d..7324ae8 100644 --- a/DungeonShooting_Godot/src/game/ui/ReloadBar.cs +++ b/DungeonShooting_Godot/src/game/ui/ReloadBar.cs @@ -16,7 +16,7 @@ slot = GetNode<Sprite>("Slot"); block = GetNode<Sprite>("Slot/Block"); width = slot.Texture.GetWidth(); - startX = -(width - 3) / 2; + startX = -(width - 3) / 2f; } /// <summary>