50 lines
988 B
GDScript
50 lines
988 B
GDScript
extends State
|
|
var target
|
|
func enter_state(n):
|
|
if n is Unit:
|
|
target=n
|
|
pass
|
|
func update_state(delta):
|
|
pass
|
|
func update_state_phy(delta):
|
|
match get_player().get_dir():
|
|
0:
|
|
get_player().play_animation("up")
|
|
1:
|
|
get_player().play_animation("down")
|
|
2:
|
|
get_player().play_animation("left_right")
|
|
3:
|
|
get_player().play_animation("left_right")
|
|
if target!=null and is_instance_valid(target):
|
|
if get_player().is_unit_instance_in_attack_area(target):
|
|
change_to_state("atk",target)
|
|
get_player().stop_move()
|
|
return
|
|
get_player().set_target_pos(target.global_position)
|
|
return
|
|
|
|
if get_player().is_move_finished():
|
|
|
|
change_to_state("idle")
|
|
print("切换为idle")
|
|
return
|
|
|
|
|
|
pass
|
|
func exit_state():
|
|
target=null
|
|
pass
|
|
|
|
func process_message(type:String,n):
|
|
match type:
|
|
"move":
|
|
get_player().set_target_pos(n)
|
|
change_to_state("run")
|
|
target=null
|
|
"attack":
|
|
get_player().set_target_pos(n.global_position)
|
|
change_to_state("run",n)
|
|
pass
|
|
pass
|