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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. extends Node
  2. signal game_over
  3. onready var foreground := $foreground
  4. onready var spawner := $spawner
  5. onready var player := $player2
  6. onready var scoreUI := $scoreUI
  7. onready var start_timer_UI := $start_timer_UI
  8. onready var instructionsUI := $instructionsUI
  9. var next_timeline_lose := ""
  10. var next_timeline_win := ""
  11. var game_mode = ""
  12. var game_goal = 10
  13. var game_difficulty = "easy"
  14. var game_version = 0
  15. var MUSIC = "res://music/mini_jeu.ogg"
  16. func _ready():
  17. Signals.connect("die", self, "on_game_over")
  18. Signals.connect("win", self, "on_win")
  19. func setup(mode: String, goal: int, difficulty: String, next_lose: String, next_win: String, version: int):
  20. game_goal = goal
  21. if(difficulty == "hard"):
  22. game_difficulty = "hard"
  23. else:
  24. game_difficulty = "easy"
  25. game_version = version
  26. print("minigame: " + mode + " " + next_lose + " " + next_win)
  27. set_mode(mode)
  28. scoreUI.init(mode, game_goal)
  29. next_timeline_lose = next_lose
  30. next_timeline_win = next_win
  31. func set_mode(mode: String):
  32. match mode:
  33. "score":
  34. game_mode = "score"
  35. "time":
  36. game_mode = "time"
  37. _:
  38. print("unkonwn mini-game mode")
  39. func start():
  40. print("starting minigame")
  41. BackgroundMusic.crossfade_to(MUSIC, -10, 1)
  42. start_timer_UI.init()
  43. var t = Timer.new()
  44. t.set_wait_time(0.5)
  45. add_child(t)
  46. t.start()
  47. for n in range(3,0,-1):
  48. start_timer_UI.update_timer(String(n))
  49. yield(t, "timeout")
  50. start_timer_UI.update_timer("GO !")
  51. instructionsUI._init()
  52. foreground.start()
  53. player.start(game_mode, game_goal)
  54. yield(t, "timeout")
  55. yield(t, "timeout")
  56. start_timer_UI.hide()
  57. spawner.start(game_difficulty, game_version)
  58. scoreUI.start(game_mode)
  59. t.queue_free()
  60. func stop():
  61. foreground.stop()
  62. player.stop()
  63. spawner.stop()
  64. func on_win():
  65. stop()
  66. emit_signal("game_over", next_timeline_win)
  67. func on_game_over():
  68. stop()
  69. emit_signal("game_over", next_timeline_lose)