/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-13 21:25:26 UTC
  • Revision ID: josh@9ix.org-20130513212526-3q6md6n9xzhcmoa6
and that fixes the corner bug

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
Rock = WrapTile:extend {
2
 
   image = 'data/rock.png',
3
 
   onNew = function(self)
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)
18
 
           end,
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)
25
 
                   -- onEndFrame to give a chance to go out of bounds then wrap
26
 
 
27
 
                   if DEBUG and the.console.visible then
28
 
                      if not self.text then
29
 
                         self.text = Text:new()
30
 
                         the.view:add(self.text)
31
 
                      end
32
 
 
33
 
                      local pVec = util.shortestVector(self, the.player)
34
 
                      self.text.text = pVec.x .. ', ' .. pVec.y
35
 
                      self.text.x, self.text.y = self.x, self.y
36
 
                      self.text.visible = true
37
 
                   else
38
 
                      if self.text then
39
 
                         self.text.visible = false
40
 
                      end
41
 
                   end
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
61
 
}
 
 
b'\\ No newline at end of file'