summaryrefslogtreecommitdiff
path: root/objects/Body.lua
diff options
context:
space:
mode:
authorEltrac <hi@guhub.cn>2025-02-28 09:46:13 +0800
committerEltrac <hi@guhub.cn>2025-02-28 09:46:13 +0800
commit1ad7373cd908ea691f60c4419caa193b0b388d9f (patch)
treef5980346d23d73d6896b22a3b70d6a192a8c1070 /objects/Body.lua
parent4b5b67470f1ac7d4e1edcac5e5ed9ed8b45eb04a (diff)
fix: incorrectly drawn sprites
refactored drawQuad function and set debug mode in config
Diffstat (limited to 'objects/Body.lua')
-rw-r--r--objects/Body.lua23
1 files changed, 13 insertions, 10 deletions
diff --git a/objects/Body.lua b/objects/Body.lua
index 47b6f08..87f9733 100644
--- a/objects/Body.lua
+++ b/objects/Body.lua
@@ -1,12 +1,13 @@
Body = {}
Body.__index = Body
-function Body:new(shape, sizeA, sizeB, sizeC)
+function Body:new(shape, sizeA, sizeB, zoom)
local obj = {
shape = shape,
r = (shape == "circle" and sizeA or nil),
w = (shape == "rectangle" and sizeA or nil),
- h = (shape == "rectangle" and sizeB or nil)
+ h = (shape == "rectangle" and sizeB or nil),
+ zoom = zoom or 1
}
setmetatable(obj, Body)
@@ -56,12 +57,14 @@ function Body:drawSprite(spriteName, x, y, angle)
)
end
-function Body:drawQuad(sheet, index, x, y, angle, zoom)
- local quad = sprite.getQuad(sheet, index)
-
- local w, h = (self.shape == "circle" and self.r or self.w), (self.shape == "circle" and self.r or self.h)
- w, h = w / 16 * (zoom or 1), h / 16 * (zoom or 1)
-
- love.graphics.draw(sprite.get(sheet), quad, x - w / 2, y - h / 2, angle or 0, w, h
- )
+function Body:drawQuad(sheet, index, x, y, angle)
+ if self.shape == "circle" then
+ local r = self.r
+ local graphicR = r * self.zoom
+ sprite.drawQuad(sheet, index, x - r, y - r, graphicR, graphicR, angle or 0)
+ else
+ local w, h = self.w, self.h
+ local graphicW, graphicH = w * self.zoom, h * self.zoom
+ sprite.drawQuad(sheet, index, x - w/2, y - h/2, graphicW, graphicH, angle or 0)
+ end
end