Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
require 'map-functions' | ||
|
||
function love.load() | ||
loadMap('maps/chez-peter.lua') | ||
end | ||
|
||
function love.draw() | ||
drawMap() | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |