/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:44:47 UTC
  • Revision ID: josh@9ix.org-20130619014447-mtpps0g4w7aeckpg
enemy "patrol path" (pick random destination)

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',
9
10
   onNew = function (self)
10
11
              self.thrust = Tile:new{image = 'data/thrust.png'}
11
12
              --the.app.view:add(self.thrust)
 
13
              self.shield = Shield:new{ship = self}
 
14
 
 
15
              self:chooseTarget()
12
16
           end,
13
17
   onStartFrame = function (self)
14
18
 
15
 
                     local pvec = vector.new(the.player.x - self.x,
16
 
                                             the.player.y - self.y)
 
19
                     local pvec = vector.new(self.target.x - self.x,
 
20
                                             self.target.y - self.y)
17
21
 
18
22
 
19
23
                     local pAngle = math.atan2(pvec.y, pvec.x)
48
52
                        self.thrust.visible = false
49
53
                     end
50
54
 
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()
 
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
61
71
                     end
62
72
 
63
73
                  end,
66
76
                 self.thrust.y = self.y
67
77
                 self.thrust.rotation = self.rotation
68
78
              end,
69
 
 
 
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
70
109
}
 
 
b'\\ No newline at end of file'