|
- -- bring in the util module
- local util = require("util")
-
- -- world stuffs
- local world = {}
- -- create a new world with given height and width
- function world.new(width, height)
- world.width = width
- world.height = height
-
- for x = 1, world.width do
- world[x] = {}
- for y = 1, world.height do
- world[x][y] = "nothing"
- end
- end
- end
-
- -- load the tile files
- function world.loadTiles()
- world.grass = love.graphics.newImage("img/tiles/grass.png")
- world.dirt = love.graphics.newImage("img/tiles/dirt.png")
- world.water = love.graphics.newImage("img/tiles/water.png")
- world.nothing = love.graphics.newImage("img/tiles/nothing.png")
- world.select = love.graphics.newImage("img/tiles/select.png")
- end
-
- -- render the world
- function world.render(offset)
- for x = 1, world.width do
- for y = 1, world.height do
- local tile = world[x][y]
- local loc = util.cartToIso({x = x, y = y})
-
- if tile == "grass" then
- image = world.grass
- elseif tile == "dirt" then
- image = world.dirt
- elseif tile == "water" then
- image = world.water
- else
- image = world.nothing
- end
-
- love.graphics.draw(image, loc.x * 16 + offset.x, loc.y * 16 + offset.y)
- end
- end
- end
-
- return world
|