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.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. var MUSIC = "res://music/mini_jeu.ogg"
  14. func _ready():
  15. Signals.connect("die", self, "on_game_over")
  16. Signals.connect("win", self, "on_win")
  17. func setup(mode: String, next_lose: String, next_win: String):
  18. print("minigame: " + mode + " " + next_lose + " " + next_win)
  19. set_mode(mode)
  20. scoreUI.init(mode)
  21. next_timeline_lose = next_lose
  22. next_timeline_win = next_win
  23. func set_mode(mode: String):
  24. match mode:
  25. "score":
  26. game_mode = "score"
  27. "time":
  28. game_mode = "time"
  29. _:
  30. print("unkonwn mini-game mode")
  31. func start():
  32. print("starting minigame")
  33. BackgroundMusic.crossfade_to(MUSIC, -10, 1)
  34. start_timer_UI.init()
  35. var t = Timer.new()
  36. t.set_wait_time(0.5)
  37. add_child(t)
  38. t.start()
  39. for n in range(3,0,-1):
  40. start_timer_UI.update_timer(String(n))
  41. yield(t, "timeout")
  42. start_timer_UI.update_timer("GO !")
  43. instructionsUI._init()
  44. foreground.start()
  45. player.start(game_mode)
  46. yield(t, "timeout")
  47. yield(t, "timeout")
  48. start_timer_UI.hide()
  49. spawner.start()
  50. scoreUI.start(game_mode)
  51. t.queue_free()
  52. func stop():
  53. foreground.stop()
  54. player.stop()
  55. spawner.stop()
  56. func on_win():
  57. stop()
  58. emit_signal("game_over", next_timeline_win)
  59. func on_game_over():
  60. stop()
  61. emit_signal("game_over", next_timeline_lose)