diff options
Diffstat (limited to 'not')
-rw-r--r-- | not/Camera.lua | 32 | ||||
-rw-r--r-- | not/PhysicalBody.lua | 3 | ||||
-rw-r--r-- | not/World.lua | 36 |
3 files changed, 33 insertions, 38 deletions
diff --git a/not/Camera.lua b/not/Camera.lua index 76f36ed..025e9e5 100644 --- a/not/Camera.lua +++ b/not/Camera.lua @@ -21,6 +21,7 @@ function Camera:initShake () } end +-- TODO: Even more magic numbers present in Camera. Translate method. function Camera:translate () local x, y = self:getPositionScaled() local dx, dy = self:getShakeScaled() @@ -47,22 +48,25 @@ function Camera:getPositionScaled () return self.x * scale, self.y * scale end -function Camera:translatePosition (x, y) - local x = x or 0 - local y = y or 0 - return (x-self.x)*getScale(), (y-self.y)*getScale() +-- TODO: Magic numbers present in camera's boundaries. +function Camera:getBoundaries () + local x, y = self:getPosition() + return x - 160, y - 100, x + 160, y + 100 end -function Camera:translatePoints (...) - local a = {...} - local r = {} - local x,y = 0,0 - for k,v in pairs(a) do - if k%2 == 1 then - table.insert(r, (v + x) * getScale()) - else - table.insert(r, (v + y) * getScale()) - end +function Camera:getBoundariesScaled () + local x, y = self:getPositionScaled() + local width, height = love.graphics.getDimensions() + width = width / 2 + height = height / 2 + return x - width, y - height, x + width, y + height +end + +-- TODO: Camera@scalePoints is left because PhysicalBody still uses it as love.graphics.scale is not used yet. +function Camera:scalePoints (...) + local a, r, scale = {...}, {}, getScale() + for _,v in pairs(a) do + table.insert(r, v * scale) end return r end diff --git a/not/PhysicalBody.lua b/not/PhysicalBody.lua index 804c706..c9b7300 100644 --- a/not/PhysicalBody.lua +++ b/not/PhysicalBody.lua @@ -77,7 +77,8 @@ function PhysicalBody:draw (offset_x, offset_y, scale, debug) if category == 3 then love.graphics.setColor(137, 0, 255, 40) end - love.graphics.polygon("fill", self.world.camera:translatePoints(self.body:getWorldPoints(fixture:getShape():getPoints()))) + local camera = self.world.camera + love.graphics.polygon("fill", camera:scalePoints(self.body:getWorldPoints(fixture:getShape():getPoints()))) end end end diff --git a/not/World.lua b/not/World.lua index aeed245..63d1182 100644 --- a/not/World.lua +++ b/not/World.lua @@ -147,7 +147,7 @@ end function World:getNautsAll () local nauts = {} for i,entity in ipairs(self.entities) do - if entity:is(require("not.Hero")) then + if entity:is(require("not.Hero")) and not entity.body:isDestroyed() then table.insert(nauts, entity) end end @@ -271,33 +271,23 @@ function World:draw () 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() - -- draw map center - love.graphics.setColor(130,130,130) + local center = self.map.center + local ax, ay, bx, by = self.camera:getBoundariesScaled() + love.graphics.setLineWidth(1) love.graphics.setLineStyle("rough") - local cx, cy = c:getPositionScaled() - local x1, y1 = c:translatePosition(self.map.center.x, cy) - local x2, y2 = c:translatePosition(self.map.center.x, cy+h) - love.graphics.line(x1,y1,x2,y2) - local x1, y1 = c:translatePosition(cx, self.map.center.y) - local x2, y2 = c:translatePosition(cx+w, self.map.center.y) - love.graphics.line(x1,y1,x2,y2) - -- draw ox, oy + + love.graphics.setColor(130,130,130) + love.graphics.line(ax,center.y,bx,center.y) + love.graphics.line(center.x,ay,center.x,by) + love.graphics.setColor(200,200,200) - love.graphics.setLineStyle("rough") - local cx, cy = c:getPositionScaled() - local x1, y1 = c:translatePosition(0, cy) - local x2, y2 = c:translatePosition(0, cy+h) - love.graphics.line(x1,y1,x2,y2) - local x1, y1 = c:translatePosition(cx, 0) - local x2, y2 = c:translatePosition(cx+w, 0) - love.graphics.line(x1,y1,x2,y2) + love.graphics.line(ax,0,bx,0) + love.graphics.line(0,ay,0,by) end + self.camera:pop() for _,naut in pairs(self:getNautsAll()) do -- I have no idea where to place them T_T |