forked from wxm/Fighting_Rthythm_game
32 lines
901 B
GDScript
32 lines
901 B
GDScript
class_name Player
|
|
extends Character
|
|
|
|
func handle_input() -> void:
|
|
if Input.is_action_just_pressed("ui_left"):
|
|
judge_rhythm_action("left")
|
|
if can_attack():
|
|
start_directional_attack(Vector2.LEFT)
|
|
return
|
|
if Input.is_action_just_pressed("ui_right"):
|
|
judge_rhythm_action("right")
|
|
if can_attack():
|
|
start_directional_attack(Vector2.RIGHT)
|
|
return
|
|
if Input.is_action_just_pressed("jump"):
|
|
judge_rhythm_action("jump")
|
|
if can_jump():
|
|
start_jump()
|
|
if state == State.IDLE or state == State.WALK:
|
|
velocity.x = 0.0
|
|
|
|
func set_heading() -> void:
|
|
if velocity.x > 0.0:
|
|
heading = Vector2.RIGHT
|
|
elif velocity.x < 0.0:
|
|
heading = Vector2.LEFT
|
|
|
|
func judge_rhythm_action(action_name: String) -> void:
|
|
var conductor: Node = get_tree().get_first_node_in_group("rhythm_conductor")
|
|
if conductor != null and conductor.has_method("judge_action"):
|
|
conductor.call("judge_action", action_name)
|