From bb2e13d34dc8a98b3a8f03534c583fa7c864bc7e Mon Sep 17 00:00:00 2001 From: serxoz Date: Mon, 4 Jul 2022 16:34:51 +0200 Subject: [PATCH] Solucionado que apareceran as ovellas enriba do cercado --- entidades/ovella.lua | 24 ++++++++++++++++++++++-- main.lua | 6 +++--- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/entidades/ovella.lua b/entidades/ovella.lua index b4993ad..5cd9bd1 100644 --- a/entidades/ovella.lua +++ b/entidades/ovella.lua @@ -77,8 +77,28 @@ function Ovella:update(pastor, cercado) end -function Ovella:draw() - love.graphics.draw(self.sprite, self.x, self.y) +function Ovella:draw(cercado) + -- love.graphics.draw(self.sprite, self.x, self.y) + local solapase = false + for y = 1,cercado.filas do + for x = 1,cercado.columnas do + if cercado.tiles[y][x].sprite then + -- print(Helpers:CheckCollision(self, cercado.tiles[y][x])) + -- if Helpers:CheckCollision(futuro, cercado.tiles[y][x]) then + if Helpers:CheckCollision( cercado.tiles[y][x],self) then + solapase = true + -- FIXME movo a ovella en diagonal para quitala de enriba + -- do cercado + self.x = self.x+50 + self.y = self.y+50 + end + end + end + end + + if not solapase then + love.graphics.draw(self.sprite, self.x, self.y) + end end return Ovella diff --git a/main.lua b/main.lua index 8b45293..2bdd7d2 100644 --- a/main.lua +++ b/main.lua @@ -63,9 +63,9 @@ function love.draw() -- ovellas for i = 1, #ovellas,1 do --itera sobre cada ovella na tabla -- print(inspect(ovellas[i])) - ovellas[i]:draw() + ovellas[i]:draw(cercado) end - + love.graphics.print("Ovellas recollidas: 0", 10, 10) end @@ -74,7 +74,7 @@ function love.update(dt) world:update(dt) --- update player object - player:update(dt, cercado) + player:update(dt, cercado) -- update ovella object for i = 1, #ovellas,1 do --itera sobre cada ovella na tabla ovellas[i]:update(player, cercado)