Advertisement
otorp2

1st state machine

Jan 3rd, 2016
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. extends Node2D
  2. var state = 0
  3. var x = 0
  4. var y = 0
  5. var speed = 3
  6.  
  7.  
  8. func _ready():
  9. set_process(true)
  10.  
  11. pass
  12.  
  13. func _process(delta):
  14. update()
  15. pass
  16.  
  17. func _draw():
  18. draw_rect(Rect2(x,y,10,10),Color(1,0,0))
  19. if state == 0:
  20.  
  21. x = x + speed
  22. if x > 200-10:
  23. x = 200 - 10
  24. state = 1
  25. if state == 1:
  26. y = y + speed
  27. if y > 200 - 10:
  28. y = 200 - 10
  29. state = 2
  30. if state == 2:
  31. x = x - speed
  32. if x < 0 :
  33. x = 0
  34. state = 3
  35. if state == 3 :
  36. y = y - speed
  37. if y < 0 :
  38. y = 0
  39. state = 0
  40. pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement