Виртуальный курсор (для управления с геймпада)
This commit is contained in:
parent
d42bd00c3d
commit
bbb66a5273
12 changed files with 135 additions and 8 deletions
|
@ -1,3 +1,4 @@
|
|||
using System.Diagnostics;
|
||||
using Godot;
|
||||
|
||||
public partial class GameCamera : Camera2D
|
||||
|
@ -6,7 +7,10 @@ public partial class GameCamera : Camera2D
|
|||
[Export] public Vector2 CameraBounds = new(40, 30);
|
||||
[Export] public Vector2 CameraFollowBounds = new(20, 10);
|
||||
[Export] public float Speed = 0.5f;
|
||||
|
||||
|
||||
[Export] public VirtualCursor Cursor;
|
||||
[Export] public const float CursorSpeed = 2.0f;
|
||||
|
||||
/// <summary>
|
||||
/// World position of the flashlight
|
||||
/// </summary>
|
||||
|
@ -14,6 +18,12 @@ public partial class GameCamera : Camera2D
|
|||
|
||||
public override void _PhysicsProcess(double delta)
|
||||
{
|
||||
Vector2 direction = Input.GetVector("cursor_left", "cursor_right", "cursor_up", "cursor_down");
|
||||
if (direction != Vector2.Zero)
|
||||
{
|
||||
FlashlightPosition += direction * CursorSpeed;
|
||||
}
|
||||
|
||||
var difference = Vector2.Zero;
|
||||
|
||||
var relativePlayerPosition = Player.Position - Position;
|
||||
|
@ -39,6 +49,8 @@ public partial class GameCamera : Camera2D
|
|||
|
||||
Position = (Position + difference).Round();
|
||||
FlashlightPosition = (FlashlightPosition + difference).Round();
|
||||
Cursor.Position = FlashlightPosition;
|
||||
|
||||
}
|
||||
|
||||
public override void _Input(InputEvent @event)
|
||||
|
@ -48,6 +60,7 @@ public partial class GameCamera : Camera2D
|
|||
if (@event is InputEventMouseMotion eventMouseMotion)
|
||||
{
|
||||
FlashlightPosition = eventMouseMotion.Position - Constants.HalfScreenSize + Position;
|
||||
//Cursor.Position = eventMouseMotion.Position - Constants.HalfScreenSize + Position;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue