WIP clean up player

This commit is contained in:
Mathilde Grapin 2023-06-28 00:07:13 +02:00
parent 97f9ec7fa1
commit a1e8f9b34d
4 changed files with 31 additions and 30 deletions

View file

@ -1,23 +1,21 @@
class_name PlayerIdleState
extends PlayerState
var collide_with_ball = false
var player_collide_with_ball = false
func enter(_msg := {}):
player.velocity = Vector2.ZERO
player.animation_player.play("idle")
func update(_delta):
if collide_with_ball && Input.is_action_pressed("hit"):
collide_with_ball = false
state_machine.transition_to("Throw")
if get_input_direction() != Vector2.ZERO:
if player_collide_with_ball && Input.is_action_pressed("hit"):
state_machine.transition_to("Hit")
if player.get_input_direction() != Vector2.ZERO:
state_machine.transition_to("Walk")
func get_input_direction():
return Input.get_vector("move_left", "move_right", "move_up", "move_down")
func _on_player_ball_starts_colliding():
player_collide_with_ball = true
func _on_player_collide_with_ball():
collide_with_ball = true
func _on_player_ball_stops_colliding():
player_collide_with_ball = false

View file

@ -5,22 +5,14 @@ func enter(_msg := {}):
player.animation_player.play("walk")
func physics_update(delta):
var direction = get_input_direction()
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("Throw")
state_machine.transition_to("Hit")
if velocity == Vector2.ZERO:
state_machine.transition_to("Idle")
func get_input_direction():
var direction = Input.get_vector("move_left", "move_right", "move_up", "move_down")
if Input.is_action_pressed("move_left"):
player.sprite.flip_h = true
elif Input.is_action_pressed("move_right"):
player.sprite.flip_h = false
return direction