Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

file 63 lines (49 sloc) 1.513 kb
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
module(..., package.seeall)

local SIZE = 32

local Map = require('map')
local EntityManager = require('entity_manager')
local EffectManager = require('effect_manager')

function mixin(mod, mix_name)
   local mix = require(mix_name)

   for k, v in pairs(mix) do
      if mod[k] and type(v) == 'function' then
         error("Name collision mixing in " .. mix_name .. ": " .. k)
      else mod[k] = v end
   end
end

methods = setmetatable({}, {__index=Map.methods})

mixin(methods, 'create_entities')
mixin(methods, 'drawing')
mixin(methods, 'physics')
mixin(methods, 'handlers')

function new(strs)
   -- All the numeric indices, to map
   local m = {}
   for _,r in ipairs(strs) do m[#m+1] = r end

   -- All str indices, to specials
   local specials = {}
   for k,v in pairs(strs) do
      if type(k) ~= 'number' then specials[k]=v end
   end

   local tbl = Map.new_from_strings(m)
   getmetatable(tbl).__index = methods
   tbl:init(specials)
   return tbl
end

function methods:init(specials)
   self.world = love.physics.newWorld(0, 0)
   self.manager = EntityManager.new(self.world)
   self.effect_manager = EffectManager.new()
   self.gem_count = 0

   self.messages = {} -- Map from point to msg structure
   -- A message looks like: {"text", dx=1, dy=2}

   self.enemies = {} -- Array of Enemies

   self:makeEdges()
   self:makeWalls()
   self:makeCrates()
   self:makeGems()
   self:makeSpecials(specials)
   self.goal = self:makeGoal()
   self.player = self:makePlayer()

   self:addHandlers()
end
Something went wrong with that request. Please try again.