From 8a009ddbfd630823fd1eaec58d90fbaf4d94653e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erkki=20Sepp=C3=A4l=C3=A4?= Date: Sun, 19 Oct 2014 07:11:15 +0300 Subject: [PATCH] Debug: support for debug circles --- entities/debug.lua | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/entities/debug.lua b/entities/debug.lua index 42bc813..8c45947 100644 --- a/entities/debug.lua +++ b/entities/debug.lua @@ -25,15 +25,38 @@ DebugVector = Class { local dist_x, dist_y = self.dx * scale, self.dy * scale local distance = math.min(100, VectorLight.len(dist_x, dist_y)) dist_x, dist_y = VectorLight.mul(distance, unit_x, unit_y) - love.graphics.printf(self.label, self.x0 + dist_x, self.y0 + dist_y, 100, "left") + love.graphics.printf(string.format("%s %f", self.label, VectorLight.len(self.dx, self.dy)), self.x0 + dist_x, self.y0 + dist_y, 100, "left") end end; } +DebugCircle = Class { + init = function(self, label, x0 , y0) + self.x0 = x0; + self.y0 = y0; + self.label = label; + end; + + + draw = function(self) + love.graphics.setColor(255, 0, 0) + love.graphics.circle("fill", self.x0, self.y0, 5, 20); + -- if self.label then + -- love.graphics.setColor(0,0,0) + -- love.graphics.setFont(font) + -- local unit_x, unit_y = VectorLight.div(VectorLight.len(self.dx, self.dy), self.dx, self.dy) + -- local dist_x, dist_y = self.dx * scale, self.dy * scale + -- local distance = math.min(100, VectorLight.len(dist_x, dist_y)) + -- dist_x, dist_y = VectorLight.mul(distance, unit_x, unit_y) + -- love.graphics.printf(string.format("%s %f", self.label, VectorLight.len(self.dx, self.dy)), self.x0 + dist_x, self.y0 + dist_y, 100, "left") + -- end + end; +} + debugEnabled = false drawDebug = function(debugVectors) - if debugEnabled then + if debugEnabled and debugVectors then for key, debugVector in pairs(debugVectors) do debugVector:draw(); end