summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAki <nthirtyone@gmail.com>2016-08-09 23:41:45 +0200
committerAki <nthirtyone@gmail.com>2016-08-09 23:41:45 +0200
commit17d519b5d84b6b5b1dadbbe58aa6eb0cbdf89d9c (patch)
tree6aca10bd62e0e0e7d39e54847015622c8afaef67
parent16a54ae01e5a025d47d95d6ed24835b0ac227ab5 (diff)
downloadroflnauts-17d519b5d84b6b5b1dadbbe58aa6eb0cbdf89d9c.zip
roflnauts-17d519b5d84b6b5b1dadbbe58aa6eb0cbdf89d9c.tar.gz
roflnauts-17d519b5d84b6b5b1dadbbe58aa6eb0cbdf89d9c.tar.bz2
First steps in rewriting camera
-rw-r--r--camera.lua19
1 files changed, 10 insertions, 9 deletions
diff --git a/camera.lua b/camera.lua
index f9cc839..2ae7c78 100644
--- a/camera.lua
+++ b/camera.lua
@@ -111,18 +111,19 @@ end
-- Move follow
function Camera:follow ()
- local m = self.world.map
- local x,y,i = m.center_x, m.center_y, 1
- for k,point in pairs(self.world.Nauts) do
- if point.body:getX() > m.center_x - m.width/2 and point.body:getX() < m.center_x + m.width/2 and
- point.body:getY() > m.center_y - m.height/2 and point.body:getY() < m.center_y + m.height/2 then
+ local map = self.world.map
+ local sum_x,sum_y,i = map.center_x, map.center_y, 1
+ for k,naut in pairs(self.world.Nauts) do
+ local naut_x,naut_y = naut:getPosition()
+ if math.abs(naut_x - map.center_x) < map.width/2 and
+ math.abs(naut_y - map.center_y) < map.height/2 then
i = i + 1
- x = point.body:getX() + x
- y = point.body:getY() + y
+ sum_x = naut_x + sum_x
+ sum_y = naut_y + sum_y
end
end
- x = x / i - love.graphics.getWidth()/self.scale/2
- y = y / i - love.graphics.getHeight()/self.scale/2 + 4*self.scale -- hotfix
+ local x = sum_x / i - love.graphics.getWidth()/self.scale/2
+ local y = sum_y / i - love.graphics.getHeight()/self.scale/2 + 4*self.scale -- hotfix
return x,y
end