pir-serious-game-ethics/mini-game/MiniGame.gd

89 lines
1.9 KiB
GDScript3
Raw Normal View History

2021-04-09 10:27:22 +02:00
extends Node
2021-04-08 12:17:48 +02:00
signal game_over
onready var background := $background
onready var foreground := $foreground
onready var spawner := $spawner
onready var player := $player2
onready var scoreUI := $scoreUI
2021-04-11 18:09:08 +02:00
onready var start_timer_UI := $start_timer_UI
onready var instructionsUI := $instructionsUI
var next_timeline_lose := ""
var next_timeline_win := ""
var game_mode = ""
2021-04-28 01:39:35 +02:00
var game_goal = 10
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-04-28 01:39:35 +02:00
2021-04-08 12:17:48 +02:00
func _ready():
Signals.connect("die", self, "on_game_over")
2021-04-11 18:09:08 +02:00
Signals.connect("win", self, "on_win")
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"
else:
game_difficulty = "easy"
game_version = version
2021-04-11 18:09:08 +02:00
print("minigame: " + mode + " " + next_lose + " " + next_win)
2021-04-08 12:17:48 +02:00
set_mode(mode)
2021-04-28 01:39:35 +02:00
scoreUI.init(mode, game_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):
start_timer_UI.update_timer(String(n))
yield(t, "timeout")
start_timer_UI.update_timer("GO !")
2021-04-12 10:48:46 +02:00
instructionsUI._init()
2021-04-08 12:17:48 +02:00
foreground.start()
2021-04-28 01:39:35 +02:00
player.start(game_mode, game_goal)
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-04-11 18:09:08 +02:00
scoreUI.start(game_mode)
2021-04-12 10:48:46 +02:00
t.queue_free()
2021-04-08 12:17:48 +02:00
func stop():
foreground.stop()
player.stop()
spawner.stop()
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
func on_game_over():
stop()
2021-04-11 18:09:08 +02:00
emit_signal("game_over", next_timeline_lose)