jumping around
This commit is contained in:
parent
88747c868f
commit
a44bb1c14a
2 changed files with 101 additions and 12 deletions
|
@ -8,6 +8,10 @@ extends CharacterBody2D
|
|||
@export var turn_acceleration: float
|
||||
@export var stopping_force: float
|
||||
|
||||
@export_group("Air Movement")
|
||||
@export var gravity: float
|
||||
@export var jump_power: float
|
||||
|
||||
@export_group("Internal References")
|
||||
@export var state_chart: StateChart
|
||||
@export var graphics: Node2D
|
||||
|
@ -26,15 +30,21 @@ func _physics_process(delta: float) -> void:
|
|||
if velocity.x != 0.0:
|
||||
graphics.scale.x = signf(velocity.x)
|
||||
|
||||
state_chart.set_expression_property(&"on_floor", is_on_floor())
|
||||
|
||||
input_dir = Input.get_vector(&"move_left", &"move_right", &"move_up", &"move_down")
|
||||
|
||||
|
||||
func _unhandled_input(event: InputEvent) -> void:
|
||||
if event.is_action_pressed(&"jump"):
|
||||
state_chart.send_event(&"jump_pressed")
|
||||
|
||||
|
||||
#region Idle
|
||||
func _slow_to_stop(delta: float) -> void:
|
||||
velocity.x = move_toward(velocity.x, 0.0, stopping_force * delta)
|
||||
#endregion
|
||||
|
||||
|
||||
#region Running
|
||||
func _apply_run_acceleration(delta: float) -> void:
|
||||
if absf(velocity.x) < max_run_speed:
|
||||
|
@ -49,3 +59,19 @@ func _scale_run_animation(delta:float) -> void:
|
|||
func _apply_turn_acceleration(delta: float) -> void:
|
||||
velocity.x += input_dir.x * turn_acceleration * delta
|
||||
#endregion
|
||||
|
||||
|
||||
#region Falling
|
||||
func _apply_gravity(delta: float) -> void:
|
||||
velocity.y += gravity * delta
|
||||
#endregion
|
||||
|
||||
|
||||
#region Jumping
|
||||
func _start_jump() -> void:
|
||||
velocity.y = -jump_power
|
||||
#endregion
|
||||
|
||||
|
||||
#region Missile
|
||||
#endregion
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue