otherworldly_simulation/scene/test/run.gd

50 lines
988 B
GDScript3
Raw Permalink Normal View History

2024-10-25 15:41:39 +08:00
extends State
2024-10-25 17:45:08 +08:00
var target
2024-10-25 15:41:39 +08:00
func enter_state(n):
2024-10-25 17:45:08 +08:00
if n is Unit:
target=n
2024-10-25 15:41:39 +08:00
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")
2024-10-25 17:45:08 +08:00
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
2024-10-25 15:41:39 +08:00
pass
func exit_state():
2024-10-25 17:45:08 +08:00
target=null
2024-10-25 15:41:39 +08:00
pass
func process_message(type:String,n):
match type:
"move":
get_player().set_target_pos(n)
change_to_state("run")
2024-10-25 17:45:08 +08:00
target=null
"attack":
get_player().set_target_pos(n.global_position)
change_to_state("run",n)
pass
2024-10-25 15:41:39 +08:00
pass