93 lines
3.3 KiB
Lua
93 lines
3.3 KiB
Lua
Cercado = {}
|
|
|
|
-- configuracion tamaño
|
|
Cercado.filas = 4
|
|
Cercado.columnas = 6
|
|
|
|
--inicialización tablas para os tiles do cercado
|
|
vsi1 = {x=0, y=0, width=50, height=50}
|
|
vsd1 = {x=0, y=0, width=50, height=50}
|
|
vii1 = {x=0, y=0, width=50, height=50}
|
|
vid1 = {x=0, y=0, width=50, height=50}
|
|
vli1 = {x=0, y=0, width=50, height=50}
|
|
vli2 = {x=0, y=0, width=50, height=50}
|
|
vld1 = {x=0, y=0, width=50, height=50}
|
|
vld2 = {x=0, y=0, width=50, height=50}
|
|
vfo1 = {x=0, y=0, width=50, height=50}
|
|
vfo2 = {x=0, y=0, width=50, height=50}
|
|
vfo3 = {x=0, y=0, width=50, height=50}
|
|
vfo4 = {x=0, y=0, width=50, height=50}
|
|
vfr1 = {x=0, y=0, width=50, height=50}
|
|
vfr2 = {x=0, y=0, width=50, height=50}
|
|
|
|
-- imaxen de cada tile
|
|
vsi1.sprite = love.graphics.newImage("img/valla-sup-ida.png")
|
|
vsd1.sprite = love.graphics.newImage("img/valla-sup-dta.png")
|
|
vii1.sprite = love.graphics.newImage("img/valla-inf-ida.png")
|
|
vid1.sprite = love.graphics.newImage("img/valla-inf-dta.png")
|
|
vli1.sprite = love.graphics.newImage("img/valla-lat-ida.png")
|
|
vli2.sprite = love.graphics.newImage("img/valla-lat-ida.png")
|
|
vld1.sprite = love.graphics.newImage("img/valla-lat-dta.png")
|
|
vld2.sprite = love.graphics.newImage("img/valla-lat-dta.png")
|
|
vfo1.sprite = love.graphics.newImage("img/valla-fondo.png")
|
|
vfo2.sprite = love.graphics.newImage("img/valla-fondo.png")
|
|
vfo3.sprite = love.graphics.newImage("img/valla-fondo.png")
|
|
vfo4.sprite = love.graphics.newImage("img/valla-fondo.png")
|
|
vfr1.sprite = love.graphics.newImage("img/valla-frente.png")
|
|
vfr2.sprite = love.graphics.newImage("img/valla-frente.png")
|
|
|
|
function Cercado:new(x, y)
|
|
-- self.sprite = love.graphics.newImage("img/cercado.png")
|
|
self.tiles = {
|
|
{vsi1,vfo1,vfo2,vfo3,vfo4,vsd1},
|
|
{vli1, 'x', 'x', 'x', 'x',vld1},
|
|
{vli2, 'x', 'x', 'x', 'x',vld2},
|
|
{vii1,vfr1, 'x', 'x',vfr2,vid1},
|
|
}
|
|
-- 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
|
|
|
|
-- Xenera as físicas para cada tile do cercado
|
|
Y = self.y
|
|
blockSize = 50
|
|
for f = 1,table.getn(self.tiles) do
|
|
X = self.x
|
|
for c = 1,table.getn(self.tiles[f]) do
|
|
if self.tiles[f][c].sprite then
|
|
-- actualiza coordenadas
|
|
self.tiles[f][c].x = X
|
|
self.tiles[f][c].y = Y
|
|
-- asocia físicas
|
|
self.tiles[f][c].body = love.physics.newBody(world, X+25, Y+25)
|
|
self.tiles[f][c].shape = love.physics.newRectangleShape(30,30)
|
|
self.tiles[f][c].fixture = love.physics.newFixture(self.tiles[f][c].body, self.tiles[f][c].shape)
|
|
end
|
|
X = X + blockSize
|
|
end
|
|
Y = Y + blockSize
|
|
end
|
|
|
|
return self
|
|
end
|
|
|
|
function Cercado:draw()
|
|
-- recorrese a tabla dos tiles
|
|
for f = 1,table.getn(self.tiles) do
|
|
for c = 1,table.getn(self.tiles[f]) do
|
|
if self.tiles[f][c].sprite then
|
|
-- dibuxa
|
|
love.graphics.polygon("fill",
|
|
self.tiles[f][c].body:getWorldPoints(
|
|
self.tiles[f][c].shape:getPoints()
|
|
))
|
|
love.graphics.draw(self.tiles[f][c].sprite, self.tiles[f][c].x, self.tiles[f][c].y)
|
|
end
|
|
end
|
|
end
|
|
end
|