local util = require('util') local window = require('window') local entity = require('entity') -- prototype of room -- - background -- - objects -- - edges local room = entity:from{ lines = { {'fill', {80, 60, 240, 60, 240, 180, 80, 180}}, {'line', {0, 0, 80, 60}}, {'line', {320, 0, 240, 60}}, {'line', {0, 240, 80, 180}}, {'line', {320, 240, 240, 180}}, }, } local from = room.from function room:from(t) local r = from(self, t) r.edges = {} r.objects = {} return r end room.mousepressed = window.propagate{'edges', 'objects'} room.draw = window.draw(function (self) self:draw_lines(self.lines) for i, v in ipairs(self.objects) do v:draw() end for i, v in ipairs(self.edges) do v:draw() end end) function room:insert(obj) util.add_entity(self.objects, obj) end function room:remove(obj) util.del_entity(self.objects, obj) end function room:onenter() if self.update then register(self) end end function room:onexit() if self.update then unregister(self) end end function room.calc_align(width, height) local sx = (320 - width)/2 local sy = (240 - height)/2 return sx, sy end return room