Advertisement
otorp2

statemachine

Dec 24th, 2016
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. ```swift
  2. extends Node2D
  3.  
  4. var x = 50
  5. var stateOne
  6. var stateTwo
  7.  
  8. signal is_jumping
  9. signal is_grounded
  10.  
  11. func _ready():
  12. self.stateTwo = StateTwo.new()
  13. self.stateOne = StateOne.new()
  14. self.connect("is_jumping",self.stateOne,"Jumping")
  15. self.connect("is_grounded",self.stateTwo,"On_ground")
  16. set_process(true)
  17.  
  18. func _process(delta):
  19. if x <10:
  20. is_jumping()
  21. else:
  22. is_grounded()
  23.  
  24. func is_grounded():
  25. emit_signal("is_grounded")
  26.  
  27. func is_jumping():
  28. emit_signal("is_jumping")
  29.  
  30. class StateTwo extends Object:
  31. func On_ground():
  32. print("character is on the ground")
  33.  
  34. class StateOne extends Object:
  35. func Jumping():
  36. print("character is Jumping")```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement