diff options
| author | the lemons <citrons@mondecitronne.com> | 2022-08-27 01:23:20 -0500 |
|---|---|---|
| committer | the lemons <citrons@mondecitronne.com> | 2022-08-27 01:23:20 -0500 |
| commit | 8bb18a89060ecd581a06238ce3fa5d2170ee3a15 (patch) | |
| tree | 25baba9d2c267b986adfe7af661b3cd99a32b346 /Transform.lua | |
| parent | 001272dbcbaa1110541e0666af3cea1c97bc199f (diff) | |
implement component system
Diffstat (limited to 'Transform.lua')
| -rw-r--r-- | Transform.lua | 28 |
1 files changed, 28 insertions, 0 deletions
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 |
