stage 3
This commit is contained in:
+45
-2
@@ -24,6 +24,13 @@ end
|
||||
|
||||
-- returns cargo_amount (actual amount transferred)
|
||||
local function transfer_cargo(source_object, destination_object, cargo_type, cargo_amount)
|
||||
if not source_object then
|
||||
source_object = { cargo_contents = { [cargo_type] = math.huge }, cargo_free_space = 0, }
|
||||
end
|
||||
if not destination_object then
|
||||
destination_object = { cargo_contents = {}, cargo_free_space = math.huge, }
|
||||
end
|
||||
|
||||
if not source_object.cargo_contents[cargo_type] then
|
||||
return 0
|
||||
end
|
||||
@@ -31,7 +38,13 @@ local function transfer_cargo(source_object, destination_object, cargo_type, car
|
||||
destination_object.cargo_contents[cargo_type] = 0
|
||||
end
|
||||
|
||||
cargo_amount = math.min(cargo_amount, source_object.cargo_contents[cargo_type])
|
||||
if cargo_amount > source_object.cargo_contents[cargo_type] then
|
||||
cargo_amount = source_object.cargo_contents[cargo_type]
|
||||
end
|
||||
if cargo_amount > destination_object.cargo_free_space then
|
||||
cargo_amount = destination_object.cargo_free_space
|
||||
end
|
||||
|
||||
destination_object.cargo_contents[cargo_type] = destination_object.cargo_contents[cargo_type] + cargo_amount
|
||||
destination_object.cargo_free_space = destination_object.cargo_free_space - cargo_amount
|
||||
source_object.cargo_contents[cargo_type] = source_object.cargo_contents[cargo_type] - cargo_amount
|
||||
@@ -44,12 +57,25 @@ local function transfer_cargo(source_object, destination_object, cargo_type, car
|
||||
return cargo_amount
|
||||
end
|
||||
|
||||
local function check_cargo_amount(source_object, cargo_type, cargo_amount)
|
||||
if not source_object.cargo_contents[cargo_type] then
|
||||
return false
|
||||
end
|
||||
if source_object.cargo_contents[cargo_type] >= cargo_amount then
|
||||
return true
|
||||
end
|
||||
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", }
|
||||
-- for i = 1, #cargo_types do
|
||||
-- cargo_types[cargo_types[i]] = i
|
||||
-- end
|
||||
|
||||
-- TODO review my previous orbits code to add extremely slow background orbits to this
|
||||
-- planets/stars/stations always have fixed orbits; ships have a fixed orbital acceleration but have their own additional
|
||||
@@ -90,7 +116,7 @@ local function spawn_3_points()
|
||||
-- NOTE can select literally anything
|
||||
local selected_type = cargo_types[math.random(#cargo_types)]
|
||||
local cargo_amount = math.random() * 10000
|
||||
transfer_cargo({ cargo_contents = { [selected_type] = cargo_amount, }, cargo_free_space = 0, }, current_point, selected_type, cargo_amount)
|
||||
transfer_cargo(nil, current_point, selected_type, cargo_amount)
|
||||
|
||||
local closest_object, distance_squared_to_object = get_closest_object(resource_points, current_point)
|
||||
if closest_object and distance_squared_to_object <= (closest_object.radar_size^2 + current_point.radar_size^2) * 1.5 then
|
||||
@@ -202,5 +228,22 @@ end
|
||||
function love.keypressed(key)
|
||||
if key == "escape" then
|
||||
love.event.quit()
|
||||
elseif key == "1" then
|
||||
-- 25x iron ore -> 5 cargo space
|
||||
if not check_cargo_amount(player_ship, "iron ore", 25) then
|
||||
last_message = "You do not have enough iron ore to upgrade your cargo space. (need 25)"
|
||||
return
|
||||
end
|
||||
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
|
||||
elseif key == "2" then
|
||||
-- 25x copper ore -> 1.1x acceleration
|
||||
if not check_cargo_amount(player_ship, "copper ore", 25) then
|
||||
last_message = "You do not have enough copper ore to upgrade your acceleration. (need 25)"
|
||||
return
|
||||
end
|
||||
transfer_cargo(player_ship, nil, "copper ore", 25)
|
||||
player_ship.acceleration = player_ship.acceleration * 1.1
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user