summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAki <nthirtyone@gmail.com>2017-09-13 10:19:02 +0200
committerAki <nthirtyone@gmail.com>2017-09-13 10:19:02 +0200
commite8bd3dfd8031930fa3f0169300620e5a0400995d (patch)
tree931077a945dbd5d1ddb113972f8f5146fa5a4847
parent2a0cef0fba687e03fd322ac73c511bbb12b1e31c (diff)
downloadroflnauts-e8bd3dfd8031930fa3f0169300620e5a0400995d.zip
roflnauts-e8bd3dfd8031930fa3f0169300620e5a0400995d.tar.gz
roflnauts-e8bd3dfd8031930fa3f0169300620e5a0400995d.tar.bz2
Another attempt to fix real scaling bug
-rw-r--r--not/Camera.lua24
-rw-r--r--not/World.lua20
2 files changed, 32 insertions, 12 deletions
diff --git a/not/Camera.lua b/not/Camera.lua
index 402a32b..b3b8128 100644
--- a/not/Camera.lua
+++ b/not/Camera.lua
@@ -26,11 +26,9 @@ function Camera:push ()
love.graphics.push()
end
--- TODO: self._scale usage is temporary, used for real scaling.
function Camera:scale (scale)
scale = scale or getScale()
love.graphics.scale(scale, scale)
- self._scale = scale
end
function Camera:translate (ratio)
@@ -46,6 +44,20 @@ function Camera:translate (ratio)
love.graphics.translate(ox - px - dx, oy - py - dy)
end
+-- TODO: TranslateReal is temporary.
+function Camera:translateReal (ratio)
+ local px, py = self:getPosition()
+ local dx, dy = self:getShake()
+ local ox, oy = self:getHalfViewSize(getRealScale())
+ if ratio then
+ dx = dx * ratio
+ dy = dy * ratio
+ px = px * ratio
+ py = py * ratio
+ end
+ love.graphics.translate(ox - px - dx, oy - py - dy)
+end
+
function Camera:pop ()
love.graphics.pop()
self._scale = nil
@@ -68,15 +80,15 @@ function Camera:getBoundaries ()
end
-- TODO: Review getViewSize of Camera.
-function Camera:getViewSize ()
- local scale = self._scale or getScale()
+function Camera:getViewSize (scale)
+ scale = scale or getScale()
local width = love.graphics.getWidth() / scale
local height = love.graphics.getHeight() / scale
return width, height
end
-function Camera:getHalfViewSize ()
- local width, height = self:getViewSize()
+function Camera:getHalfViewSize (scale)
+ local width, height = self:getViewSize(scale)
return width / 2, height / 2
end
diff --git a/not/World.lua b/not/World.lua
index e3b7695..0a560fb 100644
--- a/not/World.lua
+++ b/not/World.lua
@@ -22,12 +22,12 @@ function World:new (map, nauts)
self.entities = {}
self.map = map
+ self.camera = Camera(self.map.center.x, self.map.center.y, self)
+
self:initLayers()
self:buildMap()
self:spawnNauts(nauts)
- self.camera = Camera(self.map.center.x, self.map.center.y, self)
-
musicPlayer:play(self.map.theme)
end
@@ -62,10 +62,13 @@ end
-- Layers are drawn in reverse order, meaning that `instance.layers[1]` will be on the top.
-- Calling `instance.layers` will return iterator.
function World:initLayers ()
- local width, height = love.graphics.getDimensions()
self.layers = setmetatable({}, {__call = layersIterator})
self.layers.n = 0
- self.layers.rays = self:addLayer(320, 180, 0, 1)
+
+ local width, height = self.camera:getViewSize()
+ self.layers.rays = self:addLayer(width, height, 0, 1)
+
+ local width, height = love.graphics.getDimensions()
self.layers.tags = self:addLayer(width, height)
self.layers.platforms = self:addLayer(width, height)
self.layers.effects = self:addLayer(width, height)
@@ -100,8 +103,13 @@ function World:buildMap ()
height = height * getScale()
end
bg.layer = self:addLayer(width, height, op.ratio, getRealScale())
- print("ayyy", getScale(), getRealScale())
- print("lmao", x, y)
+ bg.layer.renderToWith = function (self, camera, func, ...)
+ camera:push()
+ camera:scale(self.scale)
+ camera:translateReal(self.ratio)
+ self:renderTo(func, ...)
+ camera:pop()
+ end
bg.layer.draw = function (self)
love.graphics.setColor(255, 255, 255, 255)
love.graphics.draw(self.canvas)