Clean up player scripts
This commit is contained in:
parent
a1e8f9b34d
commit
a08afcb147
7 changed files with 75 additions and 75 deletions
7
scripts/player/states/player_hit_ball_state.gd
Normal file
7
scripts/player/states/player_hit_ball_state.gd
Normal file
|
@ -0,0 +1,7 @@
|
|||
class_name PlayerHitBallState
|
||||
extends PlayerState
|
||||
|
||||
func enter(_msg := {}):
|
||||
player.hit_ball.emit()
|
||||
await player.play_hit_ball_animation()
|
||||
state_machine.transition_to("Idle")
|
|
@ -1,20 +0,0 @@
|
|||
class_name PlayerThrowState
|
||||
extends PlayerState
|
||||
|
||||
var is_animation_finished = false
|
||||
|
||||
func enter(_msg := {}):
|
||||
player.animation_player.speed_scale = 0.8
|
||||
player.animation_player.play("throw")
|
||||
player.hit.emit()
|
||||
|
||||
func update(_delta: float):
|
||||
if is_animation_finished:
|
||||
state_machine.transition_to("Idle")
|
||||
|
||||
func exit():
|
||||
is_animation_finished = false
|
||||
player.animation_player.speed_scale = 1
|
||||
|
||||
func _on_animation_player_animation_finished(_anim_name):
|
||||
is_animation_finished = true
|
|
@ -5,11 +5,11 @@ var player_collide_with_ball = false
|
|||
|
||||
func enter(_msg := {}):
|
||||
player.velocity = Vector2.ZERO
|
||||
player.animation_player.play("idle")
|
||||
player.play_idle_animation()
|
||||
|
||||
func update(_delta):
|
||||
if player_collide_with_ball && Input.is_action_pressed("hit"):
|
||||
state_machine.transition_to("Hit")
|
||||
state_machine.transition_to("HitBall")
|
||||
|
||||
if player.get_input_direction() != Vector2.ZERO:
|
||||
state_machine.transition_to("Walk")
|
||||
|
|
|
@ -2,17 +2,17 @@ class_name PlayerWalkState
|
|||
extends PlayerState
|
||||
|
||||
func enter(_msg := {}):
|
||||
player.animation_player.play("walk")
|
||||
player.play_walk_animation()
|
||||
|
||||
func physics_update(delta):
|
||||
var direction = player.get_input_direction()
|
||||
var velocity = direction * player.speed
|
||||
|
||||
player.flip_sprite()
|
||||
|
||||
|
||||
var collision = player.move_and_collide(velocity * delta)
|
||||
if collision and Input.is_action_pressed("hit"):
|
||||
state_machine.transition_to("Hit")
|
||||
state_machine.transition_to("HitBall")
|
||||
|
||||
if velocity == Vector2.ZERO:
|
||||
state_machine.transition_to("Idle")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue