/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 04:21:01 UTC
  • Revision ID: josh@9ix.org-20130616042101-tp1rddbd3subc8lg
enemy is back

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)
12
11
           end,
13
12
   onStartFrame = function (self)
14
13
 
15
14
                     local pvec = vector.new(the.player.x - self.x,
16
15
                                             the.player.y - self.y)
17
16
 
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
 
17
                     self.rotation = math.atan2(pvec.y, pvec.x)
39
18
 
40
19
                     local pdist2 = pvec:len2()
41
20
 
48
27
                        self.thrust.visible = false
49
28
                     end
50
29
 
51
 
                     if math.abs(aDiff) < 0.5 * math.pi and
52
 
                       pdist2 < 400^2 and
 
30
                     if pdist2 < 400^2 and
53
31
                       love.timer.getTime() - self.lastFired > 0.25 then
54
32
                       --print('pew')
55
33
                         b = Bullet:new{