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='..xMirrorX..' Y='..xMirrorY) self.xMirror = Tile:new{ image = self.image } the.app.view:add(self.xMirror) end self.xMirror.x = mirrorX self.xMirror.y = self.y self.xMirror.rotation = self.rotation elseif self.xMirror then the.app.view:remove(self.xMirror) self.xMirror = nil -- die? end if self.y ~= mirrorY then if not self.yMirror then --print('creating mirror: X='..yMirrorX..' Y='..yMirrorY) self.yMirror = Tile:new{ image = self.image } the.app.view:add(self.yMirror) end self.yMirror.x = self.x self.yMirror.y = mirrorY self.yMirror.rotation = self.rotation elseif self.yMirror then the.app.view:remove(self.yMirror) self.yMirror = nil -- die? end if self.x ~= mirrorX and self.y ~= mirrorY then if not self.xyMirror then --print('creating mirror: X='..xyMirrorX..' Y='..xyMirrorY) self.xyMirror = Tile:new{ image = self.image } the.app.view:add(self.xyMirror) end self.xyMirror.x = mirrorX self.xyMirror.y = mirrorY self.xyMirror.rotation = self.rotation elseif self.xyMirror then the.app.view:remove(self.xyMirror) self.xyMirror = nil -- die? end end, onRemove = function(self) if self.xMirror then the.app.view:remove(self.xMirror) end if self.yMirror then the.app.view:remove(self.yMirror) end if self.xyMirror then the.app.view:remove(self.xyMirror) end end, update = function (self, elapsed) Tile.update(self, elapsed) self:wrap() self:reflect() -- TODO: make sure mirrors are cleaned up when we are -- killed / removed from view end }