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

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