You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
106 lines
2.6 KiB
GDScript
106 lines
2.6 KiB
GDScript
extends AnimatedSprite3D
|
|
class_name View
|
|
|
|
@onready var status = (%Status as Status)
|
|
|
|
class Trans:
|
|
var condition:StringName
|
|
var compareType:String
|
|
var conditionValue
|
|
var from:StringName
|
|
var to:StringName
|
|
|
|
class Trigger:
|
|
var condition:StringName
|
|
var from:StringName
|
|
var to:StringName
|
|
|
|
var run_map = {}
|
|
var trans_list = []
|
|
var trigger_list = []
|
|
var move_sprite_frames:SpriteFrames
|
|
|
|
func _ready():
|
|
# 地面行走
|
|
trans("idle_loop","run1","speed_xz",">",1)
|
|
run("run1","run2_loop")
|
|
trans("run1","run3","speed_xz","<",1)
|
|
trans("run2_loop","run3","speed_xz","<",1)
|
|
run("run3","idle_loop")
|
|
trans("run3","run1","speed_xz",">",1)
|
|
|
|
# 跳跃
|
|
trigger("any","jump1","trigger_jump")
|
|
run("jump1","jump2_loop")
|
|
trans("jump2_loop","jump3","speed_y","<",0)
|
|
run("jump3","jump4_loop")
|
|
trans("jump4_loop","jump5","is_on_floor","=",true)
|
|
run("jump5","idle_loop")
|
|
trans("jump5","run1","speed_xz",">",1)
|
|
|
|
#受击
|
|
trigger("any","hit1","trigger_hit")
|
|
run("hit1","hit2_loop")
|
|
trans("hit2_loop","hit3","is_stagger","=",false)
|
|
run("hit3","idle_loop")
|
|
|
|
func _process(delta):
|
|
update_flip()
|
|
update_trigger()
|
|
if status.is_free_control:
|
|
update_trans()
|
|
|
|
func init(default:SpriteFrames):
|
|
sprite_frames = default
|
|
move_sprite_frames = default
|
|
play("idle_loop")
|
|
|
|
func reset():
|
|
sprite_frames = move_sprite_frames
|
|
play("idle_loop")
|
|
|
|
func run(from:StringName,to:StringName):
|
|
run_map[from] = to
|
|
|
|
func trans(from:StringName,to:StringName,condition,compareType,conditionValue):
|
|
var newTrans = Trans.new()
|
|
newTrans.condition = condition
|
|
newTrans.compareType = compareType
|
|
newTrans.conditionValue = conditionValue
|
|
newTrans.from = from
|
|
newTrans.to = to
|
|
trans_list.append(newTrans)
|
|
|
|
func trigger(from:StringName,to:StringName,condition):
|
|
var newTrigger = Trans.new()
|
|
newTrigger.condition = condition
|
|
newTrigger.from = from
|
|
newTrigger.to = to
|
|
trigger_list.append(newTrigger)
|
|
|
|
func update_trigger():
|
|
for trigger in trigger_list:
|
|
if trigger.from == "any" or trigger.from == animation:
|
|
if status.get(trigger.condition):
|
|
status.set(trigger.condition,false)
|
|
play(trigger.to)
|
|
|
|
func update_trans():
|
|
for trans in trans_list:
|
|
if trans.from == "any" or trans.from == animation:
|
|
var conditionValue = status.get(trans.condition)
|
|
match trans.compareType:
|
|
">":if conditionValue <= trans.conditionValue:return
|
|
"<":if conditionValue >= trans.conditionValue:return
|
|
"=":if conditionValue != trans.conditionValue:return
|
|
play(trans.to)
|
|
|
|
func update_flip():
|
|
scale.x = 1 if status.is_right else -1
|
|
|
|
func _on_animation_finished():
|
|
if animation in run_map:
|
|
var run = run_map[animation]
|
|
play(run)
|
|
|