/traderous

To get this branch, use:
bzr branch /bzr/traderous
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
Cursor = Tile:extend {
   image = 'data/cursor.png',
   inTargetArea = function(self)
                     -- TODO: memoize this per-tick

                     local mouseAngle = math.atan2(self.vector.y, self.vector.x)
                     local mouseVsShipAbs = math.abs(the.player.rotation - mouseAngle)
                     local mouseVsShip = math.min(2*math.pi - mouseVsShipAbs,
                                                  mouseVsShipAbs)

                     return mouseVsShip < 0.75
                  end,
   onStartFrame = function(self)
                     self.vector = vector.new(
                        love.mouse.getX() - the.app.width/2,
                        love.mouse.getY() - the.app.height/2
                     )
                  end,
   onUpdate = function(self)
                 if self.vector:len2() > 64^2 then
                    self.image = 'data/cursor-target.png'
                 else
                    self.image = 'data/cursor.png'
                 end

                 -- if self:inTargetArea() then
                 --    self.image = 'data/cursor-target.png'
                 -- else
                 --    self.image = 'data/cursor.png'
                 -- end
              end,
   onEndFrame = function(self)
                   self.x = love.mouse.getX() + 8 + the.player.x - the.app.width / 2
                   self.y = love.mouse.getY() + 8 + the.player.y - the.app.height / 2
                end
}