summaryrefslogtreecommitdiffhomepage
path: root/not/Camera.lua
diff options
context:
space:
mode:
authorAki <nthirtyone@gmail.com>2017-09-10 19:47:12 +0200
committerAki <nthirtyone@gmail.com>2017-09-10 19:47:12 +0200
commite6094cf0fddbd8b66426679d79020b06aacb600a (patch)
treefc7d679352f7bb4634db3c6e228c61590245ef04 /not/Camera.lua
parentb74e8f712a11cf57462c51873b1cf505d90623e3 (diff)
downloadroflnauts-e6094cf0fddbd8b66426679d79020b06aacb600a.zip
roflnauts-e6094cf0fddbd8b66426679d79020b06aacb600a.tar.gz
roflnauts-e6094cf0fddbd8b66426679d79020b06aacb600a.tar.bz2
Camera now uses love.graphics.translate
Diffstat (limited to 'not/Camera.lua')
-rw-r--r--not/Camera.lua18
1 files changed, 9 insertions, 9 deletions
diff --git a/not/Camera.lua b/not/Camera.lua
index 79ebd09..cff5d0d 100644
--- a/not/Camera.lua
+++ b/not/Camera.lua
@@ -1,6 +1,7 @@
--- Used in drawing other stuff in places.
Camera = require "not.Object":extends()
+-- TODO: Camera would really make use of vec2s (other classes would use them too).
function Camera:new (world)
self.world = world
self.x = 0
@@ -17,12 +18,15 @@ function Camera:new (world)
self:setDestination(self:follow())
end
--- Drawing offsets
-function Camera:getOffsets ()
- return -self.x,-self.y
+function Camera:translate ()
+ love.graphics.push()
+ love.graphics.translate(-self.x*getScale(), -self.y*getScale())
+end
+
+function Camera:pop ()
+ love.graphics.pop()
end
--- Position
function Camera:setPosition (x, y)
local x = x or 0
local y = y or 0
@@ -37,7 +41,6 @@ function Camera:getPositionScaled ()
return self.x*getScale(), self.y*getScale()
end
--- Destination
function Camera:setDestination (x, y)
local x = x or 0
local y = y or 0
@@ -48,14 +51,13 @@ function Camera:getDestination ()
return self.dest_x, self.dest_y
end
--- Translate points
function Camera:translatePosition (x, y)
local x = x or 0
local y = y or 0
return (x-self.x)*getScale(), (y-self.y)*getScale()
end
-function Camera:translatePoints(...)
+function Camera:translatePoints (...)
local a = {...}
local r = {}
local x,y = self:getOffsets()
@@ -96,7 +98,6 @@ function Camera:startShake ()
self.origin_x, self.origin_y = self:getPosition()
end
--- Move follow
function Camera:follow ()
local map = self.world.map
local sum_x,sum_y,i = map.center.x, map.center.y, 1
@@ -114,7 +115,6 @@ function Camera:follow ()
return x,y
end
--- Update
function Camera:update (dt)
if self.timer > 0 then
self.timer = self.timer - dt