diff --git a/src/main.lua b/src/main.lua index ca3d0b3..5932c9f 100644 --- a/src/main.lua +++ b/src/main.lua @@ -83,13 +83,13 @@ local ore_types = { "iron ore", "copper ore", "warp fuel", } -- the "zero relative velocity" key will be a burn whatever amount of fuel/acceleration necessary to match local acceleration -- which.. since the currently stored velocity is a COMPLETELY SEPARATE SYSTEM - is literally just zeroing velocity which makes it even simpler to execute local player_ship = { - position_x = screen_width / 2, - position_y = screen_height / 2, + position_x = 100, + position_y = 100, velocity_x = 0, velocity_y = 0, acceleration = 100, - radar_size = 10, + radar_size = 4, cargo_max_space = 100, cargo_free_space = 75, @@ -103,42 +103,54 @@ local player_ship = { } local resource_points = {} -- NOTE they're "planets" but I intend for them to be multiple things tbh +local function make_resource_point(x, y) + local current_point = { + position_x = x or math.random() * screen_width / 2, + position_y = y or math.random() * screen_height / 2, + radar_size = 7, + + cargo_max_space = 100000, + cargo_free_space = 100000, + cargo_contents = {}, + } + -- TODO exclude orbits that would collide + current_point.orbital_radius = math.sqrt(current_point.position_x^2 + current_point.position_y^2) + current_point.rotation_offset = math.atan2(current_point.position_y, current_point.position_x) + + -- NOTE can select literally anything + local selected_type = ore_types[math.random(#ore_types)] + local cargo_amount = math.random() * 10000 + 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 + return + end + + table.insert(resource_points, current_point) + return true +end + 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, - position_y = math.random() * screen_height, - radar_size = 10, - - cargo_max_space = 100000, - cargo_free_space = 100000, - cargo_contents = {}, - } - - -- NOTE can select literally anything - local selected_type = ore_types[math.random(#ore_types)] - local cargo_amount = math.random() * 10000 - 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 - return - end - - table.insert(resource_points, current_point) - return true - end - if not make_resource_point() then i = i - 1 end end end -add_resource_points(math.random(5)) +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) local last_message = "" +local game_time = 0 +-- 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 + -- NOTE this control scheme makes diagonal travel faster than horizontal/vertical if love.keyboard.isDown("w") or love.keyboard.isDown("up") then player_ship.velocity_y = player_ship.velocity_y - player_ship.acceleration * dt @@ -171,6 +183,19 @@ 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 + local player_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_radius / (1 / orbital_speed_constant) + player_rotation_offset), math.sin(dt / player_radius / (1 / orbital_speed_constant) + player_rotation_offset) + player_ship.position_x = x * player_radius + player_ship.position_y = y * player_radius + + for i = 1, #resource_points do + local current_point = resource_points[i] + local x, y = math.cos(game_time / current_point.orbital_radius / (1 / orbital_speed_constant) + current_point.rotation_offset), math.sin(game_time / current_point.orbital_radius / (1 / orbital_speed_constant) + current_point.rotation_offset) + current_point.position_x = x * current_point.orbital_radius + current_point.position_y = y * current_point.orbital_radius + end + -- TODO make this toggleable instead of requiring holding a key if love.keyboard.isDown("space") then local function collect_resource() @@ -208,13 +233,20 @@ local font_height = font:getHeight() function love.draw() love.graphics.setColor(1, 1, 1, 1) + -- local camera_offset = { + -- x = screen_width / 2 - player_ship.position_x, + -- y = screen_height / 2 - player_ship.position_y, + -- } + local camera_offset = { x = screen_width / 2, y = screen_height / 2, } + 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) for i = 1, #resource_points do - local resource_point = resource_points[i] - love.graphics.circle("line", resource_point.position_x, resource_point.position_y, resource_point.radar_size) + local current_point = resource_points[i] + love.graphics.circle("line", current_point.position_x, current_point.position_y, current_point.radar_size) end + love.graphics.translate(-camera_offset.x, -camera_offset.y) love.graphics.print(last_message, 1, 1) local inventory_status = {}