WrapTile = Tile:extend { wrap = function(self) if self.x < the.app.width / 2 then self.x = the.bg.width - the.app.width / 2 elseif self.x > the.bg.width - the.app.width / 2 then self.x = the.app.width / 2 end if self.y < the.app.height / 2 then self.y = the.bg.height - the.app.height / 2 elseif self.y > the.bg.height - the.app.height / 2 then self.y = the.app.height / 2 end end, reflect = function(self) local mirrorX, mirrorY = self.x, self.y if self.x > the.bg.width - the.app.width then mirrorX = self.x - the.bg.width + the.app.width elseif self.x < the.app.width then mirrorX = self.x + the.bg.width - the.app.width end if self.y > the.bg.height - the.app.height then mirrorY = self.y - the.bg.height + the.app.height elseif self.y < the.app.height then mirrorY = self.y + the.bg.height - the.app.height end if self.x ~= mirrorX then if not self.xMirror then --print('creating mirror: X='..mirrorX..' Y='..mirrorY) self.xMirror = Mirror:new{ of = self, image = self.image } the.mirrors:add(self.xMirror) end self.xMirror.x = mirrorX self.xMirror.y = self.y self.xMirror.rotation = self.rotation self.xMirror.scale = self.scale elseif self.xMirror then if self.type == 'bullet' then --print('pruning bullet') end the.mirrors:remove(self.xMirror) self.xMirror.of = nil -- break circular reference self.xMirror = nil -- die? end if self.y ~= mirrorY then if not self.yMirror then --print('creating mirror: X='..mirrorX..' Y='..mirrorY) self.yMirror = Mirror:new{ of = self, image = self.image } the.mirrors:add(self.yMirror) end self.yMirror.x = self.x self.yMirror.y = mirrorY self.yMirror.rotation = self.rotation self.yMirror.scale = self.scale elseif self.yMirror then if self.type == 'bullet' then --print('pruning bullet') end the.mirrors:remove(self.yMirror) self.yMirror.of = nil -- break circular reference self.yMirror = nil -- die? end if self.x ~= mirrorX and self.y ~= mirrorY then if not self.xyMirror then --print('creating mirror: X='..mirrorX..' Y='..mirrorY) self.xyMirror = Mirror:new{ of = self, image = self.image } the.mirrors:add(self.xyMirror) end self.xyMirror.x = mirrorX self.xyMirror.y = mirrorY self.xyMirror.rotation = self.rotation self.xyMirror.scale = self.scale elseif self.xyMirror then if self.type == 'bullet' then --print('pruning bullet') end the.mirrors:remove(self.xyMirror) self.xyMirror.of = nil -- break circular reference self.xyMirror = nil -- die? end end, onRemove = function(self) if self.xMirror then if self.type == 'bullet' then --print('removing bullet, so removing mirror') end the.mirrors:remove(self.xMirror) self.xMirror.of = nil -- break circular reference self.xMirror = nil end if self.yMirror then if self.type == 'bullet' then --print('removing bullet, so removing mirror') end the.mirrors:remove(self.yMirror) self.yMirror.of = nil -- break circular reference self.yMirror = nil end if self.xyMirror then if self.type == 'bullet' then --print('removing bullet, so removing mirror') end the.mirrors:remove(self.xyMirror) self.xyMirror.of = nil -- break circular reference self.xyMirror = nil end end, update = function (self, elapsed) Tile.update(self, elapsed) self:wrap() if self.active then self:reflect() end end }