diff --git a/DungeonShooting_Godot/prefab/weapon/Weapon0001.tscn b/DungeonShooting_Godot/prefab/weapon/Weapon0001.tscn index c140971..c4030a2 100644 --- a/DungeonShooting_Godot/prefab/weapon/Weapon0001.tscn +++ b/DungeonShooting_Godot/prefab/weapon/Weapon0001.tscn @@ -1,11 +1,10 @@ [gd_scene load_steps=7 format=3 uid="uid://c6etppq4v63xw"] [ext_resource type="PackedScene" uid="uid://cxltmhhp4rbyk" path="res://prefab/weapon/WeaponTemplate.tscn" id="1_0nysf"] -[ext_resource type="Script" path="res://src/game/activity/weapon/gun/Gun.cs" id="2_bd6qw"] +[ext_resource type="Script" path="res://src/game/activity/weapon/gun/Gun.cs" id="2_28mkv"] [ext_resource type="Shader" path="res://resource/material/Blend.gdshader" id="3_ksckd"] [ext_resource type="SpriteFrames" uid="uid://5m0qs7m4er5u" path="res://resource/spriteFrames/Weapon0001.tres" id="4_xo84l"] - [sub_resource type="ShaderMaterial" id="ShaderMaterial_5bfqf"] resource_local_to_scene = true shader = ExtResource("3_ksckd") @@ -18,10 +17,11 @@ shader_parameter/blend = Color(1, 1, 1, 1) shader_parameter/schedule = 0 -[node name="Weapon0001" node_paths=PackedStringArray("FirePoint", "ShellPoint", "AnimationPlayer", "ShadowSprite", "AnimatedSprite", "Collision") instance=ExtResource("1_0nysf")] -script = ExtResource("2_bd6qw") -FirePoint = NodePath("FirePoint") -ShellPoint = NodePath("ShellPoint") +[node name="Weapon0001" node_paths=PackedStringArray("FirePoint", "ShellPoint", "GripPoint", "AnimationPlayer", "ShadowSprite", "AnimatedSprite", "Collision") instance=ExtResource("1_0nysf")] +script = ExtResource("2_28mkv") +FirePoint = NodePath("AnimatedSprite/FirePoint") +ShellPoint = NodePath("AnimatedSprite/ShellPoint") +GripPoint = NodePath("GripPoint") AnimationPlayer = NodePath("AnimationPlayer") ShadowSprite = NodePath("ShadowSprite") AnimatedSprite = NodePath("AnimatedSprite") @@ -32,14 +32,13 @@ [node name="AnimatedSprite" parent="." index="1"] material = SubResource("ShaderMaterial_bj7y3") -position = Vector2(4, 1) sprite_frames = ExtResource("4_xo84l") -[node name="ShellPoint" parent="." index="2"] -position = Vector2(5.5, -2.5) +[node name="ShellPoint" parent="AnimatedSprite" index="0"] +position = Vector2(1.5, -3.5) -[node name="FirePoint" parent="." index="3"] -position = Vector2(18, -1) +[node name="FirePoint" parent="AnimatedSprite" index="1"] +position = Vector2(14, -2) -[node name="Collision" parent="." index="4"] -position = Vector2(4, 0) +[node name="GripPoint" parent="." index="2"] +position = Vector2(-5, -1) diff --git a/DungeonShooting_Godot/prefab/weapon/WeaponTemplate.tscn b/DungeonShooting_Godot/prefab/weapon/WeaponTemplate.tscn index 0f34e3a..6af9687 100644 --- a/DungeonShooting_Godot/prefab/weapon/WeaponTemplate.tscn +++ b/DungeonShooting_Godot/prefab/weapon/WeaponTemplate.tscn @@ -1,16 +1,16 @@ [gd_scene load_steps=8 format=3 uid="uid://cxltmhhp4rbyk"] -[ext_resource type="Shader" path="res://resource/material/Blend.gdshader" id="1_xa8r2"] +[ext_resource type="Shader" path="res://resource/material/Blend.gdshader" id="1_3p8rg"] [sub_resource type="ShaderMaterial" id="ShaderMaterial_cbiyh"] resource_local_to_scene = true -shader = ExtResource("1_xa8r2") +shader = ExtResource("1_3p8rg") shader_parameter/blend = Color(0, 0, 0, 0.470588) shader_parameter/schedule = 1 [sub_resource type="ShaderMaterial" id="ShaderMaterial_o36tv"] resource_local_to_scene = true -shader = ExtResource("1_xa8r2") +shader = ExtResource("1_3p8rg") shader_parameter/blend = Color(1, 1, 1, 1) shader_parameter/schedule = 0 @@ -65,12 +65,14 @@ [node name="AnimatedSprite" type="AnimatedSprite2D" parent="."] material = SubResource("ShaderMaterial_o36tv") -[node name="ShellPoint" type="Marker2D" parent="."] +[node name="ShellPoint" type="Marker2D" parent="AnimatedSprite"] position = Vector2(0, -2) -[node name="FirePoint" type="Marker2D" parent="."] +[node name="FirePoint" type="Marker2D" parent="AnimatedSprite"] position = Vector2(10, -2) +[node name="GripPoint" type="Marker2D" parent="."] + [node name="Collision" type="CollisionShape2D" parent="."] shape = SubResource("RectangleShape2D_3p5jk") diff --git a/DungeonShooting_Godot/resource/sprite/role/enemy0001/enemy0001.png.import b/DungeonShooting_Godot/resource/sprite/role/enemy0001/enemy0001.png.import index b20c9a6..c36be94 100644 --- a/DungeonShooting_Godot/resource/sprite/role/enemy0001/enemy0001.png.import +++ b/DungeonShooting_Godot/resource/sprite/role/enemy0001/enemy0001.png.import @@ -3,15 +3,15 @@ importer="texture" type="CompressedTexture2D" uid="uid://chd2vtesap5cf" -path="res://.godot/imported/enemy0001.png-1247a3ddf8a1a163d812cad12c4340fd.ctex" +path="res://.godot/imported/Enemy0001.png-148a38dfa95953b26d890356e8875de4.ctex" metadata={ "vram_texture": false } [deps] -source_file="res://resource/sprite/role/enemy0001/enemy0001.png" -dest_files=["res://.godot/imported/enemy0001.png-1247a3ddf8a1a163d812cad12c4340fd.ctex"] +source_file="res://resource/sprite/role/enemy0001/Enemy0001.png" +dest_files=["res://.godot/imported/Enemy0001.png-148a38dfa95953b26d890356e8875de4.ctex"] [params] diff --git a/DungeonShooting_Godot/resource/sprite/role/enemy0001/enemy0001_Debris.png.import b/DungeonShooting_Godot/resource/sprite/role/enemy0001/enemy0001_Debris.png.import index 56388a2..d563acf 100644 --- a/DungeonShooting_Godot/resource/sprite/role/enemy0001/enemy0001_Debris.png.import +++ b/DungeonShooting_Godot/resource/sprite/role/enemy0001/enemy0001_Debris.png.import @@ -3,15 +3,15 @@ importer="texture" type="CompressedTexture2D" uid="uid://d2f55lu60x64i" -path="res://.godot/imported/enemy0001_Debris.png-297a2fb6680cb862a9a085cf58f8268c.ctex" +path="res://.godot/imported/Enemy0001_Debris.png-ac416dc79cd3c1217b27e1ef1fbe0d0b.ctex" metadata={ "vram_texture": false } [deps] -source_file="res://resource/sprite/role/enemy0001/enemy0001_Debris.png" -dest_files=["res://.godot/imported/enemy0001_Debris.png-297a2fb6680cb862a9a085cf58f8268c.ctex"] +source_file="res://resource/sprite/role/enemy0001/Enemy0001_Debris.png" +dest_files=["res://.godot/imported/Enemy0001_Debris.png-ac416dc79cd3c1217b27e1ef1fbe0d0b.ctex"] [params] diff --git a/DungeonShooting_Godot/src/framework/activity/ActivityObject.cs b/DungeonShooting_Godot/src/framework/activity/ActivityObject.cs index ea4dfc8..d6306be 100644 --- a/DungeonShooting_Godot/src/framework/activity/ActivityObject.cs +++ b/DungeonShooting_Godot/src/framework/activity/ActivityObject.cs @@ -25,6 +25,7 @@ /// /// 是否是静态物体, 如果为true, 则会禁用移动处理 /// + [Export] public bool IsStatic { get; set; } /// @@ -153,10 +154,11 @@ /// 物体下坠回弹后的运动速度衰减量 /// public float BounceSpeed { get; set; } = 0.75f; - + /// /// 投抛状态下物体碰撞器大小, 如果 (x, y) 都小于 0, 则默认使用 AnimatedSprite 的默认动画第一帧的大小 /// + [Export] public Vector2 ThrowCollisionSize { get; set; } = new Vector2(-1, -1); /// @@ -277,6 +279,7 @@ ShadowSprite.Visible = false; MotionMode = MotionModeEnum.Floating; MoveController = AddComponent(); + MoveController.Enable = !IsStatic; OnInit(); } @@ -778,12 +781,16 @@ } else //只更新 MoveController 组件 { - if (!MoveController.IsReady) + if (MoveController.Enable) { - MoveController.Ready(); - MoveController.IsReady = true; + if (!MoveController.IsReady) + { + MoveController.Ready(); + MoveController.IsReady = true; + } + + MoveController.Process(newDelta); } - MoveController.Process(newDelta); } } @@ -972,12 +979,16 @@ } else //只更新 MoveController 组件 { - if (!MoveController.IsReady) + if (MoveController.Enable) { - MoveController.Ready(); - MoveController.IsReady = true; + if (!MoveController.IsReady) + { + MoveController.Ready(); + MoveController.IsReady = true; + } + + MoveController.PhysicsProcess(newDelta); } - MoveController.PhysicsProcess(newDelta); } } @@ -1138,7 +1149,7 @@ { _throwRectangleShape = new RectangleShape2D(); } - + Collision.Shape = _throwRectangleShape; Collision.Position = Vector2.Zero; Collision.Rotation = 0; diff --git a/DungeonShooting_Godot/src/framework/activity/ActivityObject_EditorTool.cs b/DungeonShooting_Godot/src/framework/activity/ActivityObject_EditorTool.cs index e005b7f..f20d17c 100644 --- a/DungeonShooting_Godot/src/framework/activity/ActivityObject_EditorTool.cs +++ b/DungeonShooting_Godot/src/framework/activity/ActivityObject_EditorTool.cs @@ -129,7 +129,7 @@ var value = propertyInfo.GetValue(this); if (value == null || ((Node)value).GetParent() == null) { - var node = GetNodeOrNull(propertyInfo.Name); + var node = _FindNodeInChild(this, propertyInfo.Name, propertyInfo.PropertyType); if (node == null) { node = (Node)Activator.CreateInstance(propertyInfo.PropertyType); @@ -144,4 +144,27 @@ } } } + + private Node _FindNodeInChild(Node node, string name, Type type) + { + var childCount = node.GetChildCount(); + for (int i = 0; i < childCount; i++) + { + var child = node.GetChild(i); + if (child.Name == name && child.GetType().IsAssignableTo(type)) + { + return child; + } + else + { + var result = _FindNodeInChild(child, name, type); + if (result != null) + { + return result; + } + } + } + + return null; + } } \ No newline at end of file diff --git a/DungeonShooting_Godot/src/game/GameApplication.cs b/DungeonShooting_Godot/src/game/GameApplication.cs index 1fc0257..2b2490b 100644 --- a/DungeonShooting_Godot/src/game/GameApplication.cs +++ b/DungeonShooting_Godot/src/game/GameApplication.cs @@ -111,7 +111,7 @@ Engine.MaxFps = 60; //调试绘制开关 ActivityObject.IsDebug = Debug; - //Engine.TimeScale = 0.4f; + //Engine.TimeScale = 0.2f; //窗体大小改变 GetWindow().SizeChanged += OnWindowSizeChanged; diff --git a/DungeonShooting_Godot/src/game/activity/weapon/Weapon.cs b/DungeonShooting_Godot/src/game/activity/weapon/Weapon.cs index 6122436..82567d9 100644 --- a/DungeonShooting_Godot/src/game/activity/weapon/Weapon.cs +++ b/DungeonShooting_Godot/src/game/activity/weapon/Weapon.cs @@ -54,6 +54,12 @@ public Marker2D ShellPoint { get; set; } /// + /// 武器握把位置 + /// + [Export, ExportFillNode] + public Marker2D GripPoint { get; set; } + + /// /// 武器的当前散射半径 /// public float CurrScatteringRange { get; private set; } = 0; @@ -159,6 +165,9 @@ //当前后坐力导致的偏移长度 private float _currBacklashLength = 0; + + //临时存放动画精灵位置 + private Vector2 _tempAnimatedSpritePosition; // ---------------------------------------------- private uint _tempLayer; @@ -180,7 +189,7 @@ _init = true; foreach (var weaponAttr in ExcelConfig.Weapon_List) { - if (string.IsNullOrEmpty(weaponAttr.WeaponId)) + if (!string.IsNullOrEmpty(weaponAttr.WeaponId)) { if (!_weaponAttributeMap.TryAdd(weaponAttr.WeaponId, weaponAttr)) { @@ -220,8 +229,6 @@ { _aiWeaponAttribute = attribute; } - //未完成 - //AnimatedSprite.Position = Attribute.ThrowSpritePosition; if (Attribute.AmmoCapacity > Attribute.MaxAmmoCapacity) { @@ -339,7 +346,6 @@ protected override void Process(float delta) { - //GD.Print("AnimatedSprite: " + AnimatedSprite.Position); //这把武器被扔在地上, 或者当前武器没有被使用 if (Master == null || Master.Holster.ActiveWeapon != this) { @@ -1055,14 +1061,15 @@ Scale *= new Vector2(1, -1); } - var angle = master.MountPoint.GlobalRotationDegrees; - GlobalRotationDegrees = angle; + var rotation = master.MountPoint.GlobalRotation; + GlobalRotation = rotation; //继承role的移动速度 InheritVelocity(master); + startPosition -= GripPoint.Position.Rotated(rotation); var startHeight = -master.MountPoint.Position.Y; - var direction = angle + Utils.RandomRangeInt(-20, 20); + var direction = Mathf.RadToDeg(rotation) + Utils.RandomRangeInt(-20, 20); var velocity = new Vector2(20, 0).Rotated(direction * Mathf.Pi / 180); var yf = Utils.RandomRangeInt(50, 70); var rotate = Utils.RandomRangeInt(-60, 60); @@ -1104,6 +1111,10 @@ ZIndex = 0; //禁用碰撞 //Collision.Disabled = true; + //精灵位置 + _tempAnimatedSpritePosition = AnimatedSprite.Position; + var position = GripPoint.Position; + AnimatedSprite.Position = new Vector2(-position.X, -position.Y); //修改层级 _tempLayer = CollisionLayer; CollisionLayer = PhysicsLayer.InHand; @@ -1120,8 +1131,7 @@ Master = null; CollisionLayer = _tempLayer; _weaponAttribute = _playerWeaponAttribute; - //未完成 - //AnimatedSprite.Position = Attribute.ThrowSpritePosition; + AnimatedSprite.Position = _tempAnimatedSpritePosition; //清除 Ai 拾起标记 RemoveSign(SignNames.AiFindWeaponSign); OnRemove();