diff --git a/DungeonShooting_Godot/scene/Hall.tscn b/DungeonShooting_Godot/scene/Hall.tscn
new file mode 100644
index 0000000..1a496c4
--- /dev/null
+++ b/DungeonShooting_Godot/scene/Hall.tscn
@@ -0,0 +1,36 @@
+[gd_scene load_steps=4 format=3 uid="uid://c2hynqudkykxl"]
+
+[ext_resource type="PackedScene" uid="uid://bqf2vks5ggnsp" path="res://scene/World.tscn" id="1_31od0"]
+[ext_resource type="Script" path="res://src/game/hall/Hall.cs" id="2_43fdu"]
+[ext_resource type="Texture2D" uid="uid://uhhfgdhpk7i4" path="res://icon.png" id="3_3cr4y"]
+
+[node name="Hall" instance=ExtResource("1_31od0")]
+script = ExtResource("2_43fdu")
+
+[node name="Icon" type="Sprite2D" parent="." index="1"]
+position = Vector2(110, 85)
+texture = ExtResource("3_3cr4y")
+
+[node name="Icon2" type="Sprite2D" parent="." index="2"]
+position = Vector2(156, 248)
+texture = ExtResource("3_3cr4y")
+
+[node name="Icon3" type="Sprite2D" parent="." index="3"]
+position = Vector2(404, 52)
+texture = ExtResource("3_3cr4y")
+
+[node name="Icon4" type="Sprite2D" parent="." index="4"]
+position = Vector2(-193, 98)
+texture = ExtResource("3_3cr4y")
+
+[node name="Icon5" type="Sprite2D" parent="." index="5"]
+position = Vector2(-150, -173)
+texture = ExtResource("3_3cr4y")
+
+[node name="Icon6" type="Sprite2D" parent="." index="6"]
+position = Vector2(230, -270)
+texture = ExtResource("3_3cr4y")
+
+[node name="Icon7" type="Sprite2D" parent="." index="7"]
+position = Vector2(269, -134)
+texture = ExtResource("3_3cr4y")
diff --git a/DungeonShooting_Godot/scene/World.tscn b/DungeonShooting_Godot/scene/World.tscn
index 0a055fc..50f8a64 100644
--- a/DungeonShooting_Godot/scene/World.tscn
+++ b/DungeonShooting_Godot/scene/World.tscn
@@ -1,6 +1,6 @@
[gd_scene load_steps=3 format=3 uid="uid://bqf2vks5ggnsp"]
-[ext_resource type="Script" path="res://src/game/room/World.cs" id="1_kt3mm"]
+[ext_resource type="Script" path="res://src/game/World.cs" id="1_kt3mm"]
[sub_resource type="Environment" id="Environment_g06jj"]
background_mode = 3
diff --git a/DungeonShooting_Godot/src/framework/activity/ActivityObject.cs b/DungeonShooting_Godot/src/framework/activity/ActivityObject.cs
index f42c523..b6d6999 100644
--- a/DungeonShooting_Godot/src/framework/activity/ActivityObject.cs
+++ b/DungeonShooting_Godot/src/framework/activity/ActivityObject.cs
@@ -661,7 +661,7 @@
{
DefaultLayer = layer;
var parent = GetParent();
- var root = GameApplication.Instance.World.GetRoomLayer(layer);
+ var root = World.Current.GetRoomLayer(layer);
if (parent != root)
{
if (parent != null)
@@ -1471,9 +1471,9 @@
{
this.AddToActivityRoot(RoomLayerEnum.YSortLayer);
}
- else if (parent != GameApplication.Instance.World.YSortLayer)
+ else if (parent != World.Current.YSortLayer)
{
- Reparent(GameApplication.Instance.World.YSortLayer);
+ Reparent(World.Current.YSortLayer);
}
CalcThrowAnimatedPosition();
@@ -1550,7 +1550,7 @@
private void ThrowOver()
{
var parent = GetParent();
- var roomLayer = GameApplication.Instance.World.GetRoomLayer(DefaultLayer);
+ var roomLayer = World.Current.GetRoomLayer(DefaultLayer);
if (parent != roomLayer)
{
parent.RemoveChild(this);
diff --git a/DungeonShooting_Godot/src/framework/activity/ActivityObject_Create.cs b/DungeonShooting_Godot/src/framework/activity/ActivityObject_Create.cs
index ebc901a..3a63bdd 100644
--- a/DungeonShooting_Godot/src/framework/activity/ActivityObject_Create.cs
+++ b/DungeonShooting_Godot/src/framework/activity/ActivityObject_Create.cs
@@ -9,7 +9,7 @@
///
public static ActivityObject Create(ExcelConfig.ActivityBase config)
{
- var world = GameApplication.Instance.World;
+ var world = World.Current;
if (world == null)
{
throw new Exception("实例化 ActivityObject 前请先调用 'GameApplication.Instance.CreateNewWorld()' 初始化 World 对象");
diff --git a/DungeonShooting_Godot/src/framework/common/NodeExtend.cs b/DungeonShooting_Godot/src/framework/common/NodeExtend.cs
index 4c3151a..e04437d 100644
--- a/DungeonShooting_Godot/src/framework/common/NodeExtend.cs
+++ b/DungeonShooting_Godot/src/framework/common/NodeExtend.cs
@@ -52,7 +52,7 @@
/// 放入的层
public static void AddToActivityRoot(this Node2D node, RoomLayerEnum layer)
{
- GameApplication.Instance.World.GetRoomLayer(layer).AddChild(node);
+ GameApplication.Instance.DungeonManager.CurrWorld.GetRoomLayer(layer).AddChild(node);
}
///
@@ -62,7 +62,7 @@
/// 放入的层
public static void AddToActivityRootDeferred(this Node2D node, RoomLayerEnum layer)
{
- GameApplication.Instance.World.GetRoomLayer(layer).CallDeferred(Node.MethodName.AddChild, node);
+ World.Current.GetRoomLayer(layer).CallDeferred(Node.MethodName.AddChild, node);
}
///
diff --git a/DungeonShooting_Godot/src/framework/map/fog/FogMask.cs b/DungeonShooting_Godot/src/framework/map/fog/FogMask.cs
index 499b276..828937c 100644
--- a/DungeonShooting_Godot/src/framework/map/fog/FogMask.cs
+++ b/DungeonShooting_Godot/src/framework/map/fog/FogMask.cs
@@ -108,7 +108,7 @@
private void HandlerTransition(Vector2I position, Vector2I size, Image image)
{
- var tileMap = GameApplication.Instance.World.TileRoot;
+ var tileMap = World.Current.TileRoot;
var autoConfig = GameApplication.Instance.DungeonManager.AutoTileConfig;
var wallCoords = autoConfig.TopMask.AutoTileCoords;
var (x, y) = position;
diff --git a/DungeonShooting_Godot/src/framework/map/room/RoomInfo.cs b/DungeonShooting_Godot/src/framework/map/room/RoomInfo.cs
index 4b3373d..15d95ac 100644
--- a/DungeonShooting_Godot/src/framework/map/room/RoomInfo.cs
+++ b/DungeonShooting_Godot/src/framework/map/room/RoomInfo.cs
@@ -8,13 +8,19 @@
///
public class RoomInfo : IDestroy
{
+ public RoomInfo(int id, DungeonRoomType type)
+ {
+ Id = id;
+ RoomType = type;
+ }
+
public RoomInfo(int id, DungeonRoomType type, DungeonRoomSplit roomSplit)
{
Id = id;
RoomType = type;
RoomSplit = roomSplit;
}
-
+
///
/// 房间 id
///
@@ -31,7 +37,7 @@
public int Layer;
///
- /// 生成该房间使用的配置数据
+ /// 生成该房间使用的配置数据, 可能为 null
///
public DungeonRoomSplit RoomSplit;
@@ -106,7 +112,7 @@
public Rect2I OuterRect { get; private set; }
///
- /// 画布占用区域
+ /// 画布占用区域, 单位: 像素
///
public Rect2I CanvasRect { get; private set; }
@@ -265,6 +271,10 @@
///
public Vector2I GetOffsetPosition()
{
+ if (RoomSplit == null)
+ {
+ return Vector2I.Zero;
+ }
return RoomSplit.RoomInfo.Position.AsVector2I() * GameConfig.TileCellSize;
}
diff --git a/DungeonShooting_Godot/src/game/GameApplication.cs b/DungeonShooting_Godot/src/game/GameApplication.cs
index 18d157c..a34f0fa 100644
--- a/DungeonShooting_Godot/src/game/GameApplication.cs
+++ b/DungeonShooting_Godot/src/game/GameApplication.cs
@@ -43,11 +43,6 @@
public Cursor Cursor { get; private set; }
///
- /// 游戏世界
- ///
- public World World { get; private set; }
-
- ///
/// 地牢管理器
///
public DungeonManager DungeonManager { get; private set; }
@@ -172,41 +167,6 @@
//协程更新
ProxyCoroutineHandler.ProxyUpdateCoroutine(ref _coroutineList, newDelta);
}
-
- ///
- /// 创建新的 World 对象, 相当于清理房间
- ///
- public World CreateNewWorld(SeedRandom random)
- {
- if (World != null)
- {
- ClearWorld();
- World.QueueFree();
- }
- World = ResourceManager.LoadAndInstantiate(ResourcePath.scene_World_tscn);
- SceneRoot.AddChild(World);
- World.InitLayer();
- World.InitRandomPool(random);
- return World;
- }
-
- ///
- /// 销毁 World 对象, 相当于清理房间
- ///
- public void DestroyWorld()
- {
- //销毁所有物体
- if (World != null)
- {
- ClearWorld();
- World.QueueFree();
- }
-
- //销毁池中所有物体
- ObjectPool.DisposeAllItem();
-
- World = null;
- }
///
/// 将 viewport 以外的全局坐标 转换成 viewport 内的全局坐标
@@ -332,27 +292,4 @@
AddChild(cursorLayer);
cursorLayer.AddChild(Cursor);
}
-
- //清理世界
- private void ClearWorld()
- {
- var childCount = World.NormalLayer.GetChildCount();
- for (var i = 0; i < childCount; i++)
- {
- var c = World.NormalLayer.GetChild(i);
- if (c is IDestroy destroy)
- {
- destroy.Destroy();
- }
- }
- childCount = World.YSortLayer.GetChildCount();
- for (var i = 0; i < childCount; i++)
- {
- var c = World.YSortLayer.GetChild(i);
- if (c is IDestroy destroy)
- {
- destroy.Destroy();
- }
- }
- }
}
diff --git a/DungeonShooting_Godot/src/game/World.cs b/DungeonShooting_Godot/src/game/World.cs
new file mode 100644
index 0000000..7438e4e
--- /dev/null
+++ b/DungeonShooting_Godot/src/game/World.cs
@@ -0,0 +1,178 @@
+using System.Collections;
+using System.Collections.Generic;
+using System.Linq;
+using Godot;
+
+///
+/// 游戏世界
+///
+public partial class World : CanvasModulate, ICoroutine
+{
+ ///
+ /// 当前的游戏世界对象
+ ///
+ public static World Current => GameApplication.Instance.DungeonManager.CurrWorld;
+
+ ///
+ /// //对象根节点
+ ///
+ public Node2D NormalLayer;
+
+ ///
+ /// 对象根节点, 带y轴排序功能
+ ///
+ public Node2D YSortLayer;
+
+ ///
+ /// 地图根节点
+ ///
+ public TileMap TileRoot;
+
+ public Node2D StaticSpriteRoot;
+ public Node2D AffiliationAreaRoot;
+ public Node2D FogMaskRoot;
+ public Node2D NavigationRoot;
+
+ ///
+ /// 是否暂停
+ ///
+ public bool Pause
+ {
+ get => _pause;
+ set
+ {
+ if (_pause != value)
+ {
+ _pause = value;
+ if (value)
+ {
+ ProcessMode = ProcessModeEnum.WhenPaused;
+ }
+ else
+ {
+ ProcessMode = ProcessModeEnum.Inherit;
+ }
+ }
+ }
+ }
+
+ ///
+ /// 所有被扔在地上的武器
+ ///
+ public HashSet Weapon_UnclaimedWeapons { get; } = new HashSet();
+
+ ///
+ /// 记录所有存活的敌人
+ ///
+ public List Enemy_InstanceList { get; } = new List();
+
+ ///
+ /// 随机数对象
+ ///
+ public SeedRandom Random { get; private set; }
+
+ ///
+ /// 随机对象池
+ ///
+ public RandomPool RandomPool { get; private set; }
+
+ private bool _pause = false;
+ private List _coroutineList;
+
+ public override void _Ready()
+ {
+ Color = Colors.Black;
+ //TileRoot.YSortEnabled = false;
+ NormalLayer = GetNode("TileRoot/NormalLayer");
+ YSortLayer = GetNode("TileRoot/YSortLayer");
+ TileRoot = GetNode("TileRoot");
+ StaticSpriteRoot = GetNode("TileRoot/StaticSpriteRoot");
+ FogMaskRoot = GetNode("TileRoot/FogMaskRoot");
+ NavigationRoot = GetNode("TileRoot/NavigationRoot");
+ AffiliationAreaRoot = GetNode("TileRoot/AffiliationAreaRoot");
+ }
+
+ public override void _Process(double delta)
+ {
+ //协程更新
+ ProxyCoroutineHandler.ProxyUpdateCoroutine(ref _coroutineList, (float)delta);
+ }
+
+ ///
+ /// 初始化 TileMap 中的层级
+ ///
+ public void InitLayer()
+ {
+ MapLayerManager.InitMapLayer(TileRoot);
+ }
+
+ ///
+ /// 获取指定层级根节点
+ ///
+ public Node2D GetRoomLayer(RoomLayerEnum layerEnum)
+ {
+ switch (layerEnum)
+ {
+ case RoomLayerEnum.NormalLayer:
+ return NormalLayer;
+ case RoomLayerEnum.YSortLayer:
+ return YSortLayer;
+ }
+
+ return null;
+ }
+
+ ///
+ /// 通知其他敌人发现目标了
+ ///
+ /// 发送通知的角色
+ /// 目标
+ public void NotifyEnemyTarget(Role self, ActivityObject target)
+ {
+ foreach (var role in Enemy_InstanceList)
+ {
+ if (role != self && !role.IsDestroyed && role.AffiliationArea == self.AffiliationArea)
+ {
+ //将未发现目标的敌人状态置为惊讶状态
+ var controller = role.StateController;
+ //延时通知效果
+ role.CallDelay(Utils.Random.RandomRangeFloat(0.2f, 1f), () =>
+ {
+ if (controller.CurrState == AIStateEnum.AiNormal)
+ {
+ controller.ChangeState(AIStateEnum.AiLeaveFor, target);
+ }
+ });
+ }
+ }
+ }
+
+ public long StartCoroutine(IEnumerator able)
+ {
+ return ProxyCoroutineHandler.ProxyStartCoroutine(ref _coroutineList, able);
+ }
+
+ public void StopCoroutine(long coroutineId)
+ {
+ ProxyCoroutineHandler.ProxyStopCoroutine(ref _coroutineList, coroutineId);
+ }
+
+ public bool IsCoroutineOver(long coroutineId)
+ {
+ return ProxyCoroutineHandler.ProxyIsCoroutineOver(ref _coroutineList, coroutineId);
+ }
+
+ public void StopAllCoroutine()
+ {
+ ProxyCoroutineHandler.ProxyStopAllCoroutine(ref _coroutineList);
+ }
+
+ ///
+ /// 初始化随机池
+ ///
+ public void InitRandomPool(SeedRandom random)
+ {
+ Random = random;
+ RandomPool = new RandomPool(this);
+ }
+}
\ No newline at end of file
diff --git a/DungeonShooting_Godot/src/game/activity/role/player/Player.cs b/DungeonShooting_Godot/src/game/activity/role/player/Player.cs
index 1331123..e12d441 100644
--- a/DungeonShooting_Godot/src/game/activity/role/player/Player.cs
+++ b/DungeonShooting_Godot/src/game/activity/role/player/Player.cs
@@ -338,7 +338,7 @@
MoveController.ClearForce();
//暂停游戏
- GameApplication.Instance.World.Pause = true;
+ World.Current.Pause = true;
//弹出结算面板
GameApplication.Instance.Cursor.SetGuiMode(true);
UiManager.Open_Settlement();
diff --git a/DungeonShooting_Godot/src/game/activity/weapon/Weapon.cs b/DungeonShooting_Godot/src/game/activity/weapon/Weapon.cs
index 5c9a069..2ee8f84 100644
--- a/DungeonShooting_Godot/src/game/activity/weapon/Weapon.cs
+++ b/DungeonShooting_Godot/src/game/activity/weapon/Weapon.cs
@@ -793,7 +793,7 @@
///
public bool IsInGround()
{
- return Master == null && GetParent() == GameApplication.Instance.World.NormalLayer;
+ return Master == null && GetParent() == World.Current.NormalLayer;
}
///
diff --git a/DungeonShooting_Godot/src/game/camera/GameCamera.cs b/DungeonShooting_Godot/src/game/camera/GameCamera.cs
index 513d058..9ae3e69 100644
--- a/DungeonShooting_Godot/src/game/camera/GameCamera.cs
+++ b/DungeonShooting_Godot/src/game/camera/GameCamera.cs
@@ -86,7 +86,7 @@
var newDelta = (float)delta;
_Shake(newDelta);
- var world = GameApplication.Instance.World;
+ var world = World.Current;
if (world != null && !world.Pause && _followTarget != null)
{
var mousePosition = InputManager.CursorPosition;
diff --git a/DungeonShooting_Godot/src/game/hall/Hall.cs b/DungeonShooting_Godot/src/game/hall/Hall.cs
new file mode 100644
index 0000000..23e4287
--- /dev/null
+++ b/DungeonShooting_Godot/src/game/hall/Hall.cs
@@ -0,0 +1,16 @@
+
+using Godot;
+
+///
+/// 游戏大厅
+///
+public partial class Hall : World
+{
+ public RoomInfo RoomInfo { get; set; }
+
+ public override void _Ready()
+ {
+ base._Ready();
+ Color = Colors.White;
+ }
+}
\ No newline at end of file
diff --git a/DungeonShooting_Godot/src/game/manager/ResourcePath.cs b/DungeonShooting_Godot/src/game/manager/ResourcePath.cs
index 6375088..7b26aa8 100644
--- a/DungeonShooting_Godot/src/game/manager/ResourcePath.cs
+++ b/DungeonShooting_Godot/src/game/manager/ResourcePath.cs
@@ -568,6 +568,7 @@
public const string resource_spriteFrames_weapon_Weapon0016_tres = "res://resource/spriteFrames/weapon/Weapon0016.tres";
public const string resource_theme_mainTheme_tres = "res://resource/theme/mainTheme.tres";
public const string resource_theme_theme1_tres = "res://resource/theme/theme1.tres";
+ public const string scene_Hall_tscn = "res://scene/Hall.tscn";
public const string scene_Main_tscn = "res://scene/Main.tscn";
public const string scene_World_tscn = "res://scene/World.tscn";
public const string scene_test_TestCreateSector_tscn = "res://scene/test/TestCreateSector.tscn";
diff --git a/DungeonShooting_Godot/src/game/room/DungeonManager.cs b/DungeonShooting_Godot/src/game/room/DungeonManager.cs
index 4eb26eb..8a73575 100644
--- a/DungeonShooting_Godot/src/game/room/DungeonManager.cs
+++ b/DungeonShooting_Godot/src/game/room/DungeonManager.cs
@@ -41,9 +41,14 @@
public DungeonConfig CurrConfig { get; private set; }
///
- /// 当前使用的世界对象
+ /// 游戏大厅
///
- public World World { get; private set; }
+ public Hall Hall { get; private set; }
+
+ ///
+ /// 当前玩家所在游戏世界对象
+ ///
+ public World CurrWorld { get; private set; }
///
/// 自动图块配置
@@ -68,6 +73,85 @@
}
///
+ /// 初始化游戏大厅
+ ///
+ public void InitHall(SeedRandom random)
+ {
+ if (Hall != null)
+ {
+ return;
+ }
+ Hall = ResourceManager.LoadAndInstantiate(ResourcePath.scene_Hall_tscn);
+ Hall.InitRandomPool(random);
+ }
+
+ ///
+ /// 创建新的 World 对象, 相当于清理房间
+ ///
+ public World CreateNewWorld(SeedRandom random)
+ {
+ if (CurrWorld != null)
+ {
+ ClearWorld();
+ CurrWorld.QueueFree();
+ }
+ CurrWorld = ResourceManager.LoadAndInstantiate(ResourcePath.scene_World_tscn);
+ CurrWorld.InitLayer();
+ CurrWorld.InitRandomPool(random);
+ return CurrWorld;
+ }
+
+ ///
+ /// 销毁 World 对象, 相当于清理房间
+ ///
+ public void DestroyWorld()
+ {
+ //销毁所有物体
+ if (CurrWorld != null)
+ {
+ ClearWorld();
+ CurrWorld.QueueFree();
+ }
+
+ //销毁池中所有物体
+ ObjectPool.DisposeAllItem();
+
+ CurrWorld = null;
+ }
+
+
+ //清理世界
+ private void ClearWorld()
+ {
+ var childCount = CurrWorld.NormalLayer.GetChildCount();
+ for (var i = 0; i < childCount; i++)
+ {
+ var c = CurrWorld.NormalLayer.GetChild(i);
+ if (c is IDestroy destroy)
+ {
+ destroy.Destroy();
+ }
+ }
+ childCount = CurrWorld.YSortLayer.GetChildCount();
+ for (var i = 0; i < childCount; i++)
+ {
+ var c = CurrWorld.YSortLayer.GetChild(i);
+ if (c is IDestroy destroy)
+ {
+ destroy.Destroy();
+ }
+ }
+ }
+
+ ///
+ /// 进入大厅
+ ///
+ public void LoadHall(Action finish = null)
+ {
+ GameApplication.Instance.StartCoroutine(RunLoadHallCoroutine(finish));
+ }
+
+ ///
/// 加载地牢
///
public void LoadDungeon(DungeonConfig config, Action finish = null)
@@ -156,7 +240,7 @@
{
if (IsInDungeon)
{
- if (World.Pause) //已经暂停
+ if (CurrWorld.Pause) //已经暂停
{
return;
}
@@ -164,7 +248,7 @@
//暂停游戏
if (InputManager.Menu)
{
- World.Pause = true;
+ CurrWorld.Pause = true;
//鼠标改为Ui鼠标
GameApplication.Instance.Cursor.SetGuiMode(true);
//打开暂停Ui
@@ -189,6 +273,77 @@
}
}
+ private IEnumerator RunLoadHallCoroutine(Action finish)
+ {
+ if (Hall != null && CurrWorld == Hall) //本来就在大厅中
+ {
+ yield break;
+ }
+ //打开 loading UI
+ UiManager.Open_Loading();
+ yield return 0;
+ InitHall(Utils.Random);
+
+ yield return 0;
+
+ if (CurrWorld == null) //从主菜单进入大厅
+ {
+ GameApplication.Instance.SceneRoot.AddChild(Hall);
+ CurrWorld = Hall;
+ }
+ else //从地牢中进入大厅
+ {
+ DestroyWorld();
+ GameApplication.Instance.SceneRoot.AddChild(Hall);
+ CurrWorld = Hall;
+ }
+ yield return 0;
+ //创建房间数据
+ var roomInfo = new RoomInfo(0, DungeonRoomType.None, null);
+ roomInfo.Size = new Vector2I(50, 50);
+ roomInfo.Position = Vector2I.Zero;
+ Hall.RoomInfo = roomInfo;
+ yield return 0;
+
+ //创建归属区域
+ var affiliation = new AffiliationArea();
+ affiliation.Name = "AffiliationArea_Hall";
+ affiliation.Init(roomInfo, new Rect2I(roomInfo.Position, roomInfo.Size * GameConfig.TileCellSize));
+ roomInfo.AffiliationArea = affiliation;
+ Hall.AffiliationAreaRoot.AddChild(affiliation);
+ yield return 0;
+
+ //静态渲染精灵根节点, 用于放置sprite
+ var spriteRoot = new RoomStaticSprite(roomInfo);
+ spriteRoot.Name = "SpriteRoot";
+ roomInfo.StaticSprite = spriteRoot;
+ Hall.StaticSpriteRoot.AddChild(spriteRoot);
+
+ //静态精灵画布
+ var canvasSprite = new ImageCanvas(roomInfo.Size.X * GameConfig.TileCellSize, roomInfo.Size.Y * GameConfig.TileCellSize);
+ canvasSprite.Position = roomInfo.Position;
+ roomInfo.StaticImageCanvas = canvasSprite;
+ roomInfo.StaticSprite.AddChild(canvasSprite);
+
+ //液体画布
+ var liquidCanvas = new LiquidCanvas(roomInfo, roomInfo.Size.X * GameConfig.TileCellSize, roomInfo.Size.Y * GameConfig.TileCellSize);
+ liquidCanvas.Position = roomInfo.Position;
+ roomInfo.LiquidCanvas = liquidCanvas;
+ roomInfo.StaticSprite.AddChild(liquidCanvas);
+
+ yield return 0;
+
+ //创建玩家
+ var player = ActivityObject.Create(ActivityObject.Ids.Id_role0001);
+ player.Name = "Player";
+ player.PutDown(RoomLayerEnum.YSortLayer);
+ Player.SetCurrentPlayer(player);
+ player.WeaponPack.PickupItem(ActivityObject.Create(ActivityObject.Ids.Id_weapon0001));
+ GameApplication.Instance.Cursor.SetGuiMode(false);
+ yield return 0;
+ UiManager.Destroy_Loading();
+ }
+
//执行加载地牢协程
private IEnumerator RunLoadDungeonCoroutine(Action finish)
{
@@ -216,7 +371,7 @@
if (!dungeonGenerator.Generate(rule)) //生成房间失败
{
dungeonGenerator.EachRoom(DisposeRoomInfo);
- UiManager.Hide_Loading();
+ UiManager.Destroy_Loading();
if (IsEditorMode) //在编辑器模式下打开的Ui
{
@@ -252,20 +407,20 @@
yield return 0;
//创建世界场景
- World = GameApplication.Instance.CreateNewWorld(_dungeonGenerator.Random);
+ CurrWorld = CreateNewWorld(_dungeonGenerator.Random);
yield return 0;
var group = GameApplication.Instance.RoomConfig[CurrConfig.GroupName];
var tileSetSplit = GameApplication.Instance.TileSetConfig[group.TileSet];
- World.TileRoot.TileSet = tileSetSplit.GetTileSet();
+ CurrWorld.TileRoot.TileSet = tileSetSplit.GetTileSet();
//填充地牢
AutoTileConfig = new AutoTileConfig(0, tileSetSplit.TileSetInfo.Sources[0].Terrain[0]);
- _dungeonTileMap = new DungeonTileMap(World.TileRoot);
- yield return _dungeonTileMap.AutoFillRoomTile(AutoTileConfig, _dungeonGenerator.StartRoomInfo, World);
- yield return _dungeonTileMap.AutoFillAisleTile(AutoTileConfig, _dungeonGenerator.StartRoomInfo, World);
+ _dungeonTileMap = new DungeonTileMap(CurrWorld.TileRoot);
+ yield return _dungeonTileMap.AutoFillRoomTile(AutoTileConfig, _dungeonGenerator.StartRoomInfo, CurrWorld);
+ yield return _dungeonTileMap.AutoFillAisleTile(AutoTileConfig, _dungeonGenerator.StartRoomInfo, CurrWorld);
//yield return _dungeonTileMap.AddOutlineTile(AutoTileConfig.WALL_BLOCK);
yield return 0;
//生成墙壁, 生成导航网格
- _dungeonTileMap.GenerateWallAndNavigation(World, AutoTileConfig);
+ _dungeonTileMap.GenerateWallAndNavigation(CurrWorld, AutoTileConfig);
yield return 0;
//初始化所有房间
yield return _dungeonGenerator.EachRoomCoroutine(InitRoom);
@@ -311,7 +466,7 @@
//打开 loading UI
UiManager.Open_Loading();
yield return 0;
- World.Pause = true;
+ CurrWorld.Pause = true;
yield return 0;
_dungeonGenerator.EachRoom(DisposeRoomInfo);
yield return 0;
@@ -322,8 +477,7 @@
UiManager.Hide_RoomUI();
yield return 0;
Player.SetCurrentPlayer(null);
- World = null;
- GameApplication.Instance.DestroyWorld();
+ DestroyWorld();
yield return 0;
FogMaskHandler.ClearRecordRoom();
LiquidBrushManager.ClearData();
@@ -409,7 +563,7 @@
(roomInfo.Size - new Vector2I(4, 5)) * GameConfig.TileCellSize));
roomInfo.AffiliationArea = affiliation;
- World.AffiliationAreaRoot.AddChild(affiliation);
+ CurrWorld.AffiliationAreaRoot.AddChild(affiliation);
}
//创建 RoomStaticSprite
@@ -452,7 +606,7 @@
roomFog.InitFog(roomInfo.Position + new Vector2I(1, 0), roomInfo.Size - new Vector2I(2, 1));
//roomFog.InitFog(roomInfo.Position + new Vector2I(1, 1), roomInfo.Size - new Vector2I(2, 2));
- World.FogMaskRoot.AddChild(roomFog);
+ CurrWorld.FogMaskRoot.AddChild(roomFog);
roomInfo.RoomFogMask = roomFog;
//生成通道迷雾
@@ -552,7 +706,7 @@
}
aisleFog.InitFog(calcRectPosition, calcRectSize);
- World.FogMaskRoot.AddChild(aisleFog);
+ CurrWorld.FogMaskRoot.AddChild(aisleFog);
roomDoorInfo.AisleFogMask = aisleFog;
roomDoorInfo.ConnectDoor.AisleFogMask = aisleFog;
@@ -566,7 +720,7 @@
);
roomDoorInfo.AisleFogArea = fogArea;
roomDoorInfo.ConnectDoor.AisleFogArea = fogArea;
- World.AffiliationAreaRoot.AddChild(fogArea);
+ CurrWorld.AffiliationAreaRoot.AddChild(fogArea);
}
//预览迷雾区域
@@ -574,13 +728,13 @@
roomDoorInfo.PreviewRoomFogMask = previewRoomFog;
previewRoomFog.Init(roomDoorInfo, PreviewFogMask.PreviewFogType.Room);
previewRoomFog.SetActive(false);
- World.FogMaskRoot.AddChild(previewRoomFog);
+ CurrWorld.FogMaskRoot.AddChild(previewRoomFog);
var previewAisleFog = new PreviewFogMask();
roomDoorInfo.PreviewAisleFogMask = previewAisleFog;
previewAisleFog.Init(roomDoorInfo, PreviewFogMask.PreviewFogType.Aisle);
previewAisleFog.SetActive(false);
- World.FogMaskRoot.AddChild(previewAisleFog);
+ CurrWorld.FogMaskRoot.AddChild(previewAisleFog);
}
}
@@ -640,7 +794,7 @@
if (room.IsSeclusion)
{
var playerAffiliationArea = Player.Current.AffiliationArea;
- foreach (var enemy in World.Enemy_InstanceList)
+ foreach (var enemy in CurrWorld.Enemy_InstanceList)
{
//不与玩家处于同一个房间
if (!enemy.IsDestroyed && enemy.AffiliationArea != playerAffiliationArea)
diff --git a/DungeonShooting_Godot/src/game/room/World.cs b/DungeonShooting_Godot/src/game/room/World.cs
deleted file mode 100644
index af57174..0000000
--- a/DungeonShooting_Godot/src/game/room/World.cs
+++ /dev/null
@@ -1,178 +0,0 @@
-using System.Collections;
-using System.Collections.Generic;
-using System.Linq;
-using Godot;
-
-///
-/// 游戏世界
-///
-public partial class World : CanvasModulate, ICoroutine
-{
- ///
- /// 当前的游戏世界对象
- ///
- public static World Current => GameApplication.Instance.World;
-
- ///
- /// //对象根节点
- ///
- public Node2D NormalLayer;
-
- ///
- /// 对象根节点, 带y轴排序功能
- ///
- public Node2D YSortLayer;
-
- ///
- /// 地图根节点
- ///
- public TileMap TileRoot;
-
- public Node2D StaticSpriteRoot;
- public Node2D AffiliationAreaRoot;
- public Node2D FogMaskRoot;
- public Node2D NavigationRoot;
-
- ///
- /// 是否暂停
- ///
- public bool Pause
- {
- get => _pause;
- set
- {
- if (_pause != value)
- {
- _pause = value;
- if (value)
- {
- ProcessMode = ProcessModeEnum.WhenPaused;
- }
- else
- {
- ProcessMode = ProcessModeEnum.Inherit;
- }
- }
- }
- }
-
- ///
- /// 所有被扔在地上的武器
- ///
- public HashSet Weapon_UnclaimedWeapons { get; } = new HashSet();
-
- ///
- /// 记录所有存活的敌人
- ///
- public List Enemy_InstanceList { get; } = new List();
-
- ///
- /// 随机数对象
- ///
- public SeedRandom Random { get; private set; }
-
- ///
- /// 随机对象池
- ///
- public RandomPool RandomPool { get; private set; }
-
- private bool _pause = false;
- private List _coroutineList;
-
- public override void _Ready()
- {
- Color = Colors.Black;
- //TileRoot.YSortEnabled = false;
- NormalLayer = GetNode("TileRoot/NormalLayer");
- YSortLayer = GetNode("TileRoot/YSortLayer");
- TileRoot = GetNode("TileRoot");
- StaticSpriteRoot = GetNode("TileRoot/StaticSpriteRoot");
- FogMaskRoot = GetNode("TileRoot/FogMaskRoot");
- NavigationRoot = GetNode("TileRoot/NavigationRoot");
- AffiliationAreaRoot = GetNode("TileRoot/AffiliationAreaRoot");
- }
-
- public override void _Process(double delta)
- {
- //协程更新
- ProxyCoroutineHandler.ProxyUpdateCoroutine(ref _coroutineList, (float)delta);
- }
-
- ///
- /// 初始化 TileMap 中的层级
- ///
- public void InitLayer()
- {
- MapLayerManager.InitMapLayer(TileRoot);
- }
-
- ///
- /// 获取指定层级根节点
- ///
- public Node2D GetRoomLayer(RoomLayerEnum layerEnum)
- {
- switch (layerEnum)
- {
- case RoomLayerEnum.NormalLayer:
- return NormalLayer;
- case RoomLayerEnum.YSortLayer:
- return YSortLayer;
- }
-
- return null;
- }
-
- ///
- /// 通知其他敌人发现目标了
- ///
- /// 发送通知的角色
- /// 目标
- public void NotifyEnemyTarget(Role self, ActivityObject target)
- {
- foreach (var role in Enemy_InstanceList)
- {
- if (role != self && !role.IsDestroyed && role.AffiliationArea == self.AffiliationArea)
- {
- //将未发现目标的敌人状态置为惊讶状态
- var controller = role.StateController;
- //延时通知效果
- role.CallDelay(Utils.Random.RandomRangeFloat(0.2f, 1f), () =>
- {
- if (controller.CurrState == AIStateEnum.AiNormal)
- {
- controller.ChangeState(AIStateEnum.AiLeaveFor, target);
- }
- });
- }
- }
- }
-
- public long StartCoroutine(IEnumerator able)
- {
- return ProxyCoroutineHandler.ProxyStartCoroutine(ref _coroutineList, able);
- }
-
- public void StopCoroutine(long coroutineId)
- {
- ProxyCoroutineHandler.ProxyStopCoroutine(ref _coroutineList, coroutineId);
- }
-
- public bool IsCoroutineOver(long coroutineId)
- {
- return ProxyCoroutineHandler.ProxyIsCoroutineOver(ref _coroutineList, coroutineId);
- }
-
- public void StopAllCoroutine()
- {
- ProxyCoroutineHandler.ProxyStopAllCoroutine(ref _coroutineList);
- }
-
- ///
- /// 初始化随机池
- ///
- public void InitRandomPool(SeedRandom random)
- {
- Random = random;
- RandomPool = new RandomPool(this);
- }
-}
\ No newline at end of file
diff --git a/DungeonShooting_Godot/src/game/ui/main/MainPanel.cs b/DungeonShooting_Godot/src/game/ui/main/MainPanel.cs
index 9815bb1..2468b16 100644
--- a/DungeonShooting_Godot/src/game/ui/main/MainPanel.cs
+++ b/DungeonShooting_Godot/src/game/ui/main/MainPanel.cs
@@ -19,18 +19,21 @@
//点击开始游戏
private void OnStartGameClick()
{
+ GameApplication.Instance.DungeonManager.LoadHall();
+ HideUi();
+
//验证该组是否满足生成地牢的条件
- var config = GameApplication.Instance.DungeonConfig;
- var result = DungeonManager.CheckDungeon(config.GroupName);
- if (result.HasError)
- {
- EditorWindowManager.ShowTips("警告", "当前组'" + config.GroupName + "'" + result.ErrorMessage + ", 不能生成地牢!");
- }
- else
- {
- GameApplication.Instance.DungeonManager.LoadDungeon(config);
- HideUi();
- }
+ // var config = GameApplication.Instance.DungeonConfig;
+ // var result = DungeonManager.CheckDungeon(config.GroupName);
+ // if (result.HasError)
+ // {
+ // EditorWindowManager.ShowTips("警告", "当前组'" + config.GroupName + "'" + result.ErrorMessage + ", 不能生成地牢!");
+ // }
+ // else
+ // {
+ // GameApplication.Instance.DungeonManager.LoadDungeon(config);
+ // HideUi();
+ // }
}
//退出游戏
diff --git a/DungeonShooting_Godot/src/game/ui/pauseMenu/PauseMenuPanel.cs b/DungeonShooting_Godot/src/game/ui/pauseMenu/PauseMenuPanel.cs
index 19e06a1..22eb40e 100644
--- a/DungeonShooting_Godot/src/game/ui/pauseMenu/PauseMenuPanel.cs
+++ b/DungeonShooting_Godot/src/game/ui/pauseMenu/PauseMenuPanel.cs
@@ -28,7 +28,7 @@
//继续游戏
private void OnContinueClick()
{
- GameApplication.Instance.World.Pause = false;
+ World.Current.Pause = false;
GameApplication.Instance.Cursor.SetGuiMode(false);
Destroy();
}