Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
46 lines (40 sloc) 1.31 KB
-- As the map is going to be large (I'm thinking 1000x200 meters),
-- only sparsely populated, and changing quite often (waves),
-- a tiled map doesn't make that much sense.
-- Instead the map will manage only entities.
-- For a future optimization the map might be split up into smaller maps
-- Entities are arranged in layers, each of which the map view has to draw
-- Entities are expected to have a position with x, y and z (layer)
-- and update and draw functions
Map = class("Map")
function Map:initialize(width, height, generator)
self.width = width
self.height = height
self.layers = {} -- here the entities are stuffed into = {}
self.generator = generator = self
function Map:addEntity(entity) = self
if not self.layers[entity.position.z] then
self.layers[entity.position.z] = {}
table.insert(self.layers[entity.position.z], entity)
-- The map is wrapped, meaning if something leaves on one side it
-- reappears on the opposing side
function Map:fitIntoMap(position)
if position.x < 0 then
position.x = self.width
elseif position.x > self.width then
position.x = 0
if position.y < 0 then
position.y = self.height
elseif position.y > self.height then
position.y = 0
return position
Something went wrong with that request. Please try again.