/traderous

To get this branch, use:
bzr branch /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

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)
12
13
              self.shield = Shield:new{ship = self}
 
14
 
 
15
              self:chooseTarget()
13
16
           end,
14
17
   onStartFrame = function (self)
15
18
 
16
 
                     local pvec = vector.new(the.player.x - self.x,
17
 
                                             the.player.y - self.y)
 
19
                     local pvec = vector.new(self.target.x - self.x,
 
20
                                             self.target.y - self.y)
18
21
 
19
22
 
20
23
                     local pAngle = math.atan2(pvec.y, pvec.x)
49
52
                        self.thrust.visible = false
50
53
                     end
51
54
 
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()
 
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
63
71
                     end
64
72
 
65
73
                  end,
91
99
                     other:die()
92
100
                     the.bullets:remove(other)
93
101
                  end
94
 
               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
95
109
}
 
 
'\\ No newline at end of file'