summaryrefslogtreecommitdiffhomepage
path: root/not/World.lua
diff options
context:
space:
mode:
authorAki <nthirtyone@gmail.com>2017-09-11 19:54:14 +0200
committerAki <nthirtyone@gmail.com>2017-09-11 19:54:14 +0200
commit4490b5b5fcaddbf55fb229caeb93c879fe254292 (patch)
tree99b9bc95a87e53c93393e71ee9556bc369ebda2e /not/World.lua
parent81ec1a6509b0f349c145dd1b4d40029d141cbd6e (diff)
downloadroflnauts-4490b5b5fcaddbf55fb229caeb93c879fe254292.zip
roflnauts-4490b5b5fcaddbf55fb229caeb93c879fe254292.tar.gz
roflnauts-4490b5b5fcaddbf55fb229caeb93c879fe254292.tar.bz2
Layer displacement ratio added to new Camera and to World for tests
Diffstat (limited to 'not/World.lua')
-rw-r--r--not/World.lua28
1 files changed, 17 insertions, 11 deletions
diff --git a/not/World.lua b/not/World.lua
index 63d1182..ca061c1 100644
--- a/not/World.lua
+++ b/not/World.lua
@@ -31,6 +31,7 @@ function World:new (map, nauts)
Layer(width, height), -- plats
Layer(width, height), -- front
}
+ self.layers[1].ratio = 0
self.map = map
self:buildMap()
@@ -67,7 +68,9 @@ function World:buildMap ()
end
if op.background then
local image = love.graphics.newImage(op.background)
- local bg = self:createDecoration(0, 0, op.background) -- TODO: Decoration does not allow Image instead of filePath!
+ local x = image:getWidth() / -2
+ local y = image:getHeight() / -2
+ local bg = self:createDecoration(x, y, op.background) -- TODO: Decoration does not allow Image instead of filePath!
bg.ratio = op.ratio
bg.layer = 1
end
@@ -233,32 +236,35 @@ function World:draw ()
-- TODO: Prototype of layering. See `World@new`.
-- TODO: Camera rewrite in progress.
- self.camera:translate()
-
for _,entity in pairs(self.entities) do
+ local layer
if entity:is(Decoration) then
if entity.layer == 1 then
- self.layers[1]:setAsCanvas()
+ layer = self.layers[1]
else
- self.layers[3]:setAsCanvas()
+ layer = self.layers[3]
end
end
if entity:is(Cloud) then
- self.layers[2]:setAsCanvas()
+ layer = self.layers[2]
end
if entity:is(Player) then
- self.layers[4]:setAsCanvas()
+ layer = self.layers[4]
end
if entity:is(Platform) or entity:is(Effect) then
- self.layers[5]:setAsCanvas()
+ layer = self.layers[5]
end
if entity:is(Ray) then
- self.layers[6]:setAsCanvas()
+ layer = self.layers[6]
+ end
+
+ if layer then
+ self.camera:translate(layer.ratio)
+ layer:renderTo(entity.draw, entity, 0, 0, scale, debug)
+ self.camera:pop()
end
- entity:draw(offset_x, offset_y, scale, debug)
end
- self.camera:pop()
love.graphics.setCanvas()
for _,layer in ipairs(self.layers) do