/traderous

To get this branch, use:
bzr branch http://9ix.org/bzr/traderous
8 by Josh C
targeting cursor (manual switch to start)
1
Cursor = Tile:extend {
2
   image = 'data/cursor.png',
14 by Josh C
only fire if cursor is in target area. change cursor to reflect this.
3
   inTargetArea = function(self)
4
                     -- TODO: memoize this per-tick
5
17 by Josh C
dead zone with no acceleration
6
                     local mouseAngle = math.atan2(self.vector.y, self.vector.x)
14 by Josh C
only fire if cursor is in target area. change cursor to reflect this.
7
                     local mouseVsShipAbs = math.abs(the.player.rotation - mouseAngle)
8
                     local mouseVsShip = math.min(2*math.pi - mouseVsShipAbs,
9
                                                  mouseVsShipAbs)
10
11
                     return mouseVsShip < 0.75
12
                  end,
17 by Josh C
dead zone with no acceleration
13
   onStartFrame = function(self)
14
                     self.vector = vector.new(
15
                        love.mouse.getX() - the.app.width/2,
16
                        love.mouse.getY() - the.app.height/2
17
                     )
18
                  end,
8 by Josh C
targeting cursor (manual switch to start)
19
   onUpdate = function(self)
17 by Josh C
dead zone with no acceleration
20
                 if self.vector:len2() > 64^2 then
8 by Josh C
targeting cursor (manual switch to start)
21
                    self.image = 'data/cursor-target.png'
14 by Josh C
only fire if cursor is in target area. change cursor to reflect this.
22
                 else
8 by Josh C
targeting cursor (manual switch to start)
23
                    self.image = 'data/cursor.png'
24
                 end
17 by Josh C
dead zone with no acceleration
25
26
                 -- if self:inTargetArea() then
27
                 --    self.image = 'data/cursor-target.png'
28
                 -- else
29
                 --    self.image = 'data/cursor.png'
30
                 -- end
8 by Josh C
targeting cursor (manual switch to start)
31
              end,
32
   onEndFrame = function(self)
12 by Josh C
fullscreen. (there must be a more subtle way...)
33
                   self.x = love.mouse.getX() + 8 + the.player.x - the.app.width / 2
34
                   self.y = love.mouse.getY() + 8 + the.player.y - the.app.height / 2
8 by Josh C
targeting cursor (manual switch to start)
35
                end
36
}