summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar alecdwm 2016-03-19 03:44:21 +0100
committerGravatar alecdwm 2016-03-19 03:44:21 +0100
commit75af64b8f4593450c5b6445ea10f80accc554334 (patch)
tree72e954a55aaa634a3bec5f86ce33ee42586234fc
parent7f58e95cc79d86924744f53b9ae253822a2fa3d3 (diff)
ship drag active when no player input
-rw-r--r--prototype/main.lua3
-rw-r--r--prototype/ship.lua19
2 files changed, 12 insertions, 10 deletions
diff --git a/prototype/main.lua b/prototype/main.lua
index 50be1c6..6fefa31 100644
--- a/prototype/main.lua
+++ b/prototype/main.lua
@@ -43,7 +43,7 @@ function love.draw()
camera:unset()
-- UI
- love.graphics.printf("Player:\nWASD / ←↑↓→\nSHIFT to sprint\n\nShip:\nWAD / ←↑→\nSHIFT to toggle drag\nSPACE to stand\n\nZoom:\nSCROLL / (-/+)", 4, 4, 200, "left")
+ love.graphics.printf("Player:\nWASD / ←↑↓→\nSHIFT to sprint\n\nShip:\nWAD / ←↑→\nSPACE to stand\n\nZoom:\nSCROLL / (-/+)", 4, 4, 200, "left")
love.graphics.print("Novastruct ap0.002", love.graphics.getWidth(), love.graphics.getHeight(), 0, 1, 1, 140, 18)
end
@@ -62,7 +62,6 @@ function love.keypressed(key, scancode, isrepeat)
love.event.quit()
end
- ship:keypressed(key, scancode, isrepeat)
player:keypressed(key, scancode, isrepeat)
if key == "-" then
diff --git a/prototype/ship.lua b/prototype/ship.lua
index 37b84b0..49f78dd 100644
--- a/prototype/ship.lua
+++ b/prototype/ship.lua
@@ -14,6 +14,7 @@ ship.image = nil
ship.controlled = false
ship.dragEnabled = false
+ship.rotDragEnabled = false
-- 0 = empty
-- 1 = wall
@@ -48,18 +49,24 @@ function ship:load()
end
function ship:update(dt)
+ self.dragEnabled = true
+ self.rotDragEnabled = true
+
if self.controlled then
-- input
if love.keyboard.isDown("a") or love.keyboard.isDown("left") then
self.vrot = self.vrot - self.torque * dt
+ self.rotDragEnabled = false
end
if love.keyboard.isDown("d") or love.keyboard.isDown("right") then
self.vrot = self.vrot + self.torque * dt
+ self.rotDragEnabled = false
end
if love.keyboard.isDown("w") or love.keyboard.isDown("up") then
self.vx = self.vx + math.sin(self.rot) * self.thrust * dt
self.vy = self.vy - math.cos(self.rot) * self.thrust * dt
+ self.dragEnabled = false
end
end
@@ -68,9 +75,11 @@ function ship:update(dt)
self.x = self.x + self.vx * dt
self.y = self.y + self.vy * dt
- if self.dragEnabled then
- -- drag
+ -- drag
+ if self.rotDragEnabled then
self.vrot = self.vrot - self.vrot * self.rotDragFactor* dt
+ end
+ if self.dragEnabled then
self.vx = self.vx - self.vx * self.dragFactor * dt
self.vy = self.vy - self.vy * self.dragFactor * dt
end
@@ -79,9 +88,3 @@ end
function ship:draw()
love.graphics.draw(self.image, self.x, self.y, self.rot, 1, 1, self.image:getWidth() / 2, self.image:getHeight() / 2)
end
-
-function ship:keypressed(key, scancode, isrepeat)
- if key == "lshift" or key == "rshift" then
- self.dragEnabled = not self.dragEnabled
- end
-end