/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-05-04 20:45:30 UTC
  • Revision ID: josh@9ix.org-20130504204530-aphxyyyo2c8rir4r
build system

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
local accelLimit = 150
2
 
local velLimit = 200
3
 
Enemy = Tile:extend {
4
 
   image = 'data/enemy.png',
5
 
   maxVelocity = {x=velLimit,y=velLimit},
6
 
   minVelocity = {x=-velLimit, y=-velLimit},
7
 
   lastFired = 0,
8
 
   onNew = function (self)
9
 
              self.thrust = Tile:new{image = 'data/thrust.png'}
10
 
           end,
11
 
   onStartFrame = function (self)
12
 
 
13
 
                     local pvec = vector.new(the.player.x - self.x,
14
 
                                             the.player.y - self.y)
15
 
 
16
 
                     self.rotation = math.atan2(pvec.y, pvec.x)
17
 
 
18
 
                     local pdist2 = pvec:len2()
19
 
 
20
 
                     if pdist2 > 400^2 then -- ... if player dist > 64?
21
 
                        self.acceleration = vector.new(300, 0)
22
 
                        self.acceleration:rotate_inplace(self.rotation)
23
 
                        self.thrust.visible = true
24
 
                     else
25
 
                        self.acceleration = {x=0, y=0}
26
 
                        self.thrust.visible = false
27
 
                     end
28
 
 
29
 
                     if pdist2 < 400^2 and
30
 
                       love.timer.getTime() - self.lastFired > 0.25 then
31
 
                       --print('pew')
32
 
                         b = Bullet:new{
33
 
                            x = self.x + self.width / 2,
34
 
                            y = self.y + self.height / 2,
35
 
                            rotation = self.rotation
36
 
                         }
37
 
                         self.lastFired = love.timer.getTime()
38
 
                     end
39
 
 
40
 
                  end,
41
 
   onUpdate = function(self)
42
 
                 self.thrust.x = self.x - self.width
43
 
                 self.thrust.y = self.y
44
 
                 self.thrust.rotation = self.rotation
45
 
              end,
46
 
 
47
 
}
 
 
b'\\ No newline at end of file'