Flowerspot.gd 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. extends Area
  2. export (String) var spot_name
  3. #FIXME: should use enum in future!!!!!!
  4. export (String) var status = "inactive"
  5. signal flowerspot_activated
  6. func _ready():
  7. var anim = self.find_node("AnimationPlayer", true, false)
  8. if anim != null:
  9. anim.connect("animation_finished", self, "anim_finished", ["MeshFlower"])
  10. var currentWorld = get_node("/root/global").getCurrentWorld()
  11. var flowerspotStatus = currentWorld.find_node("FlowerspotStatus", true, false)
  12. if flowerspotStatus != null:
  13. self.connect("flowerspot_activated", flowerspotStatus, "on_flowerspot_activated")
  14. #FIXME: what is name and name2, how to call them right???
  15. func anim_finished(name, name2):
  16. if (status == "anim"):
  17. status = "active"
  18. print ("anim finished - status = active")
  19. emit_signal("flowerspot_activated")
  20. func set_status(status):
  21. print ("status set to: " + status)
  22. self.status = status
  23. var anim = self.find_node("AnimationPlayer", true, false)
  24. if anim != null:
  25. if status == "active":
  26. anim.set_assigned_animation("MeshFlower")
  27. anim.advance(2.0)
  28. #anim.play("MeshFlower")
  29. elif status == "inactive":
  30. anim.advance(-2.0)
  31. else:
  32. print ("error in set status???")
  33. else:
  34. print ("error in set status - anim = null!!")
  35. func _process(delta):
  36. for body in get_overlapping_bodies ( ):
  37. if body.name == "Player" :
  38. var anim = self.find_node("AnimationPlayer", true, false)
  39. if anim == null:
  40. print ("fatal error - anim == null")
  41. #
  42. if Input.is_action_just_pressed("interact"):
  43. if (status == "inactive"):
  44. status = "anim"
  45. #print ("playing animation now")
  46. anim.play("MeshFlower")
  47. #part 1: emit signal here
  48. elif (status == "active"):
  49. set_status("inactive")
  50. else:
  51. status = "inactive"
  52. print ("warning: unknown state")
  53. print ("changed spot status to " + str(status))