summaryrefslogtreecommitdiffhomepage
path: root/camera.lua
diff options
context:
space:
mode:
authorAki <nthirtyone@gmail.com>2016-05-13 15:00:13 +0200
committerAki <nthirtyone@gmail.com>2016-05-13 15:00:13 +0200
commit0506e2dd9cb9641486bbfc7908c0399b26e1ce3c (patch)
tree1d673944ed31946959f4b08c9c412cc8f2df12d5 /camera.lua
parent7d4251e3a9c08b89d25ef724270752f36649f765 (diff)
downloadroflnauts-0506e2dd9cb9641486bbfc7908c0399b26e1ce3c.zip
roflnauts-0506e2dd9cb9641486bbfc7908c0399b26e1ce3c.tar.gz
roflnauts-0506e2dd9cb9641486bbfc7908c0399b26e1ce3c.tar.bz2
Basic camera added
Diffstat (limited to 'camera.lua')
-rw-r--r--camera.lua51
1 files changed, 51 insertions, 0 deletions
diff --git a/camera.lua b/camera.lua
new file mode 100644
index 0000000..793b0d1
--- /dev/null
+++ b/camera.lua
@@ -0,0 +1,51 @@
+-- `Camera`
+-- Used in drawing.
+
+-- Metatable of `Camera`
+Camera = {
+ x = 0,
+ y = 0,
+ follow = nil
+}
+
+-- Constructor of `Camera`
+function Camera:new ()
+ local o = {}
+ setmetatable(o, self)
+ self.__index = self
+ o.follow = {}
+ return o
+end
+
+-- Drawing offsets
+function Camera:getOffsets ()
+ return -self.x,-self.y
+end
+
+-- Position
+function Camera:setPosition (x, y)
+ local x = x or 0
+ local y = y or 0
+ self.x, self.y = x, y
+end
+
+-- Add follow position
+function Camera:addFollow (x, y, w)
+ local w = 1
+ if x ~= nil and y ~= nil then
+ table.insert(self.follow, {["x"] = x, ["y"] = y, ["w"] = w})
+ end
+end
+
+-- Move follow
+function Camera:moveFollow ()
+ local x,y,i = 145, 90, 1
+ for k,point in pairs(Nauts) do
+ i = i + 1
+ x = math.max(math.min(point.body:getX(),290),0) + x
+ y = math.max(math.min(point.body:getY(),180),0) + y
+ end
+ x = x / i - 145
+ y = y / i - 90
+ self:setPosition(x,y)
+end \ No newline at end of file