working on docking / ship commands

This commit is contained in:
Paul Liverman
2015-04-12 23:02:00 -07:00
parent 09614cd678
commit af14ea661f
3 changed files with 53 additions and 17 deletions

View File

@@ -72,12 +72,17 @@ end
function love.mousepressed(x, y, button) function love.mousepressed(x, y, button)
if button == "l" then if button == "l" then
if selected then
-- find out where this actually is, now the ship selected is ordered to move to this point
selected.ship:moveTo(x * scale + hx, y * scale + hy)
else
for i=1,#ships do for i=1,#ships do
if ships[i].selection.r then if ships[i].selection.r then
if pointInRadius(x, y, ships[i].x, ships[i].y, ships[i].selection.r) then if pointInRadius(x, y, ships[i].x, ships[i].y, ships[i].selection.r) then
-- selected -- selected
-- NOW CHECK IF HAS NODES AND IF WE ARE SELECTING A SHIP ON A NODE! -- NOW CHECK IF HAS NODES AND IF WE ARE SELECTING A SHIP ON A NODE!
selected = {} selected = {}
selected.ship = ships[i]
selected.x = ships[i].x selected.x = ships[i].x
selected.y = ships[i].y selected.y = ships[i].y
end end
@@ -86,11 +91,13 @@ function love.mousepressed(x, y, button)
-- we are selecting it! -- we are selecting it!
-- NOW CHECK IF HAS NODES AND IF WE ARE SELECTING A SHIP ON A NODE! -- NOW CHECK IF HAS NODES AND IF WE ARE SELECTING A SHIP ON A NODE!
selected = {} selected = {}
selected.ship = ships[i]
selected.x = ships[i].x selected.x = ships[i].x
selected.y = ships[i].y selected.y = ships[i].y
end end
end end
end end
end
elseif button == "wd" then elseif button == "wd" then
scale = scale * 1.1 scale = scale * 1.1
elseif button == "wu" then elseif button == "wu" then

View File

@@ -35,13 +35,16 @@ return function(x, y, rotation)
} }
self.dock = function(self, ship, node) self.dock = function(self, ship, node)
if self.node[node].docked then return false end if self.node[node].docked or ship.isDocked then return false end
ship.x = self.node[node].x ship.x = self.node[node].x
ship.y = self.node[node].y ship.y = self.node[node].y
ship.rotation = self.node[node].rotation ship.rotation = self.node[node].rotation
self.node[node].docked = ship self.node[node].docked = ship
ship.isDocked = true
ship.dockedTo = self
ship.dockedNode = node
return true return true
end end
@@ -49,6 +52,9 @@ return function(x, y, rotation)
if not self.node[node].docked then return false end if not self.node[node].docked then return false end
local ship = self.node[node].docked local ship = self.node[node].docked
ship.isDocked = false
ship.dockedTo = false
ship.dockedNode = false
self.node[node].docked = false self.node[node].docked = false
return ship return ship

View File

@@ -9,6 +9,12 @@ return function(x, y, rotation)
self.y = y or 0 self.y = y or 0
self.rotation = rotation or 0 self.rotation = rotation or 0
self.destination = {
x = x or 0,
y = y or 0
}
self.isMoving = false
--[[ --[[
self.selection = { self.selection = {
w = 9, w = 9,
@@ -20,6 +26,23 @@ return function(x, y, rotation)
} }
--self.node = false --self.node = false
self.isDocked = false
self.dockedTo = false
self.dockedNode = false
self.moveTo = function(self, x, y)
if self.isDocked then
self.dockedTo:undock(self.dockedNode)
end
self.destination.x = x
self.destination.y = y
self.isMoving = true
end
self.update = function(self, dt)
-- check if moving, check our speed, see how far along the "line" we can go, go there
-- if reached destination ... WELL SHIT DEST NEEDS TO BE ABLE TO KNOW IF IS SHIP OR WHATEVER
end
return self return self
end end