From ac175ef371cffdb35ab26036beedd32680cb832c Mon Sep 17 00:00:00 2001 From: Tangent Date: Fri, 28 Nov 2025 17:13:01 -0700 Subject: [PATCH] broken positioning, but functional mechanic almost --- src/main.lua | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/src/main.lua b/src/main.lua index 137f27f..5b0fd9d 100644 --- a/src/main.lua +++ b/src/main.lua @@ -124,7 +124,8 @@ local player_ship = { -- TODO fuel capacity and use (idle and while acceleration) -- TODO cargo / mass affects acceleration } -player_ship.orbital_radius = math.sqrt(player_ship.position_x^2 + player_ship.position_y^2) +-- player_ship.orbital_radius = math.sqrt(player_ship.position_x^2 + player_ship.position_y^2) +-- player_ship.rotation_offset = math.atan2(player_ship.position_y, player_ship.position_x) -- TODO this just needs to be a list of all objects - including the player local resource_points = {} -- NOTE they're "planets" but I intend for them to be multiple things tbh @@ -180,8 +181,8 @@ local core_object = { local last_message = "" local game_time = 0 --- local orbital_speed_constant = 1 -- ironically, I think 1 is exactly the speed I want (that was before the new orbit system) -local orbital_speed_constant = 50 +local orbital_speed_constant = 1 -- ironically, I think 1 is exactly the speed I want +-- local orbital_speed_constant = 50 function love.update(dt) game_time = game_time + dt @@ -233,12 +234,21 @@ 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) - player_ship.position_x = x * player_ship.orbital_radius - player_ship.position_y = y * player_ship.orbital_radius + if player_ship.velocity_x == 0 and player_ship.velocity_y == 0 then + player_ship.orbital_radius = player_ship.orbital_radius or math.sqrt(player_ship.position_x^2 + player_ship.position_y^2) + player_ship.rotation_offset = player_ship.rotation_offset or math.atan2(player_ship.position_y, player_ship.position_x) -- this will fail due to not being at timestep 0 + -- might be fixable by computing where the game thinks the player should be and then adjusting it by where they are + + -- TEMP player_ship localed to core_object orbit + local argument = game_time / player_ship.orbital_radius^1.337 * orbital_speed_constant * core_object.radar_size^2 + player_ship.rotation_offset + if (argument == math.huge) or (argument ~= argument) then + argument = 0 + end + player_ship.position_x, player_ship.position_y = core_object.position_x + player_ship.orbital_radius * math.cos(argument), core_object.position_y + player_ship.orbital_radius * math.sin(argument) + else + player_ship.orbital_radius = nil + player_ship.rotation_offset = nil + end -- TODO make this toggleable instead of requiring holding a key if love.keyboard.isDown("space") then @@ -285,7 +295,9 @@ function love.draw() love.graphics.translate(camera_offset.x, camera_offset.y) love.graphics.rectangle("line", player_ship.position_x - player_ship.radar_size / 2, player_ship.position_y - player_ship.radar_size / 2, player_ship.radar_size, player_ship.radar_size) - love.graphics.circle("line", 0, 0, player_ship.orbital_radius) + if player_ship.orbital_radius then + love.graphics.circle("line", 0, 0, player_ship.orbital_radius) + end local draw_object draw_object = function(current_object, parent_x, parent_y) @@ -351,6 +363,7 @@ function love.keypressed(key) transfer_cargo(player_ship, nil, "warp fuel", 5) player_ship.position_x = screen_width / 2 player_ship.position_y = screen_height / 2 + -- WARNING currently broken because the core_object isn't updated resource_points = {} add_resource_points(love.math.random(5)) end