Planet = Tile:extend { image = 'data/planet1.png', goods = {}, onNew = function (self) self.indicator = Tile:new{ image = 'data/planet1ind.png' } the.indicators:add(self.indicator) while not self.name do local name = PlanetNames[math.random(#PlanetNames)] local inUse = false for _, planet in ipairs(the.planets.sprites) do if name == planet.name then inUse = true end end if not inUse then self.name = name end end self.label = Text:new { text = self.name, x = self.x, y = self.y - 32, width = self.width, align = 'center', font = 20 } the.planetLabels:add(self.label) self.keyLabel = Text:new { text = 'Press L to land', x = self.x, y = self.y + self.height + 12, width = self.width, align = 'center', font = 20 } the.planetLabels:add(self.keyLabel) end, onUpdate = function (self) local hw = self.width / 2 local pvec = vector.new(the.player.x - (self.x + hw), the.player.y - (self.y + hw)) if pvec:len2() < hw ^ 2 then self.label.visible = true self.keyLabel.visible = true the.player.onPlanet = self if the.keys:justPressed('l') then the.player.velocity = {x=0, y=0} the.player.acceleration = {x=0, y=0} the.player:save() -- disengage all the enemies for _, enemy in pairs(the.enemies.sprites) do if enemy.state == 'combat' then enemy.state = 'patrolling' end end tradeView = TradeView:new{ planet = self } tradeView:activate() end else self.label.visible = false self.keyLabel.visible = false if the.player.onPlanet == self then the.player.onPlanet = false end end end, onEndFrame = function (self) local indx, indy local pvec = vector.new( self.x - the.player.x + self.width / 2, self.y - the.player.y + self.height / 2 ) -- TODO: is there a better way to specify the -- screen rectangle? if self:intersects(the.player.x - the.app.width / 2, the.player.y - the.app.height / 2, the.app.width, the.app.height) then -- planet is on the screen self.indicator.visible = false else self.indicator.visible = true if math.abs(pvec.x) / math.abs(pvec.y) > the.app.width / the.app.height then indx = (the.app.width / 2 - 10) * util.signOf(pvec.x) + 8 indy = (the.app.width / 2 - 10) * pvec.y / math.abs(pvec.x) else indy = (the.app.height / 2 - 10) * util.signOf(pvec.y) + 8 indx = (the.app.height / 2 - 10) * pvec.x / math.abs(pvec.y) end self.indicator.x = the.player.x + indx self.indicator.y = the.player.y + indy end end, onCollide = function (self, other) if other:instanceOf(Bullet) then the.bullets:remove(other) other:die() end end }