Browse Source

make pickups spawn randomly

Arnaud Vergnet 4 months ago
parent
commit
2b74499051
1 changed files with 19 additions and 8 deletions
  1. 19
    8
      mini-game/scenes/spawner/spawner.gd

+ 19
- 8
mini-game/scenes/spawner/spawner.gd View File

@@ -3,10 +3,11 @@ extends Node2D
3 3
 export (Array,PackedScene) var scenes
4 4
 
5 5
 var random_scene = RandomNumberGenerator.new()
6
+var random_timer = RandomNumberGenerator.new()
6 7
 var scene_index = 0;
7 8
 var last_object
8 9
 var end_of_game = false
9
-var timer_speed = 0.99
10
+var timer_speed : float = 1
10 11
 var random_threshold = 50
11 12
 var scenes_offset = 0
12 13
 var speed_offset : float = 0 setget set_speed_offset
@@ -14,8 +15,10 @@ var speed_offset : float = 0 setget set_speed_offset
14 15
 onready var timer := $Timer
15 16
 onready var items := $items
16 17
 
18
+var last_timer_random : float = 1
17 19
 
18 20
 func init(speed: float):
21
+	update_timer()
19 22
 	set_speed_offset(speed)
20 23
 
21 24
 
@@ -36,20 +39,28 @@ func _on_Timer_timeout():
36 39
 	tmp.speed_offset = speed_offset
37 40
 	items.add_child(tmp)
38 41
 	last_object = tmp
39
-	if(timer.wait_time <= 1):
40
-		timer.wait_time = 1
42
+	update_timer()
43
+
44
+
45
+func update_timer():
46
+	random_timer.randomize()
47
+	var random
48
+	if last_timer_random < -0.5:
49
+		random = random_scene.randf_range(-0.4, 1.5)
41 50
 	else:
42
-		timer.wait_time *= timer_speed
51
+		random = random_scene.randf_range(-0.8, 1.5)
52
+	last_timer_random = random
53
+	timer.wait_time = timer_speed + random
43 54
 
44 55
 
45 56
 func start(difficulty, version):
46 57
 	match difficulty:
47 58
 		"easy":
48
-			timer_speed = 0.99
49
-			random_threshold = 50
59
+			timer_speed = 1
60
+			random_threshold = 40
50 61
 		"hard":
51
-			timer_speed = 0.95
52
-			random_threshold = 33
62
+			timer_speed = 0.9
63
+			random_threshold = 25
53 64
 		_:
54 65
 			pass
55 66
 	scenes_offset = version

Loading…
Cancel
Save