Переглянути джерело

fixed physics with time warp

tags/v0.0.6_dev
Niro 2 роки тому
джерело
коміт
2e976fc29e
8 змінених файлів з 91 додано та 68 видалено
  1. +2
    -1
      data/info.lua
  2. +6
    -4
      data/planetdata.lua
  3. +17
    -0
      data/settings.lua
  4. +1
    -0
      import.lua
  5. +56
    -11
      main.lua
  6. +1
    -1
      src/class/Gui.lua
  7. +5
    -4
      src/class/Planet.lua
  8. +3
    -47
      src/class/Player.lua

+ 2
- 1
data/info.lua Переглянути файл

@@ -3,7 +3,8 @@ info = {}
info.name = "Questionable Örbital Mechanics"
info.version = "0.0.2_dev"
info.authors = {
"NiroUwU"
"NiroUwU",
"Madiwka4"
}

return info

+ 6
- 4
data/planetdata.lua Переглянути файл

@@ -1,14 +1,16 @@
planetdata = {
{
x = 0, y = 50000,
r = 12000, m = 5e14,
x = 0, y = 0,
r = 500000, m = 5e15,
xSpeed = 0, ySpeed = 0,
name = "Testos",
colour = {42, 04, 20},
parent = "star"
},
{
x = 30000, y = 50000,
r = 2000, m = 1e14,
x = 2000000, y = 0,
r = 40000, m = 4e7,
xSpeed = 0, ySpeed = 12000,
name = "Deez",
colour = {50, 50, 50},
parent = 1


+ 17
- 0
data/settings.lua Переглянути файл

@@ -0,0 +1,17 @@
settings = {
zoom = {
min = 0.0001,
max = 4,
step = 0.01,
reset = 0.0001
},
warp = {
min = 1,
max = 10,
step = 1,

cooldown = 10
}
}

return settings

+ 1
- 0
import.lua Переглянути файл

@@ -6,6 +6,7 @@ require "libraries"
-- General Data:
info = require "data/info"
controls = require "data/controls"
settings = require "data/settings"
texture = require "textures/textures"

-- Game Source:


+ 56
- 11
main.lua Переглянути файл

@@ -7,10 +7,14 @@ function love.load()
-- Declaration:
love.window.setTitle(info.name.." - v"..info.version)
width, height = love.graphics.getDimensions()
cam = Camera()
zoomlevel = 0.005

-- Camera:
cam = Camera()
zoomlevel = settings.zoom.reset

--Simulation:
warpspeed = 1
warpCoolDown = 0

-- Loading:
ships = {} --Potentially add other starships in the future?
@@ -36,6 +40,7 @@ function loadPlanets()
-- Planet Data Assignment:
p.x, p.y,
p.r, p.m,
p.xSpeed, p.ySpeed,
p.name,
p.colour,
p.parent
@@ -65,26 +70,26 @@ end


function cameraControls()
local zooming = 0.01
local step = settings.zoom.step

function love.wheelmoved(x, y)
if y > 0 then
-- Zoom in:
zoomlevel = zoomlevel + zooming
zoomlevel = zoomlevel + step
elseif y < 0 then
-- Zoom out:
zoomlevel = zoomlevel - zooming
zoomlevel = zoomlevel - step
end
end

-- Reset Zoom:
if love.mouse.isDown(3) then
zoomlevel = 1
if love.mouse.isDown(controls.camera.zoom.reset) then
zoomlevel = settings.zoom.reset
end

-- Zoom Limit:
local max = 4
local min = 0.001
local max = settings.zoom.max
local min = settings.zoom.min
if zoomlevel < min then
zoomlevel = min
end
@@ -95,14 +100,54 @@ function cameraControls()
cam:zoomTo(zoomlevel)
end

function timewarpControls()
-- Time Warp Toggle Cooldowns:
local maxCooldown = settings.warp.cooldown
-- Time Warp Steps:
local step = settings.warp.step
-- Time Warp Limits:
local min = settings.warp.min
local max = settings.warp.max

-- Decrease Warp
if love.keyboard.isDown(controls.flight.warp.down) and warpCoolDown <= 0 then
warpspeed = warpspeed - step
warpCoolDown = maxCooldown
end
-- Increase Warp
if love.keyboard.isDown(controls.flight.warp.up) and warpCoolDown <= 0 then
warpspeed = warpspeed + step
warpCoolDown = maxCooldown
end
-- Reset Warp
if love.keyboard.isDown(controls.flight.warp.reset) then
warpspeed = min
end

-- Value Correction
if warpspeed < min then
warpspeed = min
elseif warpspeed > max then
warpspeed = max
end

warpCoolDown = warpCoolDown - 1
return warpspeed
end



-- MAIN

function love.update(dt)
-- Game Objects:
updatePlanets()
player:update(dt)
for i=1, timewarpControls() do
-- Physics go in here:
updatePlanets()
player:update(dt)
end
player:throttleControls()

-- Gui:
gui:update(dt)


+ 1
- 1
src/class/Gui.lua Переглянути файл

@@ -16,7 +16,7 @@ function Gui:drawSpeed()
end

function Gui:drawWarp()
local warp = player.warpspeed
local warp = warpspeed
love.graphics.setColor(1, 1, 1)
love.graphics.printf("Warp Speed: x"..warp, 5, 5, width, "left")
end


+ 5
- 4
src/class/Planet.lua Переглянути файл

@@ -1,6 +1,6 @@
Planet = Class {}

function Planet:init(tempX, tempY, tempR, tempM, tempName, tempC, tempP)
function Planet:init(tempX, tempY, tempR, tempM, tempXSpeed, tempYSpeed, tempName, tempC, tempP)
-- Planet Position:
self.x = tempX
self.y = tempY
@@ -23,8 +23,9 @@ function Planet:init(tempX, tempY, tempR, tempM, tempName, tempC, tempP)

-- Planet Family:
self.children = {}
if (tempP ~= "star") then
self.ySpeed = 5
if (tempP ~= "star") then
self.xSpeed = tempXSpeed
self.ySpeed = tempYSpeed
self.parent = planet[tempP]
table.insert(planet[tempP].children, self)
end
@@ -48,7 +49,7 @@ function Planet:attract(dt) --Planet doing the attracting, divided in two parts
for i, child in ipairs(self.children) do
local grav = calc.gPull(self, child)
local dist = calc.distance(self.x, self.y, child.x, child.y)
local pull = 20/dist * grav/1e14
local pull = 20/dist * grav
child.xSpeed = child.xSpeed - (child.x - self.x)*pull
child.ySpeed = child.ySpeed - (child.y - self.y)*pull


+ 3
- 47
src/class/Player.lua Переглянути файл

@@ -17,13 +17,6 @@ function Player:init(tempX, tempY)
self.throttle = 0.5
self.speed = 0.05

-- Time Warping:
self.warpspeed = 1
self.warpLimit = 10
-- Cooldown Between Clicking:
self.warpCoolDown = 30
self.coolDown = 0

-- Landings:
self.impacttolerance = 0.5
self.landingspeed = 0
@@ -140,37 +133,6 @@ function Player:gravity()
end
end

function Player:timewarp()
local step = 1
-- Time Warp Limits:
local min = 1
local max = self.warpLimit

-- Decrease Warp
if love.keyboard.isDown(controls.flight.warp.down) and self.coolDown <= 0 then
self.warpspeed = self.warpspeed - step
self.coolDown = self.warpCoolDown
end
-- Increase Warp
if love.keyboard.isDown(controls.flight.warp.up) and self.coolDown <= 0 then
self.warpspeed = self.warpspeed + step
self.coolDown = self.warpCoolDown
end
-- Reset Warp
if love.keyboard.isDown(controls.flight.warp.reset) then
self.warpspeed = min
end

-- Value Correction
if self.warpspeed < min then
self.warpspeed = min
elseif self.warpspeed > max then
self.warpspeed = max
end

return self.warpspeed
end

function Player:updatePosition()
self.x = self.x + self.xSpeed
self.y = self.y + self.ySpeed
@@ -182,15 +144,9 @@ end

function Player:update(dt)
--debug(self.warpspeed)
self:timewarp()
for i=1, self.warpspeed do
self:gravity()
self:flightControls()
self:updatePosition()
end
self:throttleControls()
self.coolDown = self.coolDown - 1
self:gravity()
self:flightControls()
self:updatePosition()
end

function Player:draw()


Завантаження…
Відмінити
Зберегти