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

118 lines
2.2 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 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-05 18:33:03 +02:00
onready var timer := $Timer
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-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"
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-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":
timer.start()
2021-04-08 12:17:48 +02:00
func stop():
foreground.stop()
player.stop()
spawner.stop()
2021-05-05 18:33:03 +02:00
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-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
func _on_player_score() -> void:
2021-05-06 10:16:58 +02:00
update_score()
2021-05-05 18:33:03 +02:00
func _on_Timer_timeout() -> void:
2021-05-06 10:16:58 +02:00
update_score()