mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-07 21:15:54 +00:00
Crosshair
This commit is contained in:
parent
e5a60a6ccd
commit
fe552608ee
13 changed files with 264 additions and 33 deletions
70
Scripts/Components/Actors/3D/PlayerCrosshairModule3D.cs
Normal file
70
Scripts/Components/Actors/3D/PlayerCrosshairModule3D.cs
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
using Cirno.Scripts.Components.FSM;
|
||||
using Cirno.Scripts.Components.FSM._3DPlayer;
|
||||
using Cirno.Scripts.Components.FSM.Player;
|
||||
using Cirno.Scripts.Utils;
|
||||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Components.Actors._3D;
|
||||
|
||||
public partial class PlayerCrosshairModule3D : ModuleBase<PlayerState, CharacterBody3D>
|
||||
{
|
||||
[Export] public IsoPlayerStorageModule Storage { get; set; }
|
||||
[Export]
|
||||
public AnimatedSprite3D AnimatedSprite { get; private set; }
|
||||
|
||||
[Export]
|
||||
public float CrosshairDistance { get; private set; }
|
||||
|
||||
public bool Enabled { get; set; } = false;
|
||||
|
||||
private IStateMachine<PlayerState, CharacterBody3D> _machine;
|
||||
|
||||
public void UpdatePosition(Vector2 facingDirection)
|
||||
{
|
||||
AnimatedSprite.Position = CalculateCrosshairPosition(facingDirection);
|
||||
}
|
||||
|
||||
private Vector3 CalculateCrosshairPosition(Vector2 facingDirection)
|
||||
{
|
||||
var pos2d = facingDirection * CrosshairDistance;
|
||||
|
||||
var pos3d = pos2d.ToVector3(0);
|
||||
|
||||
return pos3d;
|
||||
}
|
||||
|
||||
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, CharacterBody3D> machine)
|
||||
{
|
||||
_machine = machine;
|
||||
AnimatedSprite.Hide();
|
||||
}
|
||||
|
||||
public override void Process(double delta)
|
||||
{
|
||||
if (!Enabled) return;
|
||||
|
||||
}
|
||||
|
||||
public override void PhysicsProcess(double delta)
|
||||
{
|
||||
if (!Enabled) return;
|
||||
AnimatedSprite.Position = CalculateCrosshairPosition(Storage.FacingDirection);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
uid://byiv30s1ahdyh
|
||||
35
Scripts/Components/Actors/3D/PlayerHitboxSpriteProvider3D.cs
Normal file
35
Scripts/Components/Actors/3D/PlayerHitboxSpriteProvider3D.cs
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Components.Actors._3D;
|
||||
|
||||
public partial class PlayerHitboxSpriteProvider3D : Node3D
|
||||
{
|
||||
[Export]
|
||||
public AnimatedSprite3D Hitbox { get; private set; }
|
||||
[Export]
|
||||
public AnimatedSprite3D Circle { get; private set; }
|
||||
[Export]
|
||||
public AnimatedSprite3D Square { get; private set; }
|
||||
|
||||
[Export] public float RotationSpeed { get; private set; } = 10f;
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
if (!Visible) return;
|
||||
Circle.Rotate(Vector3.Up, (float)(RotationSpeed * delta));
|
||||
Square.Rotate(Vector3.Up, (float)(-RotationSpeed * delta));
|
||||
}
|
||||
|
||||
public void SetVisibility(bool isVisible)
|
||||
{
|
||||
if (isVisible == Visible) return;
|
||||
if (isVisible)
|
||||
{
|
||||
Show();
|
||||
}
|
||||
else
|
||||
{
|
||||
Hide();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
uid://b2cqsoywem26t
|
||||
|
|
@ -17,6 +17,8 @@ public partial class Active : BaseState<PlayerState, CharacterBody3D>
|
|||
|
||||
[Export] public PlayerDamageReceiver3D DamageReceiver { get; private set; }
|
||||
|
||||
//[Export] public PlayerHitboxSpriteProvider3D HitboxSpriteProvider { get; private set; }
|
||||
|
||||
public override void Init(IStateMachine<PlayerState, CharacterBody3D> machine)
|
||||
{
|
||||
base.Init(machine);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using Cirno.Scripts.Components.Actors;
|
||||
using Cirno.Scripts.Components.Actors._3D;
|
||||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Components.FSM._3DPlayer;
|
||||
|
|
@ -8,6 +9,8 @@ public partial class IsoMovementModule : ModuleBase<PlayerState, CharacterBody3D
|
|||
[Export] public IsoPlayerStorageModule PlayerStorage { get; private set; }
|
||||
[Export] private InputProvider _inputProvider;
|
||||
|
||||
[Export] public PlayerHitboxSpriteProvider3D HitboxSpriteProvider { get; private set; }
|
||||
|
||||
[Export] public int Speed { get; set; } = 45;
|
||||
[Export] public int StrafeSpeed { get; set; } = 35;
|
||||
[Export] public float Acceleration = 8f;
|
||||
|
|
@ -65,6 +68,8 @@ public partial class IsoMovementModule : ModuleBase<PlayerState, CharacterBody3D
|
|||
var rotatedMovementDirection = movementInput.Rotated(Mathf.DegToRad(-45f));
|
||||
|
||||
PlayerStorage.MovementDirection = new Vector3(rotatedMovementDirection.X, 0, rotatedMovementDirection.Y);
|
||||
|
||||
HitboxSpriteProvider.SetVisibility(_isStrafing);
|
||||
}
|
||||
|
||||
public override void PhysicsProcess(double delta)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue