formalizing..?
This commit is contained in:
parent
6856581804
commit
78ee6923cc
@ -1,57 +1,70 @@
|
|||||||
import graphics from love
|
|
||||||
import cos, sin, pi from math
|
|
||||||
export t = 0
|
|
||||||
tau = 2 * math.pi
|
|
||||||
w, h = graphics.getDimensions!
|
|
||||||
|
|
||||||
tiny = require "tiny"
|
tiny = require "tiny"
|
||||||
|
|
||||||
|
IDTracker = tiny.system {
|
||||||
|
filter: tiny.requireAll "id"
|
||||||
|
onAdd: (entity) =>
|
||||||
|
@[entity.id] = entity
|
||||||
|
onRemove: (entity) =>
|
||||||
|
@[entity.id] = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
Time = tiny.processingSystem {
|
||||||
|
filter: tiny.requireAll "time"
|
||||||
|
process: (entity, dt) =>
|
||||||
|
entity.time += dt
|
||||||
|
}
|
||||||
|
|
||||||
|
import graphics from love
|
||||||
|
import cos, sin from math
|
||||||
|
w, h = graphics.getDimensions!
|
||||||
MapDisplay = tiny.sortedSystem {
|
MapDisplay = tiny.sortedSystem {
|
||||||
compare: (a, b) =>
|
compare: (a, b) =>
|
||||||
a.orbit.hierarchy < b.orbit.hierarchy
|
if a.orbit and b.orbit
|
||||||
filter: tiny.requireAll "orbit"
|
a.orbit.hierarchy <= b.orbit.hierarchy
|
||||||
draw: =>
|
else
|
||||||
|
true
|
||||||
|
filter: tiny.requireAny "orbit", tiny.requireAll("x", "y")
|
||||||
|
draw: (t) =>
|
||||||
graphics.translate w / 2, h / 2
|
graphics.translate w / 2, h / 2
|
||||||
for e in *@entities
|
for entity in *@entities
|
||||||
entity = e.orbit
|
if orbit = entity.orbit
|
||||||
|
orbit = entity.orbit
|
||||||
-- orbital period
|
-- orbital period
|
||||||
-- real: T = 2pi * sqrt(a^3 / G*M)
|
-- real: T = 2pi * sqrt(a^3 / G*M)
|
||||||
-- sim: T = 2pi * speed_parameter
|
-- sim: T = 2pi * speed_parameter
|
||||||
entity.x = entity.radius * cos(t / entity.speed_parameter) + entity.offset
|
entity.x = orbit.radius * cos(t / orbit.speed_parameter) + orbit.offset
|
||||||
entity.y = entity.radius * sin(t / entity.speed_parameter) + entity.offset
|
entity.y = orbit.radius * sin(t / orbit.speed_parameter) + orbit.offset
|
||||||
if entity.parent
|
if orbit.parent_id
|
||||||
entity.x += entity.parent.x
|
parent = IDTracker[orbit.parent_id]
|
||||||
entity.y += entity.parent.y
|
entity.x += parent.x
|
||||||
graphics.circle "fill", entity.x, entity.y, 5
|
entity.y += parent.y
|
||||||
|
graphics.circle "fill", entity.x, entity.y, 5 -- TEMP radius
|
||||||
}
|
}
|
||||||
|
|
||||||
world = tiny.world MapDisplay
|
|
||||||
|
|
||||||
-- TEMP demo
|
-- TEMP demo
|
||||||
sun = {
|
sun = {
|
||||||
|
id: 0
|
||||||
x: 0,
|
x: 0,
|
||||||
y: 0,
|
y: 0
|
||||||
orbit: { hierarchy: 0, radius: 0, offset: 0, speed_parameter: 1 }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
planet = {
|
planet = {
|
||||||
|
id: 1
|
||||||
orbit: {
|
orbit: {
|
||||||
hierarchy: 1
|
hierarchy: 1
|
||||||
radius: 20
|
radius: 20
|
||||||
parent: sun
|
parent_id: 0
|
||||||
offset: love.math.random!
|
offset: love.math.random!
|
||||||
speed_parameter: 0.5
|
speed_parameter: 0.5
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
game = { time: 0 }
|
||||||
world\add planet, sun
|
world = tiny.world MapDisplay, IDTracker, planet, sun, Time, game
|
||||||
|
|
||||||
love.update = (dt) ->
|
love.update = (dt) ->
|
||||||
t += dt
|
|
||||||
world\update dt
|
world\update dt
|
||||||
|
|
||||||
love.draw = ->
|
love.draw = ->
|
||||||
MapDisplay\draw!
|
MapDisplay\draw game.time
|
||||||
|
|
||||||
love.keypressed = (key) ->
|
love.keypressed = (key) ->
|
||||||
if key == "escape" love.event.quit!
|
if key == "escape" love.event.quit!
|
||||||
|
Loading…
Reference in New Issue
Block a user