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/role/Role.tscn b/prefab/role/Role.tscn
index 5c6d122..9dbcbfe 100644
--- a/prefab/role/Role.tscn
+++ b/prefab/role/Role.tscn
@@ -85,7 +85,7 @@
position = Vector2( 0, -12 )
frames = SubResource( 6 )
animation = "idle"
-frame = 3
+frame = 1
playing = true
[node name="HitArea" type="Area2D" parent="."]
diff --git a/prefab/weapon/Gun.tscn b/prefab/weapon/Gun.tscn
index b0d38ca..2acc680 100644
--- a/prefab/weapon/Gun.tscn
+++ b/prefab/weapon/Gun.tscn
@@ -1,14 +1,74 @@
-[gd_scene load_steps=6 format=2]
+[gd_scene load_steps=8 format=2]
[ext_resource path="res://src/weapon/gun/OrdinaryGun.cs" type="Script" id=1]
[ext_resource path="res://resource/materlal/Shadow.gdshader" type="Shader" id=2]
-[ext_resource path="res://resource/sprite/gun/gun1.png" type="Texture" id=3]
-[sub_resource type="ShaderMaterial" id=2]
+[sub_resource type="ShaderMaterial" id=9]
+resource_local_to_scene = true
shader = ExtResource( 2 )
shader_param/shadowColor = Color( 1, 1, 1, 1 )
shader_param/schedule = 0.0
+[sub_resource type="StreamTexture" id=8]
+load_path = "res://.import/gun1.png-f7bc3e27b4b477d47c7353ffb91687ea.stex"
+
+[sub_resource type="Animation" id=3]
+resource_name = "Floodlight"
+length = 3.0
+loop = true
+step = 0.5
+tracks/0/type = "value"
+tracks/0/path = NodePath("GunSprite:material:shader_param/shadowColor")
+tracks/0/interp = 1
+tracks/0/loop_wrap = true
+tracks/0/imported = false
+tracks/0/enabled = true
+tracks/0/keys = {
+"times": PoolRealArray( 0 ),
+"transitions": PoolRealArray( 1 ),
+"update": 0,
+"values": [ Color( 1, 1, 1, 1 ) ]
+}
+tracks/1/type = "value"
+tracks/1/path = NodePath("GunSprite:material:shader_param/schedule")
+tracks/1/interp = 1
+tracks/1/loop_wrap = true
+tracks/1/imported = false
+tracks/1/enabled = true
+tracks/1/keys = {
+"times": PoolRealArray( 0, 1.9, 2.4, 2.5, 3 ),
+"transitions": PoolRealArray( 1, 1, 1, 1, 1 ),
+"update": 0,
+"values": [ 0.0, 0.0, 1.0, 1.0, 0.0 ]
+}
+
+[sub_resource type="Animation" id=4]
+length = 0.001
+tracks/0/type = "value"
+tracks/0/path = NodePath("GunSprite:material:shader_param/shadowColor")
+tracks/0/interp = 1
+tracks/0/loop_wrap = true
+tracks/0/imported = false
+tracks/0/enabled = true
+tracks/0/keys = {
+"times": PoolRealArray( 0 ),
+"transitions": PoolRealArray( 1 ),
+"update": 0,
+"values": [ Color( 1, 1, 1, 1 ) ]
+}
+tracks/1/type = "value"
+tracks/1/path = NodePath("GunSprite:material:shader_param/schedule")
+tracks/1/interp = 1
+tracks/1/loop_wrap = true
+tracks/1/imported = false
+tracks/1/enabled = true
+tracks/1/keys = {
+"times": PoolRealArray( 0 ),
+"transitions": PoolRealArray( 1 ),
+"update": 0,
+"values": [ 0.0 ]
+}
+
[sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 7.8, 3.5 )
@@ -16,22 +76,28 @@
script = ExtResource( 1 )
[node name="GunSprite" type="Sprite" parent="."]
-material = SubResource( 2 )
-position = Vector2( 4, -3 )
+material = SubResource( 9 )
+position = Vector2( 0.4, -2.6 )
scale = Vector2( 0.8, 0.8 )
-texture = ExtResource( 3 )
+texture = SubResource( 8 )
+
+[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
+autoplay = "Floodlight"
+playback_process_mode = 0
+anims/Floodlight = SubResource( 3 )
+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/project.godot b/project.godot
index be00f17..f25ffdd 100644
--- a/project.godot
+++ b/project.godot
@@ -137,6 +137,16 @@
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":71,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
]
}
+mouse_roll_up={
+"deadzone": 0.5,
+"events": [ Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"button_mask":0,"position":Vector2( 0, 0 ),"global_position":Vector2( 0, 0 ),"factor":1.0,"button_index":4,"pressed":false,"doubleclick":false,"script":null)
+ ]
+}
+mouse_roll_down={
+"deadzone": 0.5,
+"events": [ Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"button_mask":0,"position":Vector2( 0, 0 ),"global_position":Vector2( 0, 0 ),"factor":1.0,"button_index":5,"pressed":false,"doubleclick":false,"script":null)
+ ]
+}
[layer_names]
diff --git a/resource/materlal/Shadow.tres b/resource/materlal/Shadow.tres
index c102048..df4a9bf 100644
--- a/resource/materlal/Shadow.tres
+++ b/resource/materlal/Shadow.tres
@@ -3,6 +3,7 @@
[ext_resource path="res://resource/materlal/Shadow.gdshader" type="Shader" id=1]
[resource]
+resource_local_to_scene = true
shader = ExtResource( 1 )
shader_param/shadowColor = Color( 0, 0, 0, 0.8 )
shader_param/schedule = 1.0
diff --git a/scene/Room.tscn b/scene/Room.tscn
index 23e17e9..4ad88d5 100644
--- a/scene/Room.tscn
+++ b/scene/Room.tscn
@@ -1,10 +1,9 @@
-[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/weapon/Gun.tscn" type="PackedScene" id=5]
[node name="Room" type="Node2D"]
script = ExtResource( 3 )
@@ -23,14 +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")
-
-[node name="Gun" parent="YSort" instance=ExtResource( 5 )]
-position = Vector2( 125, 132 )
-z_index = -1
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/manager/ResourceManager.cs b/src/manager/ResourceManager.cs
index 7d57c99..83f9688 100644
--- a/src/manager/ResourceManager.cs
+++ b/src/manager/ResourceManager.cs
@@ -20,6 +20,22 @@
}
private static ShaderMaterial _shadowMaterial;
+ ///
+ /// 2D阴影的Shader
+ ///
+ public static Shader ShadowShader
+ {
+ get
+ {
+ if (_shadowShader == null)
+ {
+ _shadowShader = ResourceLoader.Load("res://resource/materlal/Shadow.gdshader");
+ }
+ return _shadowShader;
+ }
+ }
+ private static Shader _shadowShader;
+
private static readonly Dictionary CachePack = new Dictionary();
///
diff --git a/src/package/Holster.cs b/src/package/Holster.cs
index e201dba..1c77cbf 100644
--- a/src/package/Holster.cs
+++ b/src/package/Holster.cs
@@ -29,8 +29,15 @@
///
public Role Master { get; }
+ ///
+ /// 当前使用的武器对象
+ ///
public Gun ActiveGun { get; private set; }
- public int ActiveIndex { get; private set; }
+
+ ///
+ /// 当前使用的武器的索引
+ ///
+ public int ActiveIndex { get; private set; } = 0;
public GunSlot[] SlotList { get; } = new GunSlot[4];
@@ -68,6 +75,7 @@
if (item.Enable && gun.Attribute.WeightType == item.Type && item.Gun == null)
{
item.Gun = gun;
+ ExchangeByIndex(i);
gun._PickUpGun(Master);
return i;
}
@@ -77,20 +85,65 @@
}
///
+ /// 移除指定位置的武器, 并返回这个武器对象, 如果移除正在使用的这把武器, 则会自动切换到上一把武器
+ ///
+ /// 所在枪套的位置索引
+ public Gun RmoveGun(int index)
+ {
+ if (index < 0 || index >= SlotList.Length)
+ {
+ return null;
+ }
+ var slot = SlotList[index];
+ if (slot.Gun == null)
+ {
+ return null;
+ }
+ var gun = slot.Gun;
+ gun.GetParent().RemoveChild(gun);
+ slot.Gun = null;
+
+ //如果是当前手持的武器, 就需要调用切换武器操作
+ if (index == ActiveIndex)
+ {
+ //没有其他武器了
+ if (ExchangePrev() == index)
+ {
+ ActiveIndex = 0;
+ ActiveGun = null;
+ }
+ }
+ gun._ThrowOutGun();
+ return gun;
+ }
+
+ ///
/// 切换到上一个武器
///
public int ExchangePrev()
{
- return 0;
+ var index = ActiveIndex - 1;
+ do
+ {
+ if (index < 0)
+ {
+ index = SlotList.Length - 1;
+ }
+ if (ExchangeByIndex(index))
+ {
+ return index;
+ }
+ } while (index-- != ActiveIndex);
+ return -1;
}
///
- /// 切换到下一个武器
+ /// 切换到下一个武器,
///
public int ExchangeNext()
{
var index = ActiveIndex + 1;
- while (index != ActiveIndex)
+ do
{
if (index >= SlotList.Length)
{
@@ -100,8 +153,8 @@
{
return index;
}
- index++;
}
+ while (index++ != ActiveIndex);
return -1;
}
@@ -110,7 +163,7 @@
///
public bool ExchangeByIndex(int index)
{
- if (index == ActiveIndex && ActiveGun != null) return true;
+ if (index == ActiveIndex && ActiveGun != null) return true;
if (index < 0 || index > SlotList.Length) return false;
var slot = SlotList[index];
if (slot == null || slot.Gun == null) return false;
@@ -118,33 +171,37 @@
//将上一把武器放到背后
if (ActiveGun != null)
{
- ActiveGun.GetParent().RemoveChild(ActiveGun);
- Master.BackMountPoint.AddChild(ActiveGun);
- if (ActiveIndex == 0)
+ var tempParent = ActiveGun.GetParentOrNull();
+ if (tempParent != null)
{
- ActiveGun.Position = new Vector2(0, 5);
- ActiveGun.RotationDegrees = 50;
- ActiveGun.Scale = new Vector2(-1, 1);
+ tempParent.RemoveChild(ActiveGun);
+ Master.BackMountPoint.AddChild(ActiveGun);
+ if (ActiveIndex == 0)
+ {
+ ActiveGun.Position = new Vector2(0, 5);
+ ActiveGun.RotationDegrees = 50;
+ ActiveGun.Scale = new Vector2(-1, 1);
+ }
+ else if (ActiveIndex == 1)
+ {
+ ActiveGun.Position = new Vector2(0, 0);
+ ActiveGun.RotationDegrees = 120;
+ ActiveGun.Scale = new Vector2(1, -1);
+ }
+ else if (ActiveIndex == 2)
+ {
+ ActiveGun.Position = new Vector2(0, 5);
+ ActiveGun.RotationDegrees = 310;
+ ActiveGun.Scale = new Vector2(1, 1);
+ }
+ else if (ActiveIndex == 3)
+ {
+ ActiveGun.Position = new Vector2(0, 0);
+ ActiveGun.RotationDegrees = 60;
+ ActiveGun.Scale = new Vector2(1, 1);
+ }
+ ActiveGun._Conceal();
}
- else if (ActiveIndex == 1)
- {
- ActiveGun.Position = new Vector2(0, 0);
- ActiveGun.RotationDegrees = 120;
- ActiveGun.Scale = new Vector2(1, -1);
- }
- else if (ActiveIndex == 2)
- {
- ActiveGun.Position = new Vector2(0, 5);
- ActiveGun.RotationDegrees = 310;
- ActiveGun.Scale = new Vector2(1, 1);
- }
- else if (ActiveIndex == 3)
- {
- ActiveGun.Position = new Vector2(0, 0);
- ActiveGun.RotationDegrees = 60;
- ActiveGun.Scale = new Vector2(1, 1);
- }
- ActiveGun._Conceal();
}
//更改父节点
diff --git a/src/role/Player.cs b/src/role/Player.cs
index e9ba08c..4a3a64b 100644
--- a/src/role/Player.cs
+++ b/src/role/Player.cs
@@ -31,8 +31,8 @@
Holster.SlotList[3].Enable = true;
PickUpGun(GunManager.GetGun1()); //0
PickUpGun(GunManager.GetGun2()); //1
- PickUpGun(GunManager.GetGun1()); //2
- PickUpGun(GunManager.GetGun2()); //3
+ PickUpGun(GunManager.GetGun3()); //2
+ PickUpGun(GunManager.GetGun4()); //3
}
public override void _Process(float delta)
@@ -51,9 +51,16 @@
{
Face = FaceDirection.Left;
}
- if (Input.IsActionJustPressed("exchange")) {
+
+ if (Input.IsActionJustPressed("exchange")) //切换武器
+ {
ExchangeNext();
}
+ else if (Input.IsActionJustPressed("throw")) //扔掉武器
+ {
+ ThrowGun();
+ }
+
//攻击
Attack();
}
diff --git a/src/role/Role.cs b/src/role/Role.cs
index 4a6b36c..689d42b 100644
--- a/src/role/Role.cs
+++ b/src/role/Role.cs
@@ -82,15 +82,51 @@
/// 武器对象
public void PickUpGun(Gun gun)
{
- var index = Holster.PickupGun(gun);
- Holster.ExchangeByIndex(index);
+ Holster.PickupGun(gun);
}
+ ///
+ /// 切换到下一个武器
+ ///
public void ExchangeNext()
{
Holster.ExchangeNext();
}
+ ///
+ /// 切换到上一个武器
+ ///
+ public void ExchangePrev()
+ {
+ Holster.ExchangePrev();
+ }
+
+ ///
+ /// 扔掉当前使用的武器, 切换到上一个武器
+ ///
+ public void ThrowGun()
+ {
+ 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)
{
if (_face != face)
diff --git a/src/room/RoomManager.cs b/src/room/RoomManager.cs
index 6785fb8..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,13 +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);
-
}
public override void _Process(float delta)
diff --git a/src/weapon/gun/Gun.cs b/src/weapon/gun/Gun.cs
index b00c87a..bca287e 100644
--- a/src/weapon/gun/Gun.cs
+++ b/src/weapon/gun/Gun.cs
@@ -34,6 +34,12 @@
public Sprite GunSprite { get; private set; }
///
+ /// 动画播放器
+ ///
+ ///
+ public AnimationPlayer AnimationPlayer { get; private set; }
+
+ ///
/// 枪攻击的目标阵营
///
public CampEnum TargetCamp { get; set; }
@@ -82,27 +88,13 @@
private float continuousCount = 0;
private bool continuousShootFlag = false;
- private float floodlightTimer = -1;
+ //状态 0 在地上, 1 被拾起
+ private int _state = 0;
public override void _Process(float delta)
{
-
if (Master == null) //这把武器被扔在地上
{
- if (floodlightTimer < 0)
- {
- floodlightTimer = 3f;
- }
- else
- {
- if (floodlightTimer >= 2.5f) {
- // Mathf.Lerp();
- }
- else if (floodlightTimer >= 2f) {
-
- }
- floodlightTimer -= delta;
- }
}
else if (Master.Holster.ActiveGun != this) //当前武器没有被使用
@@ -192,15 +184,15 @@
FirePoint = GetNode("FirePoint");
OriginPoint = GetNode("OriginPoint");
ShellPoint = GetNode("ShellPoint");
+ AnimationPlayer = GetNode("AnimationPlayer");
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();
}
@@ -366,12 +358,20 @@
public void _PickUpGun(Role master)
{
Master = master;
+ _state = 1;
+ //握把位置
+ GunSprite.Position = Attribute.HoldPosition;
+ AnimationPlayer.Play("RESET");
+ ZIndex = 0;
OnPickUp(master);
}
public void _ThrowOutGun()
{
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 761b3b1..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;
@@ -82,4 +86,87 @@
gun.Init(attr);
return gun;
}
+
+ public static Gun GetGun3()
+ {
+ //加载枪的 prefab
+ var gun = ResourceManager.LoadGunAndInstance("res://prefab/weapon/Gun.tscn");
+ //设置基础属性
+ 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;
+ attr.ScatteringRangeAddValue = 2f;
+ attr.ScatteringRangeBackSpeed = 40;
+ //连发
+ attr.ContinuousShoot = false;
+ //扳机检测间隔
+ attr.TriggerInterval = 0f;
+ //连发数量
+ attr.MinContinuousCount = 3;
+ attr.MaxContinuousCount = 3;
+ //开火前延时
+ attr.DelayedTime = 0f;
+ //攻击距离
+ attr.MinDistance = 500;
+ attr.MaxDistance = 600;
+ //发射子弹数量
+ attr.MinFireBulletCount = 1;
+ attr.MaxFireBulletCount = 1;
+ //抬起角度
+ attr.UpliftAngle = 10;
+ //枪身长度
+ attr.FirePosition = new Vector2(16, 1.5f);
+ attr.Sprite = ResourceManager.Load("res://resource/sprite/gun/gun2.png");
+ attr.BulletPack = ResourceManager.Load("res://prefab/weapon/bullet/OrdinaryBullets.tscn");
+ attr.ShellPack = ResourceManager.Load("res://prefab/weapon/shell/ShellCase.tscn");
+ gun.Init(attr);
+ return gun;
+ }
+
+ public static Gun GetGun4()
+ {
+ //加载枪的 prefab
+ var gun = ResourceManager.LoadGunAndInstance("res://prefab/weapon/Gun.tscn");
+ //设置基础属性
+ 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;
+ attr.FinalScatteringRange = 60;
+ attr.ScatteringRangeAddValue = 8f;
+ attr.ScatteringRangeBackSpeed = 40;
+ //连发
+ attr.ContinuousShoot = false;
+ //扳机检测间隔
+ attr.TriggerInterval = 0.4f;
+ //连发数量
+ attr.MinContinuousCount = 3;
+ attr.MaxContinuousCount = 3;
+ //开火前延时
+ attr.DelayedTime = 0f;
+ //攻击距离
+ attr.MinDistance = 500;
+ attr.MaxDistance = 600;
+ //发射子弹数量
+ attr.MinFireBulletCount = 1;
+ attr.MaxFireBulletCount = 1;
+ //抬起角度
+ attr.UpliftAngle = 30;
+ //枪身长度
+ attr.FirePosition = new Vector2(10, 1.5f);
+ attr.Sprite = ResourceManager.Load("res://resource/sprite/gun/gun7.png");
+ attr.BulletPack = ResourceManager.Load("res://prefab/weapon/bullet/HighSpeedBullet.tscn");
+ attr.ShellPack = ResourceManager.Load("res://prefab/weapon/shell/ShellCase.tscn");
+ gun.Init(attr);
+ return gun;
+ }
}
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