diff --git a/DungeonShooting_Godot/prefab/role/Role.tscn b/DungeonShooting_Godot/prefab/role/Role.tscn index d1e173b..28ad803 100644 --- a/DungeonShooting_Godot/prefab/role/Role.tscn +++ b/DungeonShooting_Godot/prefab/role/Role.tscn @@ -129,6 +129,7 @@ position = Vector2( 0, -12 ) frames = SubResource( 6 ) animation = "idle" +frame = 1 playing = true [node name="Collision" type="CollisionShape2D" parent="."] diff --git a/DungeonShooting_Godot/src/game/role/Enemy.cs b/DungeonShooting_Godot/src/game/role/Enemy.cs index 796f4c3..20b3a77 100644 --- a/DungeonShooting_Godot/src/game/role/Enemy.cs +++ b/DungeonShooting_Godot/src/game/role/Enemy.cs @@ -7,6 +7,7 @@ Camp = CampEnum.Camp2; MoveSpeed = 20; + LookTarget = GameApplication.Instance.Room.Player; } public override void _Process(float delta) @@ -19,16 +20,11 @@ { base._PhysicsProcess(delta); - Move(delta); - - } - - public void Move(float delta) - { - var player = GameApplication.Instance.Room.Player; - var dir = (player.GlobalPosition - GlobalPosition).Normalized() * MoveSpeed; - - MoveAndSlide(dir); - + if (LookTarget != null) + { + AnimatedSprite.Animation = AnimatorNames.ReverseRun; + Velocity = (LookTarget.GlobalPosition - GlobalPosition).Normalized() * MoveSpeed; + CalcMove(delta); + } } } diff --git a/DungeonShooting_Godot/src/game/role/Player.cs b/DungeonShooting_Godot/src/game/role/Player.cs index 4e79e98..89b3681 100644 --- a/DungeonShooting_Godot/src/game/role/Player.cs +++ b/DungeonShooting_Godot/src/game/role/Player.cs @@ -2,35 +2,16 @@ public class Player : Role { + /// - /// 当前护盾值 + /// 移动加速度 /// - public int Shield - { - get => _shield; - protected set - { - int temp = _shield; - _shield = value; - if (temp != _shield) OnChangeShield(_shield); - } - } - private int _shield = 0; - + public float Acceleration { get; set; } = 1500f; + /// - /// 最大护盾值 + /// 移动摩擦力 /// - public int MaxShield - { - get => _maxShield; - protected set - { - int temp = _maxShield; - _maxShield = value; - if (temp != _maxShield) OnChangeMaxShield(_maxShield); - } - } - private int _maxShield = 0; + public float Friction { get; set; } = 800f; public Player(): base(ResourcePath.prefab_role_Player_tscn) { @@ -123,7 +104,7 @@ public override void _PhysicsProcess(float delta) { base._PhysicsProcess(delta); - Move(delta); + HandleMoveInput(delta); //播放动画 PlayAnim(); } @@ -155,12 +136,12 @@ } } - protected void OnChangeShield(int shield) + protected override void OnChangeShield(int shield) { GameApplication.Instance.Ui.SetShield(shield); } - protected void OnChangeMaxShield(int maxShield) + protected override void OnChangeMaxShield(int maxShield) { GameApplication.Instance.Ui.SetMaxShield(maxShield); } @@ -193,12 +174,13 @@ } } - private void Move(float delta) + //处理角色移动的输入 + private void HandleMoveInput(float delta) { //角色移动 // 得到输入的 vector2 getvector方法返回值已经归一化过了noemalized Vector2 dir = Input.GetVector("move_left", "move_right", "move_up", "move_down"); - // 移动. 如果移动的数值接近0(是用 摇杆可能出现 方向 可能会出现浮点),就fricition的值 插值 到 0 + // 移动. 如果移动的数值接近0(是用 摇杆可能出现 方向 可能会出现浮点),就friction的值 插值 到 0 // 如果 有输入 就以当前速度,用acceleration 插值到 对应方向 * 最大速度 if (Mathf.IsZeroApprox(dir.x)) { @@ -217,8 +199,8 @@ { Velocity = new Vector2(Velocity.x, Mathf.MoveToward(Velocity.y, dir.y * MoveSpeed, Acceleration * delta)); } - - Velocity = MoveAndSlide(Velocity); + + CalcMove(delta); } // 播放动画 diff --git a/DungeonShooting_Godot/src/game/role/Role.cs b/DungeonShooting_Godot/src/game/role/Role.cs index 7494934..875ff37 100644 --- a/DungeonShooting_Godot/src/game/role/Role.cs +++ b/DungeonShooting_Godot/src/game/role/Role.cs @@ -69,21 +69,15 @@ private FaceDirection _face; /// - /// 移动加速度 + /// 是否启用角色移动 /// - public float Acceleration { get; set; } = 1500f; - - /// - /// 移动摩擦力 - /// - public float Friction { get; set; } = 800f; + public bool EnableMove { get; set; } = true; + /// /// 移动速度 /// public Vector2 Velocity { get; set; } = Vector2.Zero; - public Vector2 TargetVelocity { get; set; } = Vector2.Zero; - /// /// 血量 /// @@ -113,6 +107,36 @@ } } private int _maxHp = 0; + + /// + /// 当前护盾值 + /// + public int Shield + { + get => _shield; + protected set + { + int temp = _shield; + _shield = value; + if (temp != _shield) OnChangeShield(_shield); + } + } + private int _shield = 0; + + /// + /// 最大护盾值 + /// + public int MaxShield + { + get => _maxShield; + protected set + { + int temp = _maxShield; + _maxShield = value; + if (temp != _maxShield) OnChangeMaxShield(_maxShield); + } + } + private int _maxShield = 0; /// /// 当前角色所看向的对象, 也就是枪口指向的对象 @@ -144,6 +168,20 @@ protected virtual void OnChangeMaxHp(int maxHp) { } + + /// + /// 护盾值改变时调用 + /// + protected virtual void OnChangeShield(int shield) + { + } + + /// + /// 最大护盾值改变时调用 + /// + protected virtual void OnChangeMaxShield(int maxShield) + { + } /// /// 当受伤时调用 @@ -264,6 +302,17 @@ } /// + /// 计算角色移动 + /// + public virtual void CalcMove(float delta) + { + if (EnableMove && Velocity != Vector2.Zero) + { + Velocity = MoveAndSlide(Velocity); + } + } + + /// /// 拾起一个武器, 并且切换到这个武器 /// /// 武器对象 diff --git a/DungeonShooting_Godot/src/game/room/RoomManager.cs b/DungeonShooting_Godot/src/game/room/RoomManager.cs index 2e28992..d8f1587 100644 --- a/DungeonShooting_Godot/src/game/room/RoomManager.cs +++ b/DungeonShooting_Godot/src/game/room/RoomManager.cs @@ -39,7 +39,6 @@ { //播放bgm SoundManager.PlayMusic(ResourcePath.resource_sound_bgm_Intro_ogg, -17f); - _enemy.LookTarget = Player; _enemy.PickUpWeapon(WeaponManager.GetGun("1001")); WeaponManager.GetGun("1001").PutDown(new Vector2(80, 100));