Rock = WrapTile:extend { image = 'data/rock.png', onNew = function(self) --self.velocity = util.shortestVector(self, the.player):normalized() * 10 --self.scale = 1 self.collider = RockCollider:new{ --x = self.x, --y = self.y, width = self.width * self.scale, height = self.height * self.scale, rock = self } the.rockColliders:add(self.collider) end, onUpdate = function(self, dt) self.collider.x = self.x + self.width / 2 * (1 - self.scale) self.collider.y = self.y + self.height / 2 * (1 - self.scale) --self.collider.rotation = self.rotation -- ??? end, onEndFrame = function(self) -- onEndFrame to give a chance to go out of bounds then wrap if DEBUG and the.console.visible then if not self.text then self.text = Text:new() the.view:add(self.text) end local pVec = util.shortestVector(self, the.player) self.text.text = pVec.x .. ', ' .. pVec.y self.text.x, self.text.y = self.x, self.y self.text.visible = true else if self.text then self.text.visible = false end end end } RockCollider = Fill:extend { fill = {0,0,255}, onUpdate = function(self, dt) self.visible = DEBUG and the.console.visible end, onCollide = function(self, other) if other:instanceOf(Bullet) then local b = Boom:new { x = self.x, y = self.y, velocity = { rotation = util.signOf(self.rock.rotation) * 5 } } the.app.view:add(b) the.rocks:remove(self.rock) the.rockColliders:remove(self) self.rock = nil -- break circular reference the.bullets:remove(other) other:die() end end }