summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorthe lemons <citrons@mondecitronne.com>2022-08-27 02:49:55 -0500
committerthe lemons <citrons@mondecitronne.com>2022-08-27 02:50:27 -0500
commita96780e04d22c916921be996a6b99487efc4e569 (patch)
treec83eec2efa53b4f54b56bc0fd750c0c5ad46c920
parent0e89c14698023c50001fb820c82f2f59b0730b03 (diff)
store the current camera as an attribute of the world
-rw-r--r--Bolvis.lua1
-rw-r--r--Camera.lua4
-rw-r--r--main.lua6
-rw-r--r--world.lua3
4 files changed, 8 insertions, 6 deletions
diff --git a/Bolvis.lua b/Bolvis.lua
index 8d53c44..cf6a7e8 100644
--- a/Bolvis.lua
+++ b/Bolvis.lua
@@ -20,6 +20,7 @@ local Hand = component(
function Bolvis:init(inst)
inst.hand = self.obj.world:object(Hand {bolvis = self.obj})
inst.camera = self.obj.world:object(Camera {following = self.obj})
+ inst.camera[Camera]:use()
inst.blink = 10
end
diff --git a/Camera.lua b/Camera.lua
index 3b3f1a3..5a9c87b 100644
--- a/Camera.lua
+++ b/Camera.lua
@@ -5,6 +5,10 @@ local Transform = require 'Transform'
local Camera = component({Transform})
function Camera:use()
+ self.obj.world.camera = self
+end
+
+function Camera:transform()
local trans = self.obj:get(Transform):love()
local cam_trans = love.math.newTransform(1920 / 2, 1080 / 2)
love.graphics.applyTransform(cam_trans * trans:inverse())
diff --git a/main.lua b/main.lua
index 872499b..98ad56f 100644
--- a/main.lua
+++ b/main.lua
@@ -17,9 +17,7 @@ function love.load()
love.mouse.setRelativeMode(true)
level = world()
- local bolvis = level:object(Transform {pos = {960, 540}}, Bolvis())
- camera = bolvis[Bolvis].i.camera[Camera]
-
+ level:object(Transform {pos = {960, 540}}, Bolvis())
level:object(Transform {pos = {400, 540}}, Sprite {name = 'utah-teapot'})
level:object(Transform {pos = {600, 540}}, Sprite {name = 'apioform'})
level:object(Transform {pos = {960, 300}}, Sprite {name = 'test'})
@@ -51,7 +49,7 @@ end
function love.draw()
love.graphics.applyTransform(screen_transform())
- camera:use()
+ level.camera:transform()
local to_draw = {}
for o in level:iterate(Drawable) do
table.insert(to_draw, o)
diff --git a/world.lua b/world.lua
index a219589..ec35d07 100644
--- a/world.lua
+++ b/world.lua
@@ -74,8 +74,7 @@ function obj_proto:require(ct, instance)
end
local world_proto = {}
-local world_mt =
- {__index = world_proto, __newindex = function()assert(false)end}
+local world_mt = {__index = world_proto}
local function world()
local w = setmetatable({objects = {}, components = {}}, world_mt)