117 lines
2.2 KiB
GDScript
117 lines
2.2 KiB
GDScript
extends Node
|
|
|
|
signal game_over
|
|
|
|
onready var foreground := $foreground
|
|
onready var spawner := $spawner
|
|
onready var player := $player
|
|
onready var scoreUI := $scoreUI
|
|
onready var start_timer_UI := $startTimerUI
|
|
onready var instructionsUI := $instructionsUI
|
|
onready var timer := $Timer
|
|
|
|
var next_timeline_lose := ""
|
|
var next_timeline_win := ""
|
|
|
|
var game_mode = ""
|
|
var game_goal = 10
|
|
var current_goal = 0
|
|
var game_difficulty = "easy"
|
|
var game_version = 0
|
|
|
|
var MUSIC = "res://music/mini_jeu.ogg"
|
|
|
|
|
|
func _ready():
|
|
pass
|
|
|
|
|
|
func setup(mode: String, goal: int, difficulty: String, next_lose: String, next_win: String, version: int):
|
|
game_goal = goal
|
|
if(difficulty == "hard"):
|
|
game_difficulty = "hard"
|
|
else:
|
|
game_difficulty = "easy"
|
|
game_version = version
|
|
print("setup minigame: " + mode + " " + next_lose + " " + next_win)
|
|
set_mode(mode)
|
|
scoreUI.init(mode, goal)
|
|
next_timeline_lose = next_lose
|
|
next_timeline_win = next_win
|
|
|
|
|
|
func set_mode(mode: String):
|
|
match mode:
|
|
"score":
|
|
game_mode = "score"
|
|
"time":
|
|
game_mode = "time"
|
|
_:
|
|
print("unkonwn mini-game mode")
|
|
|
|
|
|
func start():
|
|
print("starting minigame")
|
|
BackgroundMusic.crossfade_to(MUSIC, -10, 1)
|
|
start_timer_UI.init()
|
|
var t = Timer.new()
|
|
t.set_wait_time(0.5)
|
|
add_child(t)
|
|
t.start()
|
|
for n in range(3,0,-1):
|
|
start_timer_UI.update_timer(n)
|
|
yield(t, "timeout")
|
|
start_timer_UI.update_timer(0)
|
|
instructionsUI._init()
|
|
foreground.start()
|
|
player.start()
|
|
yield(t, "timeout")
|
|
yield(t, "timeout")
|
|
start_timer_UI.hide()
|
|
spawner.start(game_difficulty, game_version)
|
|
if game_mode == "score":
|
|
scoreUI.start(0)
|
|
else:
|
|
scoreUI.start(game_goal)
|
|
t.queue_free()
|
|
if game_mode == "time":
|
|
timer.start()
|
|
|
|
|
|
func stop():
|
|
foreground.stop()
|
|
player.stop()
|
|
spawner.stop()
|
|
timer.stop()
|
|
|
|
|
|
func on_win():
|
|
stop()
|
|
emit_signal("game_over", next_timeline_win)
|
|
|
|
|
|
func on_game_over():
|
|
stop()
|
|
emit_signal("game_over", next_timeline_lose)
|
|
|
|
|
|
func _on_player_die() -> void:
|
|
on_game_over()
|
|
|
|
|
|
func _on_player_hit() -> void:
|
|
pass
|
|
|
|
func update_score():
|
|
current_goal += 1
|
|
scoreUI.update_score(current_goal)
|
|
if current_goal >= game_goal:
|
|
on_win()
|
|
|
|
|
|
func _on_player_score() -> void:
|
|
update_score()
|
|
|
|
|
|
func _on_Timer_timeout() -> void:
|
|
update_score()
|