Newer
Older
DungeonShooting / DungeonShooting_Godot / src / game / room / RoomDoor.cs
@小李xl 小李xl on 14 Apr 2023 2 KB 门相关修改
  1.  
  2. using Godot;
  3.  
  4. /// <summary>
  5. /// 房间的门, 门有两种状态, 打开和关闭
  6. /// </summary>
  7. [RegisterActivity(ActivityIdPrefix.Other + "0001", ResourcePath.prefab_map_RoomDoor_tscn)]
  8. public partial class RoomDoor : ActivityObject
  9. {
  10. /// <summary>
  11. /// 门的方向
  12. /// </summary>
  13. public DoorDirection Direction => _door.Direction;
  14. /// <summary>
  15. /// 门是否关闭
  16. /// </summary>
  17. public bool IsClose { get; private set; }
  18. private RoomDoorInfo _door;
  19.  
  20. /// <summary>
  21. /// 初始化调用
  22. /// </summary>
  23. public void Init(RoomDoorInfo doorInfo)
  24. {
  25. _door = doorInfo;
  26. OpenDoor();
  27.  
  28. switch (doorInfo.Direction)
  29. {
  30. case DoorDirection.E:
  31. //RotationDegrees = 90;
  32. AnimatedSprite.Frame = 1;
  33. AnimatedSprite.Position = Vector2.Zero;
  34. Collision.Position = Vector2.Zero;
  35. var collisionShape = (RectangleShape2D)Collision.Shape;
  36. collisionShape.Size = new Vector2(14, 32);
  37. break;
  38. case DoorDirection.W:
  39. //RotationDegrees = 270;
  40. AnimatedSprite.Frame = 1;
  41. AnimatedSprite.Position = Vector2.Zero;
  42. Collision.Position = Vector2.Zero;
  43. var collisionShape2 = (RectangleShape2D)Collision.Shape;
  44. collisionShape2.Size = new Vector2(14, 32);
  45. break;
  46. case DoorDirection.S:
  47. //RotationDegrees = 180;
  48. AnimatedSprite.Position = new Vector2(0, -8);
  49. break;
  50. case DoorDirection.N:
  51. ZIndex = GameConfig.MiddleMapLayer;
  52. AnimatedSprite.Position = new Vector2(0, -8);
  53. //RotationDegrees = 0;
  54. break;
  55. }
  56. }
  57.  
  58. /// <summary>
  59. /// 打开当前的门
  60. /// </summary>
  61. public void OpenDoor()
  62. {
  63. IsClose = false;
  64. Visible = false;
  65. Collision.Disabled = true;
  66. if (_door.Navigation != null)
  67. {
  68. _door.Navigation.OpenNavigationNode.Enabled = true;
  69. _door.Navigation.OpenNavigationNode.Visible = true;
  70. _door.Navigation.CloseNavigationNode.Enabled = false;
  71. _door.Navigation.CloseNavigationNode.Visible = false;
  72. }
  73. }
  74.  
  75. /// <summary>
  76. /// 关闭当前的门
  77. /// </summary>
  78. public void CloseDoor()
  79. {
  80. IsClose = true;
  81. Visible = true;
  82. Collision.Disabled = false;
  83. if (_door.Navigation != null)
  84. {
  85. _door.Navigation.OpenNavigationNode.Enabled = false;
  86. _door.Navigation.OpenNavigationNode.Visible = false;
  87. _door.Navigation.CloseNavigationNode.Enabled = true;
  88. _door.Navigation.CloseNavigationNode.Visible = true;
  89. }
  90. }
  91. }