ovellas/entidades/cercado.lua
2022-06-01 23:34:30 +02:00

64 lines
1.9 KiB
Lua

Cercado = {}
-- configuracion tamaño
Cercado.filas = 4
Cercado.columnas = 6
--inicialización tablas para os tiles do cercado
vsi = {x=0, y=0, width=50, height=50}
vsd = {x=0, y=0, width=50, height=50}
vii = {x=0, y=0, width=50, height=50}
vid = {x=0, y=0, width=50, height=50}
vli = {x=0, y=0, width=50, height=50}
vld = {x=0, y=0, width=50, height=50}
vfo = {x=0, y=0, width=50, height=50}
vfr = {x=0, y=0, width=50, height=50}
-- imaxen de cada tile
vsi.sprite = love.graphics.newImage("img/valla-sup-ida.png")
vsd.sprite = love.graphics.newImage("img/valla-sup-dta.png")
vii.sprite = love.graphics.newImage("img/valla-inf-ida.png")
vid.sprite = love.graphics.newImage("img/valla-inf-dta.png")
vli.sprite = love.graphics.newImage("img/valla-lat-ida.png")
vld.sprite = love.graphics.newImage("img/valla-lat-dta.png")
vfo.sprite = love.graphics.newImage("img/valla-fondo.png")
vfr.sprite = love.graphics.newImage("img/valla-frente.png")
function Cercado:new(x, y)
-- self.sprite = love.graphics.newImage("img/cercado.png")
self.tiles = {
{vsi,vfo,vfo,vfo,vfo,vsd},
{vli,'x','x','x','x',vld},
{vli,'x','x','x','x',vld},
{vii,vfr,'x','x',vfr,vid},
}
-- self.width = self.sprite:getWidth()
-- self.height = self.sprite:getHeight()
self.width = 300 -- cada bloque 50x50 px
self.height = 240
self.x = x-self.width/2
self.y = y-self.height/2
self.speed = 2
return self
end
function Cercado:draw()
Y = self.y
blockSize = 50
for y = 1,self.filas do
X = self.x
for x = 1,self.columnas do
if self.tiles[y][x] ~= 'x' then
-- acutaliza coordenadas
self.tiles[y][x].x = X
self.tiles[y][x].y = Y
-- dibuxa
love.graphics.draw(self.tiles[y][x].sprite, X, Y)
end
X = X + blockSize
end
Y = Y + blockSize
end
end