diff --git a/data/scripts/level.lua b/data/scripts/level.lua index db16e30..87bb839 100644 --- a/data/scripts/level.lua +++ b/data/scripts/level.lua @@ -112,48 +112,42 @@ function TileDataInitialize() end function InstanceTile(i,j,id) - LevelTiles[i][j] = {} - local tile = LevelTiles[i][j] - tile.id = id + LevelTiles[i][j] = {} + local tile = LevelTiles[i][j] - for _, Properties in pairs(TileData) do - if Properties.id == tile.id then - if type(Properties.overlay) == "table" then - tile.display_overlay = Properties.overlay[math.random(#Properties.overlay)] - else - tile.display_overlay = Properties.overlay - end + tile.id = id + local Properties = TileData[tile.id] - if type(Properties.force) == "table" then - tile.display = Properties.force[math.random(#Properties.force)] - else - tile.display = Properties.force - end - end + if Properties ~= nil then + if type(Properties.overlay) == "table" then + tile.display_overlay = Properties.overlay[math.random(#Properties.overlay)] + else + tile.display_overlay = Properties.overlay end + + if type(Properties.force) == "table" then + tile.display = Properties.force[math.random(#Properties.force)] + else + tile.display = Properties.force + end + end end function TileGetType(tile) - for _, Properties in pairs(TileData) do - if Properties.id == tile.id then - return Properties.type - end + if TileData[tile.id] ~= nil then + return TileData[tile.id].type end end function TileGetDepth(tile) - for _, Properties in pairs(TileData) do - if Properties.id == tile.id then - return Properties.depth - end + if TileData[tile.id] ~= nil then + return TileData[tile.id].depth end end function TileGetLight(tile) - for _, Properties in pairs(TileData) do - if Properties.id == tile.id then - return Properties.light - end + if TileData[tile.id] ~= nil then + return TileData[tile.id].light end end @@ -468,55 +462,84 @@ end function AnimateTiles() for _, Properties in pairs(TileData) do - if Properties.animation ~= nil then - -- calculate subimage - Properties.current_subimage = Properties.current_subimage + current_dt - -- cycle image - if Properties.current_subimage >= Properties.delay then - Properties.current_subimage = Properties.current_subimage - Properties.delay - Properties.current_image = Properties.current_image + 1 - end + if Properties ~= nil then + if Properties.animation ~= nil then + -- calculate subimage + Properties.current_subimage = Properties.current_subimage + current_dt + -- cycle image + if Properties.current_subimage >= Properties.delay then + Properties.current_subimage = Properties.current_subimage - Properties.delay + Properties.current_image = Properties.current_image + 1 + end - if Properties.current_image > Properties.image_count then - Properties.current_image = Properties.current_image - Properties.image_count + if Properties.current_image > Properties.image_count then + Properties.current_image = Properties.current_image - Properties.image_count + end end end end end function DrawTile(tile,x,y,depth) - for _, Properties in pairs(TileData) do - if tile.id == Properties.id then + local Properties = TileData[tile.id] - if Properties.animation ~= nil then - if Properties.imgs[Properties.current_image] ~= nil - and Properties.depth == depth - then love.graphics.draw( - Properties.tileset, - Properties.imgs[Properties.current_image], + if Properties ~= nil then + if Properties.animation ~= nil then + if Properties.imgs[Properties.current_image] ~= nil + and Properties.depth == depth + then love.graphics.draw( + Properties.tileset, + Properties.imgs[Properties.current_image], + x, + y, + 0, + tileProperties.scale, + tileProperties.scale + ) + end + elseif Properties.depth == depth then + if Properties.force ~= nil then + if Properties.force ~= 0 then + love.graphics.draw( + LevelData.tileset, + TileIndex[tile.display], x, y, 0, tileProperties.scale, tileProperties.scale - ) end - elseif Properties.depth == depth then - if Properties.force ~= nil then - if Properties.force ~= 0 then + ) + end + else + love.graphics.draw( + LevelData.tileset, + TileIndex[tile.id], + x, + y, + 0, + tileProperties.scale, + tileProperties.scale + ) + end + end + + if Properties.overlay ~= nil then + if Properties.overlay_depth == depth or Properties.overlay_depth == nil and Properties.depth == depth then + if Properties.overlay_animated then + local overlay_properties = TileData[Properties.overlay] love.graphics.draw( - LevelData.tileset, - TileIndex[tile.display], + overlay_properties.tileset, + overlay_properties.imgs[overlay_properties.current_image], x, y, 0, tileProperties.scale, tileProperties.scale ) - end else love.graphics.draw( LevelData.tileset, - TileIndex[Properties.id], + TileIndex[tile.display_overlay], x, y, 0, @@ -525,41 +548,11 @@ function DrawTile(tile,x,y,depth) ) end end - - if Properties.overlay ~= nil then - if Properties.overlay_depth == depth or Properties.overlay_depth == nil and Properties.depth == depth then - if Properties.overlay_animated then - for _, overlay_properties in pairs(TileData) do - if overlay_properties.id == Properties.overlay then - love.graphics.draw( - overlay_properties.tileset, - overlay_properties.imgs[overlay_properties.current_image], - x, - y, - 0, - tileProperties.scale, - tileProperties.scale - ) - end - end - else - love.graphics.draw( - LevelData.tileset, - TileIndex[tile.display_overlay], - x, - y, - 0, - tileProperties.scale, - tileProperties.scale - ) - end - end - end - --[[ - love.graphics.setColor(0,0,1) - love.graphics.print(tostring(tile.display),x+16,y) - love.graphics.setColor(1,1,1) - ]] end + --[[ + love.graphics.setColor(0,0,1) + love.graphics.print(tostring(tile.display),x+16,y) + love.graphics.setColor(1,1,1) + ]] end end diff --git a/data/tileset/library.lua b/data/tileset/library.lua index c323a55..b1d9edf 100644 --- a/data/tileset/library.lua +++ b/data/tileset/library.lua @@ -1,80 +1,81 @@ -return { - { - id = 1, - type = "whole", - depth = "foreground" - }, - { - id = 2, - type = "emtpy", - depth = "foreground" - }, - { - id = 5, - type = "emtpy", - depth = "background" - }, - { - id = 6, - type = "emtpy", - depth = "background" - }, - { - id = 7, - type = "emtpy", - depth = "background" - }, - { - id = 13, - type = "whole", - depth = "foreground" - }, - { - id = 25, - overlay = {17,19,21,23}, - type = "emtpy", - depth = "background" - }, - { - id = 26, - overlay = {18,20,22,24}, - type = "emtpy", - depth = "background" - }, - { - id = 37, - overlay = {29,31,33,35,42,44,46,48}, - type = "emtpy", - depth = "background" - }, - { - id = 38, - overlay = {30,32,34,36,41,43,45,47}, - type = "emtpy", - depth = "background" - }, - { - id = 49, - overlay = {53,55,57,59}, - type = "emtpy", - depth = "background" - }, - { - id = 50, - overlay = {54,56,58,60}, - type = "emtpy", - depth = "background" - }, - { - id = 61, - overlay = {1}, - type = "emtpy", - depth = "background" - }, - { - id = 62, - overlay = {1}, - type = "emtpy", - depth = "background" - } +local properties = {} + +properties[1] = { + type = "whole", + depth = "foreground" } + +properties[2] = { + type = "emtpy", + depth = "foreground" +} + +properties[5] = { + type = "emtpy", + depth = "background" +} + +properties[6] = { + type = "emtpy", + depth = "background" +} + +properties[7] = { + type = "emtpy", + depth = "background" +} + +properties[13] = { + type = "whole", + depth = "foreground" +} + +properties[25] = { + overlay = {17,19,21,23}, + type = "emtpy", + depth = "background" +} + +properties[26] = { + overlay = {18,20,22,24}, + type = "emtpy", + depth = "background" +} + +properties[37] = { + overlay = {29,31,33,35,41,43,45,47}, + type = "emtpy", + depth = "background" +} + +properties[38] = { + overlay = {30,32,34,36,42,44,46,48}, + type = "emtpy", + depth = "background" +} + +properties[49] = { + overlay = {53,55,57,59}, + type = "emtpy", + depth = "background" +} + +properties[50] = { + overlay = {54,56,58,60}, + type = "emtpy", + depth = "background" +} + +properties[61] = { + overlay = {1}, + type = "emtpy", + depth = "background" +} + +properties[62] = { + overlay = {1}, + type = "emtpy", + depth = "background" +} + +return properties