-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.lua
63 lines (47 loc) · 1.36 KB
/
main.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
--[[
Inspired by http://gamedevelopment.tutsplus.com/tutorials/how-to-use-bsp-trees-to-generate-game-maps--gamedev-12268
--]]
globalCols = 60
globalRows = 40
globalMapSize = globalCols * globalRows
globalTerrainData = {}
tileWidth = 16
tileHeight = 16
globalMap = {}
require "BSPNode"
require "TerrainData"
require "Terrain"
require "mapRegion"
require "map"
function love.load()
rng = love.math.newRandomGenerator()
rng:setSeed(os.time())
windowHeight = globalRows * tileHeight
windowWidth = globalCols * tileWidth
love.window.setMode(windowWidth, windowHeight, {resizable=false, vsync=false})
for i=1, globalMapSize do
globalTerrainData[i] = terrain_t:new()
end
globalMap = Map:new(0, 0, globalCols, globalRows)
globalMap:initTiles()
globalMap:buildBlocks()
end
function love.draw()
tileIndex = 1
for mapY=1,globalRows do
for mapX=1,globalCols do
local tile = globalTerrainData[tileIndex]
love.graphics.draw(tilemap, globalTerrainData[tileIndex]:image(), tile.x, tile.y)
tileIndex = tileIndex + 1
-- This will draw a grid over your map
love.graphics.rectangle("line", (mapX - 1) * tileWidth, (mapY - 1) * tileHeight, tileWidth, tileHeight)
end
end
end
function love.keypressed(key)
if key == "r" then
buildMap()
elseif key == "q" then
love.event.quit()
end
end