diff --git a/DungeonShooting_Godot/prefab/weapon/Weapon.tscn b/DungeonShooting_Godot/prefab/weapon/Weapon.tscn index 1af3403..7ad9039 100644 --- a/DungeonShooting_Godot/prefab/weapon/Weapon.tscn +++ b/DungeonShooting_Godot/prefab/weapon/Weapon.tscn @@ -69,26 +69,19 @@ position = Vector2(0.4, -2.6) scale = Vector2(0.8, 0.8) -[node name="WeaponBody" type="Area2D" parent="."] -collision_layer = 4 -collision_mask = 0 -monitoring = false - -[node name="OriginPoint" type="Marker2D" parent="WeaponBody"] +[node name="OriginPoint" type="Marker2D" parent="."] position = Vector2(-3.6, -1.1) -[node name="ShellPoint" type="Marker2D" parent="WeaponBody"] +[node name="ShellPoint" type="Marker2D" parent="."] position = Vector2(-2.6, -2.6) -[node name="FirePoint" type="Marker2D" parent="WeaponBody"] +[node name="FirePoint" type="Marker2D" parent="."] position = Vector2(7.4, -1.1) -[node name="Collision" type="CollisionShape2D" parent="WeaponBody"] +[node name="Collision" type="CollisionShape2D" parent="."] position = Vector2(0.6, 0.2) shape = SubResource("RectangleShape2D_3p5jk") -[node name="Collision" type="CollisionShape2D" parent="."] - [node name="AnimationPlayer" type="AnimationPlayer" parent="."] libraries = { "": SubResource("AnimationLibrary_trkjd") diff --git a/DungeonShooting_Godot/scene/Room.tscn b/DungeonShooting_Godot/scene/Room.tscn index e19b7e3..6895ccf 100644 --- a/DungeonShooting_Godot/scene/Room.tscn +++ b/DungeonShooting_Godot/scene/Room.tscn @@ -1,8 +1,7 @@ -[gd_scene load_steps=9 format=3 uid="uid://bqf2vks5ggnsp"] +[gd_scene load_steps=7 format=3 uid="uid://bqf2vks5ggnsp"] [ext_resource type="Texture2D" uid="uid://dj8nrd5od4fcl" path="res://resource/sprite/environment/itch-io-DungeonTileset4/16x16 dungeon ii wall reconfig v04 spritesheet.png" id="1"] [ext_resource type="Script" path="res://src/game/room/RoomManager.cs" id="1_3w1c7"] -[ext_resource type="Texture2D" uid="uid://uhhfgdhpk7i4" path="res://icon.png" id="4_lomny"] [ext_resource type="Script" path="res://src/game/camera/GameCamera.cs" id="5"] [sub_resource type="Environment" id="Environment_ji6mi"] @@ -566,9 +565,6 @@ physics_layer_0/collision_mask = 0 sources/1 = SubResource("TileSetAtlasSource_rkmbu") -[sub_resource type="RectangleShape2D" id="RectangleShape2D_h2s2y"] -size = Vector2(64, 64) - [node name="Room" type="Node2D" node_paths=PackedStringArray("NormalLayer", "YSortLayer", "TileRoot")] script = ExtResource("1_3w1c7") NormalLayer = NodePath("NormalLayer") @@ -617,29 +613,5 @@ [node name="NormalLayer" type="Node2D" parent="."] z_index = -1 -[node name="CharacterBody2D" type="CharacterBody2D" parent="NormalLayer"] -position = Vector2(178, 165) -collision_layer = 4 -collision_mask = 0 -motion_mode = 1 - -[node name="Sprite2D" type="Sprite2D" parent="NormalLayer/CharacterBody2D"] -texture = ExtResource("4_lomny") - -[node name="CollisionShape2D" type="CollisionShape2D" parent="NormalLayer/CharacterBody2D"] -shape = SubResource("RectangleShape2D_h2s2y") - -[node name="CharacterBody2D2" type="CharacterBody2D" parent="NormalLayer"] -position = Vector2(178, 165) -collision_layer = 4 -collision_mask = 0 -motion_mode = 1 - -[node name="Sprite2D" type="Sprite2D" parent="NormalLayer/CharacterBody2D2"] -texture = ExtResource("4_lomny") - -[node name="CollisionShape2D" type="CollisionShape2D" parent="NormalLayer/CharacterBody2D2"] -shape = SubResource("RectangleShape2D_h2s2y") - [node name="YSortLayer" type="Node2D" parent="."] y_sort_enabled = true diff --git a/DungeonShooting_Godot/src/framework/activity/ActivityObject.cs b/DungeonShooting_Godot/src/framework/activity/ActivityObject.cs index 1a4ef2f..1e123f2 100644 --- a/DungeonShooting_Godot/src/framework/activity/ActivityObject.cs +++ b/DungeonShooting_Godot/src/framework/activity/ActivityObject.cs @@ -67,9 +67,9 @@ } /// <summary> - /// 当前物体归属的区域 + /// 当前物体归属的区域, 如果为 null 代表不属于任何一个区域 /// </summary> - public AffiliationArea Affiliation { get; } + public AffiliationArea Affiliation { get; set; } //组件集合 private List<KeyValuePair<Type, Component>> _components = new List<KeyValuePair<Type, Component>>(); diff --git a/DungeonShooting_Godot/src/framework/map/AffiliationArea.cs b/DungeonShooting_Godot/src/framework/map/AffiliationArea.cs index ce0f009..cd0e1d7 100644 --- a/DungeonShooting_Godot/src/framework/map/AffiliationArea.cs +++ b/DungeonShooting_Godot/src/framework/map/AffiliationArea.cs @@ -8,6 +8,9 @@ { private bool _init = false; + /// <summary> + /// 根据矩形区域初始化归属区域 + /// </summary> public void Init(Rect2 rect2) { if (_init) @@ -25,6 +28,9 @@ _Init(); } + /// <summary> + /// 更具多边形初始化归属区域 + /// </summary> public void Init(Vector2[] polygon) { if (_init) @@ -44,17 +50,17 @@ Monitoring = true; Monitorable = false; CollisionLayer = PhysicsLayer.None; - CollisionMask = PhysicsLayer.Props | PhysicsLayer.Player | PhysicsLayer.Bullet; + CollisionMask = PhysicsLayer.Props | PhysicsLayer.Player | PhysicsLayer.Enemy; BodyEntered += OnBodyEntered; } private void OnBodyEntered(Node2D body) { - GD.Print("有物体进入: " + body.Name); - if (body is CharacterBody2D characterBody) + if (body is ActivityObject activityObject) { - GD.Print("layer: " + characterBody.CollisionLayer); + activityObject.Affiliation = this; + GD.Print("有物体进入: " + body.Name + ", " + Name); } } } \ No newline at end of file diff --git a/DungeonShooting_Godot/src/game/item/weapon/Weapon.cs b/DungeonShooting_Godot/src/game/item/weapon/Weapon.cs index 098bcb9..385403d 100644 --- a/DungeonShooting_Godot/src/game/item/weapon/Weapon.cs +++ b/DungeonShooting_Godot/src/game/item/weapon/Weapon.cs @@ -61,12 +61,6 @@ public Marker2D ShellPoint { get; private set; } /// <summary> - /// 碰撞器节点 - /// </summary> - /// <value></value> - public CollisionShape2D CollisionShape2D { get; private set; } - - /// <summary> /// 武器的当前散射半径 /// </summary> public float CurrScatteringRange { get; private set; } = 0; @@ -177,10 +171,9 @@ _weaponAttribute = attribute; AnimationPlayer = GetNode<AnimationPlayer>("AnimationPlayer"); - FirePoint = GetNode<Marker2D>("WeaponBody/FirePoint"); - OriginPoint = GetNode<Marker2D>("WeaponBody/OriginPoint"); - ShellPoint = GetNode<Marker2D>("WeaponBody/ShellPoint"); - CollisionShape2D = GetNode<CollisionShape2D>("WeaponBody/Collision"); + FirePoint = GetNode<Marker2D>("FirePoint"); + OriginPoint = GetNode<Marker2D>("OriginPoint"); + ShellPoint = GetNode<Marker2D>("ShellPoint"); //图标 SetDefaultTexture(ResourceLoader.Load<Texture2D>(Attribute.Sprite2D)); @@ -953,7 +946,7 @@ protected override void OnThrowOver() { //启用碰撞 - CollisionShape2D.Disabled = false; + Collision.Disabled = false; AnimationPlayer.Play("floodlight"); } @@ -986,7 +979,7 @@ sm.SetShaderParameter("schedule", 0); ZIndex = 0; //禁用碰撞 - CollisionShape2D.Disabled = true; + Collision.Disabled = true; //清除 Ai 拾起标记 RemoveSign(SignNames.AiFindWeaponSign); OnPickUp(master); diff --git a/DungeonShooting_Godot/src/game/role/Role.cs b/DungeonShooting_Godot/src/game/role/Role.cs index 70f1df6..2855d3e 100644 --- a/DungeonShooting_Godot/src/game/role/Role.cs +++ b/DungeonShooting_Godot/src/game/role/Role.cs @@ -226,8 +226,8 @@ //连接互动物体信号 InteractiveArea = GetNode<Area2D>("InteractiveArea"); - InteractiveArea.AreaEntered += _OnPropsEnter; - InteractiveArea.AreaExited += _OnPropsExit; + InteractiveArea.BodyEntered += _OnPropsEnter; + InteractiveArea.BodyExited += _OnPropsExit; } protected override void Process(float delta) @@ -514,7 +514,7 @@ /// 连接信号: InteractiveArea.area_entered /// 与物体碰撞 /// </summary> - private void _OnPropsEnter(Area2D other) + private void _OnPropsEnter(Node2D other) { ActivityObject propObject = other.AsActivityObject(); if (propObject != null) @@ -530,7 +530,7 @@ /// 连接信号: InteractiveArea.area_exited /// 物体离开碰撞区域 /// </summary> - private void _OnPropsExit(Area2D other) + private void _OnPropsExit(Node2D other) { ActivityObject propObject = other.AsActivityObject(); if (propObject != null) diff --git a/DungeonShooting_Godot/src/game/role/enemy/Enemy.cs b/DungeonShooting_Godot/src/game/role/enemy/Enemy.cs index ccbf67d..1389f75 100644 --- a/DungeonShooting_Godot/src/game/role/enemy/Enemy.cs +++ b/DungeonShooting_Godot/src/game/role/enemy/Enemy.cs @@ -28,7 +28,7 @@ /// <summary> /// 公共属性, 在哪个区域找到的目标, 所有该区域下的敌人都会知道目标的位置 /// </summary> - public static AffiliationArea FindTargetAffiliation { get; private set; } + public static HashSet<AffiliationArea> FindTargetAffiliationSet { get; } = new HashSet<AffiliationArea>(); /// <summary> /// 公共属性, 找到的目标的位置, 如果目标在视野内, 则一直更新 @@ -115,8 +115,6 @@ //默认状态 StateController.ChangeState(AiStateEnum.AiNormal); - - NavigationAgent2D.TargetPosition = GameApplication.Instance.RoomManager.Player.GlobalPosition; } public override void _EnterTree() @@ -205,7 +203,7 @@ if (currState == AiStateEnum.AiNormal || currState == AiStateEnum.AiProbe) { //判断是否在同一个房间内 - return Affiliation == FindTargetAffiliation; + return FindTargetAffiliationSet.Contains(Affiliation); } return false; @@ -217,16 +215,20 @@ public static void UpdateEnemiesView() { IsFindTarget = false; + FindTargetAffiliationSet.Clear(); for (var i = 0; i < _enemieList.Count; i++) { var enemy = _enemieList[i]; var state = enemy.StateController.CurrState; if (state == AiStateEnum.AiFollowUp || state == AiStateEnum.AiSurround) //目标在视野内 { - IsFindTarget = true; - FindTargetPosition = Player.Current.GetCenterPosition(); - FindTargetAffiliation = enemy.Affiliation; - break; + if (!IsFindTarget) + { + IsFindTarget = true; + FindTargetPosition = Player.Current.GetCenterPosition(); + FindTargetAffiliationSet.Add(Player.Current.Affiliation); + } + FindTargetAffiliationSet.Add(enemy.Affiliation); } } } diff --git a/DungeonShooting_Godot/src/game/room/RoomManager.cs b/DungeonShooting_Godot/src/game/room/RoomManager.cs index 7f3a31a..0d068e7 100644 --- a/DungeonShooting_Godot/src/game/room/RoomManager.cs +++ b/DungeonShooting_Godot/src/game/room/RoomManager.cs @@ -65,7 +65,7 @@ //门导航区域数据 _roomStaticNavigationList.AddRange(_dungeonTile.GetConnectDoorPolygonData()); //创建过道的归属区域 - CreateAisleAffiliation(aisleData); + //CreateAisleAffiliation(aisleData); //初始化所有房间 _generateDungeon.EachRoom(InitRoom); @@ -85,7 +85,7 @@ // Player.PickUpWeapon(ActivityObject.Create<Weapon>(ActivityIdPrefix.Weapon + "0004")); Player.PickUpWeapon(ActivityObject.Create<Weapon>(ActivityIdPrefix.Weapon + "0003")); - ActivityObject.Create<Gun>(ActivityIdPrefix.Weapon + "0001").PutDown(new Vector2(35, 35), RoomLayerEnum.YSortLayer); + ActivityObject.Create<Gun>(ActivityIdPrefix.Weapon + "0001").PutDown(new Vector2(35, 35), RoomLayerEnum.NormalLayer); //相机跟随玩家 GameCamera.Main.SetFollowTarget(Player); @@ -154,7 +154,7 @@ //创建敌人 foreach (var roomInfoActivityMark in roomInfo.ActivityMarks) { - //roomInfoActivityMark.BeReady(roomInfo); + roomInfoActivityMark.BeReady(roomInfo); } }