Ver a proveniência

Changed zoom, added basic effects, made ship collision a thing and fixed planet clipping

tags/v0.0.6_dev
Madiwka há 2 anos
ascendente
cometimento
c49fa0f7b4
6 ficheiros alterados com 124 adições e 30 eliminações
  1. +1
    -1
      data/settings.lua
  2. +3
    -0
      import.lua
  3. +14
    -3
      main.lua
  4. +15
    -0
      src/calc.lua
  5. +31
    -0
      src/class/FX.lua
  6. +60
    -26
      src/class/Player.lua

+ 1
- 1
data/settings.lua Ver ficheiro

@@ -2,7 +2,7 @@ settings = {
zoom = {
min = 0.0001,
max = 4,
step = 0.01,
step = 0.05,
reset = 0.0001
},
warp = {


+ 3
- 0
import.lua Ver ficheiro

@@ -13,10 +13,13 @@ texture = require "textures/textures"
calc = require "src/calc"
font = require "src/font"



-- Game Classes:
require "src/class/Player"
require "src/class/Gui"
require "src/class/Planet"
require "src/class/FX"

-- Game Data:
planetdata = require "data/planetdata"

+ 14
- 3
main.lua Ver ficheiro

@@ -25,6 +25,7 @@ function love.load()
local spawnPlanet = planet[1]
player = Player(spawnPlanet.x, spawnPlanet.y-spawnPlanet.r-1)
gui = Gui(1)
effects = {}
end


@@ -62,7 +63,16 @@ function drawPlanets()
end
end


function drawEffects()
for i=1, #effects do
effects[i]:draw()
end
for i, effect in ipairs(effects) do --Separate functions because if I remove something while processing it it WILL lead to an error
if effect.finished then
table.remove(effects, i)
end
end
end


-- Camera
@@ -75,10 +85,10 @@ function cameraControls()
function love.wheelmoved(x, y)
if y > 0 then
-- Zoom in:
zoomlevel = zoomlevel + step
zoomlevel = zoomlevel + step*(zoomlevel*10)
elseif y < 0 then
-- Zoom out:
zoomlevel = zoomlevel - step
zoomlevel = zoomlevel - step*(zoomlevel*10)
end
end

@@ -162,6 +172,7 @@ function love.draw()
cam:attach()
-- Game Objects:
drawPlanets()
drawEffects()
player:draw()

-- Camera Zoom Player Location Indicator: OVERWORK SOON PLS KAY; IT UGLY


+ 15
- 0
src/calc.lua Ver ficheiro

@@ -36,5 +36,20 @@ function calc.gPull(obj1, obj2)
return grav
end

-- Calculate closest space object to target:
function calc.closestObj(target)
local minDist = calc.distance(planet[1].x, planet[1].y, target.x, target.y)-planet[1].r
local minPlanet = planet[1]
for i, pla in ipairs(planet) do
if calc.distance(pla.x, pla.y, target.x, target.y)-pla.r < minDist then
minDist = calc.distance(pla.x, pla.y, target.x, target.y)-pla.r
minPlanet = pla
end
end

return minPlanet

end


return calc

+ 31
- 0
src/class/FX.lua Ver ficheiro

@@ -0,0 +1,31 @@
-- Effect object
FX = Class {}

function FX:init(type, x, y)
self.type = type
self.id = #effects
self.frame = 0
self.x = x
self.y = y
self.finished = false -- So that main can kill it later. For some reason it does not want to kill itself.
end


function FX:flash()
love.graphics.setColor(1,1,1,1-self.frame/1000)
love.graphics.circle("fill", self.x, self.y, self.frame)
self.frame = self.frame + 100/love.timer.getFPS()
--debug("Frame is " .. self.frame)
if self.frame > 1000 then
self.finished = true
end
end



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

+ 60
- 26
src/class/Player.lua Ver ficheiro

@@ -70,36 +70,60 @@ function Player:reset()
end

function Player:flightControls()
-- Anti-clipping feature
local closestPla = calc.closestObj(player)


-- Movement:
local speedChange = self.speed * self.throttle

-- Directional Thrust:
if love.keyboard.isDown(controls.flight.thrust.up)then
self.ySpeed = self.ySpeed - speedChange
debug("Player control: up")
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!")
else
self.ySpeed = self.ySpeed - speedChange
debug("Player control: up")
end
end

if love.keyboard.isDown(controls.flight.thrust.down) then
self.ySpeed = self.ySpeed + speedChange
debug("Player control: down")
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!")
else
self.ySpeed = self.ySpeed + speedChange
debug("Player control: down")
end
end

if love.keyboard.isDown(controls.flight.thrust.left) then
self.xSpeed = self.xSpeed - speedChange
debug("Player control: left")
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!")
else
self.xSpeed = self.xSpeed - speedChange
debug("Player control: left")
end
end

if love.keyboard.isDown(controls.flight.thrust.right) then
self.xSpeed = self.xSpeed + speedChange
debug("Player control: right")
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!")
else
self.xSpeed = self.xSpeed + speedChange
debug("Player control: right")
end
end


-- Main Engine controls:
if love.keyboard.isDown(controls.flight.thrust.engine) then
self.xSpeed = self.xSpeed + math.cos(self.angle) * speedChange
debug("Ship thrusters X: " .. math.cos(self.angle) .. " " .. math.sin(self.angle) .. " " .. self.angle)
self.ySpeed = self.ySpeed - math.sin(self.angle) * speedChange
if (calc.distance(closestPla.x, closestPla.y, self.x, self.y) > calc.distance(closestPla.x, closestPla.y, self.x+self.xSpeed + math.cos(self.angle) * speedChange*2, self.y+self.ySpeed - math.sin(self.angle) * speedChange*2) and self:isLanded()) then --Holy moly this is long
debug("Flying into a planet!")
else
self.xSpeed = self.xSpeed + math.cos(self.angle) * speedChange*2
debug("Ship thrusters X: " .. math.cos(self.angle) .. " " .. math.sin(self.angle) .. " " .. self.angle)
self.ySpeed = self.ySpeed - math.sin(self.angle) * speedChange*2
end
end
if love.keyboard.isDown(controls.flight.thrust.rotleft) then
self.angle = self.angle + 1/love.timer.getFPS()
@@ -127,21 +151,31 @@ function Player:getSpeed()
return x+y
end

function Player:isLanded()
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
landed = true
end
end
-- Save Landing Speed:
if landed then
self.landingspeed = self:getSpeed()
--debug("Landing speed: "..self.landingspeed)
end
function Player:hasCrashed() --Testing function, see if a player is inside a planet
--debug(self.landingspeed)
if self.landingspeed > self.impacttolerance then
-- Add explosion effect?
table.insert(effects, FX("flash", self.x, self.y))
self:reset()
self.landingspeed = 0
end
end

return landed
function Player:isLanded()
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
landed = true
end
end
-- Save Landing Speed:
if landed then
self.landingspeed = self:getSpeed()
debug("Landing speed: "..self.landingspeed)
end
self:hasCrashed()
return landed
end

function Player:gravity()


Carregando…
Cancelar
Guardar