/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
 
              self.shield = Shield:new{ship = self}
13
11
           end,
14
12
   onStartFrame = function (self)
15
13
 
16
14
                     local pvec = vector.new(the.player.x - self.x,
17
15
                                             the.player.y - self.y)
18
16
 
19
 
 
20
 
                     local pAngle = math.atan2(pvec.y, pvec.x)
21
 
                     local aDiff = self.rotation - pAngle
22
 
 
23
 
                     while aDiff < (-math.pi) do
24
 
                        --print(aDiff .. ' < -π')
25
 
                        aDiff = aDiff + 2 * math.pi
26
 
                     end
27
 
                     while aDiff > math.pi do
28
 
                        --print(aDiff .. ' > π')
29
 
                        aDiff = aDiff - 2 * math.pi
30
 
                     end
31
 
 
32
 
                     if math.abs(aDiff) > 0.1 then
33
 
                        -- rotation really shouldn't be negative.  I
34
 
                        -- don't understand why that is.  :\
35
 
                        self.velocity.rotation = -2 * util.signOf(aDiff)
36
 
                     else
37
 
                        --print('not rotating')
38
 
                        self.velocity.rotation = 0
39
 
                     end
 
17
                     self.rotation = math.atan2(pvec.y, pvec.x)
40
18
 
41
19
                     local pdist2 = pvec:len2()
42
20
 
49
27
                        self.thrust.visible = false
50
28
                     end
51
29
 
52
 
                     if math.abs(aDiff) < 0.5 * math.pi and
53
 
                       pdist2 < 400^2 and
 
30
                     if pdist2 < 400^2 and
54
31
                       love.timer.getTime() - self.lastFired > 0.25 then
55
32
                       --print('pew')
56
33
                         b = Bullet:new{
57
34
                            x = self.x + self.width / 2,
58
35
                            y = self.y + self.height / 2,
59
 
                            rotation = self.rotation,
60
 
                            source = self
 
36
                            rotation = self.rotation
61
37
                         }
62
38
                         self.lastFired = love.timer.getTime()
63
39
                     end
68
44
                 self.thrust.y = self.y
69
45
                 self.thrust.rotation = self.rotation
70
46
              end,
71
 
   onCollide = function (self, other)
72
 
                  if other:instanceOf(Bullet) and other.source ~= self then
73
 
                     if self.shield.strength == 0 then
74
 
                        -- die
75
 
                        the.app.view:add( Boom:new {
76
 
                                             x = self.x,
77
 
                                             y = self.y,
78
 
                                             velocity = { rotation = 5 }
79
 
                                          })
80
 
 
81
 
                        self:die()
82
 
                        self.thrust:die()
83
 
                        self.shield:die()
84
 
                        the.enemies:remove(self)
85
 
                        the.app.view:remove(self.thrust)
86
 
                        the.app.view:remove(self.shield)
87
 
                     else
88
 
                        self.shield:onHit()
89
 
                     end
90
 
 
91
 
                     other:die()
92
 
                     the.bullets:remove(other)
93
 
                  end
94
 
               end
 
47
 
95
48
}
 
 
b'\\ No newline at end of file'