Initial commit
This commit is contained in:
51
Characters/CharacterBase.cs
Normal file
51
Characters/CharacterBase.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using Godot;
|
||||
|
||||
public abstract partial class CharacterBase : CharacterBody2D
|
||||
{
|
||||
protected const string InputUp = "character_move_up";
|
||||
protected const string InputDown = "character_move_down";
|
||||
protected const string InputLeft = "character_move_left";
|
||||
protected const string InputRight = "character_move_right";
|
||||
protected const string PrimaryAction = "character_primary_action";
|
||||
|
||||
[ExportCategory("Movement")]
|
||||
[Export] public float Speed { get; set; }
|
||||
|
||||
[ExportCategory("Abilities")]
|
||||
[Export] public float PrimaryCooldown { get; set; }
|
||||
|
||||
public float FacingRotation
|
||||
=> (GetGlobalMousePosition() - GlobalPosition).Angle();
|
||||
protected bool IsPrimaryOnCooldown
|
||||
=> primaryCooldown > 0f;
|
||||
|
||||
float primaryCooldown;
|
||||
|
||||
public override void _PhysicsProcess(double delta)
|
||||
{
|
||||
HandleInput(delta);
|
||||
MoveAndSlide();
|
||||
}
|
||||
|
||||
protected virtual void _UsePrimary()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void HandleInput(double delta)
|
||||
{
|
||||
var direction = Input.GetVector(InputLeft, InputRight, InputUp, InputDown);
|
||||
|
||||
Velocity = direction * Speed;
|
||||
|
||||
if (Input.IsActionPressed(PrimaryAction) && !IsPrimaryOnCooldown)
|
||||
{
|
||||
_UsePrimary();
|
||||
primaryCooldown = PrimaryCooldown;
|
||||
}
|
||||
else if (IsPrimaryOnCooldown)
|
||||
{
|
||||
primaryCooldown -= (float)delta;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user