summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAki <nthirtyone@gmail.com>2017-09-13 10:00:59 +0200
committerAki <nthirtyone@gmail.com>2017-09-13 10:00:59 +0200
commit2a0cef0fba687e03fd322ac73c511bbb12b1e31c (patch)
treebd432a8a616152994dbef9ef56a3190233ada0ac
parent914049749fc9f6f86b9ba22d5b74a173a2c8a3bc (diff)
downloadroflnauts-2a0cef0fba687e03fd322ac73c511bbb12b1e31c.zip
roflnauts-2a0cef0fba687e03fd322ac73c511bbb12b1e31c.tar.gz
roflnauts-2a0cef0fba687e03fd322ac73c511bbb12b1e31c.tar.bz2
Fixed background bug on non-16:9 screens
-rw-r--r--not/Camera.lua24
-rw-r--r--not/Layer.lua3
-rw-r--r--not/World.lua11
3 files changed, 31 insertions, 7 deletions
diff --git a/not/Camera.lua b/not/Camera.lua
index c5449d3..402a32b 100644
--- a/not/Camera.lua
+++ b/not/Camera.lua
@@ -1,4 +1,5 @@
--- Used in drawing other stuff in places.
+-- TODO: Support for real scale translations.
Camera = require "not.Object":extends()
Camera.SHAKE_LENGTH = 0.6
@@ -25,26 +26,29 @@ 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
--- TODO: Even more magic numbers present in Camera. Translate method.
function Camera:translate (ratio)
local px, py = self:getPosition()
local dx, dy = self:getShake()
+ local ox, oy = self:getHalfViewSize()
if ratio then
dx = dx * ratio
dy = dy * ratio
px = px * ratio
py = py * ratio
end
- love.graphics.translate(160 - px - dx, 90 - py - dy)
+ love.graphics.translate(ox - px - dx, oy - py - dy)
end
function Camera:pop ()
love.graphics.pop()
+ self._scale = nil
end
function Camera:setPosition (x, y)
@@ -57,12 +61,24 @@ function Camera:getPosition ()
return self.x, self.y
end
--- TODO: Magic numbers present in camera's boundaries.
function Camera:getBoundaries ()
local x, y = self:getPosition()
- return x - 160, y - 90, x + 160, y + 90
+ local width, height = self:getHalfViewSize()
+ return x - width, y - height, x + width, y + height
end
+-- TODO: Review getViewSize of Camera.
+function Camera:getViewSize ()
+ local scale = self._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()
+ return width / 2, height / 2
+end
function Camera:startShake ()
self.shakeTime = Camera.SHAKE_LENGTH
diff --git a/not/Layer.lua b/not/Layer.lua
index 0446599..ebfb28e 100644
--- a/not/Layer.lua
+++ b/not/Layer.lua
@@ -1,4 +1,5 @@
--- A little bit more than just a Canvas.
+-- TODO: Scaled and RealScaled support should be extended.
Layer = require "not.Object":extends()
function Layer:new (width, height)
@@ -43,7 +44,7 @@ function Layer:draw ()
scale = getScale() / self.scale
end
love.graphics.setColor(255, 255, 255, 255)
- love.graphics.draw(self.canvas, 0, 0, 0, scale, scale)
+ love.graphics.draw(self.canvas, nil, nil, nil, scale, scale)
end
return Layer
diff --git a/not/World.lua b/not/World.lua
index 5392e18..e3b7695 100644
--- a/not/World.lua
+++ b/not/World.lua
@@ -76,6 +76,7 @@ end
--- Builds map using one of tables frin config files located in `config/maps/` directory.
-- TODO: Clean World@buildMap. Possibly explode into more methods.
+-- TODO: ScaledLayers and RealScaledLayers should be implemented properly with good Camera support.
function World:buildMap ()
for _,op in pairs(self.map.create) do
if op.platform then
@@ -98,7 +99,13 @@ function World:buildMap ()
width = width * getScale()
height = height * getScale()
end
- bg.layer = self:addLayer(width, height, op.ratio)
+ bg.layer = self:addLayer(width, height, op.ratio, getRealScale())
+ print("ayyy", getScale(), getRealScale())
+ print("lmao", x, y)
+ bg.layer.draw = function (self)
+ love.graphics.setColor(255, 255, 255, 255)
+ love.graphics.draw(self.canvas)
+ end
end
if op.clouds then
local width, height = love.graphics.getDimensions()
@@ -313,7 +320,7 @@ function World:draw ()
layer:draw()
layer:clear()
end
-
+
-- TODO: Debug information could possibly get its own layer so it could follow flow of draw method.
if debug then
local center = self.map.center