-
Notifications
You must be signed in to change notification settings - Fork 34
/
backgroundGame.gd
136 lines (117 loc) · 4.02 KB
/
backgroundGame.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
extends Control
var offsetX
var offsetY = -50
onready var Obstacles = preload("res://assets/obstacles.tscn")
onready var Enemys = preload("res://assets/enemys.tscn")
onready var Restartpoint = preload("res://restartPoint.tscn")
onready var Collectables = preload("res://assets/collectables.tscn")
onready var Wolke = preload("res://Wolke.tscn")
onready var viewportSize = get_viewport().size
var fakeSpeed=1000
var score = 0
var finalScore = 0
var distanceWalked = 0
var ground
var placeholderScore
var placeholderScoreSize
var spriteWidth
var obstaclesCount = 8
var enemysCount = 8
var wolkenMaxCount = 20
onready var cameraNode = get_node("cameraNode")
onready var spritesNode = get_node("sprites")
onready var enemysNode = spritesNode.get_node("enemys")
onready var constMoveNode = spritesNode.get_node("constantMovement")
onready var restartPointsNode = constMoveNode.get_node("restartPoints")
onready var obstaclesNode = constMoveNode.get_node("obstacles")
onready var wolkenNode = spritesNode.get_node("wolken")
onready var groundSprites = constMoveNode.get_node("ground")
onready var groundSprite1 = groundSprites.get_node("Sprite1")
onready var groundSprite2 = groundSprites.get_node("Sprite2")
func _ready():
spriteWidth = groundSprite1.get_texture().get_size().x
seed(0)
func mapGen():
obstaclesGen()
respawnpointGen()
enemysGen()
wolkenGen()
sync func rpcRespawnpoint(pos):
var restartPoint = Restartpoint.instance()
restartPointsNode.position.x=0
restartPointsNode.add_child(restartPoint)
restartPoint.global_position = pos
func respawnpointGen():
var distance = 1500
var restartPoint = Restartpoint.instance()
var pos = Vector2(distance ,400)
rpcRespawnpoint( pos)
sync func rpcEnemy(pos, scale, choice):#
var enemy = Enemys.instance()
enemy.choice("enemy",choice) ##only one available
enemy.position = pos
enemy.scale = scale
enemysNode.add_child(enemy)
func enemysGen():
var i = 0
while i < enemysCount:
var choice = round(rand_range(1,1)) ##only one available
var pos = Vector2(i*800+rand_range(1024,2000)-enemysNode.position.x,rand_range(10,325))
var scaleDice = rand_range(0.3,1)
var scale = Vector2(scaleDice,scaleDice)
rpcEnemy( pos, scale, choice)
i += 1
i = 0
sync func rpcObstacles(pos, flipped, scale ,choice):
var obstacle = Obstacles.instance()
obstacle.choice("kaktuss",choice)
obstacle.global_position= pos
obstacle.scale = Vector2(scale,scale)
if flipped:
obstacle.get_node("kaktuss"+str(choice)).get_node("Sprite").flip_h = true
else:
pass
obstaclesNode.add_child(obstacle)
func obstaclesGen():
var i = 0
while i < obstaclesCount and obstaclesNode.is_inside_tree():
var pos = Vector2(i*1000+rand_range(1024,2000)-obstaclesNode.global_position.x,rand_range(350,390))
var flipped
var choice = round(rand_range(1,8))
var scale = rand_range(0.8,1.2)
if rand_range(0,2) > 1:
flipped = true
else:
flipped = false
rpcObstacles( pos, flipped, scale, choice)
i += 1
i = 0
sync func rpcWolken(pos, wideness):
var wolke = Wolke.instance()
wolke.wideness = wideness
wolke.position=pos
wolkenNode.add_child(wolke)
func wolkenGen():
var currentCount = get_tree().get_nodes_in_group("wolken").size()
if currentCount < wolkenMaxCount:
var pos = Vector2(rand_range(1200,1600)-wolkenNode.position.x,rand_range(0,250))
var wideness = rand_range(1, 4)
rpcWolken( pos, wideness)
sync func setNewSpeed(_speed):
fakeSpeed +=_speed
func _process(delta):
constMoveNode.position.x-=fakeSpeed*delta
enemysNode.position.x-=fakeSpeed*delta*1.5
func _on_VisibilityNotifier2D_screen_exited():
# two ground-tiles for seamless infinite maps
# everytime a tile hast left the screen, position.x is updating and new obstacles are generating
if groundSprite1.position.x<groundSprite2.position.x:
groundSprite1.position.x = groundSprite2.position.x + spriteWidth*groundSprite1.scale.x
else:
groundSprites.position.x=0
groundSprite2.position.x = groundSprite1.position.x + spriteWidth*groundSprite1.scale.x
if is_inside_tree():
mapGen()
func endGame():
get_parent().remove_child(self)
queue_free()