/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 00:50:23 UTC
  • Revision ID: josh@9ix.org-20130619005023-necyd2i8kgqbp1s9
shield

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
 
              self.shield = Shield:new{ship = self}
14
 
 
15
 
              self:chooseTarget()
16
12
           end,
17
13
   onStartFrame = function (self)
18
14
 
19
 
                     local pvec = vector.new(self.target.x - self.x,
20
 
                                             self.target.y - self.y)
 
15
                     local pvec = vector.new(the.player.x - self.x,
 
16
                                             the.player.y - self.y)
21
17
 
22
18
 
23
19
                     local pAngle = math.atan2(pvec.y, pvec.x)
52
48
                        self.thrust.visible = false
53
49
                     end
54
50
 
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
 
51
                     if math.abs(aDiff) < 0.5 * math.pi and
 
52
                       pdist2 < 400^2 and
 
53
                       love.timer.getTime() - self.lastFired > 0.25 then
 
54
                       --print('pew')
 
55
                         b = Bullet:new{
 
56
                            x = self.x + self.width / 2,
 
57
                            y = self.y + self.height / 2,
 
58
                            rotation = self.rotation
 
59
                         }
 
60
                         self.lastFired = love.timer.getTime()
71
61
                     end
72
62
 
73
63
                  end,
76
66
                 self.thrust.y = self.y
77
67
                 self.thrust.rotation = self.rotation
78
68
              end,
79
 
   onCollide = function (self, other)
80
 
                  if other:instanceOf(Bullet) and other.source ~= self then
81
 
                     if self.shield.strength == 0 then
82
 
                        -- die
83
 
                        the.app.view:add( Boom:new {
84
 
                                             x = self.x,
85
 
                                             y = self.y,
86
 
                                             velocity = { rotation = 5 }
87
 
                                          })
88
 
 
89
 
                        self:die()
90
 
                        self.thrust:die()
91
 
                        self.shield:die()
92
 
                        the.enemies:remove(self)
93
 
                        the.app.view:remove(self.thrust)
94
 
                        the.app.view:remove(self.shield)
95
 
                     else
96
 
                        self.shield:onHit()
97
 
                     end
98
 
 
99
 
                     other:die()
100
 
                     the.bullets:remove(other)
101
 
                  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
 
69
 
109
70
}
 
 
b'\\ No newline at end of file'