From 8bb18a89060ecd581a06238ce3fa5d2170ee3a15 Mon Sep 17 00:00:00 2001 From: the lemons Date: Sat, 27 Aug 2022 01:23:20 -0500 Subject: implement component system --- Transform.lua | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 Transform.lua (limited to 'Transform.lua') diff --git a/Transform.lua b/Transform.lua new file mode 100644 index 0000000..0038cce --- /dev/null +++ b/Transform.lua @@ -0,0 +1,28 @@ +local component = require 'component' + +-- component for objects that have a position in the world +local Transform = component() +function Transform:init(inst) + inst.pos = inst.pos or {0, 0} + inst.angle = inst.angle or 0 + inst.scale = inst.scale or {1, 1} + if type(inst.scale) == 'number' then + inst.scale = {inst.scale, inst.scale} + end +end + +function Transform:love(trans) + local trans = trans or love.math.newTransform() + local x, y = unpack(self.i.pos) + local sx, sy = unpack(self.i.scale) + trans:setTransformation(x, y, self.i.angle, sx, sy) + return trans +end + +local trans = love.math.newTransform() +function Transform:use() + self:love(trans) -- this is literally me + love.graphics.applyTransform(trans) +end + +return Transform -- cgit v1.2.3