@@ -26,6 +26,9 @@ function Player:init(tempX, tempY)
-- Rotation:
self.angle = calc.pi/2
-- Status:
self.exploding = false
end
@@ -70,36 +73,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 +154,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 and not self.exploding then
-- Add explosion effect?
table.insert(effects, FX("flash", self.x, self.y, self))
self.exploding = true
return
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()
@@ -162,15 +199,17 @@ end
function Player:update(dt)
--debug(self.warpspeed)
if self.angle > calc.pi*2 then
self.angle = 0
elseif self.angle < 0 then
self.angle = calc.pi*2
end
self:gravity()
self:flightControls()
self:updatePosition()
if not self.exploding then
self:gravity()
self:flightControls()
self:updatePosition()
end
end
function Player:draw()
@@ -187,12 +226,14 @@ function Player:draw()
-- Right Bottom
x+dist, y+dist
}
love.graphics.setColor(0.5, 0.5, 0.7)
love.graphics.polygon("fill", vertices)
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)
love.graphics.setColor(1, 0, 0)
love.graphics.circle("fill", x, y, 5, 20)
-- 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)
-- 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)
end
end