Platformer 2.0
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
extends Resource
|
||||
|
||||
static var IdleState = preload("res://player/states/idle.gd")
|
||||
static var FallState = preload("res://player/states/fall.gd")
|
||||
|
||||
static func build_states() -> Array[State]:
|
||||
var list: Array[State] = []
|
||||
list.append(_named(IdleState.new(), &"idle"))
|
||||
list.append(_named(FallState.new(), &"fall"))
|
||||
return list
|
||||
|
||||
static func build_transitions() -> Array[StateTransition]:
|
||||
var list: Array[StateTransition] = []
|
||||
|
||||
var t_is_on_floor = TransitionCondition.new(func(data):
|
||||
return data.is_on_floor()
|
||||
)
|
||||
var t_n_is_on_floor = TransitionCondition.new(func(data):
|
||||
return !data.is_on_floor()
|
||||
)
|
||||
|
||||
list.append(_edge(&"idle", &"fall", t_n_is_on_floor, 10))
|
||||
list.append(_edge(&"fall", &"idle", t_is_on_floor, 10))
|
||||
|
||||
return list
|
||||
|
||||
static func _named(state: State, id: StringName) -> State:
|
||||
state.id = id
|
||||
return state
|
||||
|
||||
static func _edge(from: StringName, to: StringName, condition: TransitionCondition, priority: int) -> StateTransition:
|
||||
var t:= StateTransition.new()
|
||||
t.from = from
|
||||
t.to = to
|
||||
t.condition = condition
|
||||
t.priority = priority
|
||||
return t
|
||||
Reference in New Issue
Block a user