#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:
parent
1ece202731
commit
ac4b96ef49
6 changed files with 51 additions and 144 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue