Skip to content

Commit

Permalink
moved global variable removal for a later stage
Browse files Browse the repository at this point in the history
  • Loading branch information
kikito committed Dec 26, 2010
1 parent 3e4c9f4 commit 54bc0e4
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
2 changes: 1 addition & 1 deletion 1-tiles/f-files/main.lua
@@ -1,7 +1,7 @@
require 'map-functions'

function love.load()
love.filesystem.load('maps/chez-peter.lua')() -- attention! extra parenthesis
loadMap('maps/chez-peter.lua')
end

function love.draw()
Expand Down
29 changes: 16 additions & 13 deletions 1-tiles/f-files/map-functions.lua
@@ -1,31 +1,34 @@
function loadMap(tileW, tileH, tilesetPath, tileString, quadInfo)
Map = {}
function loadMap(path)
love.filesystem.load(path)() -- attention! extra parenthesis
end

function newMap(tileW, tileH, tilesetPath, tileString, quadInfo)

Map.tileW = tileW
Map.tileH = tileH
Map.tileset = love.graphics.newImage(tilesetPath)
TileW = tileW
TileH = tileH
Tileset = love.graphics.newImage(tilesetPath)

local tilesetW, tilesetH = Map.tileset:getWidth(), Map.tileset:getHeight()
local tilesetW, tilesetH = Tileset:getWidth(), Tileset:getHeight()

Map.quads = {}
Quads = {}

for _,info in ipairs(quadInfo) do
-- info[1] = the character, info[2] = x, info[3] = y
Map.quads[info[1]] = love.graphics.newQuad(info[2], info[3], Map.tileW, Map.tileH, tilesetW, tilesetH)
Quads[info[1]] = love.graphics.newQuad(info[2], info[3], TileW, TileH, tilesetW, tilesetH)
end

Map.tiles = {}
TileTable = {}

local width = #(tileString:match("[^\n]+"))

for x = 1,width,1 do Map.tiles[x] = {} end
for x = 1,width,1 do TileTable[x] = {} end

local x,y = 1,1
for row in tileString:gmatch("[^\n]+") do
assert(#row == width, 'Map is not squared: width of row ' .. tostring(y) .. ' should be ' .. tostring(width) .. ', but it is ' .. tostring(#row))
x = 1
for tile in row:gmatch(".") do
Map.tiles[x][y] = tile
TileTable[x][y] = tile
x = x + 1
end
y=y+1
Expand All @@ -34,9 +37,9 @@ function loadMap(tileW, tileH, tilesetPath, tileString, quadInfo)
end

function drawMap()
for x,column in ipairs(Map.tiles) do
for x,column in ipairs(TileTable) do
for y,char in ipairs(column) do
love.graphics.drawq(Map.tileset, Map.quads[ char ] , (x-1)*Map.tileW, (y-1)*Map.tileH)
love.graphics.drawq(Tileset, Quads[ char ] , (x-1)*TileW, (y-1)*TileH)
end
end
end
2 changes: 1 addition & 1 deletion 1-tiles/f-files/maps/chez-peter.lua
Expand Up @@ -31,4 +31,4 @@ local quadInfo = {
{ '#', 96, 0 } -- bricks
}

loadMap(32,32,'/images/resto.png', tileString, quadInfo)
newMap(32,32,'/images/resto.png', tileString, quadInfo)
2 changes: 1 addition & 1 deletion 1-tiles/f-files/maps/core-dump.lua
Expand Up @@ -30,4 +30,4 @@ local quadInfo = {
{ 'l', 96, 32 } -- plant bottom
}

loadMap(32,32,'/images/lab.png', tileString, quadInfo)
newMap(32,32,'/images/lab.png', tileString, quadInfo)

0 comments on commit 54bc0e4

Please sign in to comment.