From 274a15fd28b143ee0552c6f7bed5788c1246683b Mon Sep 17 00:00:00 2001 From: Tangent Date: Thu, 27 Nov 2025 02:48:38 -0700 Subject: [PATCH] tasks/ideas documented in code --- src/main.lua | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/main.lua b/src/main.lua index 1121291..653cdbd 100644 --- a/src/main.lua +++ b/src/main.lua @@ -15,7 +15,7 @@ local player_ship = { cargo_fill_speed = 10, } -local resource_points = {} +local resource_points = {} -- NOTE they're "planets" but I intend for them to be multiple things tbh for i = 1, 3 do local resource_point = { position_x = math.random() * screen_width, @@ -26,9 +26,10 @@ for i = 1, 3 do cargo_contents = {}, } - local cargo_types = { "iron ore", "copper ore", } + local cargo_types = { "iron ore", "copper ore", } -- TODO use a proper enumeration local selected_type = cargo_types[math.random(2)] local cargo_amount = math.random() * 10000 + -- TODO utility function to handle transferring cargo resource_point.cargo_contents[selected_type] = cargo_amount resource_point.cargo_free_space = resource_point.cargo_free_space - cargo_amount @@ -36,8 +37,6 @@ for i = 1, 3 do table.insert(resource_points, resource_point) end --- The player can hold a button to collect those resources and store them on their ship. - local last_message = "" function love.update(dt) if love.keyboard.isDown("w") then @@ -56,25 +55,30 @@ 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 + -- TODO there needs to be a way to zero out relative velocity? (I don't think so yet) + if love.keyboard.isDown("space") then - local selected_point, distance_to_point = nil, math.huge + -- TODO this whole thing should be a function, especially cause it uses return shortcutting + local selected_point, distance_to_point_squared = nil, math.huge for i = 1, #resource_points do local resource_point = resource_points[i] local distance_squared = (player_ship.position_x - resource_point.position_x)^2 + (player_ship.position_y - resource_point.position_y)^2 - if distance_squared < distance_to_point then + if distance_squared < distance_to_point_squared then selected_point = resource_point - distance_to_point = distance_squared + distance_to_point_squared = distance_squared end end - if distance_to_point > selected_point.radar_size^2 then + -- TODO ideally, there should be an indicator that you're close enough instead of relying on messages (to be fair, the radius is the indicator) + if distance_to_point_squared > selected_point.radar_size^2 then last_message = "Too far to pick up cargo." return end + -- TODO there should be a persistent indicator of cargo capacity and how full it is if player_ship.cargo_free_space <= 0 then last_message = "No cargo space left." return end - local cargo_type = next(selected_point.cargo_contents) + local cargo_type = next(selected_point.cargo_contents) -- TODO handle the possibility of this being empty local cargo_amount = math.min(player_ship.cargo_fill_speed * dt, selected_point.cargo_contents[cargo_type]) if cargo_amount <= 0 then last_message = "There is no cargo to pick up."