From 31f83a5222d67f369b108b3bd7d884ce69ca8c43 Mon Sep 17 00:00:00 2001 From: Abheek Dhawan Date: Tue, 2 Nov 2021 11:19:06 -0500 Subject: [PATCH] Attempt to allow asteroids to spawn to the sides as well as on top of the viewport --- Scripts/Game.gd | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Scripts/Game.gd b/Scripts/Game.gd index 59405cb..46c9825 100644 --- a/Scripts/Game.gd +++ b/Scripts/Game.gd @@ -42,8 +42,14 @@ func _process(delta): if has_node("Rocket"): var asteroid = asteroidObj.instance() add_child(asteroid) - asteroid.position.x = rand_range($Rocket.position.x - get_viewport_rect().size.x/2, $Rocket.position.x + get_viewport_rect().size.x/2) - asteroid.position.y = rand_range($Rocket.position.y - get_viewport_rect().size.y, $Rocket.position.y - 2 * get_viewport_rect().size.y) + spawnx = rand_range($Rocket.position.x - get_viewport_rect().size.x, $Rocket.position.x + get_viewport_rect().size.x) + asteroid.position.x = spawnx + if (spawnx < $Rocket.position.x - get_viewport_rect().size.x/2 or spawnx > $Rocket.position.x + get_viewport_rect().size.x/2): + asteroid.position.y = rand_range($Rocket.position.y + get_viewport_rect().size.y/2, $Rocket.position.y - 2 * get_viewport_rect().size.y) + else: + asteroid.position.y = rand_range($Rocket.position.y - get_viewport_rect().size.y, $Rocket.position.y - 2 * get_viewport_rect().size.y) + #asteroid.position.x = rand_range($Rocket.position.x - get_viewport_rect().size.x/2, $Rocket.position.x + get_viewport_rect().size.x/2) + #asteroid.position.y = rand_range($Rocket.position.y - get_viewport_rect().size.y, $Rocket.position.y - 2 * get_viewport_rect().size.y) asteroid.rotation = rand_range(0, 6.28) if asteroidSpawnRepeat == 5: asteroidSpawnRepeat = 0