Browse Source

minigame mode and restart option added

Nabzzz 6 months ago
parent
commit
2434d7371c

+ 1
- 1
dialogic/timelines/timeline-1616659306.json View File

@@ -1 +1 @@
1
-{"events":[{"change_timeline":"timeline-1616656510.json"}],"metadata":{"dialogic-version":"1.1","file":"timeline-1616659306.json","name":"_start"}}
1
+{"events":[{"change_timeline":"timeline-1617871263.json"}],"metadata":{"dialogic-version":"1.1","file":"timeline-1616659306.json","name":"_start"}}

+ 1
- 1
dialogic/timelines/timeline-1617871263.json View File

@@ -1 +1 @@
1
-{"events":[{"background":"res://backgrounds/bureauGroupe-2.jpg"},{"action":"join","character":"character-1616658373.json","portrait":"","position":{"0":false,"1":true,"2":false,"3":false,"4":false}},{"character":"character-1616658373.json","portrait":"","text":"Hello"},{"emit_signal":"setup_minigame mode _test_minigame_end"},{"background":""},{"character":"character-1616658373.json","portrait":"","text":"I explain stuff"},{"emit_signal":"start_minigame"}],"metadata":{"dialogic-version":"1.1","file":"timeline-1617871263.json","name":"_test_minigame_start"}}
1
+{"events":[{"background":"res://backgrounds/bureauGroupe-2.jpg"},{"action":"join","character":"character-1616658373.json","portrait":"","position":{"0":false,"1":true,"2":false,"3":false,"4":false}},{"character":"character-1616658373.json","portrait":"","text":"Hello"},{"emit_signal":"setup_minigame score _test_minigame_end _test_minigame_end2"},{"background":""},{"character":"character-1616658373.json","portrait":"","text":"I explain stuff"},{"emit_signal":"start_minigame"}],"metadata":{"dialogic-version":"1.1","file":"timeline-1617871263.json","name":"_test_minigame_start"}}

+ 1
- 1
dialogic/timelines/timeline-1617874348.json View File

@@ -1 +1 @@
1
-{"events":[{"action":"join","character":"character-1616658373.json","portrait":"","position":{"0":false,"1":false,"2":false,"3":true,"4":false}},{"character":"character-1616658373.json","portrait":"","text":"you lost"},{"change_timeline":"timeline-1616661658.json"}],"metadata":{"dialogic-version":"1.1","file":"timeline-1617874348.json","name":"_test_minigame_end"}}
1
+{"events":[{"action":"join","character":"character-1616658373.json","portrait":"","position":{"0":false,"1":false,"2":false,"3":true,"4":false}},{"character":"character-1616658373.json","portrait":"","text":"you lost"},{"options":[],"question":"Tu veux réessayer?"},{"choice":"Oui !"},{"emit_signal":"setup_minigame score _test_minigame_end _test_minigame_end2"},{"background":""},{"emit_signal":"start_minigame"},{"choice":"Non"},{"change_timeline":"timeline-1616661658.json"},{"endbranch":""}],"metadata":{"dialogic-version":"1.1","file":"timeline-1617874348.json","name":"_test_minigame_end"}}

+ 35
- 7
mini-game/MiniGame.gd View File

@@ -7,31 +7,56 @@ onready var foreground := $foreground
7 7
 onready var spawner := $spawner
8 8
 onready var player := $player2
9 9
 onready var scoreUI := $scoreUI
10
+onready var start_timer_UI := $start_timer_UI
11
+onready var instructionsUI := $instructionsUI
12
+
13
+var next_timeline_lose := ""
14
+var next_timeline_win := ""
15
+
16
+var game_mode = ""
10 17
 
11
-var next_timeline := ""
12 18
 
13 19
 func _ready():
14 20
 	Signals.connect("die", self, "on_game_over")
21
+	Signals.connect("win", self, "on_win")
15 22
 
16 23
 
17
-func setup(mode: String, next: String):
18
-	print("minigame: " + mode + " " + next)
24
+func setup(mode: String, next_lose: String, next_win: String):
25
+	print("minigame: " + mode + " " + next_lose + " " + next_win)
19 26
 	set_mode(mode)
20
-	scoreUI.init()
21
-	next_timeline = next
27
+	scoreUI.init(mode)
28
+	next_timeline_lose = next_lose
29
+	next_timeline_win = next_win
22 30
 
23 31
 
24 32
 func set_mode(mode: String):
25 33
 	match mode:
34
+		"score":
35
+			game_mode = "score"
36
+		"time":
37
+			game_mode = "time"
26 38
 		_:
27 39
 			print("unkonwn mini-game mode")
28 40
 	
29 41
 
30 42
 func start():
31 43
 	print("starting minigame")
44
+	start_timer_UI.init()
45
+	var t = Timer.new() 	
46
+	t.set_wait_time(1) 		
47
+	add_child(t)			
48
+	t.start()			
49
+	for n in range(3,0,-1):
50
+		start_timer_UI.update_timer(String(n))
51
+		yield(t, "timeout")
52
+	start_timer_UI.update_timer("GO !")
32 53
 	foreground.start()
33
-	player.start()
54
+	player.start(game_mode)
34 55
 	spawner.start()
56
+	instructionsUI._init()
57
+	scoreUI.start(game_mode)
58
+	yield(t, "timeout")
59
+	start_timer_UI.hide()
35 60
 
36 61
 
37 62
 func stop():
@@ -40,7 +65,10 @@ func stop():
40 65
 	spawner.stop()
41 66
 	
42 67
 
68
+func on_win():
69
+	stop()
70
+	emit_signal("game_over", next_timeline_win)
43 71
 
44 72
 func on_game_over():
45 73
 	stop()
46
-	emit_signal("game_over", next_timeline)
74
+	emit_signal("game_over", next_timeline_lose)

+ 7
- 1
mini-game/MiniGame.tscn View File

@@ -1,11 +1,13 @@
1
-[gd_scene load_steps=7 format=2]
1
+[gd_scene load_steps=9 format=2]
2 2
 
3 3
 [ext_resource path="res://mini-game/scenes/decor/background.tscn" type="PackedScene" id=1]
4 4
 [ext_resource path="res://mini-game/scenes/decor/foreground.tscn" type="PackedScene" id=2]
5 5
 [ext_resource path="res://mini-game/scenes/players/player2.tscn" type="PackedScene" id=3]
6 6
 [ext_resource path="res://mini-game/MiniGame.gd" type="Script" id=4]
7
+[ext_resource path="res://mini-game/scenes/decor/start_timer_UI.tscn" type="PackedScene" id=5]
7 8
 [ext_resource path="res://mini-game/scenes/spawner/spawner.tscn" type="PackedScene" id=6]
8 9
 [ext_resource path="res://mini-game/scenes/decor/scoreUI.tscn" type="PackedScene" id=7]
10
+[ext_resource path="res://mini-game/scenes/decor/instructionsUI.tscn" type="PackedScene" id=8]
9 11
 
10 12
 [node name="MiniGame" type="Node"]
11 13
 script = ExtResource( 4 )
@@ -21,3 +23,7 @@ position = Vector2( 2015.43, 970.395 )
21 23
 position = Vector2( 183.674, 888.367 )
22 24
 
23 25
 [node name="scoreUI" parent="." instance=ExtResource( 7 )]
26
+
27
+[node name="start_timer_UI" parent="." instance=ExtResource( 5 )]
28
+
29
+[node name="instructionsUI" parent="." instance=ExtResource( 8 )]

+ 29
- 2
mini-game/scenes/decor/scoreUI.gd View File

@@ -2,13 +2,40 @@ extends Control
2 2
 
3 3
 onready var label : Label = $MarginContainer/Label
4 4
 
5
+var game_mode
6
+var max_time = 3
7
+
5 8
 func _ready():
6 9
 	Signals.connect("update_score",self,"update_score")
7 10
 	
8 11
 
9 12
 func update_score(score: int):
10 13
 	label.text = String(score)
14
+
15
+func start(mode: String):
11 16
 	
17
+	match mode:
18
+		"score":
19
+			update_score(0)
20
+			show()
21
+		"time":
22
+			update_score(max_time)
23
+			show()
24
+			var t = Timer.new() 
25
+			t.set_wait_time(1) 
26
+			add_child(t)
27
+			t.start()
28
+			for n in range(max_time,0,-1):
29
+				update_score(n)
30
+				yield(t,"timeout")
31
+			update_score(0)
32
+			Signals.emit_signal("win")
33
+		_:
34
+			print("game_mode not recognized by scoreUI")
35
+
36
+
37
+
38
+func init(mode):
39
+	game_mode = mode
40
+	hide()
12 41
 
13
-func init():
14
-	update_score(0)

+ 4
- 0
mini-game/scripts/Signals.gd View File

@@ -3,3 +3,7 @@ extends Node2D
3 3
 signal die
4 4
 signal gain
5 5
 signal update_score
6
+signal update_timer
7
+signal win
8
+
9
+

+ 32
- 4
mini-game/scripts/player2.gd View File

@@ -3,6 +3,7 @@ extends KinematicBody2D
3 3
 var vitesse = Vector2.ZERO
4 4
 
5 5
 var score = 0
6
+var score_goal = 10
6 7
 
7 8
 export var jump_vitesse = 600.0
8 9
 export var gravite = 20.0
@@ -13,7 +14,13 @@ enum {
13 14
 	IDLE
14 15
 }
15 16
 
16
-var player_enabled = false;
17
+enum {
18
+	SCORE,
19
+	TIME
20
+}
21
+
22
+var player_enabled = false
23
+var game_mode = "score"
17 24
 
18 25
 var state = RUN
19 26
 var au_sol = true
@@ -62,16 +69,37 @@ func _on_Area2D_body_exited(body):
62 69
 
63 70
 
64 71
 func increase_score(scoretoadd):
65
-	score+=scoretoadd
66
-	Signals.emit_signal("update_score",score)
72
+	match game_mode:
73
+		"score":
74
+			score+=scoretoadd
75
+			Signals.emit_signal("update_score",score)
76
+			if score >= score_goal:
77
+				Signals.emit_signal("win")
78
+		"time":
79
+			pass
80
+		_:
81
+			print("game_mode not recognized by player2 start func")
82
+		
83
+	
84
+	
67 85
 
86
+func player_win():
87
+	stop()
68 88
 
69 89
 func player_die():
70 90
 	stop()
71 91
 
72 92
 
73
-func start():
93
+func start(mode: String):
74 94
 	show()
95
+	match mode:
96
+		"score":
97
+			game_mode = "score"
98
+		"time":
99
+			game_mode = "time"
100
+		_:
101
+			print("game_mode not recognized by player2 start func")
102
+	score = 0
75 103
 	player_enabled = true
76 104
 
77 105
 

+ 2
- 0
mini-game/scripts/spawner.gd View File

@@ -12,6 +12,7 @@ var spawner_enabled = false
12 12
 
13 13
 func _ready():
14 14
 	Signals.connect("die",self,"game_over")
15
+	Signals.connect("win",self,"game_over")
15 16
 
16 17
 
17 18
 func _on_Timer_timeout():
@@ -32,6 +33,7 @@ func game_over():
32 33
 
33 34
 func start():
34 35
 	spawner_enabled = true
36
+	self.get_node("Timer").set_paused(false)
35 37
 
36 38
 
37 39
 func stop():

+ 5
- 4
scenes/Main.gd View File

@@ -8,7 +8,8 @@ func _ready():
8 8
 	dialogic_node = Dialogic.add_as_child_of($Control)
9 9
 	$Control.move_child(dialogic_node, 0)
10 10
 	dialogic_node.connect('dialogic_signal', self, "_on_Dialogic_signal_received")
11
-	dialogic_node.start_from_save("_start")
11
+	#dialogic_node.start_from_save("_start")
12
+	dialogic_node.start("_start")
12 13
 
13 14
 
14 15
 func _on_Dialogic_signal_received(value: String):
@@ -21,15 +22,15 @@ func _on_Dialogic_signal_received(value: String):
21 22
 				start_minigame()
22 23
 			"setup_minigame":
23 24
 				if (args.size() >= 3):
24
-					setup_minigame(args[1], args[2])
25
+					setup_minigame(args[1], args[2], args[3])
25 26
 				else:
26 27
 					print("not enough arguments for start_minigame")
27 28
 			_:
28 29
 				print("wrong type")
29 30
 
30 31
 
31
-func setup_minigame(mode: String, next_timeline: String):
32
-	mini_game.setup(mode, next_timeline)
32
+func setup_minigame(mode: String, next_timeline_lose: String, next_timeline_win):
33
+	mini_game.setup(mode, next_timeline_lose, next_timeline_win)
33 34
 
34 35
 
35 36
 func start_minigame():

Loading…
Cancel
Save