Newer
Older
DungeonShooting / DungeonShooting_Godot / src / game / item / weapon / gun / Gun.cs
@小李xl 小李xl on 12 Nov 2022 4 KB 基础近战武器 (还没做完)
  1. using Godot;
  2.  
  3. /// <summary>
  4. /// 普通的枪
  5. /// </summary>
  6. [RegisterWeapon("1001", typeof(Gun.RifleAttribute))]
  7. [RegisterWeapon("1003", typeof(Gun.PistolAttribute))]
  8. public class Gun : Weapon
  9. {
  10. //步枪属性数据
  11. private class RifleAttribute : WeaponAttribute
  12. {
  13. public RifleAttribute()
  14. {
  15. Name = "步枪";
  16. Sprite = ResourcePath.resource_sprite_gun_gun4_png;
  17. Weight = 40;
  18. CenterPosition = 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. MaxAmmoCapacity = 30 * 70;
  28. //扳机检测间隔
  29. TriggerInterval = 0f;
  30. //连发数量
  31. MinContinuousCount = 3;
  32. MaxContinuousCount = 3;
  33. //开火前延时
  34. DelayedTime = 0f;
  35. //攻击距离
  36. MinDistance = 500;
  37. MaxDistance = 600;
  38. //发射子弹数量
  39. MinFireBulletCount = 1;
  40. MaxFireBulletCount = 1;
  41. //抬起角度
  42. UpliftAngle = 10;
  43. //枪身长度
  44. FirePosition = new Vector2(16, 1.5f);
  45. }
  46. }
  47.  
  48. //手枪属性数据
  49. private class PistolAttribute : WeaponAttribute
  50. {
  51. public PistolAttribute()
  52. {
  53. Name = "手枪";
  54. Sprite = ResourcePath.resource_sprite_gun_gun3_png;
  55. Weight = 20;
  56. CenterPosition = new Vector2(0.4f, -2.6f);
  57. WeightType = WeaponWeightType.DeputyWeapon;
  58. StartFiringSpeed = 300;
  59. StartScatteringRange = 5;
  60. FinalScatteringRange = 60;
  61. ScatteringRangeAddValue = 8f;
  62. ScatteringRangeBackSpeed = 40;
  63. //连发
  64. ContinuousShoot = false;
  65. AmmoCapacity = 12;
  66. MaxAmmoCapacity = 72;
  67. //扳机检测间隔
  68. TriggerInterval = 0.1f;
  69. //连发数量
  70. MinContinuousCount = 1;
  71. MaxContinuousCount = 1;
  72. //开火前延时
  73. DelayedTime = 0f;
  74. //攻击距离
  75. MinDistance = 500;
  76. MaxDistance = 600;
  77. //发射子弹数量
  78. MinFireBulletCount = 1;
  79. MaxFireBulletCount = 1;
  80. //抬起角度
  81. UpliftAngle = 30;
  82. //枪身长度
  83. FirePosition = new Vector2(10, 1.5f);
  84. }
  85. }
  86.  
  87. public Gun(string id, WeaponAttribute attribute): base(id, attribute)
  88. {
  89. }
  90.  
  91. protected override void OnFire()
  92. {
  93. //创建一个弹壳
  94. var startPos = GlobalPosition + new Vector2(0, 5);
  95. var startHeight = 6;
  96. var direction = GlobalRotationDegrees + Utils.RandRangeInt(-30, 30) + 180;
  97. var xf = Utils.RandRangeInt(20, 60);
  98. var yf = Utils.RandRangeInt(60, 120);
  99. var rotate = Utils.RandRangeInt(-720, 720);
  100. var shell = new ShellCase();
  101. shell.Throw(new Vector2(10, 5), startPos, startHeight, direction, xf, yf, rotate, true);
  102. if (Master == GameApplication.Instance.Room.Player)
  103. {
  104. //创建抖动
  105. GameCamera.Main.ProcessDirectionalShake(Vector2.Right.Rotated(GlobalRotation) * 1.5f);
  106. }
  107. //播放射击音效
  108. SoundManager.PlaySoundEffectPosition(ResourcePath.resource_sound_sfx_ordinaryBullet_ogg, GameApplication.Instance.ViewToGlobalPosition(GlobalPosition), 6f);
  109. }
  110.  
  111. protected override void OnShoot(float fireRotation)
  112. {
  113. //创建子弹
  114. //CreateBullet(BulletPack, FirePoint.GlobalPosition, fireRotation);
  115. var bullet = new Bullet(
  116. ResourcePath.prefab_weapon_bullet_Bullet_tscn,
  117. Utils.RandRange(Attribute.MinDistance, Attribute.MaxDistance),
  118. FirePoint.GlobalPosition,
  119. fireRotation,
  120. Master != null ? Master.AttackLayer : Role.DefaultAttackLayer
  121. );
  122. bullet.PutDown();
  123. }
  124. }