Newer
Older
DungeonShooting / DungeonShooting_Godot / src / game / room / World.cs
@小李xl 小李xl on 8 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. //临时处理, 加载TileSet
  79. var tileSet = ResourceManager.Load<TileSet>(ResourcePath.resource_map_tileSet_map1_TileSet1_tres);
  80. var tileSetAtlasSource = (TileSetAtlasSource)tileSet.GetSource(0);
  81. tileSetAtlasSource.Texture = ImageTexture.CreateFromImage(Image.LoadFromFile("resource/map/tileSprite/map1/16x16 dungeon ii wall reconfig v04 spritesheet.png"));
  82. TileRoot.TileSet = tileSet;
  83. TileRoot.YSortEnabled = false;
  84. }
  85.  
  86. public override void _Process(double delta)
  87. {
  88. //协程更新
  89. if (_coroutineList != null)
  90. {
  91. ProxyCoroutineHandler.ProxyUpdateCoroutine(ref _coroutineList, (float)delta);
  92. }
  93. }
  94.  
  95. /// <summary>
  96. /// 获取指定层级根节点
  97. /// </summary>
  98. public Node2D GetRoomLayer(RoomLayerEnum layerEnum)
  99. {
  100. switch (layerEnum)
  101. {
  102. case RoomLayerEnum.NormalLayer:
  103. return NormalLayer;
  104. case RoomLayerEnum.YSortLayer:
  105. return YSortLayer;
  106. }
  107.  
  108. return null;
  109. }
  110. public long StartCoroutine(IEnumerator able)
  111. {
  112. return ProxyCoroutineHandler.ProxyStartCoroutine(ref _coroutineList, able);
  113. }
  114. public void StopCoroutine(long coroutineId)
  115. {
  116. ProxyCoroutineHandler.ProxyStopCoroutine(ref _coroutineList, coroutineId);
  117. }
  118.  
  119. public bool IsCoroutineOver(long coroutineId)
  120. {
  121. return ProxyCoroutineHandler.ProxyIsCoroutineOver(ref _coroutineList, coroutineId);
  122. }
  123.  
  124. public void StopAllCoroutine()
  125. {
  126. ProxyCoroutineHandler.ProxyStopAllCoroutine(ref _coroutineList);
  127. }
  128. }