Merge pull request #6 from HumanoidSandvichDispenser/controller-support
Controller supportgodot-4.2
commit
4480ce4090
|
@ -130,7 +130,14 @@ public partial class Character : CharacterBody2D, IFaction
|
|||
StunAnimation.Stop();
|
||||
}
|
||||
|
||||
Sprite.FlipH = Target.X < 0;
|
||||
if (Target.X < 0)
|
||||
{
|
||||
Sprite.FlipH = true;
|
||||
}
|
||||
else if (Target.X > 0)
|
||||
{
|
||||
Sprite.FlipH = false;
|
||||
}
|
||||
DrawTarget();
|
||||
}
|
||||
|
||||
|
@ -214,7 +221,7 @@ public partial class Character : CharacterBody2D, IFaction
|
|||
scale.Y = -1;
|
||||
angle = Mathf.Pi - angle;
|
||||
}
|
||||
else
|
||||
else if (target.X > 0)
|
||||
{
|
||||
scale.Y = 1;
|
||||
}
|
||||
|
|
|
@ -11,9 +11,22 @@ public sealed partial class Player : Character
|
|||
{
|
||||
private string _spriteAnim;
|
||||
|
||||
private TargetTracer _targetTracer;
|
||||
private Vector2 _desiredTarget;
|
||||
|
||||
public Vector2 DesiredTarget { get; set; }
|
||||
public Vector2 DesiredTarget
|
||||
{
|
||||
get => _desiredTarget;
|
||||
set
|
||||
{
|
||||
if (value.IsZeroApprox())
|
||||
{
|
||||
return;
|
||||
}
|
||||
_desiredTarget = value;
|
||||
}
|
||||
}
|
||||
|
||||
private TargetTracer _targetTracer;
|
||||
|
||||
[Export]
|
||||
public PlayerCamera Camera { get; set; }
|
||||
|
@ -125,4 +138,26 @@ public sealed partial class Player : Character
|
|||
.WithPitchDeviation(0.125f)
|
||||
.Play();
|
||||
}
|
||||
|
||||
public Vector2 GetDesiredInputFromInput()
|
||||
{
|
||||
Vector2 mousePos = GetGlobalMousePosition();
|
||||
Vector2 dirToMouse = GlobalPosition.DirectionTo(mousePos);
|
||||
Vector2 joystick = Godot.Input.GetVector("look_left", "look_right",
|
||||
"look_up", "look_down");
|
||||
|
||||
var inputMethod = Utils.World.Instance.GlobalState
|
||||
.Settings.InputMethod;
|
||||
switch (inputMethod)
|
||||
{
|
||||
case State.Global.InputMethod.Joystick:
|
||||
if (joystick.IsZeroApprox())
|
||||
{
|
||||
return Direction;
|
||||
}
|
||||
return joystick;
|
||||
default:
|
||||
return dirToMouse;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -70,8 +70,7 @@ public partial class ShungiteSpike : Projectile
|
|||
// spawn a dart towards where the player is aiming
|
||||
if (inflictor is Characters.Player player)
|
||||
{
|
||||
var mousePos = GetGlobalMousePosition();
|
||||
var dart = CreateDart(GlobalPosition.DirectionTo(mousePos));
|
||||
var dart = CreateDart(player.Target.Normalized());
|
||||
dart.Hitbox.Faction = player.Faction;
|
||||
Hitbox.IsDisabled = true;
|
||||
}
|
||||
|
|
|
@ -27,6 +27,20 @@ public partial class Inventory : Node2D
|
|||
set => EquipItem(value, ref _selectedItem);
|
||||
}
|
||||
|
||||
private int _quickSwitchIndex = -1;
|
||||
|
||||
public const int QUICKSWITCH_SIZE = 3;
|
||||
|
||||
public int CurrentQuickSwitchIndex
|
||||
{
|
||||
get => _quickSwitchIndex;
|
||||
set
|
||||
{
|
||||
const int size = QUICKSWITCH_SIZE;
|
||||
_quickSwitchIndex = (value % size + size) % size;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsUsingItem => SelectedItem?.IsUsing ?? false;
|
||||
|
||||
public Inventory()
|
||||
|
@ -56,6 +70,16 @@ public partial class Inventory : Node2D
|
|||
base._Ready();
|
||||
}
|
||||
|
||||
public bool EquipIndex(int index)
|
||||
{
|
||||
if (index < Items.Count)
|
||||
{
|
||||
return EquipItem(Items[index], ref _selectedItem);
|
||||
}
|
||||
|
||||
return EquipItem(null, ref _selectedItem);
|
||||
}
|
||||
|
||||
private bool EquipItem(Item item, ref Item slot)
|
||||
{
|
||||
if (item is not null)
|
||||
|
|
|
@ -30,6 +30,14 @@ public abstract partial class PlayerState : CharacterState
|
|||
{
|
||||
inventory.SelectedItem = inventory.GetItemByMap("equip_3");
|
||||
}
|
||||
else if (@event.IsActionPressed("next_item"))
|
||||
{
|
||||
inventory.EquipIndex(++inventory.CurrentQuickSwitchIndex);
|
||||
}
|
||||
else if (@event.IsActionPressed("prev_item"))
|
||||
{
|
||||
inventory.EquipIndex(--inventory.CurrentQuickSwitchIndex);
|
||||
}
|
||||
|
||||
if (@event.IsActionPressed("interact"))
|
||||
{
|
||||
|
@ -47,8 +55,13 @@ public abstract partial class PlayerState : CharacterState
|
|||
"up", "down");
|
||||
Character.LookTowardsDirection();
|
||||
|
||||
Vector2 mousePos = Character.GetGlobalMousePosition();
|
||||
Vector2 dirToMouse = Character.GlobalPosition.DirectionTo(mousePos);
|
||||
var player = _player;
|
||||
var desiredTarget = player.GetDesiredInputFromInput();
|
||||
if (!desiredTarget.IsZeroApprox())
|
||||
{
|
||||
// can never be zero
|
||||
player.DesiredTarget = desiredTarget;
|
||||
}
|
||||
|
||||
if (Character.Inventory.SelectedItem is Items.Weapon weapon)
|
||||
{
|
||||
|
@ -57,7 +70,7 @@ public abstract partial class PlayerState : CharacterState
|
|||
|
||||
if (!weapon.ShouldHideIdle || isAttack1On)
|
||||
{
|
||||
Character.Target = dirToMouse;
|
||||
player.Target = player.DesiredTarget;
|
||||
}
|
||||
|
||||
if (isAttack1On)
|
||||
|
@ -68,7 +81,6 @@ public abstract partial class PlayerState : CharacterState
|
|||
{
|
||||
Character.UseCurrentItemAlt();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return base.Process(delta);
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
using Godot;
|
||||
|
||||
namespace SupaLidlGame.State.Global;
|
||||
|
||||
public enum InputMethod
|
||||
{
|
||||
Mouse,
|
||||
Joystick,
|
||||
MouseCentered,
|
||||
}
|
||||
|
||||
public partial class GameSettings : Resource
|
||||
{
|
||||
[Export]
|
||||
public InputMethod InputMethod { get; set; }
|
||||
}
|
|
@ -14,12 +14,44 @@ public partial class GlobalState : Node
|
|||
[Export]
|
||||
public Stats Stats { get; set; } = new();
|
||||
|
||||
[Export]
|
||||
public GameSettings Settings { get; set; } = new();
|
||||
|
||||
[Signal]
|
||||
public delegate void SummonBossEventHandler(string bossName);
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
ProcessMode = ProcessModeEnum.Always;
|
||||
LoadSettings();
|
||||
}
|
||||
|
||||
public override void _Notification(int what)
|
||||
{
|
||||
if (what == NotificationWMCloseRequest)
|
||||
{
|
||||
// TODO: quit prompt
|
||||
GetTree().Root
|
||||
.PropagateNotification((int)NotificationWMCloseRequest);
|
||||
SaveSettings();
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadSettings()
|
||||
{
|
||||
if (ResourceLoader.Exists("user://settings.tres"))
|
||||
{
|
||||
Settings = ResourceLoader.Load<GameSettings>("user://settings.tres");
|
||||
}
|
||||
else
|
||||
{
|
||||
Settings = new GameSettings();
|
||||
}
|
||||
}
|
||||
|
||||
public void SaveSettings()
|
||||
{
|
||||
ResourceSaver.Save(Settings, "user://settings.tres");
|
||||
}
|
||||
|
||||
public void ImportFromSave(Save save)
|
||||
|
|
|
@ -172,6 +172,16 @@ look_right={
|
|||
"events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":3,"axis_value":1.0,"script":null)
|
||||
]
|
||||
}
|
||||
next_item={
|
||||
"deadzone": 0.5,
|
||||
"events": [Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":5,"pressure":0.0,"pressed":false,"script":null)
|
||||
]
|
||||
}
|
||||
prev_item={
|
||||
"deadzone": 0.5,
|
||||
"events": [Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":4,"pressure":0.0,"pressed":false,"script":null)
|
||||
]
|
||||
}
|
||||
|
||||
[internationalization]
|
||||
|
||||
|
|
Loading…
Reference in New Issue