ovellas/entidades/cercado.lua

93 lines
3.3 KiB
Lua
Raw Normal View History

2022-05-30 20:34:58 +02:00
Cercado = {}
2022-06-01 23:34:30 +02:00
-- configuracion tamaño
Cercado.filas = 4
Cercado.columnas = 6
--inicialización tablas para os tiles do cercado
2022-06-27 23:48:45 +02:00
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}
2022-06-01 23:34:30 +02:00
-- imaxen de cada tile
2022-06-27 23:48:45 +02:00
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")
2022-06-01 23:34:30 +02:00
2022-05-30 20:34:58 +02:00
function Cercado:new(x, y)
2022-06-01 23:34:30 +02:00
-- self.sprite = love.graphics.newImage("img/cercado.png")
self.tiles = {
2022-06-27 23:48:45 +02:00
{vsi1,vfo1,vfo2,vfo3,vfo4,vsd1},
{vli1, 'x', 'x', 'x', 'x',vld1},
{vli2, 'x', 'x', 'x', 'x',vld2},
{vii1,vfr1, 'x', 'x',vfr2,vid1},
2022-06-01 23:34:30 +02:00
}
-- self.width = self.sprite:getWidth()
-- self.height = self.sprite:getHeight()
self.width = 300 -- cada bloque 50x50 px
self.height = 240
2022-05-30 20:34:58 +02:00
self.x = x-self.width/2
self.y = y-self.height/2
self.speed = 2
2022-06-27 23:48:45 +02:00
-- Xenera as físicas para cada tile do cercado
2022-06-01 23:34:30 +02:00
Y = self.y
blockSize = 50
2022-06-27 23:48:45 +02:00
for f = 1,table.getn(self.tiles) do
2022-06-01 23:34:30 +02:00
X = self.x
2022-06-27 23:48:45 +02:00
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)
2022-06-01 23:34:30 +02:00
end
X = X + blockSize
end
Y = Y + blockSize
end
2022-06-27 23:48:45 +02:00
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
2022-05-30 20:34:58 +02:00
end