From c1c1eece3904d21749dc50aa546d65fb258a312f Mon Sep 17 00:00:00 2001 From: serxoz Date: Mon, 30 May 2022 20:34:58 +0200 Subject: [PATCH] =?UTF-8?q?comprobaci=C3=B3n=20simple=20de=20colisi=C3=B3n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entidades/cercado.lua | 16 ++++++++++++++++ entidades/ovella.lua | 7 ++++++- img/pastor.png | Bin 920 -> 2146 bytes img/pastor2.png | Bin 0 -> 920 bytes lib/helpers.lua | 10 ++++++++++ main.lua | 11 ++++------- 6 files changed, 36 insertions(+), 8 deletions(-) create mode 100644 entidades/cercado.lua create mode 100644 img/pastor2.png create mode 100644 lib/helpers.lua diff --git a/entidades/cercado.lua b/entidades/cercado.lua new file mode 100644 index 0000000..96f6eb5 --- /dev/null +++ b/entidades/cercado.lua @@ -0,0 +1,16 @@ +Cercado = {} + +function Cercado:new(x, y) + self.sprite = love.graphics.newImage("img/cercado.png") + self.width = self.sprite:getWidth() + self.height = self.sprite:getHeight() + self.x = x-self.width/2 + self.y = y-self.height/2 + self.speed = 2 + + return self +end + +function Cercado:draw() + love.graphics.draw(self.sprite, self.x, self.y) +end diff --git a/entidades/ovella.lua b/entidades/ovella.lua index 27c0e2f..ce0d8b4 100644 --- a/entidades/ovella.lua +++ b/entidades/ovella.lua @@ -1,3 +1,5 @@ +require("../lib/helpers") + Ovella = {} local OvellaMT = {__index = Ovella} @@ -14,7 +16,7 @@ function Ovella:new(id, x, y) return setmetatable(instance, OvellaMT) end -function Ovella:update(pastor) +function Ovella:update(pastor, cercado) -- vector local X = pastor.x - self.x; local Y = pastor.y - self.y; @@ -43,6 +45,9 @@ function Ovella:update(pastor) if distancia < DISTANCIA then -- movemento -- FIXME comprobar que non se vai de marxenes e non choca con muros + print(Helpers:CheckCollision(self, cercado)) + + -- Establece a nova posiciĆ³n self.x = self.x - dX; self.y = self.y - dY; end diff --git a/img/pastor.png b/img/pastor.png index c11246aac3935d9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