/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-19 01:06:14 UTC
  • Revision ID: josh@9ix.org-20130619010614-j3rbcv1c0my2tw0f
enemy shields and death

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
   maxVelocity = {x=velLimit,y=velLimit},
7
7
   minVelocity = {x=-velLimit, y=-velLimit},
8
8
   lastFired = 0,
9
 
   state = 'patrolling',
10
9
   onNew = function (self)
11
10
              self.thrust = Tile:new{image = 'data/thrust.png'}
12
11
              --the.app.view:add(self.thrust)
13
12
              self.shield = Shield:new{ship = self}
14
 
 
15
 
              self:chooseTarget()
16
13
           end,
17
14
   onStartFrame = function (self)
18
15
 
19
 
                     local pvec = vector.new(self.target.x - self.x,
20
 
                                             self.target.y - self.y)
 
16
                     local pvec = vector.new(the.player.x - self.x,
 
17
                                             the.player.y - self.y)
21
18
 
22
19
 
23
20
                     local pAngle = math.atan2(pvec.y, pvec.x)
52
49
                        self.thrust.visible = false
53
50
                     end
54
51
 
55
 
                     if pdist2 < 400^2 then
56
 
                        if self.state == 'patrolling' then
57
 
                           self:chooseTarget()
58
 
                        elseif self.state == 'combat' then
59
 
                           if math.abs(aDiff) < 0.5 * math.pi and
60
 
                             love.timer.getTime() - self.lastFired > 0.25 then
61
 
                             --print('pew')
62
 
                               b = Bullet:new{
63
 
                                  x = self.x + self.width / 2,
64
 
                                  y = self.y + self.height / 2,
65
 
                                  rotation = self.rotation,
66
 
                                  source = self
67
 
                               }
68
 
                               self.lastFired = love.timer.getTime()
69
 
                            end
70
 
                        end
 
52
                     if math.abs(aDiff) < 0.5 * math.pi and
 
53
                       pdist2 < 400^2 and
 
54
                       love.timer.getTime() - self.lastFired > 0.25 then
 
55
                       --print('pew')
 
56
                         b = Bullet:new{
 
57
                            x = self.x + self.width / 2,
 
58
                            y = self.y + self.height / 2,
 
59
                            rotation = self.rotation,
 
60
                            source = self
 
61
                         }
 
62
                         self.lastFired = love.timer.getTime()
71
63
                     end
72
64
 
73
65
                  end,
99
91
                     other:die()
100
92
                     the.bullets:remove(other)
101
93
                  end
102
 
               end,
103
 
   chooseTarget = function (self)
104
 
                     self.target = {
105
 
                        x = math.random(the.bg.width),
106
 
                        y = math.random(the.bg.height)
107
 
                     }
108
 
                  end
 
94
               end
109
95
}
 
 
b'\\ No newline at end of file'