/traderous

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

« back to all changes in this revision

Viewing changes to enemy.lua

  • Committer: Josh C
  • Date: 2013-06-16 20:20:20 UTC
  • Revision ID: josh@9ix.org-20130616202020-dcra09dhl5bdx8lc
rotate enemy ship slower

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
   lastFired = 0,
9
9
   onNew = function (self)
10
10
              self.thrust = Tile:new{image = 'data/thrust.png'}
 
11
              --the.app.view:add(self.thrust)
11
12
           end,
12
13
   onStartFrame = function (self)
13
14
 
14
15
                     local pvec = vector.new(the.player.x - self.x,
15
16
                                             the.player.y - self.y)
16
17
 
17
 
                     self.rotation = math.atan2(pvec.y, pvec.x)
 
18
 
 
19
                     local pAngle = math.atan2(pvec.y, pvec.x)
 
20
                     local aDiff = self.rotation - pAngle
 
21
 
 
22
                     while aDiff < (-math.pi) do
 
23
                        --print(aDiff .. ' < -π')
 
24
                        aDiff = aDiff + 2 * math.pi
 
25
                     end
 
26
                     while aDiff > math.pi do
 
27
                        --print(aDiff .. ' > π')
 
28
                        aDiff = aDiff - 2 * math.pi
 
29
                     end
 
30
 
 
31
                     if math.abs(aDiff) > 0.1 then
 
32
                        -- rotation really shouldn't be negative.  I
 
33
                        -- don't understand why that is.  :\
 
34
                        self.velocity.rotation = -2 * util.signOf(aDiff)
 
35
                     else
 
36
                        --print('not rotating')
 
37
                        self.velocity.rotation = 0
 
38
                     end
18
39
 
19
40
                     local pdist2 = pvec:len2()
20
41
 
27
48
                        self.thrust.visible = false
28
49
                     end
29
50
 
30
 
                     if pdist2 < 400^2 and
 
51
                     if math.abs(aDiff) < 0.5 * math.pi and
 
52
                       pdist2 < 400^2 and
31
53
                       love.timer.getTime() - self.lastFired > 0.25 then
32
54
                       --print('pew')
33
55
                         b = Bullet:new{