/traderous

To get this branch, use:
bzr branch http://9ix.org/bzr/traderous

« back to all changes in this revision

Viewing changes to cursor.lua

  • Committer: Josh C
  • Date: 2013-10-21 18:31:36 UTC
  • Revision ID: josh@9ix.org-20131021183136-l3vwmptork5es02v
factor out doHit so I can try to reproduce double ships

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
Cursor = Tile:extend {
2
2
   image = 'data/cursor.png',
 
3
   inTargetArea = function(self)
 
4
                     -- TODO: memoize this per-tick
 
5
 
 
6
                     local mouseAngle = math.atan2(self.vector.y, self.vector.x)
 
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,
 
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,
3
19
   onUpdate = function(self)
4
 
                 if the.keys:justPressed('t') then
 
20
                 if self.vector:len2() > 64^2 then
5
21
                    self.image = 'data/cursor-target.png'
6
 
                 end
7
 
                 if the.keys:justPressed('c') then
 
22
                 else
8
23
                    self.image = 'data/cursor.png'
9
24
                 end
10
25
 
 
26
                 -- if self:inTargetArea() then
 
27
                 --    self.image = 'data/cursor-target.png'
 
28
                 -- else
 
29
                 --    self.image = 'data/cursor.png'
 
30
                 -- end
11
31
              end,
12
32
   onEndFrame = function(self)
13
33
                   self.x = love.mouse.getX() + 8 + the.player.x - the.app.width / 2