ft (wip): tracking across boundaries

This commit is contained in:
2026-02-07 18:01:17 +01:00
parent 0f06846157
commit bc582efb90
12 changed files with 93 additions and 43 deletions

View File

@@ -60,10 +60,10 @@ func init_screen_size(x:float, y:float) -> void:
# This can take a vector of any size (but should be 2d, other components are unused)
func get_boundaried_position(position):
## clamp
# clamp
#return position.clamp(Vector2.ZERO, screen_size)
## periodic
# periodic
position.x = wrapf(position.x, 0, screen_size.x)
position.y = wrapf(position.y, 0, screen_size.y)
return position
@@ -76,3 +76,39 @@ func get_new_flow():
flow_y = flow_mag * sin(flow_dir)
func calc_distance(one, two) -> float:
var candidate = one.distance_to(two)
var onedup = one
# FIXME: doesnt work-- predators lose track across game boundary
if one.x < screen_size.x/2:
if one.y < screen_size.y/2:
# top left
onedup.y -= screen_size.y
candidate = min(candidate, onedup.distance_to(two))
onedup.y += screen_size.y
onedup.x -= screen_size.x
candidate = min(candidate, onedup.distance_to(two))
else:
# bottom left
onedup.y += screen_size.y
candidate = min(candidate, onedup.distance_to(two))
onedup.y -= screen_size.y
onedup.x -= screen_size.x
candidate = min(candidate, onedup.distance_to(two))
else:
if one.y < screen_size.y/2:
# top right
onedup.y -= screen_size.y
candidate = min(candidate, onedup.distance_to(two))
onedup.y += screen_size.y
onedup.x += screen_size.x
candidate = min(candidate, onedup.distance_to(two))
else:
# botom right
onedup.y += screen_size.y
candidate = min(candidate, onedup.distance_to(two))
onedup.y -= screen_size.y
onedup.x += screen_size.x
candidate = min(candidate, onedup.distance_to(two))
return candidate