summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAki <nthirtyone@gmail.com>2016-05-22 19:51:51 +0200
committerAki <nthirtyone@gmail.com>2016-05-22 19:51:51 +0200
commit13e368bc2c35c35369a1f6bf76778d88cae240da (patch)
treeba4ef5f8d966cb5ff6fc3d4255cd58ef762b34ee
parent846debef23b584a3ebc16cbde3bea8d9c2d2b7c1 (diff)
downloadroflnauts-13e368bc2c35c35369a1f6bf76778d88cae240da.zip
roflnauts-13e368bc2c35c35369a1f6bf76778d88cae240da.tar.gz
roflnauts-13e368bc2c35c35369a1f6bf76778d88cae240da.tar.bz2
More on maps
-rw-r--r--camera.lua11
-rw-r--r--world.lua17
2 files changed, 15 insertions, 13 deletions
diff --git a/camera.lua b/camera.lua
index 0804860..cb367a3 100644
--- a/camera.lua
+++ b/camera.lua
@@ -83,17 +83,18 @@ end
-- Move follow
function Camera:follow ()
- local x,y,i = 145, 90, 1
+ 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() > -20 and point.body:getX() < 310 and
- point.body:getY() > -70 and point.body:getY() < 200 then
+ 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
i = i + 1
x = point.body:getX() + x
y = point.body:getY() + y
end
end
- x = x / i - 145
- y = y / i - 90
+ x = x / i - love.graphics.getWidth()/2/self.scale
+ y = y / i - love.graphics.getHeight()/2/self.scale
self:setDestination(x,y)
end
diff --git a/world.lua b/world.lua
index 62490b9..2580e0e 100644
--- a/world.lua
+++ b/world.lua
@@ -42,6 +42,11 @@ function World:new(map, ...)
o.Effects = e
-- Random init
math.randomseed(os.time())
+ -- Map
+ local map = map or "default"
+ o:loadMap(map)
+ -- Nauts
+ o:spawnNauts(...)
-- Create camera
o.camera = Camera:new(o)
-- Cloud generator
@@ -49,11 +54,6 @@ function World:new(map, ...)
for i=1,5 do
o:randomizeCloud(false)
end
- -- Map
- local map = map or "default"
- o:loadMap(map)
- -- Nauts
- o:spawnNauts(...)
return o
end
@@ -106,12 +106,13 @@ function World:randomizeCloud(outside)
outside = outside
end
local x,y,t,v
+ local m = self.map
if outside then
- x = -250+math.random(-30,30)
+ x = m.center_x-m.width+math.random(-30,30)
else
- x = math.random(-200,250)
+ x = math.random(m.center_x-m.width/2,m.center_x+m.width/2)
end
- y = math.random(-20, 170)
+ y = math.random(m.center_y-m.height/3, m.center_y+m.height/3)
t = math.random(1,3)
v = math.random(8,18)
self:createCloud(x, y, t, v)