mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-09 13:45:55 +00:00
Made crosshair into a module
This commit is contained in:
parent
625466d2d7
commit
ddadb9bd04
10 changed files with 93 additions and 36 deletions
|
|
@ -1,15 +1,19 @@
|
|||
using Godot;
|
||||
using Cirno.Scripts.Components.FSM;
|
||||
using Cirno.Scripts.Components.FSM.Player;
|
||||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Components.Actors;
|
||||
|
||||
public partial class PlayerCrosshairProvider : Node2D
|
||||
public partial class PlayerCrosshairProvider : PlayerNode2DModule
|
||||
{
|
||||
[Export] public PlayerStorageModule StorageModule { get; set; }
|
||||
[Export]
|
||||
public AnimatedSprite2D AnimatedSprite { get; private set; }
|
||||
|
||||
[Export]
|
||||
public float CrosshairDistance { get; private set; }
|
||||
|
||||
|
||||
public bool Enabled { get; set; } = false;
|
||||
public void UpdatePosition(Vector2 facingDirection)
|
||||
{
|
||||
AnimatedSprite.Position = CalculateCrosshairPosition(facingDirection);
|
||||
|
|
@ -20,13 +24,37 @@ public partial class PlayerCrosshairProvider : Node2D
|
|||
return facingDirection * CrosshairDistance;
|
||||
}
|
||||
|
||||
// public void Show()
|
||||
// {
|
||||
// AnimatedSprite.Show();
|
||||
// }
|
||||
//
|
||||
// public void Hide()
|
||||
// {
|
||||
// AnimatedSprite.Hide();
|
||||
// }
|
||||
public override void EnterState(PlayerState state)
|
||||
{
|
||||
Enabled = true;
|
||||
AnimatedSprite.Show();
|
||||
}
|
||||
|
||||
public override void ExitState(PlayerState state)
|
||||
{
|
||||
Enabled = false;
|
||||
AnimatedSprite.Hide();
|
||||
}
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
AnimatedSprite.Hide();
|
||||
}
|
||||
|
||||
public override void Init(IStateMachine<PlayerState, CharacterBody2D> machine)
|
||||
{
|
||||
AnimatedSprite.Hide();
|
||||
}
|
||||
|
||||
public override void Process(double delta)
|
||||
{
|
||||
if (!Enabled) return;
|
||||
|
||||
}
|
||||
|
||||
public override void PhysicsProcess(double delta)
|
||||
{
|
||||
if (!Enabled) return;
|
||||
AnimatedSprite.Position = CalculateCrosshairPosition(StorageModule.FacingDirection);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using Cirno.Scripts.Components.FSM.Player;
|
||||
using Cirno.Scripts.Resources;
|
||||
using Cirno.Scripts.Utils;
|
||||
using Godot;
|
||||
|
|
@ -9,6 +10,7 @@ namespace Cirno.Scripts.Components.Actors;
|
|||
|
||||
public partial class PlayerWeaponProvider : Node2D
|
||||
{
|
||||
[Export] public PlayerStorageModule StorageModule { get; set; }
|
||||
[Export] public PackedScene WeaponTemplate { get; private set; }
|
||||
public Array<Weapon> EquippedWeapons { get; set; } = [];
|
||||
|
||||
|
|
@ -157,6 +159,8 @@ public partial class PlayerWeaponProvider : Node2D
|
|||
|
||||
var weapon = this.CreateSibling<Weapon>(WeaponTemplate);
|
||||
weapon.WeaponData = startingItem.WeaponData;
|
||||
|
||||
weapon.Texture = startingItem.InventorySprite;
|
||||
|
||||
this.AddWeapon(weapon);
|
||||
return weapon;
|
||||
|
|
|
|||
|
|
@ -166,7 +166,7 @@ public partial class Active : PlayerStateBase
|
|||
_animationProvider.SetAnimationSpeed(MainObject.Velocity);
|
||||
_animationProvider.SetAnimation(FacingDirection);
|
||||
|
||||
_crosshairProvider.UpdatePosition(FacingDirection);
|
||||
//_crosshairProvider.UpdatePosition(FacingDirection);
|
||||
|
||||
HandleShoot();
|
||||
|
||||
|
|
|
|||
21
Scripts/Components/FSM/Player/PlayerNode2DModule.cs
Normal file
21
Scripts/Components/FSM/Player/PlayerNode2DModule.cs
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Components.FSM;
|
||||
|
||||
public abstract partial class PlayerNode2DModule : Node2D, IModule<PlayerState, CharacterBody2D>
|
||||
{
|
||||
public IStateMachine<PlayerState, CharacterBody2D> StateMachine { get; private set; }
|
||||
|
||||
public CharacterBody2D CharacterBody => StateMachine.MainObject;
|
||||
|
||||
|
||||
public abstract void EnterState(PlayerState state);
|
||||
public abstract void ExitState(PlayerState state);
|
||||
|
||||
public virtual void Init(IStateMachine<PlayerState, CharacterBody2D> machine)
|
||||
{
|
||||
StateMachine = machine;
|
||||
}
|
||||
public abstract void Process(double delta);
|
||||
public abstract void PhysicsProcess(double delta);
|
||||
}
|
||||
1
Scripts/Components/FSM/Player/PlayerNode2DModule.cs.uid
Normal file
1
Scripts/Components/FSM/Player/PlayerNode2DModule.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://bkowl104hcpu7
|
||||
Loading…
Add table
Add a link
Reference in a new issue