diff --git a/prefab/common/ThrowNode.tscn b/prefab/common/ThrowNode.tscn deleted file mode 100644 index a35c9a7..0000000 --- a/prefab/common/ThrowNode.tscn +++ /dev/null @@ -1,12 +0,0 @@ -[gd_scene load_steps=3 format=2] - -[ext_resource path="res://icon.png" type="Texture" id=1] -[ext_resource path="res://src/weapon/ThrowNode.cs" type="Script" id=2] - -[node name="ThrowNode" type="Node2D"] -position = Vector2( 140, 141 ) -script = ExtResource( 2 ) - -[node name="Icon" type="Sprite" parent="."] -scale = Vector2( 0.3, 0.3 ) -texture = ExtResource( 1 ) diff --git a/prefab/shell/ShellCase.tscn b/prefab/shell/ShellCase.tscn new file mode 100644 index 0000000..8741487 --- /dev/null +++ b/prefab/shell/ShellCase.tscn @@ -0,0 +1,6 @@ +[gd_scene load_steps=2 format=2] + +[ext_resource path="res://resource/sprite/shell/shellCase.png" type="Texture" id=1] + +[node name="ShellCase" type="Sprite"] +texture = ExtResource( 1 ) diff --git a/prefab/weapon/Gun.tscn b/prefab/weapon/Gun.tscn index 3bbecf2..eec577f 100644 --- a/prefab/weapon/Gun.tscn +++ b/prefab/weapon/Gun.tscn @@ -1,8 +1,9 @@ -[gd_scene load_steps=5 format=2] +[gd_scene load_steps=6 format=2] [ext_resource path="res://src/weapon/gun/OrdinaryGun.cs" type="Script" id=1] [ext_resource path="res://prefab/weapon/bullet/OrdinaryBullets.tscn" type="PackedScene" id=2] [ext_resource path="res://resource/sprite/gun/gun1.png" type="Texture" id=3] +[ext_resource path="res://prefab/shell/ShellCase.tscn" type="PackedScene" id=4] [sub_resource type="RectangleShape2D" id=1] extents = Vector2( 9.5, 3.5 ) @@ -11,6 +12,7 @@ z_index = 5 script = ExtResource( 1 ) bulletPacked = ExtResource( 2 ) +shell = ExtResource( 4 ) [node name="GunSprite" type="Sprite" parent="."] position = Vector2( 4, -3 ) diff --git a/resource/sprite/shell/shellCase.aseprite b/resource/sprite/shell/shellCase.aseprite new file mode 100644 index 0000000..b24b3c9 --- /dev/null +++ b/resource/sprite/shell/shellCase.aseprite Binary files differ diff --git a/resource/sprite/shell/shellCase.png b/resource/sprite/shell/shellCase.png new file mode 100644 index 0000000..390aef4 --- /dev/null +++ b/resource/sprite/shell/shellCase.png Binary files differ diff --git a/resource/sprite/shell/shellCase.png.import b/resource/sprite/shell/shellCase.png.import new file mode 100644 index 0000000..b4b5232 --- /dev/null +++ b/resource/sprite/shell/shellCase.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/shellCase.png-4975fbe4d212e558e86355116ac96ab2.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://resource/sprite/shell/shellCase.png" +dest_files=[ "res://.import/shellCase.png-4975fbe4d212e558e86355116ac96ab2.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=false +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +process/normal_map_invert_y=false +stream=false +size_limit=0 +detect_3d=false +svg/scale=1.0 diff --git a/scene/Room.tscn b/scene/Room.tscn index 5900efa..7223c4d 100644 --- a/scene/Room.tscn +++ b/scene/Room.tscn @@ -1,16 +1,14 @@ -[gd_scene load_steps=6 format=2] +[gd_scene load_steps=5 format=2] [ext_resource path="res://prefab/role/Player.tscn" type="PackedScene" id=1] [ext_resource path="res://resource/map/dungeon_test.tmx" type="PackedScene" id=2] [ext_resource path="res://src/room/RoomManager.cs" type="Script" id=3] [ext_resource path="res://prefab/ui/Cursor.tscn" type="PackedScene" id=4] -[ext_resource path="res://prefab/common/ThrowNode.tscn" type="PackedScene" id=5] [node name="Room" type="Node2D"] script = ExtResource( 3 ) MouseCursor = ExtResource( 4 ) UIPath = NodePath("") -ThrowNode = ExtResource( 5 ) [node name="MapRoot" type="Node2D" parent="."] @@ -23,8 +21,10 @@ smoothing_enabled = true smoothing_speed = 8.0 -[node name="Player" parent="." instance=ExtResource( 1 )] +[node name="YSort" type="YSort" parent="."] + +[node name="Player" parent="YSort" instance=ExtResource( 1 )] position = Vector2( 196, 128 ) -[node name="RemoteTransform2D" type="RemoteTransform2D" parent="Player"] -remote_path = NodePath("../../Camera2D") +[node name="RemoteTransform2D" type="RemoteTransform2D" parent="YSort/Player"] +remote_path = NodePath("../../../Camera2D") diff --git a/src/GameConfig.cs b/src/GameConfig.cs index f1fa592..3b94e9d 100644 --- a/src/GameConfig.cs +++ b/src/GameConfig.cs @@ -2,7 +2,11 @@ public static class GameConfig { /// - /// + /// 散射计算的默认距离 /// public static readonly float ScatteringDistance = 300; + /// + /// 重力加速度 + /// + public static readonly float G = 200f; } \ No newline at end of file diff --git a/src/common/CommonNodeManager.cs b/src/common/CommonNodeManager.cs index 6d0f516..83c1c90 100644 --- a/src/common/CommonNodeManager.cs +++ b/src/common/CommonNodeManager.cs @@ -2,10 +2,5 @@ public static class CommonNodeManager { - public const string ThrowNodeResPath = ""; - public static ThrowNode CreateThrowNode(Vector2 start, Vector2 target, float startHeight, float targetHeight, float moveSpeed, float rotationSpeed) - { - return null; - } } \ No newline at end of file diff --git a/src/manager/GameManager.cs b/src/manager/GameManager.cs index 24462e8..29d3962 100644 --- a/src/manager/GameManager.cs +++ b/src/manager/GameManager.cs @@ -5,5 +5,9 @@ /// public class GameManager : Node2D { - + public static GameManager Instance { get; private set; } + public GameManager() + { + GameManager.Instance = this; + } } \ No newline at end of file diff --git a/src/room/RoomManager.cs b/src/room/RoomManager.cs index 4896dad..f27f508 100644 --- a/src/room/RoomManager.cs +++ b/src/room/RoomManager.cs @@ -12,12 +12,11 @@ [Export] public NodePath UIPath; - [Export] public PackedScene ThrowNode; - public static RoomManager Current { get; private set; } public CanvasLayer UI; public Cursor Cursor { get; private set; } + public YSort ItemRoot { get; private set; } public override void _EnterTree() { @@ -27,10 +26,13 @@ Cursor = MouseCursor.Instance(); AddChild(Cursor); + ItemRoot = GetNode("YSort"); + //初始化地图 var node = GetNode("MapRoot").GetChild(0).GetNode("Config"); Color color = (Color) node.GetMeta("ClearColor"); VisualServer.SetDefaultClearColor(color); + } public override void _Draw() diff --git a/src/weapon/ThrowNode.cs b/src/weapon/ThrowNode.cs index 17a2e87..718f8ad 100644 --- a/src/weapon/ThrowNode.cs +++ b/src/weapon/ThrowNode.cs @@ -6,42 +6,44 @@ /// public class ThrowNode : Node2D { - public float MaxHeight = 30; - public float TargetHeight = 0; - public float StartHeight = 0; + public bool IsOver { get; protected set; } = true; - public Vector2 StartPos; - public Vector2 TargetPos = new Vector2(120, 100); - public Vector2 RealPosition = Vector2.Zero; + private Vector2 StartPosition; + private float Direction; + private Vector2 Velocity; + private Node2D Mount; - - public override void _Ready() + public void InitThrow(Vector2 start, float direction, Vector2 velocity, Node2D mount) { - StartPos = GlobalPosition; - RealPosition = StartPos; + IsOver = false; + GlobalPosition = StartPosition = start; + Direction = direction; + Velocity = velocity; + + Mount = mount; + AddChild(mount); + mount.Position = Vector2.Zero; + } + + protected virtual void OnOver() + { + } public override void _Process(float delta) { - if (RealPosition.DistanceSquaredTo(TargetPos) > 1) + if (!IsOver) { - float v = (StartPos.DistanceTo(RealPosition)) / (StartPos.DistanceTo(TargetPos)); - float progress = Mathf.Sin(v * Mathf.Pi); + Position += new Vector2(Velocity.x * delta, 0).Rotated(Direction * Mathf.Pi / 180); + Mount.Position = new Vector2(0, Mount.Position.y + Velocity.y * delta); + Velocity.y += GameConfig.G * delta; - float y = 0; - if (v <= 0.5f) + if (Mount.Position.y >= 0) { - y = Mathf.Lerp(StartHeight, MaxHeight, progress); + Mount.Position = new Vector2(0, 0); + IsOver = true; } - else - { - y = Mathf.Lerp(TargetHeight, MaxHeight, progress); - } - - RealPosition = RealPosition.MoveToward(TargetPos, 100 * delta); - GlobalPosition = RealPosition - new Vector2(0, y); } - } } \ No newline at end of file diff --git a/src/weapon/gun/Gun.cs b/src/weapon/gun/Gun.cs index a511109..74303f0 100644 --- a/src/weapon/gun/Gun.cs +++ b/src/weapon/gun/Gun.cs @@ -37,6 +37,12 @@ /// 枪攻击的目标阵营 /// public CampEnum TargetCamp { get; set; } + + /// + /// 该武器的拥有者 + /// + public Node2D Master { get; } + /// /// 枪管的开火点 /// @@ -322,7 +328,7 @@ bullet.GlobalRotation = globalRotation; if (parent == null) { - GetTree().CurrentScene.AddChild(bullet); + RoomManager.Current.ItemRoot.AddChild(bullet); } else { diff --git a/src/weapon/gun/OrdinaryGun.cs b/src/weapon/gun/OrdinaryGun.cs index 1bb47c5..352d95b 100644 --- a/src/weapon/gun/OrdinaryGun.cs +++ b/src/weapon/gun/OrdinaryGun.cs @@ -9,6 +9,8 @@ [Export] public PackedScene bulletPacked; + [Export] public PackedScene shell; + protected override void Init() { @@ -16,7 +18,10 @@ protected override void Fire() { - + //创建一个弹壳 + var temp = new ThrowNode(); + temp.InitThrow(GlobalPosition, 30, new Vector2(30, -100), shell.Instance()); + RoomManager.Current.ItemRoot.AddChild(temp); } protected override void ShootBullet()