Newer
Older
DungeonShooting / DungeonShooting_Godot / src / game / item / weapon / gun / Shotgun.cs
@小李xl 小李xl on 13 Feb 2023 3 KB PutDown()参数改为枚举类型
  1. using Godot;
  2.  
  3. [RegisterWeapon("1002", typeof(Shotgun.ShotgunAttribute))]
  4. public partial class Shotgun : Weapon
  5. {
  6.  
  7. private class ShotgunAttribute : WeaponAttribute
  8. {
  9. public ShotgunAttribute()
  10. {
  11. Name = "霰弹枪";
  12. Sprite2D = 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 = 200;
  35. MaxDistance = 250;
  36. //发射子弹数量
  37. MinFireBulletCount = 5;
  38. MaxFireBulletCount = 5;
  39. //抬起角度
  40. UpliftAngle = 15;
  41. MaxBacklash = 6;
  42. MinBacklash = 5;
  43. //开火位置
  44. FirePosition = new Vector2(18, 4);
  45. }
  46. }
  47. /// <summary>
  48. /// 弹壳预制体
  49. /// </summary>
  50. public PackedScene ShellPack;
  51.  
  52. public Shotgun(string typeId, WeaponAttribute attribute) : base(typeId, 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.RoomManager.Player)
  69. {
  70. //创建抖动
  71. GameCamera.Main.ProcessDirectionalShake(Vector2.Right.Rotated(GlobalRotation) * 2f);
  72. }
  73. //创建开火特效
  74. var packedScene = ResourceManager.Load<PackedScene>(ResourcePath.prefab_effect_ShotFire_tscn);
  75. var sprite = packedScene.Instantiate<Sprite2D>();
  76. sprite.GlobalPosition = FirePoint.GlobalPosition;
  77. sprite.GlobalRotation = FirePoint.GlobalRotation;
  78. sprite.AddToActivityRoot(RoomLayerEnum.YSortLayer);
  79. //播放射击音效
  80. SoundManager.PlaySoundEffectPosition(ResourcePath.resource_sound_sfx_ordinaryBullet3_mp3, GameApplication.Instance.ViewToGlobalPosition(GlobalPosition), -15);
  81. }
  82.  
  83. protected override void OnShoot(float fireRotation)
  84. {
  85. //创建子弹
  86. var bullet = new Bullet(
  87. ResourcePath.prefab_weapon_bullet_Bullet_tscn,
  88. Utils.RandRangeInt(280, 380),
  89. Utils.RandfRange(Attribute.MinDistance, Attribute.MaxDistance),
  90. FirePoint.GlobalPosition,
  91. fireRotation + Utils.RandfRange(-20 / 180f * Mathf.Pi, 20 / 180f * Mathf.Pi),
  92. GetAttackLayer()
  93. );
  94. bullet.PutDown(RoomLayerEnum.YSortLayer);
  95. }
  96. }