From 3c324e0f7658991279933422766d4903d2f3824b Mon Sep 17 00:00:00 2001 From: Tangent Date: Thu, 27 Nov 2025 16:43:37 -0700 Subject: [PATCH] system warp --- src/main.lua | 53 +++++++++++++++++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 17 deletions(-) diff --git a/src/main.lua b/src/main.lua index f8228dd..ca3d0b3 100644 --- a/src/main.lua +++ b/src/main.lua @@ -1,3 +1,4 @@ +love.window.setMode(960, 540) local screen_width, screen_height = love.graphics.getDimensions() math.randomseed(os.time()) @@ -22,6 +23,7 @@ local function get_closest_object(object_list, current_object) return selected_object, distance_squared_to_object end +-- source_object and destination_object can be nil to create/delete resources -- returns cargo_amount (actual amount transferred) local function transfer_cargo(source_object, destination_object, cargo_type, cargo_amount) if not source_object then @@ -67,12 +69,11 @@ local function check_cargo_amount(source_object, cargo_type, cargo_amount) return false end --- The resources collected by the player can be spent on something, --- like improving the ship. Speed, capacity, collection speed, etc. --- TODO future upgrade: range upgrade ? --- right now: iron -> caoacity, copper -> acceleration - -local cargo_types = { "iron ore", "copper ore", } +local ore_types = { "iron ore", "copper ore", "warp fuel", } +-- local cargo_types = {} +-- for i = 1, #ore_types do +-- cargo_types[#cargo_types + 1] = ore_types[i] +-- end -- for i = 1, #cargo_types do -- cargo_types[cargo_types[i]] = i -- end @@ -91,8 +92,10 @@ local player_ship = { radar_size = 10, cargo_max_space = 100, - cargo_free_space = 100, - cargo_contents = {}, + cargo_free_space = 75, + cargo_contents = { + ["warp fuel"] = 25, + }, cargo_fill_speed = 10, -- TODO fuel capacity and use (idle and while acceleration) @@ -100,8 +103,8 @@ local player_ship = { } local resource_points = {} -- NOTE they're "planets" but I intend for them to be multiple things tbh -local function spawn_3_points() - for i = 1, 3 do +local function add_resource_points(point_count) + for i = 1, point_count do local function make_resource_point() local current_point = { position_x = math.random() * screen_width, @@ -114,7 +117,7 @@ local function spawn_3_points() } -- NOTE can select literally anything - local selected_type = cargo_types[math.random(#cargo_types)] + local selected_type = ore_types[math.random(#ore_types)] local cargo_amount = math.random() * 10000 transfer_cargo(nil, current_point, selected_type, cargo_amount) @@ -132,26 +135,26 @@ local function spawn_3_points() end end end -spawn_3_points() +add_resource_points(math.random(5)) local last_message = "" function love.update(dt) -- NOTE this control scheme makes diagonal travel faster than horizontal/vertical - if love.keyboard.isDown("w") then + if love.keyboard.isDown("w") or love.keyboard.isDown("up") then player_ship.velocity_y = player_ship.velocity_y - player_ship.acceleration * dt end - if love.keyboard.isDown("a") then + if love.keyboard.isDown("a") or love.keyboard.isDown("left") then player_ship.velocity_x = player_ship.velocity_x - player_ship.acceleration * dt end - if love.keyboard.isDown("s") then + if love.keyboard.isDown("s") or love.keyboard.isDown("down") then player_ship.velocity_y = player_ship.velocity_y + player_ship.acceleration * dt end - if love.keyboard.isDown("d") then + if love.keyboard.isDown("d") or love.keyboard.isDown("right") then player_ship.velocity_x = player_ship.velocity_x + player_ship.acceleration * dt end -- NOTE this zeros out diagonal velocities faster than horizontal/vertical - if love.keyboard.isDown("x") then + if love.keyboard.isDown("lshift") or love.keyboard.isDown("rshift") then if player_ship.velocity_x > 0 then player_ship.velocity_x = math.max(0, player_ship.velocity_x - player_ship.acceleration * dt) elseif player_ship.velocity_x < 0 then @@ -168,6 +171,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 + -- TODO make this toggleable instead of requiring holding a key if love.keyboard.isDown("space") then local function collect_resource() local closest_object, distance_squared_to_object = get_closest_object(resource_points, player_ship) @@ -234,6 +238,7 @@ function love.keypressed(key) last_message = "You do not have enough iron ore to upgrade your cargo space. (need 25)" return end + last_message = "Cargo space increased by 5." transfer_cargo(player_ship, nil, "iron ore", 25) player_ship.cargo_max_space = player_ship.cargo_max_space + 5 player_ship.cargo_free_space = player_ship.cargo_free_space + 5 @@ -243,7 +248,21 @@ function love.keypressed(key) last_message = "You do not have enough copper ore to upgrade your acceleration. (need 25)" return end + last_message = "Acceleration increased by 10%." transfer_cargo(player_ship, nil, "copper ore", 25) player_ship.acceleration = player_ship.acceleration * 1.1 + elseif key == "return" or key == "kpenter" then + -- NOTE soft lock is possible when no warp fuel is generated / left / you use it all up without realizing + if not check_cargo_amount(player_ship, "warp fuel", 5) then + last_message = "You do not have enough warp fuel to go to a new system. (need 5)" + return + end + -- TODO require not being moving to warp + last_message = "Warped to new system!" + transfer_cargo(player_ship, nil, "warp fuel", 5) + player_ship.position_x = screen_width / 2 + player_ship.position_y = screen_height / 2 + resource_points = {} + add_resource_points(math.random(5)) end end