Deozaan

SMTemplate.gd

Jan 1st, 2021 (edited)
213
213 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. extends StateMachine
  2.  
  3.  
  4. # declare all states here and set the initial state
  5. func _ready():
  6.     # add all possible states
  7.     #add_state("idle")
  8.     #add_state("run")
  9.     # set initial state
  10.     #call_deferred("set_state", states.idle)
  11.     pass
  12.  
  13.  
  14. # what should happen based on the current state
  15. func _state_logic(_delta):
  16.     #if state == states.run:
  17.     #   parent.move_player()
  18.     # checking multiple states is easier with an array
  19.     #if [states.idle, states.run].has(state):
  20.         # current state is one of the above states
  21.     pass
  22.  
  23.  
  24. # this is where the logic for transitioning from one state to another goes
  25. # i.e., which states can the current state transition to,
  26. # and under which circumstances? Order is important here
  27. func _get_transition(_delta):
  28.     # logic for changing states
  29.     #match state:
  30.     #   states.idle:
  31.     #   if (velocity.x != 0):
  32.     #       return states.run
  33.    
  34.     return null
  35.  
  36.  
  37. func _enter_state(_new_state, _old_state):
  38.     # logic for any changes that happen just once when entering the state
  39.     #match new_state:
  40.     #   states.run:
  41.     #       animation.play("running")
  42.     pass
  43.  
  44.  
  45. func _exit_state(_old_state, _new_state):
  46.     # logic for any changes that happen just once when leaving the state
  47.     #match old_state:
  48.     #   states.idle:
  49.     #       is_idling = false
  50.     pass
  51.  
RAW Paste Data