/traderous

To get this branch, use:
bzr branch http://9ix.org/bzr/traderous

« back to all changes in this revision

Viewing changes to rock.lua

  • Committer: Josh C
  • Date: 2013-05-14 16:39:54 UTC
  • Revision ID: josh@9ix.org-20130514163954-tpi9djio3pm6vswf
prepare a collision box for the rocks

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 
6
6
              --self.scale = 1
7
7
 
8
 
              self.collider = RockCollider:new{
 
8
              self.collider = Fill:new{
 
9
                 fill = {0,0,255},
9
10
                 --x = self.x,
10
11
                 --y = self.y,
11
12
                 width = self.width * self.scale,
12
13
                 height = self.height * self.scale,
 
14
                 visible = false,
13
15
                 rock = self
14
16
              }
15
17
 
16
 
              the.rockColliders:add(self.collider)
 
18
              the.app.view:add(self.collider)
 
19
              table.insert(the.rockColliders, self.collider)
17
20
           end,
18
21
   onUpdate = function(self, dt)
19
22
                 self.collider.x = self.x + self.width / 2 * (1 - self.scale)
40
43
                   end
41
44
                end
42
45
}
43
 
 
44
 
RockCollider = Fill:extend {
45
 
   fill = {0,0,255},
46
 
   onUpdate = function(self, dt)
47
 
                 self.visible = DEBUG and the.console.visible
48
 
              end,
49
 
   onCollide = function(self, other)
50
 
                  if other:instanceOf(Bullet) then
51
 
                     local b = Boom:new {
52
 
                        x = self.x,
53
 
                        y = self.y,
54
 
                        velocity = {
55
 
                           rotation = util.signOf(self.rock.rotation) * 5
56
 
                        }
57
 
                     }
58
 
                     the.app.view:add(b)
59
 
 
60
 
                     the.rocks:remove(self.rock)
61
 
                     the.rockColliders:remove(self)
62
 
                     self.rock = nil -- break circular reference
63
 
 
64
 
                     the.bullets:remove(other)
65
 
                     other:die()
66
 
                  end
67
 
               end
68
 
}
 
 
b'\\ No newline at end of file'