2021-04-09 10:27:22 +02:00
|
|
|
extends Node
|
2021-04-08 12:17:48 +02:00
|
|
|
|
|
|
|
signal game_over
|
|
|
|
|
|
|
|
onready var foreground := $foreground
|
|
|
|
onready var spawner := $spawner
|
2021-05-05 18:33:03 +02:00
|
|
|
onready var player := $player
|
2021-04-08 12:17:48 +02:00
|
|
|
onready var scoreUI := $scoreUI
|
2021-05-05 18:33:03 +02:00
|
|
|
onready var start_timer_UI := $startTimerUI
|
2021-04-11 18:09:08 +02:00
|
|
|
onready var instructionsUI := $instructionsUI
|
2021-05-06 11:03:04 +02:00
|
|
|
onready var score_timer := $ScoreTimer
|
|
|
|
onready var speed_timer := $SpeedTimer
|
2021-04-11 18:09:08 +02:00
|
|
|
|
|
|
|
var next_timeline_lose := ""
|
|
|
|
var next_timeline_win := ""
|
|
|
|
|
|
|
|
var game_mode = ""
|
2021-04-28 01:39:35 +02:00
|
|
|
var game_goal = 10
|
2021-05-05 18:33:03 +02:00
|
|
|
var current_goal = 0
|
2021-04-28 01:39:35 +02:00
|
|
|
var game_difficulty = "easy"
|
|
|
|
var game_version = 0
|
2021-04-08 12:17:48 +02:00
|
|
|
|
2021-04-23 15:59:32 +02:00
|
|
|
var MUSIC = "res://music/mini_jeu.ogg"
|
2021-04-08 12:17:48 +02:00
|
|
|
|
2021-05-06 11:03:04 +02:00
|
|
|
var game_speed = 0 setget set_game_speed
|
|
|
|
|
|
|
|
export var speed_increments := 0.1
|
|
|
|
export var max_speed := 8
|
2021-04-28 01:39:35 +02:00
|
|
|
|
2021-04-08 12:17:48 +02:00
|
|
|
func _ready():
|
2021-05-05 18:33:03 +02:00
|
|
|
pass
|
2021-04-08 12:17:48 +02:00
|
|
|
|
|
|
|
|
2021-04-28 01:39:35 +02:00
|
|
|
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"
|
2021-05-06 11:03:04 +02:00
|
|
|
game_speed = 2
|
2021-04-28 01:39:35 +02:00
|
|
|
else:
|
|
|
|
game_difficulty = "easy"
|
|
|
|
game_version = version
|
2021-05-04 09:05:50 +02:00
|
|
|
print("setup minigame: " + mode + " " + next_lose + " " + next_win)
|
2021-04-08 12:17:48 +02:00
|
|
|
set_mode(mode)
|
2021-05-06 11:03:04 +02:00
|
|
|
foreground.init(game_speed)
|
|
|
|
spawner.init(game_speed)
|
2021-05-05 19:42:35 +02:00
|
|
|
scoreUI.init(mode, goal)
|
2021-04-11 18:09:08 +02:00
|
|
|
next_timeline_lose = next_lose
|
|
|
|
next_timeline_win = next_win
|
2021-04-08 12:17:48 +02:00
|
|
|
|
|
|
|
|
|
|
|
func set_mode(mode: String):
|
|
|
|
match mode:
|
2021-04-11 18:09:08 +02:00
|
|
|
"score":
|
|
|
|
game_mode = "score"
|
|
|
|
"time":
|
|
|
|
game_mode = "time"
|
2021-04-08 12:17:48 +02:00
|
|
|
_:
|
|
|
|
print("unkonwn mini-game mode")
|
|
|
|
|
|
|
|
|
|
|
|
func start():
|
|
|
|
print("starting minigame")
|
2021-04-23 15:59:32 +02:00
|
|
|
BackgroundMusic.crossfade_to(MUSIC, -10, 1)
|
2021-04-11 18:09:08 +02:00
|
|
|
start_timer_UI.init()
|
2021-04-12 10:48:46 +02:00
|
|
|
var t = Timer.new()
|
|
|
|
t.set_wait_time(0.5)
|
|
|
|
add_child(t)
|
|
|
|
t.start()
|
2021-04-11 18:09:08 +02:00
|
|
|
for n in range(3,0,-1):
|
2021-05-05 18:33:03 +02:00
|
|
|
start_timer_UI.update_timer(n)
|
2021-04-11 18:09:08 +02:00
|
|
|
yield(t, "timeout")
|
2021-05-05 18:33:03 +02:00
|
|
|
start_timer_UI.update_timer(0)
|
2021-04-12 10:48:46 +02:00
|
|
|
instructionsUI._init()
|
2021-04-08 12:17:48 +02:00
|
|
|
foreground.start()
|
2021-05-05 18:33:03 +02:00
|
|
|
player.start()
|
2021-04-12 10:48:46 +02:00
|
|
|
yield(t, "timeout")
|
|
|
|
yield(t, "timeout")
|
|
|
|
start_timer_UI.hide()
|
2021-04-28 01:39:35 +02:00
|
|
|
spawner.start(game_difficulty, game_version)
|
2021-05-05 18:33:03 +02:00
|
|
|
if game_mode == "score":
|
|
|
|
scoreUI.start(0)
|
|
|
|
else:
|
|
|
|
scoreUI.start(game_goal)
|
2021-04-12 10:48:46 +02:00
|
|
|
t.queue_free()
|
2021-05-05 18:33:03 +02:00
|
|
|
if game_mode == "time":
|
2021-05-06 11:03:04 +02:00
|
|
|
score_timer.start()
|
|
|
|
speed_timer.start()
|
2021-04-08 12:17:48 +02:00
|
|
|
|
|
|
|
|
|
|
|
func stop():
|
|
|
|
foreground.stop()
|
|
|
|
player.stop()
|
|
|
|
spawner.stop()
|
2021-05-06 11:03:04 +02:00
|
|
|
score_timer.stop()
|
|
|
|
speed_timer.stop()
|
2021-05-04 09:05:50 +02:00
|
|
|
|
2021-04-08 12:17:48 +02:00
|
|
|
|
2021-04-11 18:09:08 +02:00
|
|
|
func on_win():
|
|
|
|
stop()
|
|
|
|
emit_signal("game_over", next_timeline_win)
|
2021-04-08 12:17:48 +02:00
|
|
|
|
2021-05-04 09:05:50 +02:00
|
|
|
|
2021-04-08 12:17:48 +02:00
|
|
|
func on_game_over():
|
|
|
|
stop()
|
2021-04-11 18:09:08 +02:00
|
|
|
emit_signal("game_over", next_timeline_lose)
|
2021-05-05 18:33:03 +02:00
|
|
|
|
|
|
|
|
|
|
|
func _on_player_die() -> void:
|
|
|
|
on_game_over()
|
|
|
|
|
|
|
|
|
|
|
|
func _on_player_hit() -> void:
|
|
|
|
pass
|
|
|
|
|
2021-05-06 11:03:04 +02:00
|
|
|
|
2021-05-05 19:42:35 +02:00
|
|
|
func update_score():
|
|
|
|
current_goal += 1
|
|
|
|
scoreUI.update_score(current_goal)
|
|
|
|
if current_goal >= game_goal:
|
|
|
|
on_win()
|
|
|
|
|
2021-05-05 18:33:03 +02:00
|
|
|
|
2021-05-06 11:03:04 +02:00
|
|
|
func set_game_speed(new_value: float):
|
|
|
|
game_speed = new_value
|
|
|
|
if game_speed > max_speed:
|
|
|
|
game_speed = max_speed
|
|
|
|
foreground.speed_offset = game_speed
|
|
|
|
spawner.speed_offset = game_speed
|
|
|
|
|
|
|
|
|
2021-05-05 18:33:03 +02:00
|
|
|
func _on_player_score() -> void:
|
2021-05-06 10:16:58 +02:00
|
|
|
update_score()
|
|
|
|
|
2021-05-05 18:33:03 +02:00
|
|
|
|
2021-05-06 11:03:04 +02:00
|
|
|
func _on_ScoreTimer_timeout() -> void:
|
2021-05-06 10:16:58 +02:00
|
|
|
update_score()
|
2021-05-06 11:03:04 +02:00
|
|
|
|
|
|
|
|
|
|
|
func _on_SpeedTimer_timeout() -> void:
|
|
|
|
set_game_speed(game_speed + speed_increments)
|