it works tm

This commit is contained in:
UndeadMaelys
2022-06-02 21:18:09 +02:00
parent 6afc7dc5e3
commit c92bfd7f6b
2 changed files with 97 additions and 21 deletions

View File

@@ -12,37 +12,101 @@ function love.load()
CONST_S = 0.15
T = 0
DT = 1/120
TIME_SPEED = 0.25
VIEW = {}
VIEW.x = 0
VIEW.y = 0
VIEW.prints = {}
require "class"
require "body"
newBody(0,0,300,{1,0,0})
newBody(0,100,100,{0,1,0})
newBody(100,0,200,{0,0,1})
newBody(100,100,50,{1,1,0})
newBody(100,200,250,{1,0,1})
newBody(200,100,150,{0,1,1})
newBody(
{0, 0, 0},
{0, 0, 0},
40000,
{1,0,0}
)
newBody(
{10000, 0, 0},
{0, 100000, 0},
200,
{0,1,0}
)
newBody(
{20000, 0, 0},
{0, 100000, 0},
400,
{0,0,1}
)
newBody(
{0, 20000, 0},
{-200000, 0, 0},
3000,
{0,1,1}
)
end
function love.update(dt)
T = T + dt * TIME_SPEED
T = math.floor((T + DT * TIME_SPEED)*1000)/1000
UpdateBodiesAcceleration()
UpdateBodiesVelocity(dt * TIME_SPEED)
UpdateBodiesPosition(dt * TIME_SPEED)
UpdateBodiesVelocity(DT * TIME_SPEED)
UpdateBodiesPosition(DT * TIME_SPEED)
end
function love.draw()
-- center camera on bigger one
local vm = 0
for n, body in pairs(BodyList) do
if body.mass > vm then
vm = body.mass
VIEW.x = -body.x
VIEW.y = -body.y
end
end
local vm = 0
for n, body in pairs(BodyList) do
if body.max_distance > vm then
vm = body.max_distance
VIEW.size = math.sqrt(body.max_distance)
end
end
love.graphics.setColor(1,1,1)
-- draw bodies
for n, body in pairs(BodyList) do
love.graphics.setColor(body.color[1],body.color[2],body.color[3])
love.graphics.circle("line",body.x+SCREEN_WIDTH/2,body.y+SCREEN_HEIGHT/2,math.sqrt(body.mass))
addPrint(body)
end
drawPrints()
-- draw info
love.graphics.setColor(1,1,1)
love.graphics.print(T)
love.graphics.print("x,y: " .. VIEW.x .. VIEW.y .. " size: " .. VIEW.size .. " T: ".. T)
for n, body in pairs(BodyList) do
love.graphics.print("mass: "..body.mass.." x,y: "..body.x..", "..body.y,0,15*(n))
love.graphics.setColor(body.color[1],body.color[2],body.color[3])
love.graphics.print("mass: "..body.mass..", x,y: "..body.x..", "..body.y..", vx, vy:"..body.vx..", "..body.vy,0,15*n)
end
end
function addPrint(body)
VIEW.print_time = 10
table.insert(VIEW.prints,{
pos = {
x = body.x,
y = body.y
},
mass = body.mass,
color = body.color,
time = VIEW.print_time
})
end
function drawPrints()
for n, print in pairs(VIEW.prints) do
love.graphics.setColor(print.color[1],print.color[2],print.color[3],print.time/VIEW.print_time)
love.graphics.circle("line",(VIEW.x+print.pos.x)/VIEW.size+SCREEN_WIDTH/2,(VIEW.y+print.pos.y)/VIEW.size+SCREEN_HEIGHT/2,(print.time/VIEW.print_time)*math.sqrt(print.mass)*5/VIEW.size)
print.time = print.time - 1
if print.time < 1 then VIEW.prints[n] = nil end
end
end