Platformer 2.0
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
extends CharacterBody2D
|
||||
|
||||
@export var gravity = 900.0
|
||||
|
||||
var movement_fsm: StateMachine
|
||||
@onready var animation_player: AnimationPlayer = $AnimationPlayer
|
||||
|
||||
var FSMSetup = preload("res://player/setup_state.gd")
|
||||
var movement_states: Array[State] = []
|
||||
var movement_transitions: Array[StateTransition] = []
|
||||
var movement_init_state: StringName = &"idle"
|
||||
|
||||
func _ready() -> void:
|
||||
movement_states = FSMSetup.build_states()
|
||||
movement_transitions = FSMSetup.build_transitions()
|
||||
|
||||
movement_fsm = StateMachine.new()
|
||||
movement_fsm.setup(movement_states, movement_transitions, movement_init_state)
|
||||
if movement_fsm.current_state:
|
||||
movement_fsm.current_state.enter(self)
|
||||
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
if(movement_fsm):
|
||||
movement_fsm.process(self, delta)
|
||||
print("Current state: %s" % movement_fsm.current_state.id)
|
||||
|
||||
func play_animation(anim_name: String) -> void:
|
||||
if animation_player == null:
|
||||
push_warning("State '%s': player_anims is null, cannot play '%s'" % [movement_fsm.current_state.id, anim_name])
|
||||
return
|
||||
# TODO:
|
||||
# null checks: no sprite frames
|
||||
# no animation by name
|
||||
|
||||
if animation_player.current_animation != anim_name:
|
||||
animation_player.play(anim_name)
|
||||
Reference in New Issue
Block a user