@@ -1,14 +1,16 @@ | |||||
planetdata = { | planetdata = { | ||||
{ | { | ||||
x = 0, y = 50000, | |||||
r = 12000, m = 5e14, | |||||
x = 0, y = 0, | |||||
r = 500000, m = 5e15, | |||||
xSpeed = 0, ySpeed = 0, | |||||
name = "Testos", | name = "Testos", | ||||
colour = {42, 04, 20}, | colour = {42, 04, 20}, | ||||
parent = "star" | parent = "star" | ||||
}, | }, | ||||
{ | { | ||||
x = 30000, y = 50000, | |||||
r = 2000, m = 1e14, | |||||
x = 2000000, y = 0, | |||||
r = 40000, m = 4e7, | |||||
xSpeed = 0, ySpeed = 12000, | |||||
name = "Deez", | name = "Deez", | ||||
colour = {50, 50, 50}, | colour = {50, 50, 50}, | ||||
parent = 1 | parent = 1 | ||||
@@ -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 |
@@ -6,6 +6,7 @@ require "libraries" | |||||
-- General Data: | -- General Data: | ||||
info = require "data/info" | info = require "data/info" | ||||
controls = require "data/controls" | controls = require "data/controls" | ||||
settings = require "data/settings" | |||||
texture = require "textures/textures" | texture = require "textures/textures" | ||||
-- Game Source: | -- Game Source: | ||||
@@ -7,10 +7,14 @@ function love.load() | |||||
-- Declaration: | -- Declaration: | ||||
love.window.setTitle(info.name.." - v"..info.version) | love.window.setTitle(info.name.." - v"..info.version) | ||||
width, height = love.graphics.getDimensions() | width, height = love.graphics.getDimensions() | ||||
cam = Camera() | |||||
zoomlevel = 0.5 | |||||
-- Camera: | |||||
cam = Camera() | |||||
zoomlevel = settings.zoom.reset | |||||
--Simulation: | |||||
warpspeed = 1 | |||||
warpCoolDown = 0 | |||||
-- Loading: | -- Loading: | ||||
ships = {} --Potentially add other starships in the future? | ships = {} --Potentially add other starships in the future? | ||||
@@ -36,6 +40,7 @@ function loadPlanets() | |||||
-- Planet Data Assignment: | -- Planet Data Assignment: | ||||
p.x, p.y, | p.x, p.y, | ||||
p.r, p.m, | p.r, p.m, | ||||
p.xSpeed, p.ySpeed, | |||||
p.name, | p.name, | ||||
p.colour, | p.colour, | ||||
p.parent | p.parent | ||||
@@ -65,26 +70,26 @@ end | |||||
function cameraControls() | function cameraControls() | ||||
local zooming = 0.01 | |||||
local step = settings.zoom.step | |||||
function love.wheelmoved(x, y) | function love.wheelmoved(x, y) | ||||
if y > 0 then | if y > 0 then | ||||
-- Zoom in: | -- Zoom in: | ||||
zoomlevel = zoomlevel + zooming | |||||
zoomlevel = zoomlevel + step | |||||
elseif y < 0 then | elseif y < 0 then | ||||
-- Zoom out: | -- Zoom out: | ||||
zoomlevel = zoomlevel - zooming | |||||
zoomlevel = zoomlevel - step | |||||
end | end | ||||
end | end | ||||
-- Reset Zoom: | -- Reset Zoom: | ||||
if love.mouse.isDown(3) then | |||||
zoomlevel = 1 | |||||
if love.mouse.isDown(controls.camera.zoom.reset) then | |||||
zoomlevel = settings.zoom.reset | |||||
end | end | ||||
-- Zoom Limit: | -- Zoom Limit: | ||||
local max = 4 | |||||
local min = 0.001 | |||||
local max = settings.zoom.max | |||||
local min = settings.zoom.min | |||||
if zoomlevel < min then | if zoomlevel < min then | ||||
zoomlevel = min | zoomlevel = min | ||||
end | end | ||||
@@ -95,14 +100,54 @@ function cameraControls() | |||||
cam:zoomTo(zoomlevel) | cam:zoomTo(zoomlevel) | ||||
end | 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 | -- MAIN | ||||
function love.update(dt) | function love.update(dt) | ||||
-- Game Objects: | -- Game Objects: | ||||
updatePlanets() | |||||
player:update(dt) | |||||
for i=1, timewarpControls() do | |||||
-- Physics go in here: | |||||
updatePlanets() | |||||
player:update(dt) | |||||
end | |||||
player:throttleControls() | |||||
-- Gui: | -- Gui: | ||||
gui:update(dt) | gui:update(dt) | ||||
@@ -16,7 +16,7 @@ function Gui:drawSpeed() | |||||
end | end | ||||
function Gui:drawWarp() | function Gui:drawWarp() | ||||
local warp = player.warpspeed | |||||
local warp = warpspeed | |||||
love.graphics.setColor(1, 1, 1) | love.graphics.setColor(1, 1, 1) | ||||
love.graphics.printf("Warp Speed: x"..warp, 5, 5, width, "left") | love.graphics.printf("Warp Speed: x"..warp, 5, 5, width, "left") | ||||
end | end | ||||
@@ -1,6 +1,6 @@ | |||||
Planet = Class {} | 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: | -- Planet Position: | ||||
self.x = tempX | self.x = tempX | ||||
self.y = tempY | self.y = tempY | ||||
@@ -23,8 +23,9 @@ function Planet:init(tempX, tempY, tempR, tempM, tempName, tempC, tempP) | |||||
-- Planet Family: | -- Planet Family: | ||||
self.children = {} | self.children = {} | ||||
if (tempP ~= "star") then | |||||
self.ySpeed = 5 | |||||
if (tempP ~= "star") then | |||||
self.xSpeed = tempXSpeed | |||||
self.ySpeed = tempYSpeed | |||||
self.parent = planet[tempP] | self.parent = planet[tempP] | ||||
table.insert(planet[tempP].children, self) | table.insert(planet[tempP].children, self) | ||||
end | 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 | for i, child in ipairs(self.children) do | ||||
local grav = calc.gPull(self, child) | local grav = calc.gPull(self, child) | ||||
local dist = calc.distance(self.x, self.y, child.x, child.y) | 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.xSpeed = child.xSpeed - (child.x - self.x)*pull | ||||
child.ySpeed = child.ySpeed - (child.y - self.y)*pull | child.ySpeed = child.ySpeed - (child.y - self.y)*pull | ||||
@@ -17,13 +17,6 @@ function Player:init(tempX, tempY) | |||||
self.throttle = 0.5 | self.throttle = 0.5 | ||||
self.speed = 0.05 | self.speed = 0.05 | ||||
-- Time Warping: | |||||
self.warpspeed = 1 | |||||
self.warpLimit = 10 | |||||
-- Cooldown Between Clicking: | |||||
self.warpCoolDown = 30 | |||||
self.coolDown = 0 | |||||
-- Landings: | -- Landings: | ||||
self.impacttolerance = 0.5 | self.impacttolerance = 0.5 | ||||
self.landingspeed = 0 | self.landingspeed = 0 | ||||
@@ -158,37 +151,6 @@ function Player:gravity() | |||||
end | end | ||||
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() | function Player:updatePosition() | ||||
self.x = self.x + self.xSpeed | self.x = self.x + self.xSpeed | ||||
self.y = self.y + self.ySpeed | self.y = self.y + self.ySpeed | ||||
@@ -200,19 +162,15 @@ end | |||||
function Player:update(dt) | function Player:update(dt) | ||||
--debug(self.warpspeed) | --debug(self.warpspeed) | ||||
self:timewarp() | |||||
for i=1, self.warpspeed do | |||||
self:gravity() | |||||
self:flightControls() | |||||
self:updatePosition() | |||||
end | |||||
self:throttleControls() | |||||
if self.angle > calc.pi*2 then | if self.angle > calc.pi*2 then | ||||
self.angle = 0 | self.angle = 0 | ||||
elseif self.angle < 0 then | elseif self.angle < 0 then | ||||
self.angle = calc.pi*2 | self.angle = calc.pi*2 | ||||
end | end | ||||
self.coolDown = self.coolDown - 1 | |||||
self:gravity() | |||||
self:flightControls() | |||||
self:updatePosition() | |||||
end | end | ||||
function Player:draw() | function Player:draw() | ||||