Made player movement fully digital
This commit is contained in:
parent
9f404261ae
commit
c0ad61933e
2 changed files with 37 additions and 10 deletions
|
|
@ -39,25 +39,25 @@ enabled=PackedStringArray("res://addons/AsepriteWizard/plugin.cfg", "res://addon
|
||||||
[input]
|
[input]
|
||||||
|
|
||||||
move_left={
|
move_left={
|
||||||
"deadzone": 0.2,
|
"deadzone": 0.25,
|
||||||
"events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":0,"axis_value":-1.0,"script":null)
|
"events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":0,"axis_value":-1.0,"script":null)
|
||||||
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":65,"key_label":0,"unicode":97,"location":0,"echo":false,"script":null)
|
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":65,"key_label":0,"unicode":97,"location":0,"echo":false,"script":null)
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
move_right={
|
move_right={
|
||||||
"deadzone": 0.2,
|
"deadzone": 0.25,
|
||||||
"events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":0,"axis_value":1.0,"script":null)
|
"events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":0,"axis_value":1.0,"script":null)
|
||||||
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":68,"key_label":0,"unicode":100,"location":0,"echo":false,"script":null)
|
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":68,"key_label":0,"unicode":100,"location":0,"echo":false,"script":null)
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
move_up={
|
move_up={
|
||||||
"deadzone": 0.2,
|
"deadzone": 0.25,
|
||||||
"events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":1,"axis_value":-1.0,"script":null)
|
"events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":1,"axis_value":-1.0,"script":null)
|
||||||
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":87,"key_label":0,"unicode":119,"location":0,"echo":false,"script":null)
|
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":87,"key_label":0,"unicode":119,"location":0,"echo":false,"script":null)
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
move_down={
|
move_down={
|
||||||
"deadzone": 0.2,
|
"deadzone": 0.25,
|
||||||
"events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":1,"axis_value":1.0,"script":null)
|
"events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":1,"axis_value":1.0,"script":null)
|
||||||
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":83,"key_label":0,"unicode":115,"location":0,"echo":false,"script":null)
|
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":83,"key_label":0,"unicode":115,"location":0,"echo":false,"script":null)
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Specialized;
|
using System.Diagnostics;
|
||||||
using Chickensoft.LogicBlocks;
|
using Chickensoft.LogicBlocks;
|
||||||
using Chickensoft.LogicBlocks.Auto;
|
using Chickensoft.LogicBlocks.Auto;
|
||||||
|
|
||||||
|
|
@ -95,11 +95,11 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
|
||||||
|| @event.IsAction("move_up")
|
|| @event.IsAction("move_up")
|
||||||
|| @event.IsAction("move_down"))
|
|| @event.IsAction("move_down"))
|
||||||
{
|
{
|
||||||
_currentDirection = Input.GetVector(
|
_currentDirection = To8DirectionVector(Input.GetVector(
|
||||||
"move_left",
|
"move_left",
|
||||||
"move_right",
|
"move_right",
|
||||||
"move_up",
|
"move_up",
|
||||||
"move_down");
|
"move_down"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (@event.IsAction("jump") || @event.IsAction("attack"))
|
if (@event.IsAction("jump") || @event.IsAction("attack"))
|
||||||
|
|
@ -130,7 +130,7 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
|
||||||
// Walking on the floor
|
// Walking on the floor
|
||||||
else if (IsOnFloor())
|
else if (IsOnFloor())
|
||||||
{
|
{
|
||||||
var walkInput = IsInputVecSide(_currentDirection) ? _currentDirection.X : 0f;
|
var walkInput = _currentDirection.X;
|
||||||
if (Mathf.Sign(velocity.X) != Mathf.Sign(walkInput))
|
if (Mathf.Sign(velocity.X) != Mathf.Sign(walkInput))
|
||||||
velocity.X *= Mathf.Pow(GroundedSpeedStopDecay, deltaF);
|
velocity.X *= Mathf.Pow(GroundedSpeedStopDecay, deltaF);
|
||||||
else
|
else
|
||||||
|
|
@ -261,7 +261,7 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
|
||||||
|
|
||||||
if (input.Event.IsAction("jump"))
|
if (input.Event.IsAction("jump"))
|
||||||
{
|
{
|
||||||
if (input.Event.IsPressed() && IsInputVecDown(input.Direction) && IsOnFloor())
|
if (input.Event.IsPressed() && input.Direction.Y > 0 && IsOnFloor())
|
||||||
{
|
{
|
||||||
inputFound = true;
|
inputFound = true;
|
||||||
DropDown();
|
DropDown();
|
||||||
|
|
@ -269,7 +269,7 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
|
||||||
else if (
|
else if (
|
||||||
input.Event.IsPressed()
|
input.Event.IsPressed()
|
||||||
&& JumpAllowedTime > 0
|
&& JumpAllowedTime > 0
|
||||||
&& (!IsOnFloor() || !IsInputVecDown(input.Direction)))
|
&& (!IsOnFloor() || input.Direction.Y <= 0))
|
||||||
{
|
{
|
||||||
inputFound = true;
|
inputFound = true;
|
||||||
GroundJump();
|
GroundJump();
|
||||||
|
|
@ -345,6 +345,33 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Vector2 To8DirectionVector(Vector2 input)
|
||||||
|
{
|
||||||
|
if (input.IsEqualApprox(Vector2.Zero)) return Vector2.Zero;
|
||||||
|
var angle = input.Angle();
|
||||||
|
const float eighthCircle = float.Pi / 4;
|
||||||
|
const float sixteenthCircle = float.Pi / 8;
|
||||||
|
var sector = Mathf.FloorToInt((angle + sixteenthCircle) / eighthCircle) % 8;
|
||||||
|
if (sector < 0) sector += 8;
|
||||||
|
return sector switch
|
||||||
|
{
|
||||||
|
0 => Vector2.Right,
|
||||||
|
1 => Vector2.Right + Vector2.Down,
|
||||||
|
2 => Vector2.Down,
|
||||||
|
3 => Vector2.Down + Vector2.Left,
|
||||||
|
4 => Vector2.Left,
|
||||||
|
5 => Vector2.Left + Vector2.Up,
|
||||||
|
6 => Vector2.Up,
|
||||||
|
7 => Vector2.Up + Vector2.Right,
|
||||||
|
_ => throw new UnreachableException(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void _Draw()
|
||||||
|
{
|
||||||
|
DrawLine(GlobalPosition, GlobalPosition + _currentDirection * 20f, Colors.Aquamarine);
|
||||||
|
}
|
||||||
|
|
||||||
private bool IsInputVecDown(Vector2 vec)
|
private bool IsInputVecDown(Vector2 vec)
|
||||||
{
|
{
|
||||||
return Mathf.Abs(vec.AngleTo(Vector2.Down)) < DownInputAngle && vec.Length() > 0.01f;
|
return Mathf.Abs(vec.AngleTo(Vector2.Down)) < DownInputAngle && vec.Length() > 0.01f;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue