LoonyLips.gd 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. extends Control
  2. var playerWords = []
  3. var currentStory = {}
  4. onready var playerText = $VBoxContainer/HBoxContainer/PlayerText
  5. onready var displayText = $VBoxContainer/DisplayText
  6. onready var okayLabel = $VBoxContainer/HBoxContainer/Label
  7. func _ready():
  8. pickCurrentStory()
  9. displayText.text = "Welcome to LoonyLips. This is a story generator \"game\". "
  10. checkPlayerWordsLength()
  11. playerText.grab_focus()
  12. func pickCurrentStory():
  13. randomize()
  14. var stories = $StoryBook.get_child_count()
  15. var selectedStory = randi() % stories
  16. currentStory.prompts = $StoryBook.get_child(selectedStory).prompts
  17. currentStory.story = $StoryBook.get_child(selectedStory).story
  18. func _on_PlayerText_text_entered(new_text):
  19. addToPlayerWords()
  20. func _on_TextureButton2_pressed():
  21. if isStoryDone():
  22. get_tree().reload_current_scene()
  23. else:
  24. addToPlayerWords()
  25. func addToPlayerWords():
  26. playerWords.append(playerText.text)
  27. displayText.text = ""
  28. playerText.clear()
  29. checkPlayerWordsLength()
  30. func isStoryDone():
  31. return playerWords.size() == currentStory.prompts.size()
  32. func checkPlayerWordsLength():
  33. if isStoryDone():
  34. endGame()
  35. else:
  36. promptPlayer()
  37. func tellStory():
  38. displayText.text = currentStory.story % playerWords
  39. func promptPlayer():
  40. displayText.text += "May I have " + currentStory.prompts[playerWords.size()] + ", please?"
  41. func endGame():
  42. playerText.queue_free()
  43. tellStory()
  44. okayLabel.text = "Again!"