summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar alecdwm 2016-03-19 03:36:52 +0100
committerGravatar alecdwm 2016-03-19 03:36:52 +0100
commit7f58e95cc79d86924744f53b9ae253822a2fa3d3 (patch)
treec73b683538a6eee13ebc3cabecd6c1715d09d200
parent0c35d511fc53ad7d3aa32cb73c91e0672daab638 (diff)
optional ship drag
-rw-r--r--prototype/main.lua3
-rw-r--r--prototype/ship.lua16
2 files changed, 18 insertions, 1 deletions
diff --git a/prototype/main.lua b/prototype/main.lua
index 6fefa31..50be1c6 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 / ←↑→\nSPACE to stand\n\nZoom:\nSCROLL / (-/+)", 4, 4, 200, "left")
+ 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.print("Novastruct ap0.002", love.graphics.getWidth(), love.graphics.getHeight(), 0, 1, 1, 140, 18)
end
@@ -62,6 +62,7 @@ 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 3fcaf6a..37b84b0 100644
--- a/prototype/ship.lua
+++ b/prototype/ship.lua
@@ -5,12 +5,15 @@ ship.vx = 0
ship.vy = 0
ship.rot = 0
ship.vrot = 0
+ship.dragFactor = 0.2
+ship.rotDragFactor = 1
ship.thrust = 40
ship.torque = 6
ship.image = nil
ship.controlled = false
+ship.dragEnabled = false
-- 0 = empty
-- 1 = wall
@@ -64,8 +67,21 @@ function ship:update(dt)
self.rot = self.rot + self.vrot * dt
self.x = self.x + self.vx * dt
self.y = self.y + self.vy * dt
+
+ if self.dragEnabled then
+ -- drag
+ self.vrot = self.vrot - self.vrot * self.rotDragFactor* dt
+ self.vx = self.vx - self.vx * self.dragFactor * dt
+ self.vy = self.vy - self.vy * self.dragFactor * dt
+ end
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