Added jump buffer, controller input
This commit is contained in:
1 parent
22a1232e63
commit
c5b67bc07c
2 files changed
+20
-1
No files matched your search
+12
-1
@@ -10,6 +10,7 @@ enum FaceDirection{LEFT, RIGHT}
|
||||
|
||||
var facing : FaceDirection = FaceDirection.RIGHT
|
||||
var direction : float = 0.0
|
||||
var jump_buffer_timer : Timer
|
||||
var push_target : RigidBody2D
|
||||
var push_enabled : bool = false
|
||||
|
||||
@@ -18,6 +19,10 @@ var push_enabled : bool = false
|
||||
@onready var right_spawn: Marker2D = $RightSpawn
|
||||
@onready var left_spawn: Marker2D = $LeftSpawn
|
||||
|
||||
func _ready() -> void:
|
||||
jump_buffer_timer = Timer.new()
|
||||
add_child(jump_buffer_timer)
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
handle_input()
|
||||
handle_movement(delta)
|
||||
@@ -27,8 +32,14 @@ func _physics_process(delta: float) -> void:
|
||||
func handle_input() -> void:
|
||||
|
||||
# Handle jumping.
|
||||
if Input.is_action_just_pressed("jump") and is_on_floor():
|
||||
if Input.is_action_just_pressed("jump"):
|
||||
jump_buffer_timer.start(0.1)
|
||||
|
||||
if is_on_floor() and jump_buffer_timer.time_left > 0:
|
||||
velocity.y = JUMP_VELOCITY
|
||||
jump_buffer_timer.stop()
|
||||
|
||||
# Set direction.
|
||||
direction = Input.get_axis("move_left", "move_right")
|
||||
if direction < 0:
|
||||
facing = FaceDirection.LEFT
|
||||
|
||||
Reference in new issue
Block a user