Browse Source

Merge branch 'main' into master

tags/v0.0.6_dev
Madiwka 2 years ago
committed by GitHub
parent
commit
da00dd181d
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 90 additions and 66 deletions
  1. +6
    -4
      data/planetdata.lua
  2. +17
    -0
      data/settings.lua
  3. +1
    -0
      import.lua
  4. +56
    -11
      main.lua
  5. +1
    -1
      src/class/Gui.lua
  6. +5
    -4
      src/class/Planet.lua
  7. +4
    -46
      src/class/Player.lua

+ 6
- 4
data/planetdata.lua View File

@@ -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 View File

@@ -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 View File

@@ -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 View File

@@ -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.5

-- 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 View File

@@ -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 View File

@@ -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


+ 4
- 46
src/class/Player.lua View File

@@ -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
@@ -158,37 +151,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
@@ -200,19 +162,15 @@ 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()
if self.angle > calc.pi*2 then
self.angle = 0
elseif self.angle < 0 then
self.angle = calc.pi*2
end
self.coolDown = self.coolDown - 1
self:gravity()
self:flightControls()
self:updatePosition()
end

function Player:draw()


Loading…
Cancel
Save