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