Can't get auto tile to work
Posted: Thu May 10, 2018 9:15 pm
Hi!
I'm trying to write an extremely basic auto tile-system for my game as I have not found any libraries or such for it, but I can't seem to get it to work properly. Can someone give me a hint about what I am doing wrong or what I could be doing better? Please excuse my code as I am a beginner!
I'm trying to write an extremely basic auto tile-system for my game as I have not found any libraries or such for it, but I can't seem to get it to work properly. Can someone give me a hint about what I am doing wrong or what I could be doing better? Please excuse my code as I am a beginner!
Code: Select all
blocksIndex = {}
Block = Object:extend()
function Block:new(x,y)
self.sprite = groundMiddle2
self.x = x
self.y = y
self.width = 32
self.height = 32
self.connectedLeft = false
self.connectedRight = false
self.connectedUp = false
self.connectedDown = false
self.connectedUpperLeft = false
self.connectedUpperRight = false
self.connectedLowerLeft = false
self.connectedLowerRight = false
end
function Block:draw()
love.graphics.draw(spritesheet, self.sprite, self.x, self.y)
end
function updateBlockConnections()
for i, v in ipairs(blocksIndex) do
for o, b in ipairs(blocksIndex) do
if v.x == b.x + b.width then v.connectedLeft = true end
if v.x + v.width == b.x then v.connectedRight = true end
if v.y == b.y + b.height then v.connectedUp = true end
if v.y + v.height == b.y then v.connectedDown = true end
end
end
for i, v in ipairs(blocksIndex) do
--MIDDLE
if v.connectedLeft == true
and v.connectedRight == true
and v.connectedUp == true
and v.connectedDown == true
then v.sprite = groundMiddle
--LEFT
elseif v.connectedLeft == false
and v.connectedRight == true
and v.connectedUp == true
and v.connectedDown == true
then v.sprite = groundLeft
--RIGHT
elseif v.connectedLeft == true
and v.connectedRight == false
and v.connectedUp == true
and v.connectedDown == true
then v.sprite = groundRight
--UP
elseif v.connectedLeft == true
and v.connectedRight == true
and v.connectedUp == false
and v.connectedDown == true
then v.sprite = groundUp
--DOWN
elseif v.connectedLeft == true
and v.connectedRight == true
and v.connectedUp == true
and v.connectedDown == false
then v.sprite = groundDown
--UPPER LEFT
elseif v.connectedLeft == false
and v.connectedRight == true
and v.connectedUp == false
and v.connectedDown == true
then v.sprite = groundUpperLeft
--UPPER RIGHT
elseif v.connectedLeft == true
and v.connectedRight == false
and v.connectedUp == false
and v.connectedDown == true
then v.sprite = groundUpperRight
--LOWER RIGHT
elseif v.connectedLeft == true
and v.connectedRight == false
and v.connectedUp == true
and v.connectedDown == false
then v.sprite = groundLowerRight
--LOWER LEFT
elseif v.connectedLeft == false
and v.connectedRight == true
and v.connectedUp == true
and v.connectedDown == false
then v.sprite = groundLowerLeft
end
end
end
function insertBlock(x,y)
table.insert(blocksIndex, Block(x,y))
end