Created
January 26, 2012 00:25
-
-
Save lukebitts/1679981 to your computer and use it in GitHub Desktop.
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
function Tile(x, y, z, path) | |
_x = x or 0 | |
_y = y or 0 | |
_z = z or 0 | |
return | |
{ | |
img = love.graphics.newImage(path), | |
x = _x, | |
y = _y, | |
z = _z, | |
draw = function(this) | |
pixelX = math.sqrt(3)*27*(_z/2+_x) | |
pixelY = 3/2*27*_z | |
love.graphics.draw(this.img,pixelX,pixelY) | |
end | |
} | |
end | |
function Map() | |
_tiles = {} | |
return | |
{ | |
createMap = function(this,radius) | |
xyz = {0,0,0} | |
deltas = {{1,0,-1},{0,1,-1},{-1,1,0},{-1,0,1},{0,-1,1},{1,-1,0}} | |
_tiles[0] = {} | |
_tiles[0][0] = Tile(0,0,0,"hex1.png") | |
for i=1, radius do | |
x = xyz[1] | |
y = xyz[2]-i | |
z = xyz[3]+i | |
for j=1, 6 do | |
for k=1, i-1 do | |
x = x+deltas[j][1] | |
y = y+deltas[j][2] | |
z = z+deltas[j][3] | |
--table.insert(this._tiles,nil,Tile(x,y,z,"hex1.png")) | |
if _tiles[x] == nil then | |
_tiles[x] = {} | |
end | |
_tiles[x][y] = Tile(x,y,z,"hex1.png") | |
end | |
end | |
end | |
end, | |
draw = function() | |
for x,tile in pairs(_tiles) do | |
for y,t in pairs(_tiles[x]) do | |
_tiles[x][y]:draw() | |
end | |
end | |
end | |
} | |
end | |
function main() | |
map = Map() | |
map:createMap(2) | |
function love.draw() | |
love.graphics.print("lala", 400, 300) | |
map:draw() | |
end | |
end | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment