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 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. extends Node
  2. signal game_over
  3. onready var foreground := $foreground
  4. onready var spawner := $spawner
  5. onready var player := $player
  6. onready var scoreUI := $scoreUI
  7. onready var start_timer_UI := $startTimerUI
  8. onready var instructionsUI := $instructionsUI
  9. onready var timer := $Timer
  10. var next_timeline_lose := ""
  11. var next_timeline_win := ""
  12. var game_mode = ""
  13. var game_goal = 10
  14. var current_goal = 0
  15. var game_difficulty = "easy"
  16. var game_version = 0
  17. var MUSIC = "res://music/mini_jeu.ogg"
  18. func _ready():
  19. pass
  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("setup minigame: " + mode + " " + next_lose + " " + next_win)
  28. set_mode(mode)
  29. scoreUI.init(mode, 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(n)
  50. yield(t, "timeout")
  51. start_timer_UI.update_timer(0)
  52. instructionsUI._init()
  53. foreground.start()
  54. player.start()
  55. yield(t, "timeout")
  56. yield(t, "timeout")
  57. start_timer_UI.hide()
  58. spawner.start(game_difficulty, game_version)
  59. if game_mode == "score":
  60. scoreUI.start(0)
  61. else:
  62. scoreUI.start(game_goal)
  63. t.queue_free()
  64. if game_mode == "time":
  65. timer.start()
  66. func stop():
  67. foreground.stop()
  68. player.stop()
  69. spawner.stop()
  70. timer.stop()
  71. func on_win():
  72. stop()
  73. emit_signal("game_over", next_timeline_win)
  74. func on_game_over():
  75. stop()
  76. emit_signal("game_over", next_timeline_lose)
  77. func _on_player_die() -> void:
  78. on_game_over()
  79. func _on_player_hit() -> void:
  80. pass
  81. func update_score():
  82. current_goal += 1
  83. scoreUI.update_score(current_goal)
  84. if current_goal >= game_goal:
  85. on_win()
  86. func _on_player_score() -> void:
  87. update_score()
  88. func _on_Timer_timeout() -> void:
  89. update_score()