Compare commits
1 Commits
main
...
display_ge
Author | SHA1 | Date | |
---|---|---|---|
|
600f0bc9f8 |
34
src/generators/MapDisplay.moon
Normal file
34
src/generators/MapDisplay.moon
Normal file
@ -0,0 +1,34 @@
|
||||
import graphics from love
|
||||
import cos, sin from math
|
||||
|
||||
w, h = graphics.getDimensions!
|
||||
|
||||
tiny = require "tiny"
|
||||
IDTracker = require "systems/IDTracker"
|
||||
|
||||
MapDisplay = (system_id) ->
|
||||
return tiny.sortedSystem {
|
||||
compare: (a, b) =>
|
||||
if a.orbit and b.orbit
|
||||
a.orbit.hierarchy <= b.orbit.hierarchy
|
||||
else
|
||||
true
|
||||
filter: tiny.requireAny "orbit", tiny.requireAll("x", "y", system_id)
|
||||
draw: (t) =>
|
||||
graphics.translate w / 2, h / 2
|
||||
for entity in *@entities
|
||||
if orbit = entity.orbit
|
||||
orbit = entity.orbit
|
||||
-- orbital period
|
||||
-- real: T = 2pi * sqrt(a^3 / G*M)
|
||||
-- sim: T = 2pi * speed_parameter
|
||||
entity.x = orbit.radius * cos(t / orbit.speed_parameter) + orbit.offset
|
||||
entity.y = orbit.radius * sin(t / orbit.speed_parameter) + orbit.offset
|
||||
if orbit.parent_id
|
||||
parent = IDTracker[orbit.parent_id]
|
||||
entity.x += parent.x
|
||||
entity.y += parent.y
|
||||
graphics.circle "fill", entity.x, entity.y, 5 -- TEMP radius
|
||||
}
|
||||
|
||||
return MapDisplay
|
@ -1,4 +1,5 @@
|
||||
tiny = require "tiny"
|
||||
MapDisplay = require "generators/MapDisplay"
|
||||
|
||||
systems = {}
|
||||
for name in *love.filesystem.getDirectoryItems "systems"
|
||||
@ -17,11 +18,14 @@ makeEntity = (tab) ->
|
||||
return tab
|
||||
|
||||
world = tiny.world game, unpack systems
|
||||
local map
|
||||
|
||||
system = ->
|
||||
system_id = "someuuidthing"
|
||||
sun = makeEntity {
|
||||
x: 0,
|
||||
y: 0
|
||||
[system_id]: true
|
||||
}
|
||||
planet = makeEntity {
|
||||
orbit: {
|
||||
@ -31,8 +35,11 @@ system = ->
|
||||
offset: love.math.random!
|
||||
speed_parameter: 0.5
|
||||
}
|
||||
[system_id]: true
|
||||
}
|
||||
map = MapDisplay system_id
|
||||
world\add sun, planet
|
||||
world\add map
|
||||
|
||||
system!
|
||||
|
||||
@ -40,7 +47,7 @@ love.update = (dt) ->
|
||||
world\update dt
|
||||
|
||||
love.draw = ->
|
||||
systems.MapDisplay\draw game.time
|
||||
map\draw game.time
|
||||
|
||||
love.keypressed = (key) ->
|
||||
if key == "escape" love.event.quit!
|
||||
|
59
src/systems/disabled/MapDisplayManager.moon
Normal file
59
src/systems/disabled/MapDisplayManager.moon
Normal file
@ -0,0 +1,59 @@
|
||||
import graphics from love
|
||||
import cos, sin from math
|
||||
|
||||
w, h = graphics.getDimensions!
|
||||
|
||||
tiny = require "tiny"
|
||||
IDTracker = require "systems/IDTracker"
|
||||
|
||||
|
||||
|
||||
MapDisplayManager = tiny.system {
|
||||
known: {}
|
||||
filter: tiny.requireAll "system_id"
|
||||
onAdd: (entity) =>
|
||||
unless @known[entity.system_id]
|
||||
@known[entity.system_id] = true
|
||||
makeDisplay entity.system_id
|
||||
onRemove: (entity) =>
|
||||
}
|
||||
|
||||
|
||||
|
||||
IDTracker = tiny.system {
|
||||
filter: tiny.requireAll "id"
|
||||
onAdd: (entity) =>
|
||||
@[entity.id] = entity
|
||||
onRemove: (entity) =>
|
||||
@[entity.id] = nil
|
||||
}
|
||||
return MapDisplayManager
|
||||
|
||||
|
||||
|
||||
|
||||
MapDisplay = tiny.sortedSystem {
|
||||
compare: (a, b) =>
|
||||
if a.orbit and b.orbit
|
||||
a.orbit.hierarchy <= b.orbit.hierarchy
|
||||
else
|
||||
true
|
||||
filter: tiny.requireAny "orbit", tiny.requireAll("x", "y")
|
||||
draw: (t) =>
|
||||
graphics.translate w / 2, h / 2
|
||||
for entity in *@entities
|
||||
if orbit = entity.orbit
|
||||
orbit = entity.orbit
|
||||
-- orbital period
|
||||
-- real: T = 2pi * sqrt(a^3 / G*M)
|
||||
-- sim: T = 2pi * speed_parameter
|
||||
entity.x = orbit.radius * cos(t / orbit.speed_parameter) + orbit.offset
|
||||
entity.y = orbit.radius * sin(t / orbit.speed_parameter) + orbit.offset
|
||||
if orbit.parent_id
|
||||
parent = IDTracker[orbit.parent_id]
|
||||
entity.x += parent.x
|
||||
entity.y += parent.y
|
||||
graphics.circle "fill", entity.x, entity.y, 5 -- TEMP radius
|
||||
}
|
||||
|
||||
return MapDisplay
|
Loading…
Reference in New Issue
Block a user