|
|
@@ -20,6 +20,9 @@ public partial class PlayerPhysicsController : CharacterBody2D {
|
|
|
|
[Signal]
|
|
|
|
[Signal]
|
|
|
|
public delegate void OnJumpEventHandler(JumpKind kind, bool isOnGround, bool isOnWall);
|
|
|
|
public delegate void OnJumpEventHandler(JumpKind kind, bool isOnGround, bool isOnWall);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Signal]
|
|
|
|
|
|
|
|
public delegate void OnJumpFailEventHandler();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[ExportCategory("Accelerations and Impulses")]
|
|
|
|
[ExportCategory("Accelerations and Impulses")]
|
|
|
|
[Export]
|
|
|
|
[Export]
|
|
|
@@ -139,6 +142,7 @@ public partial class PlayerPhysicsController : CharacterBody2D {
|
|
|
|
float velx = (Velocity.X / UnitToPx);
|
|
|
|
float velx = (Velocity.X / UnitToPx);
|
|
|
|
float vely = (Velocity.Y / UnitToPx) + Gravity * (float)delta;
|
|
|
|
float vely = (Velocity.Y / UnitToPx) + Gravity * (float)delta;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var jumped = false;
|
|
|
|
var grounded = this.IsOnFloor();
|
|
|
|
var grounded = this.IsOnFloor();
|
|
|
|
var coyoteGrounded = _timeOffGround < CoyoteTiming;
|
|
|
|
var coyoteGrounded = _timeOffGround < CoyoteTiming;
|
|
|
|
if (grounded || coyoteGrounded) {
|
|
|
|
if (grounded || coyoteGrounded) {
|
|
|
@@ -147,6 +151,7 @@ public partial class PlayerPhysicsController : CharacterBody2D {
|
|
|
|
|
|
|
|
|
|
|
|
if (Input.IsActionJustPressed("jump")) {
|
|
|
|
if (Input.IsActionJustPressed("jump")) {
|
|
|
|
EmitSignal(SignalName.OnJump, (int)JumpKind.Ground, this.IsOnFloor(), this.IsOnWall());
|
|
|
|
EmitSignal(SignalName.OnJump, (int)JumpKind.Ground, this.IsOnFloor(), this.IsOnWall());
|
|
|
|
|
|
|
|
jumped = true;
|
|
|
|
vely = -_lv;
|
|
|
|
vely = -_lv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@@ -194,6 +199,7 @@ public partial class PlayerPhysicsController : CharacterBody2D {
|
|
|
|
GD.Print($"Theta: {theta * (180 / Mathf.Pi)}, turnjump: {turnjump}");
|
|
|
|
GD.Print($"Theta: {theta * (180 / Mathf.Pi)}, turnjump: {turnjump}");
|
|
|
|
velx = turnjump.X;
|
|
|
|
velx = turnjump.X;
|
|
|
|
vely = turnjump.Y;
|
|
|
|
vely = turnjump.Y;
|
|
|
|
|
|
|
|
jumped = true;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
// does not have jump point
|
|
|
|
// does not have jump point
|
|
|
|
// float theta = Mathf.Atan2(-yAxis, Mathf.Abs(xAxis));
|
|
|
|
// float theta = Mathf.Atan2(-yAxis, Mathf.Abs(xAxis));
|
|
|
@@ -209,6 +215,7 @@ public partial class PlayerPhysicsController : CharacterBody2D {
|
|
|
|
|
|
|
|
|
|
|
|
if (Input.IsActionJustPressed("jump") && Mathf.Abs(vely) < MaxDoubleJumpFallSpeed) {
|
|
|
|
if (Input.IsActionJustPressed("jump") && Mathf.Abs(vely) < MaxDoubleJumpFallSpeed) {
|
|
|
|
EmitSignal(SignalName.OnJump, (int)JumpKind.Midair, this.IsOnFloor(), this.IsOnWall());
|
|
|
|
EmitSignal(SignalName.OnJump, (int)JumpKind.Midair, this.IsOnFloor(), this.IsOnWall());
|
|
|
|
|
|
|
|
jumped = true;
|
|
|
|
vely = -_lv;
|
|
|
|
vely = -_lv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@@ -221,6 +228,9 @@ public partial class PlayerPhysicsController : CharacterBody2D {
|
|
|
|
else velx += autostop;
|
|
|
|
else velx += autostop;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (Input.IsActionJustPressed("jump") && !jumped)
|
|
|
|
|
|
|
|
EmitSignal(SignalName.OnJumpFail);
|
|
|
|
|
|
|
|
|
|
|
|
var maxXSpeed = grounded ? Input.IsActionPressed("run") ? MaxRunSpeed : MaxWalkSpeed : MaxAirSpeed;
|
|
|
|
var maxXSpeed = grounded ? Input.IsActionPressed("run") ? MaxRunSpeed : MaxWalkSpeed : MaxAirSpeed;
|
|
|
|
var maxYSpeed = vely > 0 ? MaxFallSpeed : MaxRiseSpeed;
|
|
|
|
var maxYSpeed = vely > 0 ? MaxFallSpeed : MaxRiseSpeed;
|
|
|
|
var (absvelx, absvely) = (Mathf.Abs(velx), Mathf.Abs(vely));
|
|
|
|
var (absvelx, absvely) = (Mathf.Abs(velx), Mathf.Abs(vely));
|
|
|
|