Browse Source

progressively increase game speed

Arnaud Vergnet 4 months ago
parent
commit
ce56d3e2f6

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

@@ -8,7 +8,8 @@ onready var player := $player
8 8
 onready var scoreUI := $scoreUI
9 9
 onready var start_timer_UI := $startTimerUI
10 10
 onready var instructionsUI := $instructionsUI
11
-onready var timer := $Timer
11
+onready var score_timer := $ScoreTimer
12
+onready var speed_timer := $SpeedTimer
12 13
 
13 14
 var next_timeline_lose := ""
14 15
 var next_timeline_win := ""
@@ -21,6 +22,10 @@ var game_version = 0
21 22
 
22 23
 var MUSIC = "res://music/mini_jeu.ogg"
23 24
 
25
+var game_speed = 0 setget set_game_speed
26
+
27
+export var speed_increments := 0.1
28
+export var max_speed := 8
24 29
 
25 30
 func _ready():
26 31
 	pass
@@ -30,11 +35,14 @@ func setup(mode: String, goal: int, difficulty: String, next_lose: String, next_
30 35
 	game_goal = goal
31 36
 	if(difficulty == "hard"):
32 37
 		game_difficulty = "hard"
38
+		game_speed = 2
33 39
 	else:
34 40
 		game_difficulty = "easy"
35 41
 	game_version = version
36 42
 	print("setup minigame: " + mode + " " + next_lose + " " + next_win)
37 43
 	set_mode(mode)
44
+	foreground.init(game_speed)
45
+	spawner.init(game_speed)
38 46
 	scoreUI.init(mode, goal)
39 47
 	next_timeline_lose = next_lose
40 48
 	next_timeline_win = next_win
@@ -75,14 +83,16 @@ func start():
75 83
 		scoreUI.start(game_goal)
76 84
 	t.queue_free()
77 85
 	if game_mode == "time":
78
-		timer.start()
86
+		score_timer.start()
87
+	speed_timer.start()
79 88
 
80 89
 
81 90
 func stop():
82 91
 	foreground.stop()
83 92
 	player.stop()
84 93
 	spawner.stop()
85
-	timer.stop()
94
+	score_timer.stop()
95
+	speed_timer.stop()
86 96
 
87 97
 
88 98
 func on_win():
@@ -102,6 +112,7 @@ func _on_player_die() -> void:
102 112
 func _on_player_hit() -> void:
103 113
 	pass
104 114
 
115
+
105 116
 func update_score():
106 117
 	current_goal += 1
107 118
 	scoreUI.update_score(current_goal)
@@ -109,9 +120,21 @@ func update_score():
109 120
 		on_win()
110 121
 
111 122
 
123
+func set_game_speed(new_value: float):
124
+	game_speed = new_value
125
+	if game_speed > max_speed:
126
+		game_speed = max_speed
127
+	foreground.speed_offset = game_speed
128
+	spawner.speed_offset = game_speed
129
+
130
+
112 131
 func _on_player_score() -> void:
113 132
 	update_score()
114 133
 
115 134
 
116
-func _on_Timer_timeout() -> void:
135
+func _on_ScoreTimer_timeout() -> void:
117 136
 	update_score()
137
+
138
+
139
+func _on_SpeedTimer_timeout() -> void:
140
+	set_game_speed(game_speed + speed_increments)

+ 5
- 2
mini-game/MiniGame.tscn View File

@@ -28,9 +28,12 @@ position = Vector2( 183.674, 888.367 )
28 28
 
29 29
 [node name="instructionsUI" parent="." instance=ExtResource( 8 )]
30 30
 
31
-[node name="Timer" type="Timer" parent="."]
31
+[node name="ScoreTimer" type="Timer" parent="."]
32
+
33
+[node name="SpeedTimer" type="Timer" parent="."]
32 34
 
33 35
 [connection signal="die" from="player" to="." method="_on_player_die"]
34 36
 [connection signal="hit" from="player" to="." method="_on_player_hit"]
35 37
 [connection signal="score" from="player" to="." method="_on_player_score"]
36
-[connection signal="timeout" from="Timer" to="." method="_on_Timer_timeout"]
38
+[connection signal="timeout" from="ScoreTimer" to="." method="_on_ScoreTimer_timeout"]
39
+[connection signal="timeout" from="SpeedTimer" to="." method="_on_SpeedTimer_timeout"]

+ 2
- 1
mini-game/scenes/decor/ForegroundSprite.gd View File

@@ -2,6 +2,7 @@ extends Sprite
2 2
 
3 3
 export var scroll_speed = 9
4 4
 
5
+var speed_offset : float = 0
5 6
 var moving = false
6 7
 
7 8
 signal viewport_entered(object)
@@ -22,7 +23,7 @@ func _physics_process(delta):
22 23
 
23 24
 
24 25
 func move():
25
-	position.x -= scroll_speed
26
+	position.x -= scroll_speed + speed_offset
26 27
 
27 28
 
28 29
 func _on_VisibilityNotifier2D_viewport_entered(viewport: Viewport) -> void:

+ 13
- 0
mini-game/scenes/decor/foreground.gd View File

@@ -5,11 +5,23 @@ var sprite_scene = preload("res://mini-game/scenes/decor/ForegroundSprite.tscn")
5 5
 var textures := []
6 6
 var moving := false
7 7
 
8
+var speed_offset : float = 0 setget set_speed_offset
9
+
8 10
 func _ready():
9 11
 	textures.append($ForegroundSprite)
10 12
 	stop()
11 13
 
12 14
 
15
+func init(speed: float):
16
+	set_speed_offset(speed)
17
+
18
+
19
+func set_speed_offset(new_value: float):
20
+	speed_offset = new_value
21
+	for t in textures:
22
+		t.speed_offset = speed_offset
23
+
24
+
13 25
 func stop():
14 26
 	moving = false
15 27
 	for t in textures:
@@ -25,6 +37,7 @@ func start():
25 37
 func _on_ForegroundSprite_viewport_entered(object: Sprite) -> void:
26 38
 	var new_sprite = sprite_scene.instance()
27 39
 	new_sprite.position = Vector2(1920, 0)
40
+	new_sprite.speed_offset = speed_offset
28 41
 	new_sprite.connect("viewport_entered", self, "_on_ForegroundSprite_viewport_entered")
29 42
 	new_sprite.connect("viewport_exited", self, "_on_ForegroundSprite_viewport_exited")
30 43
 	if moving:

+ 2
- 1
mini-game/scenes/spawner/pickup.gd View File

@@ -3,6 +3,7 @@ extends Node2D
3 3
 export var sprite_texture : Texture
4 4
 export var type := "bonus" setget , get_type
5 5
 export var scroll_speed = 9
6
+var speed_offset : float = 0
6 7
 
7 8
 onready var sprite = $Sprite
8 9
 onready var audio_stream = $AudioStreamPlayer
@@ -32,7 +33,7 @@ func get_type():
32 33
 
33 34
 
34 35
 func move():
35
-	self.position.x -= scroll_speed
36
+	self.position.x -= scroll_speed + speed_offset
36 37
 
37 38
 
38 39
 func pickup():

+ 13
- 1
mini-game/scenes/spawner/spawner.gd View File

@@ -9,11 +9,22 @@ var end_of_game = false
9 9
 var timer_speed = 0.99
10 10
 var random_threshold = 50
11 11
 var scenes_offset = 0
12
+var speed_offset : float = 0 setget set_speed_offset
12 13
 
13 14
 onready var timer := $Timer
14 15
 onready var items := $items
15 16
 
16 17
 
18
+func init(speed: float):
19
+	set_speed_offset(speed)
20
+
21
+
22
+func set_speed_offset(new_value: float):
23
+	speed_offset = new_value
24
+	for obj in items.get_children():
25
+		obj.speed_offset = speed_offset
26
+
27
+
17 28
 func _on_Timer_timeout():
18 29
 	random_scene.randomize()
19 30
 	scene_index = random_scene.randi_range(1,100)
@@ -22,6 +33,7 @@ func _on_Timer_timeout():
22 33
 	else:
23 34
 		scene_index = 0
24 35
 	var tmp = scenes[scene_index+scenes_offset*2].instance()
36
+	tmp.speed_offset = speed_offset
25 37
 	items.add_child(tmp)
26 38
 	last_object = tmp
27 39
 	if(timer.wait_time <= 1):
@@ -46,6 +58,6 @@ func start(difficulty, version):
46 58
 
47 59
 func stop():
48 60
 	timer.stop()
49
-	for obj in $items.get_children():
61
+	for obj in items.get_children():
50 62
 		remove_child(obj)
51 63
 		obj.queue_free()

Loading…
Cancel
Save