Skip to content

Commit

Permalink
added 1g
Browse files Browse the repository at this point in the history
  • Loading branch information
kikito committed Dec 26, 2010
1 parent dbbc45d commit 48ee3b2
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 0 deletions.
Binary file added 1-tiles/g-global-variables/images/lab.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 1-tiles/g-global-variables/images/resto.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions 1-tiles/g-global-variables/main.lua
@@ -0,0 +1,9 @@
require 'map-functions'

function love.load()
loadMap('maps/chez-peter.lua')
end

function love.draw()
drawMap()
end
46 changes: 46 additions & 0 deletions 1-tiles/g-global-variables/map-functions.lua
@@ -0,0 +1,46 @@
function loadMap(path)
love.filesystem.load(path)() -- attention! extra parenthesis
end

function newMap(tileW, tileH, tilesetPath, tileString, quadInfo)
Map = {}

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

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

Map.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)
end

Map.tiles = {}

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

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

local x,y = 1,1
for row in tileString:gmatch("[^\n]+") do
assert(#row == width, 'Map is not aligned: 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
x = x + 1
end
y=y+1
end

end

function drawMap()
for x,column in ipairs(Map.tiles) do
for y,char in ipairs(column) do
love.graphics.drawq(Map.tileset, Map.quads[ char ] , (x-1)*Map.tileW, (y-1)*Map.tileH)
end
end
end
34 changes: 34 additions & 0 deletions 1-tiles/g-global-variables/maps/chez-peter.lua
@@ -0,0 +1,34 @@

local tileString = [[
#########################
# # #
# L[]R L[]R # L[]R #
# L()R L()R # L()R #
# # #
# ### ###
# L[]R L[]R #
# L()R L()R L[]R #
# L()R #
# #
# L[]R L[]R #
# L()R L()R ### ###
# #LL RR#
# #LL RR#
# L[]R L[]R #LL RR#
# L()R L()R #LL RR#
# #LL RR#
#########################
]]

local quadInfo = {
{ ' ', 0, 0 }, -- floor
{ '[', 32, 0 }, -- table top left
{ ']', 64, 0 }, -- table top right
{ '(', 32, 32 }, -- table bottom left
{ ')', 64, 32 }, -- table bottom right
{ 'L', 0, 32 }, -- chair on the left
{ 'R', 96, 32 }, -- chair on the right
{ '#', 96, 0 } -- bricks
}

newMap(32,32,'/images/resto.png', tileString, quadInfo)
33 changes: 33 additions & 0 deletions 1-tiles/g-global-variables/maps/core-dump.lua
@@ -0,0 +1,33 @@
local tileString = [[
#########################
# AAA^AAAAAA # ^^^ #
# |||@|||||| # @@@ #
# # #
# AAAAAAA^AA ### ###
# |||||||@|| # # #
# * * #
# * l l #
# l #
^ #
@ #
# * #
# l #
# #
# AAAAA^AAA^AAA^ ^^ #
# |||||@|||@|||@ @@ #
# #
#########################
]]

local quadInfo = {
{ ' ', 0, 0 }, -- gray floor
{ '#', 0, 32 }, -- brick wall
{ '^', 32, 0 }, -- mainframe 1 top
{ '@', 32, 32 }, -- mainframe 1 bottom
{ 'A', 64, 0 }, -- mainframe 2 top
{ '|', 64, 32 }, -- maingrame 2 bottom
{ '*', 96, 0 }, -- plant top
{ 'l', 96, 32 } -- plant bottom
}

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

0 comments on commit 48ee3b2

Please sign in to comment.