#139: the prologue's debris belt keeps off the screen too

The belt was laid out with its own arithmetic - a centre BELT_AHEAD in front
of the fleet, rocks spread BELT_DEPTH either side of it - so its near edge
reached back to within a screen of the convoy. At the aspect it was
eyeballed on that was just outside the view; at a wider one, or any zoom
out, rocks appeared in plain sight.

#126 already answered this question for the rest of the game, so the answer
is borrowed rather than restated: AsteroidField's keep-out rect and its
push-out-through-the-nearest-edge placement are public now, and the belt
runs through them. That also means the two cannot drift apart later.

The distance moves as well, 2200 to 2900. The clamp alone would work, but it
would work by pressing every stray rock onto the boundary line; with the
belt properly out in front, the clamp has almost nothing left to do and the
belt still looks laid out ahead rather than pinned to the edge of the
screen. Measured: nearest rock 1551 units out, against a keep-out that
reaches 1100.
This commit is contained in:
Loïc Wisniewski 2026-08-28 15:37:11 +02:00
commit ac4b96ef49
6 changed files with 51 additions and 144 deletions

View file

@ -77,12 +77,16 @@ func _chebyshev_chunk_distance(a: Vector2i, b: Vector2i) -> int:
# The area a new asteroid must stay out of: whatever is on screen, or the
# fallback bubble around the fleet when there is no screen to measure.
#
# Public since #139: the prologue lays its own debris belt (IntroDirector)
# with its own arithmetic and had the same bug this fixed - rocks appearing
# inside the view. One rule, in one place, borrowed rather than restated.
#
# Chunks are populated around wherever the fleet happens to be, including the
# chunk it is standing in, so without this a rock could appear directly on a
# ship - worst on the frame a scene loads, where arriving back from a planet
# could cost a vessel instantly. #126 widens that from "not on the fleet" to
# "not in view", which is the same rule the player actually notices.
func _keep_out_rect(centre: Vector2) -> Rect2:
func keep_out_rect(centre: Vector2) -> Rect2:
var fallback := Rect2(centre - Vector2(safe_spawn_radius, safe_spawn_radius),
Vector2(safe_spawn_radius, safe_spawn_radius) * 2.0)
if get_viewport() == null:
@ -96,7 +100,7 @@ func _keep_out_rect(centre: Vector2) -> Rect2:
return visible_rect.merge(fallback)
func _safe_position(candidate: Vector2, keep_out: Rect2) -> Vector2:
func safe_position(candidate: Vector2, keep_out: Rect2) -> Vector2:
if not keep_out.has_point(candidate):
return candidate
# Pushed out through the nearest edge rather than dropped, so the field
@ -123,12 +127,12 @@ func _spawn_chunk_asteroids(chunk: Vector2i) -> void:
# Measured once per chunk rather than per asteroid: it cannot change
# between two rocks placed in the same frame, and it is a viewport
# transform rather than a field read.
var keep_out: Rect2 = _keep_out_rect(fleet.get_centroid())
var keep_out: Rect2 = keep_out_rect(fleet.get_centroid())
for i in range(asteroids_per_chunk):
var local_pos: Vector2 = Vector2(randf() * WorldGen.CHUNK_SIZE, randf() * WorldGen.CHUNK_SIZE)
var asteroid: Node2D = asteroid_scene.instantiate()
asteroid.position = _safe_position(origin + local_pos, keep_out)
asteroid.position = safe_position(origin + local_pos, keep_out)
var angle: float = randf() * TAU
var speed: float = randf_range(min_speed, max_speed)
asteroid.velocity = Vector2(cos(angle), sin(angle)) * speed

View file

@ -59,7 +59,12 @@ const AMBUSH_AHEAD: float = 1100.0
# #125: the run was over in about four seconds at cruise. Far enough now
# that the convoy is genuinely under way before anything interrupts it.
const RUN_DISTANCE: float = 3400.0
const BELT_AHEAD: float = 2200.0
# #139: far enough that the near edge of the belt is well past the screen
# even before the keep-out below trims it. The two together, rather than
# either alone: the distance keeps the belt looking laid out ahead rather
# than pinned to the screen edge, and the keep-out is what actually
# guarantees nothing appears in view at any aspect ratio or zoom.
const BELT_AHEAD: float = 2900.0
const BELT_ROCKS: int = 90
const BELT_HALF_WIDTH: float = 2600.0
const BELT_DEPTH: float = 1400.0
@ -422,12 +427,22 @@ func _spawn_belt() -> void:
rock.queue_free()
rocks.clear()
belt_at = fleet.get_centroid() + Vector2(0.0, -BELT_AHEAD)
# #139: rocks were popping into existence on screen. The belt is spread
# BELT_DEPTH either side of its centre, so its near edge reached back to
# within a screen of the fleet - and at a wider aspect than the one it
# was eyeballed on, into the view outright.
#
# The rule is the asteroid field's own (#126), borrowed rather than
# restated here: anything that lands in view is pushed out through the
# nearest edge, so the belt keeps its density instead of thinning where
# the player is looking.
var keep_out: Rect2 = asteroid_field.keep_out_rect(fleet.get_centroid())
var scene: PackedScene = load("res://world/Asteroid.tscn")
for i in range(BELT_ROCKS):
var rock: Node2D = scene.instantiate()
rock.position = belt_at + Vector2(
rock.position = asteroid_field.safe_position(belt_at + Vector2(
randf_range(-BELT_HALF_WIDTH, BELT_HALF_WIDTH),
randf_range(-BELT_DEPTH, BELT_DEPTH))
randf_range(-BELT_DEPTH, BELT_DEPTH)), keep_out)
get_parent().add_child(rock)
rocks.append(rock)