summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAki <nthirtyone@gmail.com>2016-05-17 20:52:04 +0200
committerAki <nthirtyone@gmail.com>2016-05-17 20:52:04 +0200
commitc9bce04e8187e0b6ef9bc8950a094b1dbd44566c (patch)
tree2dd47199001aefc7f9ea902bd0100dea8c9677da
parente255bb314ca0a1d23cfde2c5ca20266c6e1a25af (diff)
downloadroflnauts-c9bce04e8187e0b6ef9bc8950a094b1dbd44566c.zip
roflnauts-c9bce04e8187e0b6ef9bc8950a094b1dbd44566c.tar.gz
roflnauts-c9bce04e8187e0b6ef9bc8950a094b1dbd44566c.tar.bz2
Camera world ref
-rw-r--r--camera.lua7
-rw-r--r--world.lua2
2 files changed, 5 insertions, 4 deletions
diff --git a/camera.lua b/camera.lua
index 79e680b..e2b2362 100644
--- a/camera.lua
+++ b/camera.lua
@@ -6,15 +6,17 @@ Camera = {
x = 0,
y = 0,
scale = 4,
+ world = nil, -- game world
follow = nil
}
-- Constructor of `Camera`
-function Camera:new ()
+function Camera:new (world)
local o = {}
setmetatable(o, self)
self.__index = self
o.follow = {}
+ o.world = world
return o
end
@@ -33,8 +35,7 @@ end
-- Move follow
function Camera:moveFollow ()
local x,y,i = 105, 120, 1
- -- w.Nauts [!] temporary
- for k,point in pairs(w.Nauts) do
+ for k,point in pairs(self.world.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),20) + y
diff --git a/world.lua b/world.lua
index 80e7210..4b0beeb 100644
--- a/world.lua
+++ b/world.lua
@@ -41,7 +41,7 @@ function World:new()
-- Random init
math.randomseed(os.time())
-- Create camera
- o.camera = Camera:new()
+ o.camera = Camera:new(o)
-- Cloud generator
o.clouds_initial = o.clouds_delay
for i=1,5 do