import the woofer
This commit is contained in:
parent
825fee53e2
commit
3e89acfea8
92 changed files with 5783 additions and 0 deletions
59
objects/player/player.gd
Normal file
59
objects/player/player.gd
Normal file
|
@ -0,0 +1,59 @@
|
|||
class_name Player
|
||||
extends CharacterBody2D
|
||||
|
||||
|
||||
@export var gravity: float
|
||||
@export var run_speed: float
|
||||
@export var jump_force: float
|
||||
|
||||
@export_group("Node References")
|
||||
@export var state_chart: StateChart
|
||||
@export var graphics: Node2D
|
||||
|
||||
|
||||
#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
|
||||
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
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)
|
||||
|
||||
move_and_slide()
|
||||
#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)
|
||||
|
||||
func _process_gravity(delta: float) -> void:
|
||||
velocity.y += gravity * delta
|
||||
#endregion
|
||||
|
||||
|
||||
#region State One-Shots
|
||||
func _do_jump() -> void:
|
||||
velocity.y = -jump_force
|
||||
position.y -= 1.0
|
||||
|
||||
func _stop_moving() -> void:
|
||||
velocity = Vector2.ZERO
|
||||
#endregion
|
Loading…
Add table
Add a link
Reference in a new issue