init
This commit is contained in:
46
player/scripts/state_stun.gd
Normal file
46
player/scripts/state_stun.gd
Normal file
@@ -0,0 +1,46 @@
|
||||
class_name StateStun extends State
|
||||
|
||||
@export var knockback_speed: float = 200.0
|
||||
@export var decelerate_speed: float = 10.0
|
||||
@export var invulnerable_duration: float = 1.0
|
||||
|
||||
@onready var idle: State = $"../idle"
|
||||
|
||||
var hurtbox: Hurtbox
|
||||
var direction: Vector2
|
||||
|
||||
var next_state: State
|
||||
|
||||
|
||||
func init() -> void:
|
||||
player.player_damaged.connect(on_damaged)
|
||||
|
||||
func enter() -> void:
|
||||
player.animation_player.animation_finished.connect(on_animation_finished)
|
||||
direction = player.global_position.direction_to(hurtbox.global_position)
|
||||
player.velocity = direction * -knockback_speed
|
||||
player.set_direction()
|
||||
player.update_animation("stun")
|
||||
player.make_invulnerable(invulnerable_duration)
|
||||
player.effect_animation.play("damaged")
|
||||
|
||||
func exit() -> void:
|
||||
player.animation_player.animation_finished.disconnect(on_animation_finished)
|
||||
next_state = null
|
||||
|
||||
func process(delta: float) -> State:
|
||||
player.velocity -= player.velocity * decelerate_speed * delta
|
||||
return next_state
|
||||
|
||||
func physics(_delta: float) -> State:
|
||||
return null
|
||||
|
||||
func handle_input(_event: InputEvent) -> State:
|
||||
return null
|
||||
|
||||
func on_damaged(incomig_hurtbox: Hurtbox) -> void:
|
||||
hurtbox = incomig_hurtbox
|
||||
state_machine.change_state(self)
|
||||
|
||||
func on_animation_finished(_name: String) -> void:
|
||||
next_state = idle
|
||||
Reference in New Issue
Block a user