summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAki <nthirtyone@gmail.com>2017-09-12 01:45:36 +0200
committerAki <nthirtyone@gmail.com>2017-09-12 01:45:36 +0200
commit44bc9aa6fa62c1b23d1e98de8729c72132a88abc (patch)
treeb1505717b590f7e8ba3c93c2899da1b739a49c4b
parent9b047199eb4b90c16101b70dcd2405e0d37f7283 (diff)
downloadroflnauts-44bc9aa6fa62c1b23d1e98de8729c72132a88abc.zip
roflnauts-44bc9aa6fa62c1b23d1e98de8729c72132a88abc.tar.gz
roflnauts-44bc9aa6fa62c1b23d1e98de8729c72132a88abc.tar.bz2
Proper Camera scaling introduction
-rw-r--r--not/Camera.lua20
-rw-r--r--not/World.lua14
2 files changed, 24 insertions, 10 deletions
diff --git a/not/Camera.lua b/not/Camera.lua
index 1fa01d3..c3aaae6 100644
--- a/not/Camera.lua
+++ b/not/Camera.lua
@@ -21,18 +21,26 @@ function Camera:initShake ()
}
end
+function Camera:push ()
+ love.graphics.push()
+end
+
+function Camera:scale (scale)
+ scale = scale or getScale()
+ love.graphics.scale(scale, scale)
+end
+
-- TODO: Even more magic numbers present in Camera. Translate method.
function Camera:translate (ratio)
- local x, y = self:getPositionScaled()
- local dx, dy = self:getShakeScaled()
+ local px, py = self:getPosition()
+ local dx, dy = self:getShake()
if ratio then
dx = dx * ratio
dy = dy * ratio
- x = x * ratio
- y = y * ratio
+ px = px * ratio
+ py = py * ratio
end
- love.graphics.push()
- love.graphics.translate(160*getScale() - x - dx, 90*getScale() - y - dy)
+ love.graphics.translate(160 - px - dx, 90 - py - dy)
end
function Camera:pop ()
diff --git a/not/World.lua b/not/World.lua
index 118346b..b9e89d3 100644
--- a/not/World.lua
+++ b/not/World.lua
@@ -255,17 +255,23 @@ function World:update (dt)
end
function World:draw ()
- local scale = getScale()
+ local scale = 1
-- TODO: Prototype of layering. See `World@new`.
-- TODO: Camera rewrite in progress.
for _,entity in pairs(self.entities) do
- if entity.draw and entity.layer then
+ if entity:is(Ray) then
+ entity.layer:renderTo(entity.draw, entity)
+ elseif entity.draw and entity.layer then
+ self.camera:push()
+ self.camera:scale()
self.camera:translate(entity.layer.ratio)
entity.layer:renderTo(entity.draw, entity, 0, 0, scale, debug) -- TODO: Offsets are passed as zeroes in World@draw for compatibility reasons. Remove them.
self.camera:pop()
end
if entity.drawTag then
+ self.camera:push()
+ self.camera:scale()
self.camera:translate()
self.layers[6]:renderTo(entity.drawTag, entity, 0, 0, scale) -- TODO: Offsets passed. See `World@draw`.
self.camera:pop()
@@ -280,7 +286,8 @@ function World:draw ()
if debug then
local center = self.map.center
local ax, ay, bx, by = self.camera:getBoundariesScaled()
-
+
+ self.camera:push()
self.camera:translate()
love.graphics.setLineWidth(1)
love.graphics.setLineStyle("rough")
@@ -292,7 +299,6 @@ function World:draw ()
love.graphics.setColor(200,200,200)
love.graphics.line(ax,0,bx,0)
love.graphics.line(0,ay,0,by)
-
self.camera:pop()
end