44 lines
1.3 KiB
GDScript
44 lines
1.3 KiB
GDScript
extends PlayerState
|
|
|
|
|
|
func _enter(_previous_state_path: String, _data: Dictionary = {}) -> void:
|
|
print("entering running")
|
|
player.move_and_slide()
|
|
|
|
|
|
func _state_physics_update(_delta: float) -> void:
|
|
var movement_vector: Vector2 = player.get_movement_vector()
|
|
var direction: Vector2 = movement_vector.normalized()
|
|
player.velocity = direction * player.max_speed
|
|
|
|
player.move_and_slide()
|
|
|
|
if movement_vector.length() <= player.DEADZONE:
|
|
finished.emit(IDLE)
|
|
return
|
|
elif Input.is_action_just_pressed('p'+str(player.id)+'_hit_left'):
|
|
finished.emit(HITTING, {"hit": "left"})
|
|
return
|
|
elif Input.is_action_just_pressed('p'+str(player.id)+'_hit_right'):
|
|
finished.emit(HITTING, {"hit": "right"})
|
|
return
|
|
|
|
if abs(player.velocity.x) > abs(player.velocity.y):
|
|
# TODO: implement walk left animation to stop doing flip_h
|
|
if player.velocity.x > 0:
|
|
if player.anim_player.current_animation != "walk_right": player.anim_player.play("walk_right")
|
|
player.sprite.flip_h = false
|
|
else:
|
|
if player.anim_player.current_animation != "walk_left": player.anim_player.play("walk_left")
|
|
player.sprite.flip_h = true
|
|
else:
|
|
# TODO: walking up and down animations
|
|
#player.anim_dir = 'down' if player.velocity.y > 0 else 'up'
|
|
pass
|
|
|
|
#player.sprite.play(player.anim_dir)
|
|
|
|
func _exit() -> void:
|
|
player.anim_player.stop()
|
|
player.sprite.flip_h = false
|
|
print("exit")
|