usurpation of the olde norm
This commit is contained in:
parent
021bf19153
commit
60a6df808e
12 changed files with 277 additions and 554 deletions
|
@ -2,70 +2,83 @@ class_name Player
|
|||
extends CharacterBody2D
|
||||
|
||||
|
||||
@export var gravity: float
|
||||
@export var run_speed: float
|
||||
@export var jump_force: float
|
||||
@export_group("Ground Movement")
|
||||
@export var run_acceleration: float
|
||||
@export var max_run_speed: float
|
||||
@export var turn_acceleration: float
|
||||
@export var stopping_force: float
|
||||
|
||||
@export_group("Node References")
|
||||
@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
|
||||
@export var run_animation: SpritesheetAnimation
|
||||
|
||||
@onready var start_position = position
|
||||
@onready var voice = %Voice
|
||||
|
||||
var ices_touched:int = 0:
|
||||
var input_dir: Vector2 = Vector2.ZERO:
|
||||
set(value):
|
||||
ices_touched = value
|
||||
if ices_touched <= 0:
|
||||
ices_touched = 0
|
||||
state_chart.send_event(&"ground_touched")
|
||||
else:
|
||||
state_chart.send_event(&"ice_touched")
|
||||
|
||||
#region Notifications
|
||||
func _ready() -> void:
|
||||
state_chart.set_expression_property(&"player", self)
|
||||
|
||||
func _unhandled_input(event: InputEvent) -> void:
|
||||
if event.is_action_pressed(&"ui_accept"):
|
||||
state_chart.send_event(&"jump_pressed")
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if is_on_floor():
|
||||
graphics.rotation = get_floor_angle()
|
||||
else:
|
||||
graphics.rotation = 0.0
|
||||
input_dir = value.sign()
|
||||
state_chart.set_expression_property(&"input_dir", input_dir)
|
||||
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
move_and_slide()
|
||||
state_chart.set_expression_property(&"velocity", velocity)
|
||||
if velocity.x != 0.0:
|
||||
graphics.scale.x = signf(velocity.x)
|
||||
|
||||
state_chart.set_expression_property(&"on_floor", is_on_floor())
|
||||
|
||||
var h_input = Input.get_axis(&"ui_left", &"ui_right")
|
||||
state_chart.set_expression_property(&"horizontal_input", h_input != 0.0)
|
||||
input_dir = Input.get_vector(&"move_left", &"move_right", &"move_up", &"move_down")
|
||||
|
||||
move_and_slide()
|
||||
state_chart.send_event(&"tick")
|
||||
|
||||
|
||||
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:
|
||||
velocity.x += input_dir.x * run_acceleration * delta
|
||||
|
||||
func _scale_run_animation(delta:float) -> void:
|
||||
run_animation.speed_scale = inverse_lerp(0.0, max_run_speed, absf(velocity.x))
|
||||
#endregion
|
||||
|
||||
|
||||
#region State Processing
|
||||
func _process_run(delta: float) -> void:
|
||||
var h_input = Input.get_axis(&"ui_left", &"ui_right")
|
||||
velocity.x = h_input * run_speed
|
||||
graphics.scale.x = signf(h_input)
|
||||
#region Turning
|
||||
func _apply_turn_acceleration(delta: float) -> void:
|
||||
velocity.x += input_dir.x * turn_acceleration * delta
|
||||
#endregion
|
||||
|
||||
func _process_gravity(delta: float) -> void:
|
||||
|
||||
#region Falling
|
||||
func _apply_gravity(delta: float) -> void:
|
||||
velocity.y += gravity * delta
|
||||
#endregion
|
||||
|
||||
|
||||
#region State One-Shots
|
||||
func _do_jump() -> void:
|
||||
voice.stream = load("res://assets/audio/vox/capri_jump.ogg")
|
||||
voice.play()
|
||||
velocity.y = -jump_force
|
||||
position.y -= 1.0
|
||||
|
||||
func _stop_moving() -> void:
|
||||
velocity = Vector2.ZERO
|
||||
#region Jumping
|
||||
func _start_jump() -> void:
|
||||
velocity.y = -jump_power
|
||||
#endregion
|
||||
|
||||
|
||||
#region Missile
|
||||
func _face_towards_velocity(_delta: float) -> void:
|
||||
graphics.rotation = Vector2(graphics.scale.x, 0.0).angle_to(velocity)
|
||||
|
||||
func _restore_graphics_rotation() -> void:
|
||||
graphics.rotation = 0.0
|
||||
#endregion
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue