Newer
Older
DungeonShooting / DungeonShooting_Godot / src / game / item / weapon / gun / Shotgun.cs
  1. using Godot;
  2.  
  3. [RegisterWeapon("1002", typeof(Shotgun.ShotgunAttribute))]
  4. public class Shotgun : Weapon
  5. {
  6.  
  7. private class ShotgunAttribute : WeaponAttribute
  8. {
  9. public ShotgunAttribute()
  10. {
  11. Name = "霰弹枪";
  12. Sprite = ResourcePath.resource_sprite_gun_gun2_png;
  13. Weight = 40;
  14. CenterPosition = new Vector2(0.4f, -2.6f);
  15. StartFiringSpeed = 120;
  16. StartScatteringRange = 30;
  17. FinalScatteringRange = 90;
  18. ScatteringRangeAddValue = 50f;
  19. ScatteringRangeBackSpeed = 50;
  20. //连发
  21. ContinuousShoot = false;
  22. AmmoCapacity = 7;
  23. StandbyAmmoCapacity = 42;
  24. MaxAmmoCapacity = 42;
  25. AloneReload = true;
  26. AloneReloadCanShoot = true;
  27. ReloadTime = 0.3f;
  28. //连发数量
  29. MinContinuousCount = 1;
  30. MaxContinuousCount = 1;
  31. //开火前延时
  32. DelayedTime = 0f;
  33. //攻击距离
  34. MinDistance = 500;
  35. MaxDistance = 600;
  36. //发射子弹数量
  37. MinFireBulletCount = 1;
  38. MaxFireBulletCount = 1;
  39. //抬起角度
  40. UpliftAngle = 15;
  41. MaxBacklash = 6;
  42. MinBacklash = 5;
  43. //枪身长度
  44. FirePosition = new Vector2(16, 1.5f);
  45. }
  46. }
  47. /// <summary>
  48. /// 弹壳预制体
  49. /// </summary>
  50. public PackedScene ShellPack;
  51.  
  52. public Shotgun(string id, WeaponAttribute attribute) : base(id, attribute)
  53. {
  54. ShellPack = ResourceManager.Load<PackedScene>(ResourcePath.prefab_weapon_shell_ShellCase_tscn);
  55. }
  56.  
  57. protected override void OnFire()
  58. {
  59. //创建一个弹壳
  60. var startPos = GlobalPosition + new Vector2(0, 5);
  61. var startHeight = 6;
  62. var direction = GlobalRotationDegrees + Utils.RandRangeInt(-30, 30) + 180;
  63. var xf = Utils.RandRangeInt(20, 60);
  64. var yf = Utils.RandRangeInt(60, 120);
  65. var rotate = Utils.RandRangeInt(-720, 720);
  66. var shell = new ShellCase();
  67. shell.Throw(new Vector2(5, 10), startPos, startHeight, direction, xf, yf, rotate, true);
  68. if (Master == GameApplication.Instance.Room.Player)
  69. {
  70. //创建抖动
  71. GameCamera.Main.ProcessDirectionalShake(Vector2.Right.Rotated(GlobalRotation) * 1.5f);
  72. }
  73. //播放射击音效
  74. SoundManager.PlaySoundEffectPosition(ResourcePath.resource_sound_sfx_ordinaryBullet_ogg, GameApplication.Instance.ViewToGlobalPosition(GlobalPosition), 6f);
  75. }
  76.  
  77. protected override void OnShoot(float fireRotation)
  78. {
  79. for (int i = 0; i < 5; i++)
  80. {
  81. //创建子弹
  82. //CreateBullet(BulletPack, FirePoint.GlobalPosition, fireRotation + MathUtils.RandRange(-20 / 180f * Mathf.Pi, 20 / 180f * Mathf.Pi));
  83. var bullet = new Bullet(
  84. ResourcePath.prefab_weapon_bullet_Bullet_tscn,
  85. Utils.RandRange(Attribute.MinDistance, Attribute.MaxDistance),
  86. FirePoint.GlobalPosition,
  87. fireRotation + Utils.RandRange(-20 / 180f * Mathf.Pi, 20 / 180f * Mathf.Pi),
  88. GetAttackLayer()
  89. );
  90. bullet.PutDown();
  91. }
  92. }
  93. }