|
- -- bring in the util module
- local util = require("util")
-
- local entities = {}
-
- -- initialize the entities table
- function entities.init()
- entities.staticEntities = {}
- entities.dynamicEntities = {}
- end
-
- -- load all sprites to memory
- function entities.loadSprites()
- entities.sprites = {}
- entities.sprites.town = love.graphics.newImage("img/building.png")
- end
-
- -- create a new static entity that will always align with the map grid
- function entities.newStatic(x, y, z, type)
- local static = {}
- static.x = x
- static.y = y
- static.z = z
- static.type = type
-
- table.insert(entities.staticEntities, static)
- end
-
- -- render all entities
- function entities.render(offset)
- -- render static entities
- for _, entity in ipairs(entities.staticEntities) do
- local type = entity.type
- local loc = util.cartToIso({x = entity.x, y = entity.y})
-
- if type == "town" then
- image = entities.sprites.town
- end
-
- if image ~= nil then
- love.graphics.draw(image, loc.x * 16 + offset.x, loc.y * 16 + offset.y - entity.z * 16)
- end
- end
-
- end
-
- return entities
|