No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MiniGame.gd 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. extends Node
  2. signal game_over
  3. onready var background := $background
  4. onready var foreground := $foreground
  5. onready var spawner := $spawner
  6. onready var player := $player2
  7. onready var scoreUI := $scoreUI
  8. onready var start_timer_UI := $start_timer_UI
  9. onready var instructionsUI := $instructionsUI
  10. var next_timeline_lose := ""
  11. var next_timeline_win := ""
  12. var game_mode = ""
  13. func _ready():
  14. Signals.connect("die", self, "on_game_over")
  15. Signals.connect("win", self, "on_win")
  16. func setup(mode: String, next_lose: String, next_win: String):
  17. print("minigame: " + mode + " " + next_lose + " " + next_win)
  18. set_mode(mode)
  19. scoreUI.init(mode)
  20. next_timeline_lose = next_lose
  21. next_timeline_win = next_win
  22. func set_mode(mode: String):
  23. match mode:
  24. "score":
  25. game_mode = "score"
  26. "time":
  27. game_mode = "time"
  28. _:
  29. print("unkonwn mini-game mode")
  30. func start():
  31. print("starting minigame")
  32. start_timer_UI.init()
  33. var t = Timer.new()
  34. t.set_wait_time(1)
  35. add_child(t)
  36. t.start()
  37. for n in range(3,0,-1):
  38. start_timer_UI.update_timer(String(n))
  39. yield(t, "timeout")
  40. start_timer_UI.update_timer("GO !")
  41. foreground.start()
  42. player.start(game_mode)
  43. spawner.start()
  44. instructionsUI._init()
  45. scoreUI.start(game_mode)
  46. yield(t, "timeout")
  47. start_timer_UI.hide()
  48. func stop():
  49. foreground.stop()
  50. player.stop()
  51. spawner.stop()
  52. func on_win():
  53. stop()
  54. emit_signal("game_over", next_timeline_win)
  55. func on_game_over():
  56. stop()
  57. emit_signal("game_over", next_timeline_lose)