/spacey

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

« back to all changes in this revision

Viewing changes to rock.lua

  • Committer: Josh C
  • Date: 2013-05-14 17:13:43 UTC
  • Revision ID: josh@9ix.org-20130514171343-s251e971hc92mzb0
shoot things!

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
   image = 'data/rock.png',
3
3
   onNew = function(self)
4
4
              --self.velocity = util.shortestVector(self, the.player):normalized() * 10
 
5
 
 
6
              --self.scale = 1
 
7
 
 
8
              self.collider = RockCollider:new{
 
9
                 --x = self.x,
 
10
                 --y = self.y,
 
11
                 width = self.width * self.scale,
 
12
                 height = self.height * self.scale,
 
13
                 rock = self
 
14
              }
 
15
 
 
16
              the.app.view:add(self.collider)
 
17
              the.rockColliders:add(self.collider)
5
18
           end,
6
 
   onEndFrame = function(self, dt)
 
19
   onUpdate = function(self, dt)
 
20
                 self.collider.x = self.x + self.width / 2 * (1 - self.scale)
 
21
                 self.collider.y = self.y + self.height / 2 * (1 - self.scale)
 
22
                 --self.collider.rotation = self.rotation -- ???
 
23
              end,
 
24
   onEndFrame = function(self)
7
25
                   -- onEndFrame to give a chance to go out of bounds then wrap
8
26
 
9
27
                   if DEBUG and the.console.visible then
11
29
                         self.text = Text:new()
12
30
                         the.view:add(self.text)
13
31
                      end
14
 
                      
 
32
 
15
33
                      local pVec = util.shortestVector(self, the.player)
16
34
                      self.text.text = pVec.x .. ', ' .. pVec.y
17
35
                      self.text.x, self.text.y = self.x, self.y
22
40
                      end
23
41
                   end
24
42
                end
 
43
}
 
44
 
 
45
RockCollider = Fill:extend {
 
46
   fill = {0,0,255},
 
47
   onUpdate = function(self, dt)
 
48
                 self.visible = DEBUG and the.console.visible
 
49
              end,
 
50
   onCollide = function(self, other)
 
51
                  if other:instanceOf(Bullet) then
 
52
                     the.app.view:remove(self.rock)
 
53
                     the.app.view:remove(self)
 
54
                     the.rockColliders:remove(self)
 
55
                     self.rock = nil -- break circular reference
 
56
 
 
57
                     the.app.view:remove(other)
 
58
                     the.bullets:remove(other)
 
59
                  end
 
60
               end
25
61
}
 
 
b'\\ No newline at end of file'