From aa3d4e377fddf077e2b8cc77f17c1eefd5f97b5e Mon Sep 17 00:00:00 2001 From: Eltrac Date: Thu, 13 Mar 2025 10:55:24 +0800 Subject: refactor: remove body:draw method --- objects/Body.lua | 30 ------------------------------ objects/Obstacle.lua | 4 +++- 2 files changed, 3 insertions(+), 31 deletions(-) (limited to 'objects') diff --git a/objects/Body.lua b/objects/Body.lua index 4ca50d1..30ac165 100644 --- a/objects/Body.lua +++ b/objects/Body.lua @@ -15,34 +15,4 @@ function Body:new(shape, sizeA, sizeB, zoom) return obj end -function Body:draw(x, y) - if self.shape == "circle" then - love.graphics.circle("fill", x, y, self.r) - elseif self.shape == "rectangle" then - love.graphics.rectangle("fill", x - self.w / 2, y - self.h / 2, self.w, self.h) - end -end - -function Body:drawSprite(spriteName, x, y, angle) - local sprite = sprite.get(spriteName) - local w, h = (self.shape == "circle" and self.r or self.w), (self.shape == "circle" and self.r or self.h) - - love.graphics.draw(sprite, x, y, angle, - w / sprite:getWidth(), - h / sprite:getHeight() - ) -end - -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 - return Body diff --git a/objects/Obstacle.lua b/objects/Obstacle.lua index 51a1ee6..74297cd 100644 --- a/objects/Obstacle.lua +++ b/objects/Obstacle.lua @@ -13,7 +13,9 @@ function Obstacle:new(name, location, body) presetLocation = (type(location) == "string" and location) or nil, x = (type(location) == "table" and location.x) or nil, y = (type(location) == "table" and location.y) or nil, - body = body or Body:new("rectangle", 50, 50) + body = body or Body:new("rectangle", 50, 50), + w = 50, + h = 50, } setmetatable(obj, Obstacle) -- cgit v1.2.3