From 4490b5b5fcaddbf55fb229caeb93c879fe254292 Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 11 Sep 2017 19:54:14 +0200 Subject: Layer displacement ratio added to new Camera and to World for tests --- not/Camera.lua | 8 +++++++- not/World.lua | 28 +++++++++++++++++----------- 2 files changed, 24 insertions(+), 12 deletions(-) (limited to 'not') diff --git a/not/Camera.lua b/not/Camera.lua index 025e9e5..4f57327 100644 --- a/not/Camera.lua +++ b/not/Camera.lua @@ -22,9 +22,15 @@ function Camera:initShake () end -- TODO: Even more magic numbers present in Camera. Translate method. -function Camera:translate () +function Camera:translate (ratio) local x, y = self:getPositionScaled() local dx, dy = self:getShakeScaled() + if ratio then + dx = dx * ratio + dy = dy * ratio + x = x * ratio + y = y * ratio + end love.graphics.push() love.graphics.translate(160*getScale() - x - dx, 100*getScale() - y - dy) end 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 -- cgit v1.1