diff options
author | ubq323 <ubq323@ubq323.website> | 2023-01-27 21:53:57 +0000 |
---|---|---|
committer | ubq323 <ubq323@ubq323.website> | 2023-01-27 22:03:22 +0000 |
commit | 9fff52daa2df79133a29ff94d340bdaf406eb514 (patch) | |
tree | ab695c761cd325c76a9607dcba7c5f750e9910fd /client/camera.lua | |
parent | d0916d568a00f5171b96fbc3bfc19ff263affc27 (diff) |
multitudinous things
Diffstat (limited to 'client/camera.lua')
-rw-r--r-- | client/camera.lua | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/client/camera.lua b/client/camera.lua new file mode 100644 index 0000000..bc65044 --- /dev/null +++ b/client/camera.lua @@ -0,0 +1,25 @@ +local coords = require"common.coords" + +-- 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) + zoom = zoom or 30 + return setmetatable({pos=pos,zoom=zoom},Camera) +end +function Camera.apply_trans(self) + love.graphics.origin() + -- centre (0,0) in the middle of the screen + love.graphics.translate(screen_width/2,screen_height/2) + -- apply camera transformations + + love.graphics.scale(self.zoom) + love.graphics.translate(-self.pos.x,-self.pos.y) +end + + +return {Camera=Camera} |