2022-08-04 17:56:22 -06:00
|
|
|
extends Node2D
|
|
|
|
|
|
|
|
onready var topBorder = $TopBorder
|
|
|
|
onready var bottomBorder = $BottomBorder
|
|
|
|
onready var leftBorder = $LeftBorder
|
|
|
|
onready var rightBorder = $RightBorder
|
|
|
|
|
2022-08-05 17:15:17 -06:00
|
|
|
export var NUM_CLOUDS = 12
|
2022-08-04 17:56:22 -06:00
|
|
|
|
2022-08-05 17:15:17 -06:00
|
|
|
var clouds = []
|
|
|
|
var speeds = []
|
2022-08-04 17:56:22 -06:00
|
|
|
var rng = RandomNumberGenerator.new()
|
|
|
|
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
|
|
func _ready():
|
2022-08-05 17:15:17 -06:00
|
|
|
for num in range(NUM_CLOUDS):
|
|
|
|
var cloud_image_path = "res://assets/cloud%s.png" % (num % 4 + 1)
|
|
|
|
var new_cloud_sprite = Sprite.new()
|
|
|
|
new_cloud_sprite.texture = load(cloud_image_path)
|
|
|
|
add_child(new_cloud_sprite)
|
|
|
|
clouds.append(new_cloud_sprite)
|
|
|
|
var rand_speed = rng.randf_range(0.5,2)
|
|
|
|
speeds.append(rand_speed)
|
2022-08-04 17:56:22 -06:00
|
|
|
rng.randomize()
|
|
|
|
_start_position()
|
|
|
|
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
|
|
func _process(delta):
|
2022-08-05 17:15:17 -06:00
|
|
|
var index := 0
|
2022-08-04 17:56:22 -06:00
|
|
|
for cloud in clouds:
|
2022-08-05 17:15:17 -06:00
|
|
|
if cloud.global_position.x + speeds[index] < rightBorder.global_position.x:
|
|
|
|
cloud.global_position.x = cloud.global_position.x + speeds[index]
|
2022-08-04 17:56:22 -06:00
|
|
|
else:
|
|
|
|
cloud.global_position.x = leftBorder.global_position.x
|
2022-08-05 17:15:17 -06:00
|
|
|
cloud.global_position.y = rng.randi_range(topBorder.global_position.y, bottomBorder.global_position.y)
|
|
|
|
index += 1
|
2022-08-04 17:56:22 -06:00
|
|
|
|
|
|
|
func _start_position():
|
|
|
|
rng.randomize()
|
|
|
|
for cloud in clouds:
|
|
|
|
var y = rng.randi_range(topBorder.global_position.y, bottomBorder.global_position.y)
|
|
|
|
var x = rng.randi_range(leftBorder.global_position.x, rightBorder.global_position.x)
|
|
|
|
cloud.global_position = Vector2(x, y)
|
|
|
|
|
2022-08-08 15:32:57 -06:00
|
|
|
func _set_paused(paused: bool) -> void:
|
|
|
|
set_process(!paused)
|
2022-08-04 17:56:22 -06:00
|
|
|
|