Browse Source

fix minigame reset

Arnaud Vergnet 4 months ago
parent
commit
9059eddb1e

+ 4
- 2
mini-game/MiniGame.gd View File

@@ -32,7 +32,7 @@ func setup(mode: String, goal: int, difficulty: String, next_lose: String, next_
32 32
 	else:
33 33
 		game_difficulty = "easy"
34 34
 	game_version = version
35
-	print("minigame: " + mode + " " + next_lose + " " + next_win)
35
+	print("setup minigame: " + mode + " " + next_lose + " " + next_win)
36 36
 	set_mode(mode)
37 37
 	scoreUI.init(mode, game_goal)
38 38
 	next_timeline_lose = next_lose
@@ -76,12 +76,14 @@ func stop():
76 76
 	foreground.stop()
77 77
 	player.stop()
78 78
 	spawner.stop()
79
-	
79
+	scoreUI.stop()
80
+
80 81
 
81 82
 func on_win():
82 83
 	stop()
83 84
 	emit_signal("game_over", next_timeline_win)
84 85
 
86
+
85 87
 func on_game_over():
86 88
 	stop()
87 89
 	emit_signal("game_over", next_timeline_lose)

+ 21
- 12
mini-game/scenes/decor/scoreUI.gd View File

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

+ 4
- 0
mini-game/scenes/decor/scoreUI.tscn View File

@@ -39,3 +39,7 @@ align = 1
39 39
 __meta__ = {
40 40
 "_edit_use_anchors_": false
41 41
 }
42
+
43
+[node name="Timer" type="Timer" parent="."]
44
+
45
+[connection signal="timeout" from="Timer" to="." method="_on_Timer_timeout"]

+ 5
- 4
mini-game/scenes/players/player2.tscn View File

@@ -24,14 +24,14 @@
24 24
 
25 25
 [sub_resource type="SpriteFrames" id=1]
26 26
 animations = [ {
27
-"frames": [ ExtResource( 7 ), ExtResource( 10 ), ExtResource( 9 ), ExtResource( 4 ), ExtResource( 8 ), ExtResource( 2 ), ExtResource( 3 ), ExtResource( 1 ) ],
27
+"frames": [ ExtResource( 12 ), ExtResource( 11 ), ExtResource( 5 ) ],
28 28
 "loop": true,
29
-"name": "run",
29
+"name": "jump",
30 30
 "speed": 5.0
31 31
 }, {
32
-"frames": [ ExtResource( 12 ), ExtResource( 11 ), ExtResource( 5 ) ],
32
+"frames": [ ExtResource( 7 ), ExtResource( 10 ), ExtResource( 9 ), ExtResource( 4 ), ExtResource( 8 ), ExtResource( 2 ), ExtResource( 3 ), ExtResource( 1 ) ],
33 33
 "loop": true,
34
-"name": "jump",
34
+"name": "run",
35 35
 "speed": 5.0
36 36
 }, {
37 37
 "frames": [ ExtResource( 18 ), ExtResource( 15 ), ExtResource( 14 ), ExtResource( 19 ), ExtResource( 20 ), ExtResource( 21 ), ExtResource( 13 ), ExtResource( 17 ) ],
@@ -73,5 +73,6 @@ shape = SubResource( 2 )
73 73
 position = Vector2( -0.0400658, 9.23466 )
74 74
 scale = Vector2( 0.609429, 0.281311 )
75 75
 shape = SubResource( 3 )
76
+
76 77
 [connection signal="body_entered" from="Area2D" to="." method="_on_Area2D_body_entered"]
77 78
 [connection signal="body_exited" from="Area2D" to="." method="_on_Area2D_body_exited"]

+ 2
- 3
mini-game/scripts/bonus1.gd View File

@@ -4,15 +4,14 @@ extends "scroll_movement.gd"
4 4
 onready var notifier = $notifier
5 5
 
6 6
 func _ready():
7
-	get_node("notifier").connect("screen_exited", self, "_on_screen_exited")
7
+	notifier.connect("screen_exited", self, "_on_screen_exited")
8 8
 
9 9
 func _on_screen_exited():
10
-	print("Bonus exited the screen")
11 10
 	queue_free()
12 11
 
12
+
13 13
 func _physics_process(delta):
14 14
 	move()
15
-	
16 15
 
17 16
 
18 17
 func _on_pick_bonus_body_entered(body):

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

@@ -74,20 +74,19 @@ func increase_score(scoretoadd):
74 74
 	match game_mode:
75 75
 		"score":
76 76
 			score+=scoretoadd
77
-			Signals.emit_signal("update_score",score)
77
+			Signals.emit_signal("update_score", score)
78 78
 			if score >= score_goal:
79 79
 				Signals.emit_signal("win")
80 80
 		"time":
81 81
 			pass
82 82
 		_:
83 83
 			print("game_mode not recognized by player2 start func")
84
-		
85
-	
86
-	
84
+
87 85
 
88 86
 func player_win():
89 87
 	stop()
90 88
 
89
+
91 90
 func player_die():
92 91
 	stop()
93 92
 

+ 10
- 7
mini-game/scripts/spawner.gd View File

@@ -11,6 +11,9 @@ var timer_speed = 0.99
11 11
 var random_threshold = 50
12 12
 var scenes_offset = 0
13 13
 
14
+onready var timer := $Timer
15
+onready var items := $items
16
+
14 17
 func _ready():
15 18
 	Signals.connect("die",self,"game_over")
16 19
 	Signals.connect("win",self,"game_over")
@@ -25,17 +28,17 @@ func _on_Timer_timeout():
25 28
 		else:
26 29
 			scene_index = 0
27 30
 		var tmp = scenes[scene_index+scenes_offset*2].instance()
28
-		$items.add_child(tmp)
31
+		items.add_child(tmp)
29 32
 		last_object = tmp
30
-		if(self.get_node("Timer").wait_time <= 1):
31
-			self.get_node("Timer").wait_time = 1
33
+		if(timer.wait_time <= 1):
34
+			timer.wait_time = 1
32 35
 		else:
33
-			self.get_node("Timer").wait_time *= timer_speed
34
-		self.get_node("Timer").start()
36
+			timer.wait_time *= timer_speed
37
+		timer.start()
35 38
 
36 39
 
37 40
 func game_over():
38
-	self.get_node("Timer").set_paused(true)
41
+	timer.set_paused(true)
39 42
 	#last_object.queue_free()
40 43
 
41 44
 
@@ -51,7 +54,7 @@ func start(difficulty, version):
51 54
 			pass
52 55
 	scenes_offset = version
53 56
 	spawner_enabled = true
54
-	self.get_node("Timer").set_paused(false)
57
+	timer.set_paused(false)
55 58
 
56 59
 
57 60
 func stop():

+ 2
- 1
scenes/Main.gd View File

@@ -10,8 +10,8 @@ var USER_MUSIC = "res://music/utilisateur.ogg"
10 10
 
11 11
 func _ready():
12 12
 	dialogic_node = Dialogic.start_from_save('00_start')
13
-	add_child_below_node(mini_game, dialogic_node)
14 13
 	dialogic_node.connect('dialogic_signal', self, "_on_Dialogic_signal_received")
14
+	add_child_below_node(mini_game, dialogic_node)
15 15
 	play_music()
16 16
 
17 17
 
@@ -57,6 +57,7 @@ func start_minigame():
57 57
 
58 58
 
59 59
 func _on_MiniGame_game_over(next_timeline: String):
60
+	print("game over received: " + next_timeline)
60 61
 	dialogic_node = Dialogic.start(next_timeline, false)
61 62
 	dialogic_node.connect('dialogic_signal', self, "_on_Dialogic_signal_received")
62 63
 	add_child_below_node(mini_game, dialogic_node)

Loading…
Cancel
Save