Newer
Older
DungeonShooting / DungeonShooting_Godot / src / game / room / World.cs
@小李xl 小李xl on 28 Oct 2023 3 KB 激光武器,制作中
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using Godot;
  4.  
  5. /// <summary>
  6. /// 游戏世界
  7. /// </summary>
  8. public partial class World : CanvasModulate, ICoroutine
  9. {
  10. /// <summary>
  11. /// 当前的游戏世界对象
  12. /// </summary>
  13. public static World Current => GameApplication.Instance.World;
  14. /// <summary>
  15. /// //对象根节点
  16. /// </summary>
  17. [Export] public Node2D NormalLayer;
  18. /// <summary>
  19. /// 对象根节点, 带y轴排序功能
  20. /// </summary>
  21. [Export] public Node2D YSortLayer;
  22. /// <summary>
  23. /// 地图根节点
  24. /// </summary>
  25. [Export] public TileMap TileRoot;
  26.  
  27. [Export] public Node2D StaticSpriteRoot;
  28. [Export] public Node2D AffiliationAreaRoot;
  29. [Export] public Node2D FogMaskRoot;
  30. /// <summary>
  31. /// 是否暂停
  32. /// </summary>
  33. public bool Pause
  34. {
  35. get => _pause;
  36. set
  37. {
  38. if (_pause != value)
  39. {
  40. _pause = value;
  41. if (value)
  42. {
  43. ProcessMode = ProcessModeEnum.WhenPaused;
  44. }
  45. else
  46. {
  47. ProcessMode = ProcessModeEnum.Inherit;
  48. }
  49. }
  50. }
  51. }
  52. /// <summary>
  53. /// 所有被扔在地上的武器
  54. /// </summary>
  55. public HashSet<Weapon> Weapon_UnclaimedWeapons { get; } = new HashSet<Weapon>();
  56. /// <summary>
  57. /// 记录所有存活的敌人
  58. /// </summary>
  59. public List<Enemy> Enemy_InstanceList { get; } = new List<Enemy>();
  60. /// <summary>
  61. /// 公共属性, 敌人是否找到目标, 如果找到目标, 则与目标同房间的所有敌人都会知道目标的位置
  62. /// </summary>
  63. public bool Enemy_IsFindTarget { get; set; }
  64.  
  65. /// <summary>
  66. /// 公共属性, 敌人在哪个区域找到的目标, 所有该区域下的敌人都会知道目标的位置
  67. /// </summary>
  68. public HashSet<AffiliationArea> Enemy_FindTargetAffiliationSet { get; } = new HashSet<AffiliationArea>();
  69. /// <summary>
  70. /// 公共属性, 敌人找到的目标的位置, 如果目标在视野内, 则一直更新
  71. /// </summary>
  72. public Vector2 Enemy_FindTargetPosition { get; set; }
  73. private bool _pause = false;
  74. private List<CoroutineData> _coroutineList;
  75.  
  76. public override void _Ready()
  77. {
  78. Color = Colors.Black;
  79. //临时处理, 加载TileSet
  80. var tileSet = ResourceManager.Load<TileSet>(ResourcePath.resource_map_tileSet_map1_TileSet1_tres);
  81. var tileSetAtlasSource = (TileSetAtlasSource)tileSet.GetSource(0);
  82. tileSetAtlasSource.Texture = ImageTexture.CreateFromImage(Image.LoadFromFile("resource/map/tileSprite/map1/16x16 dungeon ii wall reconfig v04 spritesheet.png"));
  83. TileRoot.TileSet = tileSet;
  84. TileRoot.YSortEnabled = false;
  85. }
  86.  
  87. public override void _Process(double delta)
  88. {
  89. //协程更新
  90. ProxyCoroutineHandler.ProxyUpdateCoroutine(ref _coroutineList, (float)delta);
  91. }
  92.  
  93. /// <summary>
  94. /// 获取指定层级根节点
  95. /// </summary>
  96. public Node2D GetRoomLayer(RoomLayerEnum layerEnum)
  97. {
  98. switch (layerEnum)
  99. {
  100. case RoomLayerEnum.NormalLayer:
  101. return NormalLayer;
  102. case RoomLayerEnum.YSortLayer:
  103. return YSortLayer;
  104. }
  105.  
  106. return null;
  107. }
  108. public long StartCoroutine(IEnumerator able)
  109. {
  110. return ProxyCoroutineHandler.ProxyStartCoroutine(ref _coroutineList, able);
  111. }
  112. public void StopCoroutine(long coroutineId)
  113. {
  114. ProxyCoroutineHandler.ProxyStopCoroutine(ref _coroutineList, coroutineId);
  115. }
  116.  
  117. public bool IsCoroutineOver(long coroutineId)
  118. {
  119. return ProxyCoroutineHandler.ProxyIsCoroutineOver(ref _coroutineList, coroutineId);
  120. }
  121.  
  122. public void StopAllCoroutine()
  123. {
  124. ProxyCoroutineHandler.ProxyStopAllCoroutine(ref _coroutineList);
  125. }
  126. }