failing to orbit other objects

This commit is contained in:
2025-11-27 22:37:01 -07:00
parent a53c19b350
commit 2cc0a7de25
+16 -3
View File
@@ -1,5 +1,5 @@
love.window.setMode(960, 540)
local screen_width, screen_height = love.graphics.getDimensions()
local screen_width, screen_height = 960, 540
love.window.setMode(screen_width, screen_height)
math.randomseed(os.time())
-- returns selected_object, distance_squared_to_object (if object_list is empty, returns nil, math.huge)
@@ -135,7 +135,7 @@ local function add_resource_points(point_count)
end
end
end
add_resource_points(8)
-- add_resource_points(8)
-- DEBUG hardcoded points to compare against (except they can still fail to spawn if something else is too close)
make_resource_point(10, 0)
make_resource_point(screen_width / 2 - 10, 0)
@@ -180,6 +180,7 @@ function love.update(dt)
player_ship.position_x = player_ship.position_x + player_ship.velocity_x * dt
player_ship.position_y = player_ship.position_y + player_ship.velocity_y * dt
-- NOTE hardcoded player_ship orbiting center
player_ship.orbital_radius = math.sqrt(player_ship.position_x^2 + player_ship.position_y^2)
local player_rotation_offset = math.atan2(player_ship.position_y, player_ship.position_x)
local x, y = math.cos(dt / player_ship.orbital_radius / (1 / orbital_speed_constant) + player_rotation_offset), math.sin(dt / player_ship.orbital_radius / (1 / orbital_speed_constant) + player_rotation_offset)
@@ -193,6 +194,14 @@ function love.update(dt)
current_point.position_y = y * current_point.orbital_radius
end
-- NOTE this fails to account for parent movement I think? either way, it doesn't orbit correctly
-- local closest_object, distance_squared_to_object = get_closest_object(resource_points, player_ship)
-- player_ship.orbital_radius = math.sqrt(distance_squared_to_object)
-- local player_rotation_offset = math.atan2(player_ship.position_y - closest_object.position_y, player_ship.position_x - closest_object.position_x)
-- local x, y = math.cos(dt / player_ship.orbital_radius / (1 / orbital_speed_constant) + player_rotation_offset), math.sin(dt / player_ship.orbital_radius / (1 / orbital_speed_constant) + player_rotation_offset)
-- player_ship.position_x = x * player_ship.orbital_radius + closest_object.position_x
-- player_ship.position_y = y * player_ship.orbital_radius + closest_object.position_y
-- TODO make this toggleable instead of requiring holding a key
if love.keyboard.isDown("space") then
local function collect_resource()
@@ -247,6 +256,10 @@ function love.draw()
end
love.graphics.circle("line", 0, 0, player_ship.orbital_radius)
-- NOTE if player is orbiting another object
-- local closest_object = get_closest_object(resource_points, player_ship)
-- love.graphics.circle("line", closest_object.position_x, closest_object.position_y, player_ship.orbital_radius)
love.graphics.translate(-camera_offset.x, -camera_offset.y)
love.graphics.print(last_message, 1, 1)