From 1ebd7d9b7b62c8e05d527611a1944ed1a876b890 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Fri, 3 Feb 2023 19:37:28 +0000 Subject: debug drawing change, zoom clamping, partial refactoring of class mechanisms to allow inheritance, minor refactor of noise generator, changes to temp worldgen, rework of class constructor mechanism --- client/camera.lua | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'client/camera.lua') diff --git a/client/camera.lua b/client/camera.lua index 6309e38..528b45b 100644 --- a/client/camera.lua +++ b/client/camera.lua @@ -1,15 +1,15 @@ local coords = require"common.coords" +local class = require"common.class" -- in screen units local screen_width, screen_height = love.graphics.getDimensions() -- zoom is screen pixels per world unit -local Camera = {} -Camera.__index = Camera -function Camera.make(pos,zoom) - pos = pos or coords.Pos.make(0,0) +local Camera = class() +function Camera.make(cls,pos,zoom) + pos = pos or coords.Pos:make(0,0) zoom = zoom or 30 - return setmetatable({pos=pos,zoom=zoom},Camera) + return setmetatable({pos=pos,zoom=zoom},cls) end function Camera.apply_trans(self) love.graphics.origin() @@ -21,7 +21,7 @@ function Camera.apply_trans(self) love.graphics.translate(-self.pos.x,-self.pos.y) end -local screen_offset = coords.Pos.make(screen_width/2,screen_height/2) +local screen_offset = coords.Pos:make(screen_width/2,screen_height/2) function Camera.screen_to_world(self,pos) return (pos-screen_offset)/self.zoom + self.pos end @@ -31,8 +31,8 @@ end function Camera.extents(self) -- returns top left and bottom right pos's in world coords - return self:screen_to_world(coords.Pos.make(0,0)), - self:screen_to_world(coords.Pos.make(screen_width,screen_height)) + return self:screen_to_world(coords.Pos:make(0,0)), + self:screen_to_world(coords.Pos:make(screen_width,screen_height)) end -- cgit v1.2.3