Browse Source

allow setting different backgrounds

Arnaud Vergnet 4 months ago
parent
commit
29b571317f

+ 6
- 5
mini-game/MiniGame.gd View File

@@ -3,6 +3,7 @@ extends Node
3 3
 signal game_over
4 4
 
5 5
 onready var foreground := $foreground
6
+onready var background := $background
6 7
 onready var spawner := $spawner
7 8
 onready var player := $player
8 9
 onready var scoreUI := $scoreUI
@@ -35,14 +36,14 @@ func setup(mode: String, goal: int, difficulty: String, next_lose: String, next_
35 36
 	game_goal = goal
36 37
 	if(difficulty == "hard"):
37 38
 		game_difficulty = "hard"
38
-		game_speed = 2
39 39
 	else:
40 40
 		game_difficulty = "easy"
41 41
 	game_version = version
42
-	print("setup minigame: " + mode + " " + next_lose + " " + next_win)
42
+	print("setup minigame: " + mode + " " + next_lose + " " + next_win + " | version: " + String(version))
43 43
 	set_mode(mode)
44
-	foreground.init(game_speed)
45
-	spawner.init(game_speed)
44
+	background.init(game_version)
45
+	foreground.init(game_speed, game_version)
46
+	spawner.init(game_difficulty, game_version)
46 47
 	scoreUI.init(mode, goal)
47 48
 	next_timeline_lose = next_lose
48 49
 	next_timeline_win = next_win
@@ -76,7 +77,7 @@ func start():
76 77
 	yield(t, "timeout")
77 78
 	yield(t, "timeout")
78 79
 	start_timer_UI.hide()
79
-	spawner.start(game_difficulty, game_version)
80
+	spawner.start()
80 81
 	if game_mode == "score":
81 82
 		scoreUI.start(0)
82 83
 	else:

+ 11
- 0
mini-game/scenes/decor/ForegroundSprite.gd View File

@@ -2,8 +2,11 @@ extends Sprite
2 2
 
3 3
 export var scroll_speed = 9
4 4
 
5
+export(Array, Texture) var textures := []
6
+
5 7
 var speed_offset : float = 0
6 8
 var moving = false
9
+var game_version := 0 setget set_game_version
7 10
 
8 11
 signal viewport_entered(object)
9 12
 signal viewport_exited(object)
@@ -26,6 +29,14 @@ func move():
26 29
 	position.x -= scroll_speed + speed_offset
27 30
 
28 31
 
32
+func set_game_version(new_value: int):
33
+	game_version = new_value
34
+	if game_version < textures.size():
35
+		texture = textures[game_version]
36
+	else:
37
+		texture = textures[0]
38
+
39
+
29 40
 func _on_VisibilityNotifier2D_viewport_entered(viewport: Viewport) -> void:
30 41
 	emit_signal("viewport_entered", self)
31 42
 

+ 3
- 1
mini-game/scenes/decor/ForegroundSprite.tscn View File

@@ -1,7 +1,8 @@
1
-[gd_scene load_steps=5 format=2]
1
+[gd_scene load_steps=6 format=2]
2 2
 
3 3
 [ext_resource path="res://mini-game/ressources/backgrounds/road3.png" type="Texture" id=1]
4 4
 [ext_resource path="res://mini-game/scenes/decor/ForegroundSprite.gd" type="Script" id=2]
5
+[ext_resource path="res://mini-game/ressources/backgrounds/road.png" type="Texture" id=3]
5 6
 
6 7
 [sub_resource type="Shader" id=1]
7 8
 code = "shader_type canvas_item;
@@ -28,6 +29,7 @@ script = ExtResource( 2 )
28 29
 __meta__ = {
29 30
 "_editor_description_": ""
30 31
 }
32
+textures = [ ExtResource( 1 ), ExtResource( 3 ) ]
31 33
 
32 34
 [node name="VisibilityNotifier2D" type="VisibilityNotifier2D" parent="."]
33 35
 position = Vector2( 1930, 540 )

+ 12
- 0
mini-game/scenes/decor/background.gd View File

@@ -0,0 +1,12 @@
1
+extends Control
2
+
3
+export(Array, Texture) var textures := []
4
+
5
+var game_version := 0
6
+
7
+func init(version: int):
8
+	game_version = version
9
+	if version < textures.size():
10
+		$TextureRect.texture = textures[version]
11
+	else:
12
+		$TextureRect.texture = textures[0]

+ 5
- 1
mini-game/scenes/decor/background.tscn View File

@@ -1,13 +1,17 @@
1
-[gd_scene load_steps=2 format=2]
1
+[gd_scene load_steps=4 format=2]
2 2
 
3 3
 [ext_resource path="res://mini-game/ressources/backgrounds/city.png" type="Texture" id=1]
4
+[ext_resource path="res://mini-game/scenes/decor/background.gd" type="Script" id=2]
5
+[ext_resource path="res://mini-game/ressources/backgrounds/background.png" type="Texture" id=3]
4 6
 
5 7
 [node name="background" type="Control"]
6 8
 anchor_right = 1.0
7 9
 anchor_bottom = 1.0
10
+script = ExtResource( 2 )
8 11
 __meta__ = {
9 12
 "_edit_use_anchors_": false
10 13
 }
14
+textures = [ ExtResource( 1 ), ExtResource( 3 ) ]
11 15
 
12 16
 [node name="TextureRect" type="TextureRect" parent="."]
13 17
 anchor_right = 1.0

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

@@ -2,35 +2,39 @@ extends Node2D
2 2
 
3 3
 var sprite_scene = preload("res://mini-game/scenes/decor/ForegroundSprite.tscn")
4 4
 
5
-var textures := []
5
+var sprites := []
6
+var game_version := 0
6 7
 var moving := false
7 8
 
8 9
 var speed_offset : float = 0 setget set_speed_offset
9 10
 
10 11
 func _ready():
11
-	textures.append($ForegroundSprite)
12
+	sprites.append($ForegroundSprite)
12 13
 	stop()
13 14
 
14 15
 
15
-func init(speed: float):
16
+func init(speed: float, version: int):
17
+	game_version = version
18
+	for s in sprites:
19
+		s.game_version = game_version
16 20
 	set_speed_offset(speed)
17 21
 
18 22
 
19 23
 func set_speed_offset(new_value: float):
20 24
 	speed_offset = new_value
21
-	for t in textures:
25
+	for t in sprites:
22 26
 		t.speed_offset = speed_offset
23 27
 
24 28
 
25 29
 func stop():
26 30
 	moving = false
27
-	for t in textures:
31
+	for t in sprites:
28 32
 		t.stop()
29 33
 
30 34
 
31 35
 func start():
32 36
 	moving = true
33
-	for t in textures:
37
+	for t in sprites:
34 38
 		t.start()
35 39
 
36 40
 
@@ -42,10 +46,11 @@ func _on_ForegroundSprite_viewport_entered(object: Sprite) -> void:
42 46
 	new_sprite.connect("viewport_exited", self, "_on_ForegroundSprite_viewport_exited")
43 47
 	if moving:
44 48
 		new_sprite.start()
49
+	new_sprite.game_version = game_version
45 50
 	add_child(new_sprite)
46
-	textures.append(new_sprite)
51
+	sprites.append(new_sprite)
47 52
 
48 53
 
49 54
 func _on_ForegroundSprite_viewport_exited(object: Sprite) -> void:
50
-	textures.remove(textures.find(object))
55
+	sprites.remove(sprites.find(object))
51 56
 	object.queue_free()

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

@@ -17,9 +17,19 @@ onready var items := $items
17 17
 
18 18
 var last_timer_random : float = 1
19 19
 
20
-func init(speed: float):
20
+func init(difficulty: String, version: int):
21
+	match difficulty:
22
+		"easy":
23
+			timer_speed = 1
24
+			random_threshold = 40
25
+		"hard":
26
+			timer_speed = 0.9
27
+			random_threshold = 25
28
+		_:
29
+			pass
30
+	scenes_offset = version
21 31
 	update_timer()
22
-	set_speed_offset(speed)
32
+	set_speed_offset(0)
23 33
 
24 34
 
25 35
 func set_speed_offset(new_value: float):
@@ -53,17 +63,7 @@ func update_timer():
53 63
 	timer.wait_time = timer_speed + random
54 64
 
55 65
 
56
-func start(difficulty, version):
57
-	match difficulty:
58
-		"easy":
59
-			timer_speed = 1
60
-			random_threshold = 40
61
-		"hard":
62
-			timer_speed = 0.9
63
-			random_threshold = 25
64
-		_:
65
-			pass
66
-	scenes_offset = version
66
+func start():
67 67
 	timer.start()
68 68
 
69 69
 

Loading…
Cancel
Save