Newer
Older
DungeonShooting / DungeonShooting_Godot / src / game / item / weapon / gun / Gun.cs
@小李xl 小李xl on 7 Jun 2023 6 KB 加载武器
  1. using Godot;
  2.  
  3. /// <summary>
  4. /// 普通的枪
  5. /// </summary>
  6. [Tool, GlobalClass]
  7. public partial class Gun : Weapon
  8. {
  9. // //步枪属性数据
  10. // private class RifleAttribute : WeaponAttribute
  11. // {
  12. // public RifleAttribute()
  13. // {
  14. // Name = "步枪";
  15. // Icon = ResourcePath.resource_sprite_gun_gun4_png;
  16. // SpriteFrames = ResourcePath.resource_spriteFrames_Weapon0001_tres;
  17. // Weight = 40;
  18. // ThrowSpritePosition = new Vector2(0.4f, -2.6f);
  19. // StartFiringSpeed = 480;
  20. // StartScatteringRange = 30;
  21. // FinalScatteringRange = 90;
  22. // ScatteringRangeAddValue = 2f;
  23. // ScatteringRangeBackSpeed = 40;
  24. // //连发
  25. // ContinuousShoot = true;
  26. // AmmoCapacity = 30;
  27. // StandbyAmmoCapacity = 30 * 3;
  28. // MaxAmmoCapacity = 30 * 3;
  29. // //扳机检测间隔
  30. // TriggerInterval = 0f;
  31. //
  32. // //开火前延时
  33. // DelayedTime = 0f;
  34. // //攻击距离
  35. // MinDistance = 300;
  36. // MaxDistance = 400;
  37. // //发射子弹数量
  38. // MinFireBulletCount = 1;
  39. // MaxFireBulletCount = 1;
  40. // //抬起角度
  41. // UpliftAngle = 10;
  42. // //开火位置
  43. // FirePosition = new Vector2(21, -3f);
  44. // //精灵位置
  45. // SpritePosition = new Vector2(6, -1);
  46. // ShellPosition = new Vector2(7.5f, -4.5f);
  47. //
  48. // AiUseAttribute = Clone();
  49. // AiUseAttribute.AiTargetLockingTime = 0.5f;
  50. // AiUseAttribute.TriggerInterval = 3f;
  51. // AiUseAttribute.ContinuousShoot = false;
  52. // AiUseAttribute.MinContinuousCount = 3;
  53. // AiUseAttribute.MaxContinuousCount = 3;
  54. // }
  55. // }
  56. //
  57. // //手枪属性数据
  58. // private class PistolAttribute : WeaponAttribute
  59. // {
  60. // public PistolAttribute()
  61. // {
  62. // Name = "手枪";
  63. // Icon = ResourcePath.resource_sprite_gun_gun3_png;
  64. // SpriteFrames = ResourcePath.resource_spriteFrames_Weapon0003_tres;
  65. // Weight = 20;
  66. // ThrowSpritePosition = new Vector2(0.4f, -2.6f);
  67. // WeightType = WeaponWeightType.DeputyWeapon;
  68. // StartFiringSpeed = 300;
  69. // FinalFiringSpeed = 300;
  70. // StartScatteringRange = 5;
  71. // FinalScatteringRange = 60;
  72. // ScatteringRangeAddValue = 8f;
  73. // ScatteringRangeBackSpeed = 40;
  74. // ScatteringRangeBackTime = 0.5f;
  75. // //连发
  76. // ContinuousShoot = false;
  77. // AmmoCapacity = 12;
  78. // StandbyAmmoCapacity = 72;
  79. // MaxAmmoCapacity = 72;
  80. // //扳机检测间隔
  81. // TriggerInterval = 0.1f;
  82. // //连发数量
  83. // MinContinuousCount = 1;
  84. // MaxContinuousCount = 1;
  85. // //开火前延时
  86. // DelayedTime = 0f;
  87. // //攻击距离
  88. // MinDistance = 250;
  89. // MaxDistance = 300;
  90. // //发射子弹数量
  91. // MinFireBulletCount = 1;
  92. // MaxFireBulletCount = 1;
  93. // //抬起角度
  94. // UpliftAngle = 20;
  95. // //开火位置
  96. // FirePosition = new Vector2(13, -2);
  97. // //精灵位置
  98. // SpritePosition = new Vector2(5, 0);
  99. // ShellPosition = new Vector2(5, -3);
  100. //
  101. // AiUseAttribute = Clone();
  102. // AiUseAttribute.AiTargetLockingTime = 1f;
  103. // AiUseAttribute.TriggerInterval = 2f;
  104. // }
  105. // }
  106. //
  107. // //狙击步枪
  108. // private class SniperRifleAttribute : WeaponAttribute
  109. // {
  110. // public SniperRifleAttribute()
  111. // {
  112. // Name = "狙击步枪";
  113. // Icon = ResourcePath.resource_sprite_gun_gun3_png;
  114. // SpriteFrames = ResourcePath.resource_spriteFrames_Weapon0005_tres;
  115. // Weight = 20;
  116. // ThrowSpritePosition = new Vector2(0.4f, -2.6f);
  117. // WeightType = WeaponWeightType.DeputyWeapon;
  118. // StartFiringSpeed = 60;
  119. // FinalFiringSpeed = 60;
  120. // StartScatteringRange = 0;
  121. // FinalScatteringRange = 20;
  122. // ScatteringRangeAddValue = 10;
  123. // ScatteringRangeBackSpeed = 10;
  124. // //连发
  125. // ContinuousShoot = false;
  126. // AmmoCapacity = 10;
  127. // StandbyAmmoCapacity = 50;
  128. // MaxAmmoCapacity = 50;
  129. // //扳机检测间隔
  130. // TriggerInterval = 0.1f;
  131. // //连发数量
  132. // MinContinuousCount = 1;
  133. // MaxContinuousCount = 1;
  134. // //开火前延时
  135. // DelayedTime = 0f;
  136. // //攻击距离
  137. // MinDistance = 600;
  138. // MaxDistance = 800;
  139. // //发射子弹数量
  140. // MinFireBulletCount = 1;
  141. // MaxFireBulletCount = 1;
  142. // //抬起角度
  143. // UpliftAngle = 15;
  144. // UpliftAngleRestore = 3.5f;
  145. // //开火位置
  146. // FirePosition = new Vector2(28, -3.5f);
  147. // //精灵位置
  148. // SpritePosition = new Vector2(9, 0);
  149. // ShellPosition = new Vector2(7, -3.5f);
  150. // MinBacklash = 6;
  151. // MinBacklash = 8;
  152. // BacklashRegressionSpeed = 20;
  153. // ReloadTime = 3.5f;
  154. //
  155. // AiUseAttribute = Clone();
  156. // AiUseAttribute.AiTargetLockingTime = 1f;
  157. // AiUseAttribute.TriggerInterval = 2f;
  158. // }
  159. // }
  160. protected override void OnFire()
  161. {
  162. //创建一个弹壳
  163. ThrowShell("0001");
  164. if (Master == Player.Current)
  165. {
  166. //创建抖动
  167. GameCamera.Main.DirectionalShake(Vector2.Right.Rotated(GlobalRotation) * 2f);
  168. }
  169.  
  170. //创建开火特效
  171. var packedScene = ResourceManager.Load<PackedScene>(ResourcePath.prefab_effect_ShotFire_tscn);
  172. var sprite = packedScene.Instantiate<Sprite2D>();
  173. sprite.GlobalPosition = FirePoint.GlobalPosition;
  174. sprite.GlobalRotation = FirePoint.GlobalRotation;
  175. sprite.AddToActivityRoot(RoomLayerEnum.YSortLayer);
  176.  
  177. //播放射击音效
  178. SoundManager.PlaySoundEffectPosition(ResourcePath.resource_sound_sfx_ordinaryBullet2_mp3, GameApplication.Instance.ViewToGlobalPosition(GlobalPosition), -8);
  179. }
  180.  
  181. protected override void OnShoot(float fireRotation)
  182. {
  183. //创建子弹
  184. var bullet = ActivityObject.Create<Bullet>(Attribute.BulletId);
  185. bullet.Init(
  186. this,
  187. 350,
  188. Utils.RandomRangeFloat(Attribute.MinDistance, Attribute.MaxDistance),
  189. FirePoint.GlobalPosition,
  190. fireRotation,
  191. GetAttackLayer()
  192. );
  193. bullet.PutDown(RoomLayerEnum.YSortLayer);
  194. }
  195. }