diff --git a/prefab/role/Player.tscn b/prefab/role/Player.tscn
index abab257..41d150d 100644
--- a/prefab/role/Player.tscn
+++ b/prefab/role/Player.tscn
@@ -8,3 +8,6 @@
collision_layer = 8
script = ExtResource( 2 )
GunPrefab = ExtResource( 4 )
+
+[node name="AnimatedSprite" parent="." index="0"]
+frame = 3
diff --git a/prefab/weapon/Gun.tscn b/prefab/weapon/Gun.tscn
index 7b63e3f..2acc680 100644
--- a/prefab/weapon/Gun.tscn
+++ b/prefab/weapon/Gun.tscn
@@ -73,12 +73,11 @@
extents = Vector2( 7.8, 3.5 )
[node name="Gun" type="Node2D"]
-z_index = -1
script = ExtResource( 1 )
[node name="GunSprite" type="Sprite" parent="."]
material = SubResource( 9 )
-position = Vector2( 4, -3 )
+position = Vector2( 0.4, -2.6 )
scale = Vector2( 0.8, 0.8 )
texture = SubResource( 8 )
@@ -89,16 +88,16 @@
anims/RESET = SubResource( 4 )
[node name="OriginPoint" type="Position2D" parent="."]
-position = Vector2( 0, -1.5 )
+position = Vector2( -3.60001, -1.1 )
[node name="ShellPoint" type="Position2D" parent="."]
-position = Vector2( 1, -3 )
+position = Vector2( -2.60001, -2.60001 )
[node name="FirePoint" type="Position2D" parent="."]
-position = Vector2( 11, -1.5 )
+position = Vector2( 7.39999, -1.1 )
[node name="Area" type="Area2D" parent="."]
-visible = false
+position = Vector2( -3.60001, 0.399996 )
collision_layer = 4
collision_mask = 0
diff --git a/scene/Room.tscn b/scene/Room.tscn
index 64eb6c2..4ad88d5 100644
--- a/scene/Room.tscn
+++ b/scene/Room.tscn
@@ -22,10 +22,12 @@
smoothing_enabled = true
smoothing_speed = 8.0
-[node name="YSort" type="YSort" parent="."]
+[node name="ObjectRoot" type="Node2D" parent="."]
-[node name="Player" parent="YSort" instance=ExtResource( 1 )]
+[node name="ItemRoot" type="YSort" parent="."]
+
+[node name="Player" parent="ItemRoot" instance=ExtResource( 1 )]
position = Vector2( 196, 128 )
-[node name="RemoteTransform2D" type="RemoteTransform2D" parent="YSort/Player"]
+[node name="RemoteTransform2D" type="RemoteTransform2D" parent="ItemRoot/Player"]
remote_path = NodePath("../../../Camera2D")
diff --git a/src/effect/ThrowNode.cs b/src/effect/ThrowNode.cs
index 2d22955..99aba7c 100644
--- a/src/effect/ThrowNode.cs
+++ b/src/effect/ThrowNode.cs
@@ -60,6 +60,10 @@
///
public Sprite ShadowSprite { get; protected set; }
+ protected Sprite ShadowTarget { get; set; }
+
+ private bool inversionX = false;
+
public override void _Ready()
{
//只与墙壁碰撞
@@ -71,8 +75,6 @@
shape.Extents = Size * 0.5f;
CollisionShape.Shape = shape;
AddChild(CollisionShape);
-
-
}
///
@@ -118,22 +120,31 @@
/// 纵轴速度
/// 旋转速度
/// 需要挂载的节点
- /// 抛射的节点显示的纹理, 用于渲染阴影用
- public void InitThrow(Vector2 size, Vector2 start, float startHeight, float direction, float xSpeed, float ySpeed, float rotate, Node2D mount, Texture texutre)
+ /// 抛射的节点显示的纹理, 用于渲染阴影用
+ public void InitThrow(Vector2 size, Vector2 start, float startHeight, float direction, float xSpeed, float ySpeed, float rotate, Node2D mount, Sprite shadowTarget)
{
InitThrow(size, start, startHeight, direction, xSpeed, ySpeed, rotate, mount);
- if (texutre != null)
+ ShadowTarget = shadowTarget;
+ if (shadowTarget != null)
{
if (ShadowSprite == null)
{
//阴影
ShadowSprite = new Sprite();
- ShadowSprite.ZIndex = -1;
+ ShadowSprite.ZIndex = -5;
ShadowSprite.Material = ResourceManager.ShadowMaterial;
- ShadowSprite.Position = new Vector2(0, 1);
AddChild(ShadowSprite);
}
- ShadowSprite.Texture = texutre;
+ inversionX = mount.Scale.y < 0 ? true : false;
+ if (inversionX)
+ {
+ ShadowSprite.Scale = shadowTarget.Scale * new Vector2(1, -1);
+ }
+ else
+ {
+ ShadowSprite.Scale = shadowTarget.Scale;
+ }
+ ShadowSprite.Texture = shadowTarget.Texture;
}
else if (ShadowSprite != null)
{
@@ -142,9 +153,9 @@
}
///
- /// 初始化时调用
+ /// 达到最高点时调用
///
- protected virtual void OnInit()
+ protected virtual void OnMaxHeight(float height)
{
}
@@ -168,9 +179,17 @@
if (ShadowSprite != null)
{
ShadowSprite.GlobalRotationDegrees = rotate;
+ // ShadowSprite.GlobalRotationDegrees = rotate + (inversionX ? 180 : 0);
+ ShadowSprite.GlobalPosition = ShadowTarget.GlobalPosition + new Vector2(0, 1 - Mount.Position.y);
}
+ var ysp = YSpeed;
YSpeed -= GameConfig.G * delta;
-
+ //达到最高点
+ if (ysp * YSpeed < 0)
+ {
+ OnMaxHeight(-Mount.Position.y);
+ }
+ //落地判断
if (Mount.Position.y >= 0)
{
Mount.Position = new Vector2(0, 0);
diff --git a/src/package/Holster.cs b/src/package/Holster.cs
index c9027ad..1c77cbf 100644
--- a/src/package/Holster.cs
+++ b/src/package/Holster.cs
@@ -113,6 +113,7 @@
ActiveGun = null;
}
}
+ gun._ThrowOutGun();
return gun;
}
diff --git a/src/role/Role.cs b/src/role/Role.cs
index 4bf5f92..689d42b 100644
--- a/src/role/Role.cs
+++ b/src/role/Role.cs
@@ -106,7 +106,25 @@
///
public void ThrowGun()
{
- Holster.RmoveGun(Holster.ActiveIndex);
+ var gun = Holster.RmoveGun(Holster.ActiveIndex);
+ //播放抛出效果
+ if (gun != null)
+ {
+ if (Face == FaceDirection.Left) {
+ gun.Scale *= new Vector2(1, -1);
+ gun.RotationDegrees = 180;
+ }
+ gun.Position = Vector2.Zero;
+ var temp = new ThrowGun();
+ var startPos = GlobalPosition + new Vector2(0, 0);
+ var startHeight = 6;
+ var direction = GlobalRotationDegrees + MathUtils.RandRangeInt(-20, 20);
+ var xf = 30;
+ var yf = MathUtils.RandRangeInt(60, 120);
+ var rotate = MathUtils.RandRangeInt(-180, 180);
+ temp.InitThrow(new Vector2(16, 7), startPos, startHeight, direction, xf, yf, rotate, gun, gun.GunSprite);
+ RoomManager.Current.ObjectRoot.AddChild(temp);
+ }
}
private void SetFace(FaceDirection face)
diff --git a/src/room/RoomManager.cs b/src/room/RoomManager.cs
index 30d1d59..c9ffbb4 100644
--- a/src/room/RoomManager.cs
+++ b/src/room/RoomManager.cs
@@ -17,6 +17,7 @@
public CanvasLayer UI;
public Cursor Cursor { get; private set; }
public Player Player { get; set; }
+ public Node2D ObjectRoot { get; private set; }
public YSort ItemRoot { get; private set; }
public override void _EnterTree()
@@ -27,17 +28,13 @@
Cursor = MouseCursor.Instance();
AddChild(Cursor);
- ItemRoot = GetNode("YSort");
+ ItemRoot = GetNode("ItemRoot");
+ ObjectRoot = GetNode("ObjectRoot");
//初始化地图
var node = GetNode("MapRoot").GetChild(0).GetNode("Config");
Color color = (Color) node.GetMeta("ClearColor");
VisualServer.SetDefaultClearColor(color);
-
-
- var gun = GunManager.GetGun2();
- gun.Position = new Vector2(100, 100);
- ItemRoot.AddChild(gun);
}
public override void _Process(float delta)
diff --git a/src/weapon/gun/Gun.cs b/src/weapon/gun/Gun.cs
index 373b9ef..bca287e 100644
--- a/src/weapon/gun/Gun.cs
+++ b/src/weapon/gun/Gun.cs
@@ -95,7 +95,7 @@
{
if (Master == null) //这把武器被扔在地上
{
-
+
}
else if (Master.Holster.ActiveGun != this) //当前武器没有被使用
{
@@ -189,11 +189,10 @@
Attribute = attribute;
//更新图片
GunSprite.Texture = attribute.Sprite;
+ GunSprite.Position = Attribute.CenterPosition;
//开火位置
FirePoint.Position = new Vector2(attribute.FirePosition.x, -attribute.FirePosition.y);
OriginPoint.Position = new Vector2(0, -attribute.FirePosition.y);
- //握把位置
- GunSprite.Position = attribute.HoldPosition;
Init();
}
@@ -360,7 +359,10 @@
{
Master = master;
_state = 1;
+ //握把位置
+ GunSprite.Position = Attribute.HoldPosition;
AnimationPlayer.Play("RESET");
+ ZIndex = 0;
OnPickUp(master);
}
@@ -368,6 +370,7 @@
{
Master = null;
_state = 0;
+ GunSprite.Position = Attribute.CenterPosition;
AnimationPlayer.Play("Floodlight");
OnThrowOut();
}
diff --git a/src/weapon/gun/GunAttribute.cs b/src/weapon/gun/GunAttribute.cs
index 5e5147b..c5195f6 100644
--- a/src/weapon/gun/GunAttribute.cs
+++ b/src/weapon/gun/GunAttribute.cs
@@ -102,6 +102,10 @@
///
public float MinDistance = 800;
///
+ /// 武器精灵的旋转中心坐标
+ ///
+ public Vector2 CenterPosition = new Vector2(0, 0);
+ ///
/// 开火位置
///
public Vector2 FirePosition = new Vector2(11, 0);
diff --git a/src/weapon/gun/GunManager.cs b/src/weapon/gun/GunManager.cs
index c0a19a1..c690018 100644
--- a/src/weapon/gun/GunManager.cs
+++ b/src/weapon/gun/GunManager.cs
@@ -12,6 +12,8 @@
var attr = new GunAttribute();
attr.Id = "1";
attr.Name = "Gun1";
+ attr.Weight = 40;
+ attr.CenterPosition = new Vector2(0.4f, -2.6f);
attr.StartFiringSpeed = 480;
attr.StartScatteringRange = 30;
attr.FinalScatteringRange = 90;
@@ -51,6 +53,8 @@
var attr = new GunAttribute();
attr.Id = "2";
attr.Name = "Gun2";
+ attr.Weight = 20;
+ attr.CenterPosition = new Vector2(0.4f, -2.6f);
attr.WeightType = GunWeightType.DeputyWeapon;
attr.StartFiringSpeed = 600;
attr.StartScatteringRange = 5;
@@ -91,6 +95,8 @@
var attr = new GunAttribute();
attr.Id = "3";
attr.Name = "Gun3";
+ attr.Weight = 30;
+ attr.CenterPosition = new Vector2(0.4f, -2.6f);
attr.StartFiringSpeed = 480;
attr.StartScatteringRange = 30;
attr.FinalScatteringRange = 90;
@@ -130,6 +136,8 @@
var attr = new GunAttribute();
attr.Id = "4";
attr.Name = "Gun4";
+ attr.Weight = 10;
+ attr.CenterPosition = new Vector2(0.4f, -2.6f);
attr.WeightType = GunWeightType.DeputyWeapon;
attr.StartFiringSpeed = 600;
attr.StartScatteringRange = 5;
diff --git a/src/weapon/gun/OrdinaryGun.cs b/src/weapon/gun/OrdinaryGun.cs
index 1934940..7423f0b 100644
--- a/src/weapon/gun/OrdinaryGun.cs
+++ b/src/weapon/gun/OrdinaryGun.cs
@@ -15,7 +15,7 @@
protected override void Fire()
{
//创建一个弹壳
- var temp = new Shell();
+ var temp = new ThrowShell();
var startPos = GlobalPosition + new Vector2(0, 5);
var startHeight = 6;
var direction = GlobalRotationDegrees + MathUtils.RandRangeInt(-30, 30) + 180;
@@ -23,8 +23,8 @@
var yf = MathUtils.RandRangeInt(60, 120);
var rotate = MathUtils.RandRangeInt(-720, 720);
var sprite = Attribute.ShellPack.Instance();
- temp.InitThrow(new Vector2(5, 10), startPos, startHeight, direction, xf, yf, rotate, sprite, sprite.Texture);
- RoomManager.Current.ItemRoot.AddChild(temp);
+ temp.InitThrow(new Vector2(5, 10), startPos, startHeight, direction, xf, yf, rotate, sprite, sprite);
+ RoomManager.Current.ObjectRoot.AddChild(temp);
}
protected override void ShootBullet()
diff --git a/src/weapon/gun/ThrowGun.cs b/src/weapon/gun/ThrowGun.cs
new file mode 100644
index 0000000..64e4c35
--- /dev/null
+++ b/src/weapon/gun/ThrowGun.cs
@@ -0,0 +1,25 @@
+using Godot;
+
+public class ThrowGun : ThrowNode
+{
+
+ public override void _Ready()
+ {
+ base._Ready();
+ ZIndex = 2;
+ }
+
+ protected override void OnOver()
+ {
+ //如果落地高度不够低, 再抛一次
+ if (StartYSpeed > 1)
+ {
+ InitThrow(Size, GlobalPosition, 0, Direction, XSpeed * 0.8f, StartYSpeed * 0.5f, RotateSpeed * 0.5f, null);
+ }
+ }
+
+ protected override void OnMaxHeight(float height)
+ {
+ ZIndex = 0;
+ }
+}
\ No newline at end of file
diff --git a/src/weapon/shell/Shell.cs b/src/weapon/shell/Shell.cs
deleted file mode 100644
index fb6afde..0000000
--- a/src/weapon/shell/Shell.cs
+++ /dev/null
@@ -1,34 +0,0 @@
-using Godot;
-
-///
-/// 弹壳
-///
-public class Shell : ThrowNode
-{
- protected override void OnInit()
- {
-
- }
-
- protected override void OnOver()
- {
- //如果落地高度不够低, 再抛一次
- if (StartYSpeed > 1)
- {
- InitThrow(Size, GlobalPosition, 0, Direction, XSpeed * 0.8f, StartYSpeed * 0.5f, RotateSpeed * 0.5f, null);
- }
- else
- {
- //等待被销毁
- AwaitDestroy();
- }
- }
-
- private async void AwaitDestroy()
- {
- CollisionShape.Disabled = true;
- //20秒后销毁
- await ToSignal(GetTree().CreateTimer(20), "timeout");
- QueueFree();
- }
-}
\ No newline at end of file
diff --git a/src/weapon/shell/ThrowShell.cs b/src/weapon/shell/ThrowShell.cs
new file mode 100644
index 0000000..2320cfe
--- /dev/null
+++ b/src/weapon/shell/ThrowShell.cs
@@ -0,0 +1,41 @@
+using Godot;
+
+///
+/// 弹壳
+///
+public class ThrowShell : ThrowNode
+{
+
+ public override void _Ready()
+ {
+ base._Ready();
+ ZIndex = 2;
+ }
+
+ protected override void OnOver()
+ {
+ //如果落地高度不够低, 再抛一次
+ if (StartYSpeed > 1)
+ {
+ InitThrow(Size, GlobalPosition, 0, Direction, XSpeed * 0.8f, StartYSpeed * 0.5f, RotateSpeed * 0.5f, null);
+ }
+ else
+ {
+ //等待被销毁
+ AwaitDestroy();
+ }
+ }
+
+ private async void AwaitDestroy()
+ {
+ CollisionShape.Disabled = true;
+ //60秒后销毁
+ await ToSignal(GetTree().CreateTimer(60), "timeout");
+ QueueFree();
+ }
+
+ protected override void OnMaxHeight(float height)
+ {
+ ZIndex = 0;
+ }
+}
\ No newline at end of file