Code: Select all
mainfont = love.graphics.newFont("ahronbd.ttf",14)
winCenter = love.graphics.getWidth()/2
tileSize = 20
grid_size = 10 -- Refers to number of points, for tiles use: tiles = grid_size - 1. Note that in order to center a character it would be best to have an odd number of tiles.
grid_x = love.graphics.getHeight() - 400
rectX = 20
grid_y = 150
gridData = {}
mouseToGrid = {}
function love.load()
--[[music = love.audio.newSource("music.s3m","stream")
music:setLooping(true)
music:setVolume(0.3)
love.audio.play(music)]]--
love.mouse.setVisible(false)
print("Program launched.\n Console is active so that it may potentially be used later to\n monitor networking.")
for gridX = 1,grid_size do
gridData[gridX] = {}
for gridY = 1,grid_size do
gridData[gridX][gridY] = { ["X"] = 0,
["Y"] = 0,
["midX"] = 0,
["midY"] = 0,
["Z"] = 0
}
end
end
print(getMidPoint(1,1))
mouseToGrid["X"] = 0
mouseToGrid["Y"] = 0
gridLoad()
end
function gridLoad()
print(getMidPoint(1,1))
for x = 1,grid_size do
print(getMidPoint(1,1))
for y = 1,grid_size do
--if x < grid_size and y < grid_size then
gridData[x][y]["X"] = ((grid_x + (tileSize*(x-1)) + (((grid_size * tileSize) - (tileSize*(y-1)))/2)) * 1.5) - 20
gridData[x][y]["Y"] = grid_y + (tileSize*(y-1))
if x < grid_size and y < grid_size then
gridData[x][y]["midX"],gridData[x][y]["midY"] = getMidPoint(x,y)
print(string.format("midX: %d midY: %d",x,y))
end
--print(string.format("midX: %d midY: %d",x,y))
end
end
end
function getMidPoint(x,y) --Will calculate with regard to grid, top left corner, or when transformed isometrically, top corner.
--if x < grid_size and y < grid_size then
bigX = gridData[x+1][y]["X"]-- WHY IN THE FUCK??
bigY = gridData[x][y+1]["Y"]
smallX = gridData[x][y]["X"]
smallY = gridData[x][y]["Y"]
if gridData[x+1][y+1]["X"] > bigX then
bigX = gridData[x+1][y+1]["X"]
end
if gridData[x+1][y+1]["Y"] > bigY then
bigY = gridData[x+1][y+1]["Y"]
end
if gridData[x][y+1]["X"] < smallX then
smallX = gridData[x][y+1]["X"]
end
if gridData[x+1][y]["Y"] < smallY then
smallY = gridData[x+1][y]["Y"]
end
--end
return smallX + ((bigX - smallX) / 2), smallY + ((bigY - smallY) / 2)
end