4 Commits

Author SHA1 Message Date
  Niro fd64b84fcd please work 2 years ago
  Niro 030e216bd6 added broken textures, broken relative landing speed and something else i probably forgot 2 years ago
  Madiwka b19d074d1f
Merge pull request #4 from NiroUwU/testing 2 years ago
  Madiwka b6738e3343 Reworked gravity. added moons and stuff 2 years ago
12 changed files with 139 additions and 69 deletions
Unified View
  1. +4
    -1
      data/controls.lua
  2. +12
    -4
      data/planetdata.lua
  3. +14
    -0
      data/starshipTypes.lua
  4. +2
    -1
      import.lua
  5. +4
    -3
      main.lua
  6. +20
    -0
      src/Abilities.lua
  7. +0
    -1
      src/calc.lua
  8. +1
    -1
      src/class/FX.lua
  9. +21
    -10
      src/class/Planet.lua
  10. +53
    -47
      src/class/Player.lua
  11. BIN
      textures/player/orbiter.png
  12. +8
    -1
      textures/textures.lua

+ 4
- 1
data/controls.lua View File

@@ -29,7 +29,10 @@ controls = {
reset = "-", reset = "-",
down = ",", down = ",",
up = "." up = "."
}
},

-- Special
special = "f"
}, },
-- Player Camera Controls: -- Player Camera Controls:


+ 12
- 4
data/planetdata.lua View File

@@ -1,19 +1,27 @@
planetdata = { planetdata = {
{ {
x = 0, y = 0, x = 0, y = 0,
r = 500000, m = 5e15,
xSpeed = 0, ySpeed = 0,
r = 500000, m = 1e12,
xSpeed = 0, ySpeed = 100,
name = "Testos", name = "Testos",
colour = {42, 04, 20}, colour = {42, 04, 20},
parent = "star" parent = "star"
}, },
{ {
x = 2000000, y = 0, x = 2000000, y = 0,
r = 40000, m = 4e7,
xSpeed = 0, ySpeed = 12000,
r = 100000, m = 4e9,
xSpeed = 0, ySpeed = 175,
name = "Deez", name = "Deez",
colour = {50, 50, 50}, colour = {50, 50, 50},
parent = 1 parent = 1
},
{
x = 2200000, y = 0,
r = 10000, m = 1e4,
xSpeed = 0, ySpeed = 35,
name = "Ligos",
colour = {10, 50, 20},
parent = 2
} }
} }



+ 14
- 0
data/starshipTypes.lua View File

@@ -0,0 +1,14 @@
-- This is completely temporary, THIS WILL CHANGE
starshipTypes = {
orbiter = {
name = "Classic Orbiter",
description = "Dolor fugiat irure sit aliqua labore. Culpa voluptate occaecat anim exercitation proident sint ex dolor. Officia in labore sint Lorem ea. Ad minim aliqua aliqua non commodo qui in ea sit excepteur excepteur qui.",
impacttolerance = 0.5,
mass = 100000, -- idk, feels better but holy fuck thats a thicc ass boi xD
speed = 0.05,
specials = {"orbitSync"},
texture = texture.player.orbiter
}
}

return starshipTypes

+ 2
- 1
import.lua View File

@@ -5,9 +5,10 @@ require "libraries"


-- General Data: -- General Data:
info = require "data/info" info = require "data/info"
texture = require "textures/textures"
controls = require "data/controls" controls = require "data/controls"
settings = require "data/settings" settings = require "data/settings"
texture = require "textures/textures"
starshipTypes = require "data/starshipTypes"


-- Game Source: -- Game Source:
calc = require "src/calc" calc = require "src/calc"


+ 4
- 3
main.lua View File

@@ -6,6 +6,7 @@ calc.isDebug = true
function love.load() function love.load()
-- Declaration: -- Declaration:
love.window.setTitle(info.name.." - v"..info.version) love.window.setTitle(info.name.." - v"..info.version)
--love.graphics.setDefaultFilter("nearest", "nearest")
width, height = love.graphics.getDimensions() width, height = love.graphics.getDimensions()


-- Camera: -- Camera:
@@ -23,7 +24,8 @@ function love.load()
loadPlanets() loadPlanets()


local spawnPlanet = planet[1] local spawnPlanet = planet[1]
player = Player(spawnPlanet.x, spawnPlanet.y-spawnPlanet.r-1)
player = Player(spawnPlanet.x, spawnPlanet.y-spawnPlanet.r-1, "orbiter")
player.xSpeed, player.ySpeed = spawnPlanet.xSpeed, spawnPlanet.ySpeed
gui = Gui(1) gui = Gui(1)
effects = {} effects = {}
end end
@@ -33,8 +35,7 @@ end


function loadPlanets() function loadPlanets()
debug("Planets in planet table: "..#planetdata) debug("Planets in planet table: "..#planetdata)
for i=1, #planetdata do
local p = planetdata[i]
for i, p in ipairs(planetdata) do
debug(p.name.." is loading") debug(p.name.." is loading")
table.insert(planet, i, table.insert(planet, i,
Planet( Planet(


+ 20
- 0
src/Abilities.lua View File

@@ -0,0 +1,20 @@
-- THIS ENTIRE THING WILL NOT BE USED PROBABLY, JUST TESTING OUT POSSIBLE WAYS THIS COULD WORK


Abilities = {}

function Abilities.orbitSync() --Synchronise speed with closest orbit
end


function Abilities.update(dt)
for i, #player.abilities do
if player.abilities[i] == "orbitSync" then
Abilities.orbitSync()
end
end
end




+ 0
- 1
src/calc.lua View File

@@ -48,7 +48,6 @@ function calc.closestObj(target)
end end


return minPlanet return minPlanet

end end





+ 1
- 1
src/class/FX.lua View File

@@ -29,7 +29,7 @@ end




function FX:draw() function FX:draw()
debug("drawing flash")
--debug("drawing flash")
if self.type == "flash" then if self.type == "flash" then
self:flash() self:flash()
end end

+ 21
- 10
src/class/Planet.lua View File

@@ -9,6 +9,10 @@ function Planet:init(tempX, tempY, tempR, tempM, tempXSpeed, tempYSpeed, tempNam
self.xSpeed = 0 self.xSpeed = 0
self.ySpeed = 0 self.ySpeed = 0


-- Orbital speed:
self.orbitalX = 0
self.orbitalY = 0

-- Speed Change: (throttle 0 - 1; variable) (speed; constant (max speed change)) -- Speed Change: (throttle 0 - 1; variable) (speed; constant (max speed change))
self.throttle = 0.5 self.throttle = 0.5
self.speed = 0.05 self.speed = 0.05
@@ -29,8 +33,6 @@ function Planet:init(tempX, tempY, tempR, tempM, tempXSpeed, tempYSpeed, tempNam
self.parent = planet[tempP] self.parent = planet[tempP]
table.insert(planet[tempP].children, self) table.insert(planet[tempP].children, self)
end end


end end




@@ -38,10 +40,14 @@ end


-- FUNCTIONS -- FUNCTIONS


function Planet:getSpeed()
return math.abs(self.xSpeed) + math.abs(self.ySpeed)
end

function Planet:updatePosition() function Planet:updatePosition()
self.x = self.x + self.xSpeed
self.y = self.y + self.ySpeed
debug("Updating position of planet " .. self.name .. ": " .. self.x .. " " .. self.y)
self.x = self.x + self.xSpeed + self.orbitalX
self.y = self.y + self.ySpeed + self.orbitalY
--debug("Updating position of planet " .. self.name .. ": " .. self.x .. " " .. self.y)
end end


function Planet:attract(dt) --Planet doing the attracting, divided in two parts: function Planet:attract(dt) --Planet doing the attracting, divided in two parts:
@@ -49,10 +55,16 @@ 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
child.xSpeed = child.xSpeed - (child.x - self.x)*pull
child.ySpeed = child.ySpeed - (child.y - self.y)*pull

-- Reworked planetary gravity, now works with multiple layers of parent-children. Also more realistc??
local angle = math.atan((child.y-self.y)/(child.x-self.x))
if self.x < child.x then
angle = angle - 3.14159
end
child.orbitalX = self.xSpeed + self.orbitalX
child.orbitalY = self.ySpeed + self.orbitalY
child.xSpeed = child.xSpeed + grav/child.m*math.cos(angle)*1e9
child.ySpeed = child.ySpeed + grav/child.m*math.sin(angle)*1e9
end end


--Attracting the player --Attracting the player
@@ -83,5 +95,4 @@ function Planet:draw()
local col = self.colour local col = self.colour
love.graphics.setColor(calc.c(col[1]), calc.c(col[2]), calc.c(col[3])) love.graphics.setColor(calc.c(col[1]), calc.c(col[2]), calc.c(col[3]))
love.graphics.circle("fill", self.x, self.y, self.r) love.graphics.circle("fill", self.x, self.y, self.r)
end end

+ 53
- 47
src/class/Player.lua View File

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


function Player:init(tempX, tempY)
function Player:init(tempX, tempY, tempT)
-- Position: (variable) -- Position: (variable)
self.x = tempX self.x = tempX
self.y = tempY self.y = tempY
@@ -15,20 +15,24 @@ function Player:init(tempX, tempY)


-- Speed Change: (throttle 0 - 1; variable) (speed; constant (max speed change)) -- Speed Change: (throttle 0 - 1; variable) (speed; constant (max speed change))
self.throttle = 0.5 self.throttle = 0.5
self.speed = 0.05
self.speed = starshipTypes[tempT].speed


-- Landings: -- Landings:
self.impacttolerance = 0.5
self.impacttolerance = starshipTypes[tempT].impacttolerance
self.landingspeed = 0 self.landingspeed = 0
self.landedOn = nil


-- Mass: -- Mass:
self.m = 10
self.m = starshipTypes[tempT].mass


-- Rotation: -- Rotation:
self.angle = calc.pi/2 self.angle = calc.pi/2


-- Status: -- Status:
self.exploding = false self.exploding = false

--TEXTURE HERE?
self.texture = love.graphics.newImage(starshipTypes[tempT].texture)
end end




@@ -76,44 +80,39 @@ function Player:flightControls()
-- Anti-clipping feature -- Anti-clipping feature
local closestPla = calc.closestObj(player) local closestPla = calc.closestObj(player)



-- Movement: -- Movement:
local speedChange = self.speed * self.throttle local speedChange = self.speed * self.throttle
-- Directional Thrust: -- Directional Thrust:
if love.keyboard.isDown(controls.flight.thrust.up)then if love.keyboard.isDown(controls.flight.thrust.up)then
if (calc.distance(closestPla.x, closestPla.y, self.x, self.y) > calc.distance(closestPla.x, closestPla.y, self.x, self.y-10) and self:isLanded()) then if (calc.distance(closestPla.x, closestPla.y, self.x, self.y) > calc.distance(closestPla.x, closestPla.y, self.x, self.y-10) and self:isLanded()) then
debug("Flying into a planet!")
--debug("Flying into a planet!")
else else
self.ySpeed = self.ySpeed - speedChange self.ySpeed = self.ySpeed - speedChange
debug("Player control: up")
end end
end end


if love.keyboard.isDown(controls.flight.thrust.down) then if love.keyboard.isDown(controls.flight.thrust.down) then
if (calc.distance(closestPla.x, closestPla.y, self.x, self.y) > calc.distance(closestPla.x, closestPla.y, self.x, self.y+10) and self:isLanded()) then if (calc.distance(closestPla.x, closestPla.y, self.x, self.y) > calc.distance(closestPla.x, closestPla.y, self.x, self.y+10) and self:isLanded()) then
debug("Flying into a planet!")
--debug("Flying into a planet!")
else else
self.ySpeed = self.ySpeed + speedChange self.ySpeed = self.ySpeed + speedChange
debug("Player control: down")
end end
end end


if love.keyboard.isDown(controls.flight.thrust.left) then if love.keyboard.isDown(controls.flight.thrust.left) then
if (calc.distance(closestPla.x, closestPla.y, self.x, self.y) > calc.distance(closestPla.x, closestPla.y, self.x-10, self.y) and self:isLanded()) then if (calc.distance(closestPla.x, closestPla.y, self.x, self.y) > calc.distance(closestPla.x, closestPla.y, self.x-10, self.y) and self:isLanded()) then
debug("Flying into a planet!")
--debug("Flying into a planet!")
else else
self.xSpeed = self.xSpeed - speedChange self.xSpeed = self.xSpeed - speedChange
debug("Player control: left")
end end
end end


if love.keyboard.isDown(controls.flight.thrust.right) then if love.keyboard.isDown(controls.flight.thrust.right) then
if (calc.distance(closestPla.x, closestPla.y, self.x, self.y) > calc.distance(closestPla.x, closestPla.y, self.x+10, self.y) and self:isLanded()) then if (calc.distance(closestPla.x, closestPla.y, self.x, self.y) > calc.distance(closestPla.x, closestPla.y, self.x+10, self.y) and self:isLanded()) then
debug("Flying into a planet!")
--debug("Flying into a planet!")
else else
self.xSpeed = self.xSpeed + speedChange self.xSpeed = self.xSpeed + speedChange
debug("Player control: right")
end end
end end


@@ -124,7 +123,7 @@ function Player:flightControls()
debug("Flying into a planet!") debug("Flying into a planet!")
else else
self.xSpeed = self.xSpeed + math.cos(self.angle) * speedChange*2 self.xSpeed = self.xSpeed + math.cos(self.angle) * speedChange*2
debug("Ship thrusters X: " .. math.cos(self.angle) .. " " .. math.sin(self.angle) .. " " .. self.angle)
--debug("Ship thrusters X: " .. math.cos(self.angle) .. " " .. math.sin(self.angle) .. " " .. self.angle)
self.ySpeed = self.ySpeed - math.sin(self.angle) * speedChange*2 self.ySpeed = self.ySpeed - math.sin(self.angle) * speedChange*2
end end
end end
@@ -139,19 +138,19 @@ function Player:flightControls()
-- Reset: -- Reset:
if love.keyboard.isDown(controls.flight.reset) then if love.keyboard.isDown(controls.flight.reset) then
self:reset() self:reset()
debug("Player control: reset")
end end
end end


function Player:getSpeed()
local x, y = self.xSpeed, self.ySpeed
if x < 0 then
x = -x
end
if y < 0 then
y = -y
end
return x+y
function Player:getSpeed() -- absolute speed
return math.abs(self.xSpeed) + math.abs(self.ySpeed)
end

function Player:getSpeedTo(obj) -- relative speed to an object
return math.abs(self:getSpeed() - obj:getSpeed())
end

function Player:getOrbitHeight(obj) -- gets the height of the orbit (above surface)
return calc.distance(self.x, self.y, obj.x, obj.y)-obj.r
end end


function Player:hasCrashed() --Testing function, see if a player is inside a planet function Player:hasCrashed() --Testing function, see if a player is inside a planet
@@ -166,15 +165,19 @@ end


function Player:isLanded() function Player:isLanded()
local landed = false local landed = false
for i=1, #planet do
local pla = planet[i]
if calc.distance(self.x, self.y, pla.x, pla.y) <= pla.r then
for i, p in ipairs(planet) do
if self:getOrbitHeight(p) <= 0 then
landed = true landed = true
self.landedOn = p
debug("Player touched down on: "..p.name)
end end
end end
-- Save Landing Speed: -- Save Landing Speed:
if landed then if landed then
self.landingspeed = self:getSpeed()
local player = math.abs(self:getSpeed())
local planet = math.abs(self.landedOn:getSpeed())

self.landingspeed = math.abs(player-planet)
debug("Landing speed: "..self.landingspeed) debug("Landing speed: "..self.landingspeed)
end end
self:hasCrashed() self:hasCrashed()
@@ -184,7 +187,8 @@ end
function Player:gravity() function Player:gravity()
if self:isLanded() then if self:isLanded() then
-- Player is landed: -- Player is landed:
self.xSpeed, self.ySpeed = 0, 0
local p = self.landedOn
self.xSpeed, self.ySpeed = math.abs(p.xSpeed), math.abs(p.ySpeed)
end end
end end


@@ -193,13 +197,23 @@ function Player:updatePosition()
self.y = self.y + self.ySpeed self.y = self.y + self.ySpeed
end end


function Player:drawTexture(x, y, r)
-- Texture offset and size
local t = {s = 50}
t.x = x - love.graphics.getPixelWidth(self.texture)/2 -- ?????????????????????????????????
t.y = y - love.graphics.getPixelHeight(self.texture)/2

-- Draw Texture
love.graphics.setColor(1, 1, 1)
love.graphics.draw(self.texture, t.x, t.y, r)
debug("Angle: "..self.angle)
end





-- MAIN -- MAIN


function Player:update(dt) function Player:update(dt)
--debug(self.warpspeed)
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
@@ -215,23 +229,15 @@ end
function Player:draw() function Player:draw()
local x, y = self.x, self.y local x, y = self.x, self.y
local dist = 10 local dist = 10
-- Funky arrow type form
local vertices = {
-- Top
x, y-dist,
-- Left Bottom
x-dist, y+dist,
-- Middle Down
x, y+dist/2,
-- Right Bottom
x+dist, y+dist
}
if not self.exploding then
love.graphics.setColor(0.5, 0.5, 0.7)
love.graphics.polygon("fill", vertices)


love.graphics.setColor(1, 0, 0)
love.graphics.circle("fill", x, y, 5, 20)
self:drawTexture(x, y, calc.pi/2 - self.angle)

if not self.exploding then
if calc.isDebug then
-- Debugging Draw of actual Player Position
love.graphics.setColor(1, 0, 0)
love.graphics.circle("fill", x, y, 5, 20)
end


-- Directional Circle (temporary until actual rotatable ship texture is made) -- Directional Circle (temporary until actual rotatable ship texture is made)
love.graphics.circle("fill", x+dist*(1/zoomlevel*2)*math.cos(self.angle), y-dist*(1/zoomlevel*2)*math.sin(self.angle), 1/zoomlevel*2) love.graphics.circle("fill", x+dist*(1/zoomlevel*2)*math.cos(self.angle), y-dist*(1/zoomlevel*2)*math.sin(self.angle), 1/zoomlevel*2)


BIN
textures/player/orbiter.png View File

Before After
Width: 326  |  Height: 381  |  Size: 52 KiB

+ 8
- 1
textures/textures.lua View File

@@ -1,3 +1,10 @@
texture = {}
texture = {
player = {
orbiter = "textures/player/orbiter.png"
},
planet = {
-- here will go planet textures in future
}
}


return texture return texture

Loading…
Cancel
Save