summaryrefslogtreecommitdiffhomepage
path: root/not
diff options
context:
space:
mode:
Diffstat (limited to 'not')
-rw-r--r--not/Camera.lua18
-rw-r--r--not/World.lua19
2 files changed, 23 insertions, 14 deletions
diff --git a/not/Camera.lua b/not/Camera.lua
index 79ebd09..cff5d0d 100644
--- a/not/Camera.lua
+++ b/not/Camera.lua
@@ -1,6 +1,7 @@
--- Used in drawing other stuff in places.
Camera = require "not.Object":extends()
+-- TODO: Camera would really make use of vec2s (other classes would use them too).
function Camera:new (world)
self.world = world
self.x = 0
@@ -17,12 +18,15 @@ function Camera:new (world)
self:setDestination(self:follow())
end
--- Drawing offsets
-function Camera:getOffsets ()
- return -self.x,-self.y
+function Camera:translate ()
+ love.graphics.push()
+ love.graphics.translate(-self.x*getScale(), -self.y*getScale())
+end
+
+function Camera:pop ()
+ love.graphics.pop()
end
--- Position
function Camera:setPosition (x, y)
local x = x or 0
local y = y or 0
@@ -37,7 +41,6 @@ function Camera:getPositionScaled ()
return self.x*getScale(), self.y*getScale()
end
--- Destination
function Camera:setDestination (x, y)
local x = x or 0
local y = y or 0
@@ -48,14 +51,13 @@ function Camera:getDestination ()
return self.dest_x, self.dest_y
end
--- Translate points
function Camera:translatePosition (x, y)
local x = x or 0
local y = y or 0
return (x-self.x)*getScale(), (y-self.y)*getScale()
end
-function Camera:translatePoints(...)
+function Camera:translatePoints (...)
local a = {...}
local r = {}
local x,y = self:getOffsets()
@@ -96,7 +98,6 @@ function Camera:startShake ()
self.origin_x, self.origin_y = self:getPosition()
end
--- Move follow
function Camera:follow ()
local map = self.world.map
local sum_x,sum_y,i = map.center.x, map.center.y, 1
@@ -114,7 +115,6 @@ function Camera:follow ()
return x,y
end
--- Update
function Camera:update (dt)
if self.timer > 0 then
self.timer = self.timer - dt
diff --git a/not/World.lua b/not/World.lua
index ae00b48..6aee966 100644
--- a/not/World.lua
+++ b/not/World.lua
@@ -220,11 +220,15 @@ function World:update (dt)
end
function World:draw ()
- local offset_x, offset_y = self.camera:getOffsets()
+ -- TODO: Offests are here to keep compatibility.
+ local offset_x, offset_y = 0, 0
local scale = getScale()
local scaler = getRealScale()
-- TODO: Prototype of layering. See `World@new`.
+ -- TODO: Camera rewrite in progress.
+ self.camera:translate()
+
for _,entity in pairs(self.entities) do
if entity:is(Decoration) then
if entity.layer == 1 then
@@ -248,12 +252,21 @@ function World:draw ()
entity:draw(offset_x, offset_y, scale, debug)
end
+ self.camera:pop()
love.graphics.setCanvas()
+
for _,layer in ipairs(self.layers) do
layer:draw()
layer:clear()
end
+ -- TODO: Just move heroes' tags to front layer.
+ self.camera:translate()
+ for _,naut in pairs(self:getNautsAlive()) do
+ naut:drawTag(offset_x, offset_y, scale)
+ end
+ self.camera:pop()
+
if debug then
local c = self.camera
local w, h = love.graphics.getWidth(), love.graphics.getHeight()
@@ -280,10 +293,6 @@ function World:draw ()
love.graphics.line(x1,y1,x2,y2)
end
- for _,naut in pairs(self:getNautsAlive()) do
- naut:drawTag(offset_x, offset_y, scale)
- end
-
for _,naut in pairs(self:getNautsAll()) do
-- I have no idea where to place them T_T
-- let's do: bottom-left, bottom-right, top-left, top-right