local util = require('util') local window = require('window') local entity = require('entity') -- prototype of room -- - background -- - objects -- - edges local room = entity:from{ lines = { {'line', 0, 0, 120, 80}, {'line', 320, 0, 200, 80}, {'line', 0, 240, 120, 160}, {'line', 320, 240, 200, 160}, {'fill', 120, 80, 200, 80, 200, 160, 200, 80}, }, } local from = room.from function room:from(t) local r = from(self, t) r.edges = {} r.objects = {} return r end function room:insert(obj) util.add_entity(self.objects, obj) end function room:remove(obj) util.del_entity(self.objects, obj) end room.mousepressed = window.propagate{'edges', 'objects'} function room:draw() 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.calc_align(width, height) local sx = (320 - width)/2 local sy = (240 - height)/2 return sx, sy end return room