From 5faa0436582f24b30d36f2313e76cd178d77235f Mon Sep 17 00:00:00 2001 From: Paul Liverman III Date: Thu, 7 Mar 2019 13:21:37 -0800 Subject: [PATCH] init --- .gitignore | 1 + src/main.moon | 69 +++++++++++++++++++++++++++++++++++++++++++++++ src/notes.moon | 23 ++++++++++++++++ src/ships.moon | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 166 insertions(+) create mode 100644 .gitignore create mode 100644 src/main.moon create mode 100644 src/notes.moon create mode 100644 src/ships.moon diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d907c43 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.lua diff --git a/src/main.moon b/src/main.moon new file mode 100644 index 0000000..aac14fa --- /dev/null +++ b/src/main.moon @@ -0,0 +1,69 @@ +-- changes: +-- reposition center based on weighted values from all points +-- so it is relatively near the center of mass +-- mass will be the number of parts that can be added? +-- if so, need to make minimum size of ship 3 (or 4? for the jump drive?) + +ships = {} +justGenerated = false + +make = -> + generate = require "ships" + for i=1, 75 + ship = generate! + minx = 0 + maxx = 0 + miny = 0 + maxy = 0 + for i=1, #ship.polygon, 2 + minx = math.min minx, ship.polygon[i] + maxx = math.max maxx, ship.polygon[i] + for i=2, #ship.polygon, 2 + miny = math.min miny, ship.polygon[i] + maxy = math.max maxy, ship.polygon[i] + ship.ratio = (maxx - minx) / (miny - maxy) + table.insert ships, ship + -- table.sort ships, (A, B) -> A.ratio > B.ratio + table.sort ships, (A, B) -> A.area > B.area +make! + +love.draw = -> + for i=1, #ships + love.graphics.setColor 1, 1, 1, 1 + love.graphics.translate (i + 1) % 14 * 55, 100 * (1 + math.floor i / 14) + ship = ships[i] + for triangle in *ship.triangles + love.graphics.polygon "fill", triangle + love.graphics.origin! + +love.olddraw = -> + love.graphics.scale 10, 10 + love.graphics.translate 5, 5.5 + -- for ship in *ships + for i=1, #ships + love.graphics.setColor 1, 1, 1, 1 + ship = ships[i] + for triangle in *ship.triangles + love.graphics.polygon "fill", triangle + -- love.graphics.print ship.area, 1, 1 + love.graphics.setColor 1, 0, 0, 1 + love.graphics.circle "fill", 0, 0, 0.25 + love.graphics.setColor 1, 1, 1, 1 + love.graphics.push! + love.graphics.origin! + love.graphics.print math.floor(math.log(ship.area)), (1 + (i-1) % 15) * 50, math.floor((i-1)/15+1) * 110 + love.graphics.pop! + love.graphics.translate 5, 0 + if i % 15 == 0 + love.graphics.translate -5*15, 11 + -- if justGenerated + -- justGenerated = false + -- love.graphics.captureScreenshot "#{love.filesystem.getSourceBaseDirectory!}/#{love.math.random!}.png" + +love.keypressed = (key) -> + if key == "escape" then + love.event.quit! + elseif key == "r" then + ships = {} + make! + justGenerated = true diff --git a/src/notes.moon b/src/notes.moon new file mode 100644 index 0000000..c3da4ca --- /dev/null +++ b/src/notes.moon @@ -0,0 +1,23 @@ +-- 'infinte' galaxy map +-- star colors (use chart w its percentages for now, later use ED data) +-- ship construction: grid of modules +-- - life support: replaces some sensors, controls, tanks +-- - resource handler: replaces tanks, cargo space, docking ports, airlocks +-- - storage system: replaces tanks & cargo space (expansion based on resource handler) +-- - survival system: combines cockpit & life support +-- - integrated drive system: combines reactor, rcs thrusters, ion drive, battery, and gyroscopes +-- - radar, lidar, radio, infrared sensor, spectrometer, radiation sensor (geiger counter), +-- camera, cpu, motion detector +-- starter ship: resource handler, integrated drive system, survival system +-- grammars for generating names of star systems, stars, planets, parts, vessels +-- remember to generate colors and color sets for ships? + +Part: { + materials: {} -- what it is made of (a percentage can be reclaimed by recycling) + modules: {} -- what features are added at what strengths +} + +-- what needs to be done every tick +-- - each 'on' system runs in turn based on priority, taking available energy +-- - alerts may trigger if a system cannot function +-- - systems should be responsible for everything else :D diff --git a/src/ships.moon b/src/ships.moon new file mode 100644 index 0000000..96024d9 --- /dev/null +++ b/src/ships.moon @@ -0,0 +1,73 @@ +localGenerator = love.math.newRandomGenerator os.time! + +distance = (x, y, X, Y) -> + x2 = x - X + y2 = y - Y + return math.sqrt x2*x2 + y2*y2 + +generate = (seed) -> + -- random = love.math.newRandomGenerator(seed) if seed + -- random = localGenerator unless random + random = love.math -- TEMP love bug + + -- length can be up to 2 * segmentLength longer + targetLength = math.max 1, random.randomNormal 2, 3 + -- does not count ends + segmentCount = math.floor math.max 1, random.randomNormal 2, 3 + segmentLength = targetLength / segmentCount + polygon = {} + -- generate right side + for i=1, segmentCount + table.insert polygon, math.max 0.5, random.randomNormal 1.5, 1.25 + table.insert polygon, segmentLength * i + -- place rear center point? + if love.math.random! < 0.8 + table.insert polygon, 0 + table.insert polygon, targetLength + segmentLength + -- clone right side backwards to make left side + for i=#polygon-1, 1, -2 + if polygon[i] != 0 + table.insert polygon, -polygon[i] + table.insert polygon, polygon[i + 1] + -- place front center point? + if love.math.random! > 0.2 + table.insert polygon, 0 + table.insert polygon, 0 + -- do not accept triangles + if #polygon <= 6 + return generate seed + + -- find center of mass + y = 0 + weight = 0 + for i=1, #polygon - 1, 2 + if polygon[i] == 0 -- ends have a 1.5 weighting + y += math.abs 1.5 * polygon[i + 1] + weight += math.abs 1.5 + else + y += math.abs polygon[i] * polygon[i + 1] + weight += math.abs polygon[i] + y /= weight + for i=2, #polygon, 2 + polygon[i] -= y + + ship = { + polygon: polygon + triangles: love.math.triangulate polygon + area: 0 -- calculated below + } + + for triangle in *ship.triangles + a = distance triangle[1], triangle[2], triangle[3], triangle[4] + b = distance triangle[3], triangle[4], triangle[5], triangle[6] + c = distance triangle[1], triangle[2], triangle[5], triangle[6] + s = 0.5 * ( a + b + c ) + ship.area += 10 * math.sqrt s * (s - a) * (s - b) * (s - c) + + for triangle in *ship.triangles + for i=1, 6 + triangle[i] *= 10 --+ math.log ship.area + + return ship + +return generate